diff --git a/MetadataCrypt.cpp b/MetadataCrypt.cpp index fb8ed22..088960e 100644 --- a/MetadataCrypt.cpp +++ b/MetadataCrypt.cpp @@ -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(0, nr_sec, is_legacy ? "AES-256-XTS" : "aes-xts-plain64", - hex_key, data_rec->blk_device, 0, is_legacy, set_dun); + table.Emplace(0, nr_sec, cipher, hex_key, data_rec->blk_device, 0, + is_legacy, set_dun); auto& dm = DeviceMapper::Instance(); for (int i = 0;; i++) {