Set metadata cipher in fstab
Bug: 147814592
Test: Cuttlefish can use adiantum
Change-Id: I6805ae4acff4dd1ff7cecff9153dbf29e0274165
diff --git a/MetadataCrypt.cpp b/MetadataCrypt.cpp
index fb8ed22..088960e 100644
--- a/MetadataCrypt.cpp
+++ b/MetadataCrypt.cpp
@@ -153,6 +153,22 @@
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 @@
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 @@
}
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++) {