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 android {
|
||||||
namespace vold {
|
namespace vold {
|
||||||
|
|
||||||
constexpr int FS_AES_256_XTS_KEY_SIZE = 64;
|
|
||||||
|
|
||||||
bool randomKey(KeyBuffer* key) {
|
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) {
|
if (ReadRandomBytes(key->size(), key->data()) != 0) {
|
||||||
// TODO status_t plays badly with PLOG, fix it.
|
// TODO status_t plays badly with PLOG, fix it.
|
||||||
LOG(ERROR) << "Random read failed";
|
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];
|
unsigned char key_ref2[SHA512_DIGEST_LENGTH];
|
||||||
SHA512_Final(key_ref2, &c);
|
SHA512_Final(key_ref2, &c);
|
||||||
|
|
||||||
static_assert(FS_KEY_DESCRIPTOR_SIZE <= SHA512_DIGEST_LENGTH, "Hash too short for descriptor");
|
static_assert(FSCRYPT_KEY_DESCRIPTOR_SIZE <= SHA512_DIGEST_LENGTH,
|
||||||
return std::string((char*)key_ref2, FS_KEY_DESCRIPTOR_SIZE);
|
"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) {
|
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();
|
LOG(ERROR) << "Wrong size key " << key.size();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static_assert(FS_AES_256_XTS_KEY_SIZE <= sizeof(fs_key->raw), "Key too long!");
|
static_assert(FSCRYPT_MAX_KEY_SIZE == sizeof(fs_key->raw), "Mismatch of max key sizes");
|
||||||
fs_key->mode = FS_ENCRYPTION_MODE_AES_256_XTS;
|
fs_key->mode = 0; // unused by kernel
|
||||||
fs_key->size = key.size();
|
|
||||||
memset(fs_key->raw, 0, sizeof(fs_key->raw));
|
|
||||||
memcpy(fs_key->raw, key.data(), key.size());
|
memcpy(fs_key->raw, key.data(), key.size());
|
||||||
|
fs_key->size = key.size();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue