Merge "Clean up providing key via old API" am: 180b1a7f89
am: fe823efdae
Change-Id: Ic130119f9887dcb0d8459770aed2253bcbf909c1
This commit is contained in:
commit
270e041a14
1 changed files with 8 additions and 10 deletions
18
KeyUtil.cpp
18
KeyUtil.cpp
|
@ -35,10 +35,8 @@
|
|||
namespace android {
|
||||
namespace vold {
|
||||
|
||||
constexpr int FS_AES_256_XTS_KEY_SIZE = 64;
|
||||
|
||||
bool randomKey(KeyBuffer* key) {
|
||||
*key = KeyBuffer(FS_AES_256_XTS_KEY_SIZE);
|
||||
*key = KeyBuffer(FSCRYPT_MAX_KEY_SIZE);
|
||||
if (ReadRandomBytes(key->size(), key->data()) != 0) {
|
||||
// TODO status_t plays badly with PLOG, fix it.
|
||||
LOG(ERROR) << "Random read failed";
|
||||
|
@ -97,20 +95,20 @@ static std::string generateKeyRef(const uint8_t* key, int length) {
|
|||
unsigned char key_ref2[SHA512_DIGEST_LENGTH];
|
||||
SHA512_Final(key_ref2, &c);
|
||||
|
||||
static_assert(FS_KEY_DESCRIPTOR_SIZE <= SHA512_DIGEST_LENGTH, "Hash too short for descriptor");
|
||||
return std::string((char*)key_ref2, FS_KEY_DESCRIPTOR_SIZE);
|
||||
static_assert(FSCRYPT_KEY_DESCRIPTOR_SIZE <= SHA512_DIGEST_LENGTH,
|
||||
"Hash too short for descriptor");
|
||||
return std::string((char*)key_ref2, FSCRYPT_KEY_DESCRIPTOR_SIZE);
|
||||
}
|
||||
|
||||
static bool fillKey(const KeyBuffer& key, fscrypt_key* fs_key) {
|
||||
if (key.size() != FS_AES_256_XTS_KEY_SIZE) {
|
||||
if (key.size() != FSCRYPT_MAX_KEY_SIZE) {
|
||||
LOG(ERROR) << "Wrong size key " << key.size();
|
||||
return false;
|
||||
}
|
||||
static_assert(FS_AES_256_XTS_KEY_SIZE <= sizeof(fs_key->raw), "Key too long!");
|
||||
fs_key->mode = FS_ENCRYPTION_MODE_AES_256_XTS;
|
||||
fs_key->size = key.size();
|
||||
memset(fs_key->raw, 0, sizeof(fs_key->raw));
|
||||
static_assert(FSCRYPT_MAX_KEY_SIZE == sizeof(fs_key->raw), "Mismatch of max key sizes");
|
||||
fs_key->mode = 0; // unused by kernel
|
||||
memcpy(fs_key->raw, key.data(), key.size());
|
||||
fs_key->size = key.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue