Refactor key generation to handle both normal and metadata encryption.
Bug: 147733587
Test: Treehugger
Change-Id: Iee176037dec2621c84da325c2627f988fcebbc8d
Merged-In: Iee176037dec2621c84da325c2627f988fcebbc8d
diff --git a/model/Disk.cpp b/model/Disk.cpp
index bfaf2cd..f92435d 100644
--- a/model/Disk.cpp
+++ b/model/Disk.cpp
@@ -16,6 +16,7 @@
#include "Disk.h"
#include "FsCrypt.h"
+#include "KeyUtil.h"
#include "PrivateVolume.h"
#include "PublicVolume.h"
#include "Utils.h"
@@ -505,11 +506,12 @@
return -EIO;
}
- std::string keyRaw;
- if (ReadRandomBytes(cryptfs_get_keysize(), keyRaw) != OK) {
+ KeyBuffer key;
+ if (!generateStorageKey(cryptfs_get_keygen(), &key)) {
LOG(ERROR) << "Failed to generate key";
return -EIO;
}
+ std::string keyRaw(key.begin(), key.end());
std::string partGuid;
StrToHex(partGuidRaw, partGuid);