Merge "Correct AES bit size for generic crypto"
This commit is contained in:
committed by
Android (Google) Code Review
commit
eb8d77d8f1
@@ -706,7 +706,7 @@ OEMCryptoResult SessionContext::LoadEntitledContentKeys(
|
||||
key_data->content_key_id,
|
||||
key_data->content_key_id + key_data->content_key_id_length);
|
||||
if (!DecryptMessage(*entitlement_key, iv, encrypted_content_key,
|
||||
&content_key)) {
|
||||
&content_key, 256 /* key size */)) {
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
if (!session_keys_->SetContentKey(entitlement_key_id, content_key_id,
|
||||
@@ -726,7 +726,8 @@ OEMCryptoResult SessionContext::InstallKey(
|
||||
std::vector<uint8_t> content_key;
|
||||
std::vector<uint8_t> key_control_str;
|
||||
|
||||
if (!DecryptMessage(encryption_key_, key_data_iv, key_data, &content_key)) {
|
||||
if (!DecryptMessage(encryption_key_, key_data_iv, key_data, &content_key,
|
||||
128 /* key size */)) {
|
||||
LOGE("[Installkey(): Could not decrypt key data]");
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
@@ -749,7 +750,7 @@ OEMCryptoResult SessionContext::InstallKey(
|
||||
return OEMCrypto_ERROR_INVALID_CONTEXT;
|
||||
}
|
||||
if (!DecryptMessage(content_key, key_control_iv, key_control,
|
||||
&key_control_str)) {
|
||||
&key_control_str, 128 /* key size */)) {
|
||||
LOGE("[Installkey(): ERROR: Could not decrypt content key]");
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
@@ -881,7 +882,7 @@ OEMCryptoResult SessionContext::RefreshKey(
|
||||
LOGD("Key control block is encrypted.");
|
||||
}
|
||||
if (!DecryptMessage(content_key_value, key_control_iv, key_control,
|
||||
&control)) {
|
||||
&control, 128 /* key size */)) {
|
||||
if (LogCategoryEnabled(kLoggingDumpKeyControlBlocks)) {
|
||||
LOGD("Error decrypting key control block.");
|
||||
}
|
||||
@@ -1170,7 +1171,8 @@ bool SessionContext::UpdateMacKeys(const std::vector<uint8_t>& enc_mac_keys,
|
||||
const std::vector<uint8_t>& iv) {
|
||||
// Decrypt mac key from enc_mac_key using device_keya
|
||||
std::vector<uint8_t> mac_keys;
|
||||
if (!DecryptMessage(encryption_key_, iv, enc_mac_keys, &mac_keys)) {
|
||||
if (!DecryptMessage(encryption_key_, iv, enc_mac_keys, &mac_keys,
|
||||
128 /* key size */)) {
|
||||
return false;
|
||||
}
|
||||
mac_key_server_ = std::vector<uint8_t>(
|
||||
@@ -1318,7 +1320,8 @@ OEMCryptoResult SessionContext::CopyOldUsageEntry(
|
||||
bool SessionContext::DecryptMessage(const std::vector<uint8_t>& key,
|
||||
const std::vector<uint8_t>& iv,
|
||||
const std::vector<uint8_t>& message,
|
||||
std::vector<uint8_t>* decrypted) {
|
||||
std::vector<uint8_t>* decrypted,
|
||||
uint32_t key_size) {
|
||||
if (key.empty() || iv.empty() || message.empty() || !decrypted) {
|
||||
LOGE("[DecryptMessage(): OEMCrypto_ERROR_INVALID_CONTEXT]");
|
||||
return false;
|
||||
@@ -1327,7 +1330,7 @@ bool SessionContext::DecryptMessage(const std::vector<uint8_t>& key,
|
||||
uint8_t iv_buffer[16];
|
||||
memcpy(iv_buffer, &iv[0], 16);
|
||||
AES_KEY aes_key;
|
||||
AES_set_decrypt_key(&key[0], key.size() * 8, &aes_key);
|
||||
AES_set_decrypt_key(&key[0], key_size, &aes_key);
|
||||
AES_cbc_encrypt(&message[0], &(decrypted->front()), message.size(), &aes_key,
|
||||
iv_buffer, AES_DECRYPT);
|
||||
return true;
|
||||
|
||||
@@ -189,7 +189,8 @@ class SessionContext {
|
||||
bool DecryptMessage(const std::vector<uint8_t>& key,
|
||||
const std::vector<uint8_t>& iv,
|
||||
const std::vector<uint8_t>& message,
|
||||
std::vector<uint8_t>* decrypted);
|
||||
std::vector<uint8_t>* decrypted,
|
||||
uint32_t key_size); // AES key size, in bits.
|
||||
// Either verify the nonce or usage entry, as required by the key control
|
||||
// block.
|
||||
OEMCryptoResult CheckNonceOrEntry(const KeyControlBlock& key_control_block);
|
||||
|
||||
Reference in New Issue
Block a user