Refactor OEMCrypto_SetDecryptHash
The current implementation of OEMCrypto_SetDecryptHash gives developers flexibility to use different types of hashes. However, all the implementations we have seen thus far use crc32. Because of this, crc32 should be sufficient and we can refactor OEMCrypto_SetDecryptHash to only use the crc32 hash. Bug: 287706586 Change-Id: I4aaa253b2656dfd9c984f77dfb08fe160b23b47c
This commit is contained in:
@@ -55,15 +55,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
uint32_t* const failed_frame_number =
|
||||
fuzzed_data.ConsumeBool() ? &failed_frame_number_data : nullptr;
|
||||
|
||||
const std::vector<uint8_t> hash =
|
||||
fuzzed_data.ConsumeRemainingBytes<uint8_t>();
|
||||
const uint32_t crc32 = fuzzed_data.ConsumeIntegral<uint32_t>();
|
||||
|
||||
license_api_fuzz.LoadLicense();
|
||||
std::vector<uint8_t> key_handle;
|
||||
wvoec::GetKeyHandleIntoVector(session_id, content_key_id.data(),
|
||||
content_key_id.size(),
|
||||
OEMCrypto_CipherMode_CENC, key_handle);
|
||||
OEMCrypto_SetDecryptHash(session_id, frame_number, hash.data(), hash.size());
|
||||
OEMCrypto_SetDecryptHash(session_id, frame_number, crc32);
|
||||
OEMCrypto_DecryptCENC(key_handle.data(), key_handle.size(), &sample, 1,
|
||||
&pattern);
|
||||
OEMCrypto_GetHashErrorCode(session_id, failed_frame_number);
|
||||
|
||||
@@ -242,12 +242,10 @@ TEST_P(OEMCryptoLicenseTest, HashForbiddenAPI15) {
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, license_messages_.LoadResponse());
|
||||
|
||||
uint32_t frame_number = 1;
|
||||
uint32_t hash = 42;
|
||||
const uint32_t crc32 = 42;
|
||||
// It is OK to set the hash before loading the keys
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS,
|
||||
OEMCrypto_SetDecryptHash(session_.session_id(), frame_number,
|
||||
reinterpret_cast<const uint8_t*>(&hash),
|
||||
sizeof(hash)));
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_SetDecryptHash(session_.session_id(),
|
||||
frame_number, crc32));
|
||||
// It is OK to select the key and decrypt.
|
||||
ASSERT_NO_FATAL_FAILURE(session_.TestDecryptCTR());
|
||||
// But the error code should be bad.
|
||||
@@ -257,11 +255,10 @@ TEST_P(OEMCryptoLicenseTest, HashForbiddenAPI15) {
|
||||
|
||||
// This test verifies OEMCrypto_SetDecryptHash for out of range frame number.
|
||||
TEST_P(OEMCryptoLicenseTest, DecryptHashForOutOfRangeFrameNumber) {
|
||||
uint32_t frame_number = kHugeRandomNumber;
|
||||
uint32_t hash = 42;
|
||||
ASSERT_NO_FATAL_FAILURE(OEMCrypto_SetDecryptHash(
|
||||
session_.session_id(), frame_number,
|
||||
reinterpret_cast<const uint8_t*>(&hash), sizeof(hash)));
|
||||
const uint32_t frame_number = kHugeRandomNumber;
|
||||
const uint32_t crc32 = 42;
|
||||
ASSERT_NO_FATAL_FAILURE(
|
||||
OEMCrypto_SetDecryptHash(session_.session_id(), frame_number, crc32));
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -386,11 +386,9 @@ class OEMCryptoSessionTestsDecryptTests
|
||||
if (verify_crc_) {
|
||||
const TestSample& sample = samples_[0];
|
||||
|
||||
uint32_t hash =
|
||||
uint32_t crc32 =
|
||||
util::wvcrc32(sample.truth_buffer.data(), sample.truth_buffer.size());
|
||||
OEMCrypto_SetDecryptHash(session_.session_id(), 1,
|
||||
reinterpret_cast<const uint8_t*>(&hash),
|
||||
sizeof(hash));
|
||||
OEMCrypto_SetDecryptHash(session_.session_id(), 1, crc32);
|
||||
}
|
||||
|
||||
// Build an array of just the sample descriptions.
|
||||
|
||||
@@ -599,11 +599,10 @@ TEST_F(OEMCryptoSessionTests,
|
||||
TEST_F(OEMCryptoMemoryLicenseTest,
|
||||
OEMCryptoMemoryDecryptHashForHugeHashBuffer) {
|
||||
uint32_t session_id = session_.session_id();
|
||||
auto f = [session_id](size_t hash_length) {
|
||||
uint32_t frame_number = 1;
|
||||
vector<uint8_t> hash_buffer(hash_length);
|
||||
return OEMCrypto_SetDecryptHash(session_id, frame_number,
|
||||
hash_buffer.data(), hash_buffer.size());
|
||||
auto f = [session_id]() {
|
||||
const uint32_t frame_number = 1;
|
||||
const uint32_t crc32 = 0;
|
||||
return OEMCrypto_SetDecryptHash(session_id, frame_number, crc32);
|
||||
};
|
||||
TestHugeLengthDoesNotCrashAPI(f, kCheckStatus);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user