Set metadata cipher in fstab
Bug: 147814592 Test: Cuttlefish can use adiantum Change-Id: I6805ae4acff4dd1ff7cecff9153dbf29e0274165
This commit is contained in:
parent
92a14b6b16
commit
84e84c5f33
1 changed files with 21 additions and 2 deletions
|
@ -153,6 +153,22 @@ static bool get_number_of_sectors(const std::string& real_blkdev, uint64_t* nr_s
|
|||
return true;
|
||||
}
|
||||
|
||||
static std::string lookup_cipher(const std::string& cipher_name, bool is_legacy) {
|
||||
if (is_legacy) {
|
||||
if (cipher_name.empty() || cipher_name == "aes-256-xts") {
|
||||
return "AES-256-XTS";
|
||||
}
|
||||
} else {
|
||||
if (cipher_name.empty() || cipher_name == "aes-256-xts") {
|
||||
return "aes-xts-plain64";
|
||||
} else if (cipher_name == "adiantum") {
|
||||
return "xchacha12,aes-adiantum-plain64";
|
||||
}
|
||||
}
|
||||
LOG(ERROR) << "No metadata cipher named " << cipher_name << " found, is_legacy=" << is_legacy;
|
||||
return "";
|
||||
}
|
||||
|
||||
static bool create_crypto_blk_dev(const std::string& dm_name, const FstabEntry* data_rec,
|
||||
const KeyBuffer& key, std::string* crypto_blkdev) {
|
||||
uint64_t nr_sec;
|
||||
|
@ -161,6 +177,9 @@ static bool create_crypto_blk_dev(const std::string& dm_name, const FstabEntry*
|
|||
bool is_legacy;
|
||||
if (!DmTargetDefaultKey::IsLegacy(&is_legacy)) return false;
|
||||
|
||||
auto cipher = lookup_cipher(data_rec->metadata_cipher, is_legacy);
|
||||
if (cipher.empty()) return false;
|
||||
|
||||
KeyBuffer hex_key_buffer;
|
||||
if (android::vold::StrToHex(key, hex_key_buffer) != android::OK) {
|
||||
LOG(ERROR) << "Failed to turn key to hex";
|
||||
|
@ -176,8 +195,8 @@ static bool create_crypto_blk_dev(const std::string& dm_name, const FstabEntry*
|
|||
}
|
||||
|
||||
DmTable table;
|
||||
table.Emplace<DmTargetDefaultKey>(0, nr_sec, is_legacy ? "AES-256-XTS" : "aes-xts-plain64",
|
||||
hex_key, data_rec->blk_device, 0, is_legacy, set_dun);
|
||||
table.Emplace<DmTargetDefaultKey>(0, nr_sec, cipher, hex_key, data_rec->blk_device, 0,
|
||||
is_legacy, set_dun);
|
||||
|
||||
auto& dm = DeviceMapper::Instance();
|
||||
for (int i = 0;; i++) {
|
||||
|
|
Loading…
Reference in a new issue