Remove OEMCrypto_InitializeDecryptHash
Merge from Widevine repo of http://go/wvgerrit/68464 The Full Decrypt Path Testing design has changed to remove OEMCrypto_InitializeDecryptHash. This CL updates the unit tests and reference code. Bug: 120795057 Test: unit tests Change-Id: Iee28fa9034dc21cee81c5b894c192e260375eeee
This commit is contained in:
committed by
Srujan Gaddam
parent
f42038d89a
commit
9c95e4caae
@@ -1168,7 +1168,6 @@ OEMCryptoResult SessionContext::SelectContentKey(
|
||||
LOGE("No key matches key id");
|
||||
return OEMCrypto_ERROR_NO_CONTENT_KEY;
|
||||
}
|
||||
compute_hash_ = false;
|
||||
content_key->set_ctr_mode(cipher_mode == OEMCrypto_CipherMode_CTR);
|
||||
current_content_key_ = content_key;
|
||||
const KeyControlBlock& control = current_content_key()->control();
|
||||
@@ -1285,7 +1284,7 @@ OEMCryptoResult SessionContext::DecryptCENC(
|
||||
const uint8_t* iv, size_t block_offset,
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern, const uint8_t* cipher_data,
|
||||
size_t cipher_data_length, bool is_encrypted, uint8_t* clear_data,
|
||||
OEMCryptoBufferType buffer_type) {
|
||||
OEMCryptoBufferType buffer_type, uint8_t subsample_flags) {
|
||||
OEMCryptoResult result =
|
||||
ChooseDecrypt(iv, block_offset, pattern, cipher_data, cipher_data_length,
|
||||
is_encrypted, clear_data, buffer_type);
|
||||
@@ -1293,13 +1292,30 @@ OEMCryptoResult SessionContext::DecryptCENC(
|
||||
if (current_content_key() == NULL ||
|
||||
(current_content_key()->control().control_bits() &
|
||||
wvoec::kControlAllowHashVerification) == 0) {
|
||||
// This should not happen: this check should already have occured in
|
||||
// InitializeDecryptHash or the hash should have been discarded in
|
||||
// SelectContentKey. But it doesn't hurt to double check.
|
||||
LOGE("[DecryptCENC(): OEMCrypto_ERROR_UNKNOWN_FAILURE]");
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
hash_error_ = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
compute_hash_ = false;
|
||||
current_hash_ = 0;
|
||||
current_frame_number_ = 0;
|
||||
} else {
|
||||
if (OEMCrypto_FirstSubsample & subsample_flags) {
|
||||
current_hash_ = wvcrc32Init();
|
||||
}
|
||||
current_hash_ =
|
||||
wvcrc32Cont(clear_data, cipher_data_length, current_hash_);
|
||||
if (OEMCrypto_LastSubsample & subsample_flags) {
|
||||
if (current_hash_ != given_hash_) {
|
||||
LOGE("CRC for frame %d is %08x, should be %08x\n",
|
||||
current_frame_number_, current_hash_, given_hash_);
|
||||
// Update bad_frame_number_ only if this is the first bad frame.
|
||||
if (hash_error_ == OEMCrypto_SUCCESS) {
|
||||
bad_frame_number_ = current_frame_number_;
|
||||
hash_error_ = OEMCrypto_ERROR_BAD_HASH;
|
||||
}
|
||||
}
|
||||
compute_hash_ = false;
|
||||
}
|
||||
}
|
||||
current_hash_ = wvcrc32Cont(clear_data, cipher_data_length, current_hash_);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1526,36 +1542,9 @@ OEMCryptoResult SessionContext::DecryptCTR(const uint8_t* key_u8,
|
||||
return OEMCrypto_SUCCESS;
|
||||
}
|
||||
|
||||
OEMCryptoResult SessionContext::InitializeDecryptHash() {
|
||||
// Check there is a content key, and it is allowed.
|
||||
if (current_content_key() == NULL ||
|
||||
(current_content_key()->control().control_bits() &
|
||||
wvoec::kControlAllowHashVerification) == 0) {
|
||||
LOGE("[InitializeDecryptHash(): OEMCrypto_ERROR_UNKNOWN_FAILURE]");
|
||||
compute_hash_ = false;
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
compute_hash_ = true;
|
||||
current_hash_ = wvcrc32Init();
|
||||
return OEMCrypto_SUCCESS;
|
||||
}
|
||||
|
||||
OEMCryptoResult SessionContext::SetDecryptHash(uint32_t frame_number,
|
||||
const uint8_t* hash,
|
||||
size_t hash_length) {
|
||||
// Check there is a content key, and it is allowed.
|
||||
if (current_content_key() == NULL ||
|
||||
(current_content_key()->control().control_bits() &
|
||||
wvoec::kControlAllowHashVerification) == 0) {
|
||||
LOGE("[SetDecryptHash(): OEMCrypto_ERROR_UNKNOWN_FAILURE]");
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
if (!compute_hash_) {
|
||||
// This would happen if somebody computes the hash, and then changes keys.
|
||||
LOGE("[SetDecryptHash(): OEMCrypto_ERROR_UNKNOWN_FAILURE]");
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
compute_hash_ = false;
|
||||
if (hash_length < sizeof(uint32_t)) {
|
||||
LOGE("[SetDecryptHash(): short buffer]");
|
||||
return OEMCrypto_ERROR_SHORT_BUFFER;
|
||||
@@ -1564,15 +1553,9 @@ OEMCryptoResult SessionContext::SetDecryptHash(uint32_t frame_number,
|
||||
LOGE("[SetDecryptHash(): long buffer]");
|
||||
return OEMCrypto_ERROR_BUFFER_TOO_LARGE;
|
||||
}
|
||||
uint32_t given_hash = *reinterpret_cast<const uint32_t*>(hash);
|
||||
if (current_hash_ != given_hash) {
|
||||
LOGE("CRC for frame %d is %08x, should be %08x\n", frame_number,
|
||||
current_hash_, given_hash);
|
||||
// Update bad_frame_number_ only if this is the first bad frame.
|
||||
if (hash_error_ == OEMCrypto_SUCCESS) bad_frame_number_ = frame_number;
|
||||
hash_error_ = OEMCrypto_ERROR_BAD_HASH;
|
||||
}
|
||||
// Return success if the hash was compared, even if there was an error.
|
||||
compute_hash_ = true;
|
||||
current_frame_number_ = frame_number;
|
||||
given_hash_ = *reinterpret_cast<const uint32_t*>(hash);
|
||||
return OEMCrypto_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user