Pick widevine oemcrypto-v18 change
No-Typo-Check: From a third party header file Bug: 260918793 Test: unit tests Test: atp v2/widevine-eng/drm_compliance Change-Id: I36effd6a10a99bdb2399ab1f4a0fad026d607c70
This commit is contained in:
@@ -49,11 +49,12 @@ namespace wvoec {
|
||||
// Decrypts the given array of samples. Handles fallback behavior correctly if
|
||||
// the OEMCrypto implementation does not accept multiple samples.
|
||||
OEMCryptoResult DecryptFallbackChain::Decrypt(
|
||||
OEMCrypto_SESSION session_id, const OEMCrypto_SampleDescription* samples,
|
||||
size_t samples_length, OEMCryptoCipherMode cipher_mode,
|
||||
const uint8_t* key_handle, size_t key_handle_length,
|
||||
const OEMCrypto_SampleDescription* samples, size_t samples_length,
|
||||
OEMCryptoCipherMode cipher_mode,
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern) {
|
||||
OEMCryptoResult sts =
|
||||
OEMCrypto_DecryptCENC(session_id, samples, samples_length, pattern);
|
||||
OEMCryptoResult sts = OEMCrypto_DecryptCENC(key_handle, key_handle_length,
|
||||
samples, samples_length, pattern);
|
||||
|
||||
// No need for a fallback. Abort early.
|
||||
if (sts != OEMCrypto_ERROR_BUFFER_TOO_LARGE) {
|
||||
@@ -65,7 +66,8 @@ OEMCryptoResult DecryptFallbackChain::Decrypt(
|
||||
|
||||
// Fall back to decrypting individual samples.
|
||||
for (size_t i = 0; i < samples_length; ++i) {
|
||||
sts = DecryptSample(session_id, samples[i], cipher_mode, pattern);
|
||||
sts = DecryptSample(key_handle, key_handle_length, samples[i], cipher_mode,
|
||||
pattern);
|
||||
if (sts != OEMCrypto_SUCCESS) return sts;
|
||||
}
|
||||
|
||||
@@ -75,10 +77,11 @@ OEMCryptoResult DecryptFallbackChain::Decrypt(
|
||||
// Decrypts the given sample. Handles fallback behavior correctly if the
|
||||
// OEMCrypto implementation does not accept full samples.
|
||||
OEMCryptoResult DecryptFallbackChain::DecryptSample(
|
||||
OEMCrypto_SESSION session_id, const OEMCrypto_SampleDescription& sample,
|
||||
OEMCryptoCipherMode cipher_mode,
|
||||
const uint8_t* key_handle, size_t key_handle_length,
|
||||
const OEMCrypto_SampleDescription& sample, OEMCryptoCipherMode cipher_mode,
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern) {
|
||||
OEMCryptoResult sts = OEMCrypto_DecryptCENC(session_id, &sample, 1, pattern);
|
||||
OEMCryptoResult sts =
|
||||
OEMCrypto_DecryptCENC(key_handle, key_handle_length, &sample, 1, pattern);
|
||||
|
||||
// No need for a fallback. Abort early.
|
||||
if (sts != OEMCrypto_ERROR_BUFFER_TOO_LARGE) {
|
||||
@@ -99,7 +102,8 @@ OEMCryptoResult DecryptFallbackChain::DecryptSample(
|
||||
fake_sample.subsamples = &subsample;
|
||||
fake_sample.subsamples_length = 1;
|
||||
|
||||
sts = DecryptSubsample(session_id, fake_sample, pattern, cipher_mode);
|
||||
sts = DecryptSubsample(key_handle, key_handle_length, fake_sample, pattern,
|
||||
cipher_mode);
|
||||
if (sts != OEMCrypto_SUCCESS) return sts;
|
||||
|
||||
fake_sample.buffers.input_data += length;
|
||||
@@ -116,10 +120,12 @@ OEMCryptoResult DecryptFallbackChain::DecryptSample(
|
||||
// Decrypts the given subsample. Handles fallback behavior correctly if the
|
||||
// OEMCrypto implementation does not accept full subsamples.
|
||||
OEMCryptoResult DecryptFallbackChain::DecryptSubsample(
|
||||
OEMCrypto_SESSION session_id, const OEMCrypto_SampleDescription& sample,
|
||||
const uint8_t* key_handle, size_t key_handle_length,
|
||||
const OEMCrypto_SampleDescription& sample,
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern,
|
||||
OEMCryptoCipherMode cipher_mode) {
|
||||
OEMCryptoResult sts = OEMCrypto_DecryptCENC(session_id, &sample, 1, pattern);
|
||||
OEMCryptoResult sts =
|
||||
OEMCrypto_DecryptCENC(key_handle, key_handle_length, &sample, 1, pattern);
|
||||
|
||||
// No need for a fallback. Abort early.
|
||||
if (sts != OEMCrypto_ERROR_BUFFER_TOO_LARGE) {
|
||||
@@ -149,7 +155,8 @@ OEMCryptoResult DecryptFallbackChain::DecryptSubsample(
|
||||
subsample.num_bytes_encrypted == 0)
|
||||
fake_subsample.subsample_flags |= OEMCrypto_LastSubsample;
|
||||
|
||||
sts = DecryptSubsampleHalf(session_id, fake_sample, pattern, cipher_mode);
|
||||
sts = DecryptSubsampleHalf(key_handle, key_handle_length, fake_sample,
|
||||
pattern, cipher_mode);
|
||||
if (sts != OEMCrypto_SUCCESS) return sts;
|
||||
|
||||
// Advance the buffers for the other half, in case they're needed.
|
||||
@@ -171,7 +178,8 @@ OEMCryptoResult DecryptFallbackChain::DecryptSubsample(
|
||||
if (subsample.subsample_flags & OEMCrypto_LastSubsample)
|
||||
fake_subsample.subsample_flags |= OEMCrypto_LastSubsample;
|
||||
|
||||
sts = DecryptSubsampleHalf(session_id, fake_sample, pattern, cipher_mode);
|
||||
sts = DecryptSubsampleHalf(key_handle, key_handle_length, fake_sample,
|
||||
pattern, cipher_mode);
|
||||
if (sts != OEMCrypto_SUCCESS) return sts;
|
||||
}
|
||||
|
||||
@@ -182,13 +190,15 @@ OEMCryptoResult DecryptFallbackChain::DecryptSubsample(
|
||||
// an OEMCrypto_ERROR_BUFFER_TOO_LARGE produced here will be returned to the
|
||||
// caller.
|
||||
OEMCryptoResult DecryptFallbackChain::DecryptSubsampleHalf(
|
||||
OEMCrypto_SESSION session_id, const OEMCrypto_SampleDescription& sample,
|
||||
const uint8_t* key_handle, size_t key_handle_length,
|
||||
const OEMCrypto_SampleDescription& sample,
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern,
|
||||
OEMCryptoCipherMode cipher_mode) {
|
||||
if (ShouldGenerateCorpus()) {
|
||||
WriteDecryptCencCorpus(cipher_mode, &sample, pattern, 1);
|
||||
}
|
||||
return OEMCrypto_DecryptCENC(session_id, &sample, 1, pattern);
|
||||
return OEMCrypto_DecryptCENC(key_handle, key_handle_length, &sample, 1,
|
||||
pattern);
|
||||
// In a real CDM, you would want some fallback here to handle the case where
|
||||
// the buffer is too big for the OEMCrypto implementation. But in the case of
|
||||
// the tests, we won't be passing a buffer that's too big unless we are trying
|
||||
@@ -198,26 +208,64 @@ OEMCryptoResult DecryptFallbackChain::DecryptSubsampleHalf(
|
||||
|
||||
// Used for OEMCrypto Fuzzing: Corpus format is as below, let | be separator.
|
||||
// cipher_mode + pattern + sample_data for all samples |
|
||||
// subsample_data for all samples
|
||||
// input_data for all samples | subsample_data for all samples
|
||||
void WriteDecryptCencCorpus(
|
||||
OEMCryptoCipherMode cipher_mode,
|
||||
const OEMCrypto_SampleDescription* samples_description,
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern, size_t samples_length) {
|
||||
const std::string file_name =
|
||||
GetFileName("oemcrypto_decrypt_cenc_fuzz_seed_corpus");
|
||||
|
||||
// Cipher mode and Pattern.
|
||||
OEMCrypto_Decrypt_Cenc_Fuzz decrypt_cenc_fuzz_struct;
|
||||
decrypt_cenc_fuzz_struct.cipher_mode = cipher_mode;
|
||||
decrypt_cenc_fuzz_struct.pattern = *pattern;
|
||||
// Cipher mode and Pattern.
|
||||
AppendToFile(file_name,
|
||||
reinterpret_cast<const char*>(&decrypt_cenc_fuzz_struct),
|
||||
sizeof(OEMCrypto_Decrypt_Cenc_Fuzz));
|
||||
|
||||
// Sample data for all samples.
|
||||
for (size_t i = 0; i < samples_length; i++) {
|
||||
OEMCrypto_SampleDescription_Fuzz sample_description_data;
|
||||
sample_description_data.buffers.input_data_length =
|
||||
samples_description[i].buffers.input_data_length;
|
||||
sample_description_data.buffers.output_descriptor.type =
|
||||
samples_description[i].buffers.output_descriptor.type;
|
||||
switch (sample_description_data.buffers.output_descriptor.type) {
|
||||
case OEMCrypto_BufferType_Clear:
|
||||
sample_description_data.buffers.output_descriptor.buffer_config =
|
||||
samples_description[i]
|
||||
.buffers.output_descriptor.buffer.clear.clear_buffer_length;
|
||||
break;
|
||||
|
||||
case OEMCrypto_BufferType_Secure:
|
||||
sample_description_data.buffers.output_descriptor.buffer_config =
|
||||
samples_description[i]
|
||||
.buffers.output_descriptor.buffer.secure.secure_buffer_length;
|
||||
break;
|
||||
|
||||
case OEMCrypto_BufferType_Direct:
|
||||
sample_description_data.buffers.output_descriptor.buffer_config =
|
||||
samples_description[i]
|
||||
.buffers.output_descriptor.buffer.direct.is_video;
|
||||
break;
|
||||
}
|
||||
memcpy(sample_description_data.iv, samples_description[i].iv,
|
||||
sizeof(sample_description_data.iv));
|
||||
sample_description_data.subsamples_length =
|
||||
samples_description[i].subsamples_length;
|
||||
AppendToFile(file_name,
|
||||
reinterpret_cast<const char*>(&samples_description[i]),
|
||||
sizeof(OEMCrypto_SampleDescription));
|
||||
reinterpret_cast<const char*>(&sample_description_data),
|
||||
sizeof(OEMCrypto_SampleDescription_Fuzz));
|
||||
}
|
||||
AppendSeparator(file_name);
|
||||
|
||||
// Input data for all samples.
|
||||
for (size_t i = 0; i < samples_length; i++) {
|
||||
AppendToFile(file_name,
|
||||
reinterpret_cast<const char*>(
|
||||
samples_description[i].buffers.input_data),
|
||||
samples_description[i].buffers.input_data_length);
|
||||
}
|
||||
AppendSeparator(file_name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user