Add backward compatibility to OEMCrypto_CopyBuffer
Merge from Widevine repository of http://go/wvgerrit/13912 This CL falls back to OEMCrypto_DecryptCTR if the oemcrypto library does not implement OEMCrypto_CopyBuffer. This allows devices with oem crypto version 9 to function as they previously did. Change-Id: Id3a4a94b1fd559f426ee260cfbf7077fa9101d8b
This commit is contained in:
@@ -660,25 +660,28 @@ CdmResponseType CryptoSession::Decrypt(const CdmDecryptionParameters& params) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
OEMCryptoResult sts;
|
OEMCryptoResult sts = OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
||||||
if (params.is_encrypted) {
|
if (!params.is_encrypted) {
|
||||||
|
sts = OEMCrypto_CopyBuffer(requested_security_level_,
|
||||||
|
params.encrypt_buffer, params.encrypt_length,
|
||||||
|
&buffer_descriptor, params.subsample_flags);
|
||||||
|
}
|
||||||
|
if (params.is_encrypted || sts == OEMCrypto_ERROR_NOT_IMPLEMENTED) {
|
||||||
AutoLock auto_lock(crypto_lock_);
|
AutoLock auto_lock(crypto_lock_);
|
||||||
// Check if key needs to be selected
|
// Check if key needs to be selected
|
||||||
if (key_id_ != *params.key_id) {
|
if (params.is_encrypted) {
|
||||||
if (SelectKey(*params.key_id)) {
|
if (key_id_ != *params.key_id) {
|
||||||
key_id_ = *params.key_id;
|
if (SelectKey(*params.key_id)) {
|
||||||
} else {
|
key_id_ = *params.key_id;
|
||||||
return NEED_KEY;
|
} else {
|
||||||
|
return NEED_KEY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sts = OEMCrypto_DecryptCTR(
|
sts = OEMCrypto_DecryptCTR(
|
||||||
oec_session_id_, params.encrypt_buffer, params.encrypt_length,
|
oec_session_id_, params.encrypt_buffer, params.encrypt_length,
|
||||||
params.is_encrypted, &(*params.iv).front(), params.block_offset,
|
params.is_encrypted, &(*params.iv).front(), params.block_offset,
|
||||||
&buffer_descriptor, params.subsample_flags);
|
&buffer_descriptor, params.subsample_flags);
|
||||||
} else {
|
|
||||||
sts = OEMCrypto_CopyBuffer(requested_security_level_,
|
|
||||||
params.encrypt_buffer, params.encrypt_length,
|
|
||||||
&buffer_descriptor, params.subsample_flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sts) {
|
switch (sts) {
|
||||||
|
|||||||
@@ -1068,10 +1068,12 @@ OEMCryptoResult SessionContext::DecryptCTR(
|
|||||||
OEMCryptoBufferType buffer_type) {
|
OEMCryptoBufferType buffer_type) {
|
||||||
// If the data is clear, we do not need a current key selected.
|
// If the data is clear, we do not need a current key selected.
|
||||||
if (!is_encrypted) {
|
if (!is_encrypted) {
|
||||||
if (buffer_type == OEMCrypto_BufferType_Direct)
|
if (buffer_type != OEMCrypto_BufferType_Direct){
|
||||||
return OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
memcpy(reinterpret_cast<uint8_t*>(clear_data), cipher_data,
|
||||||
memcpy(reinterpret_cast<uint8_t*>(clear_data), cipher_data,
|
cipher_data_length);
|
||||||
cipher_data_length);
|
return OEMCrypto_SUCCESS;
|
||||||
|
}
|
||||||
|
// For reference implementation, we quietly drop the clear direct video.
|
||||||
return OEMCrypto_SUCCESS;
|
return OEMCrypto_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -536,10 +536,11 @@ OEMCryptoResult SetDestination(OEMCrypto_DestBufferDesc* out_buffer,
|
|||||||
+ out_buffer->buffer.secure.offset;
|
+ out_buffer->buffer.secure.offset;
|
||||||
*max_length = out_buffer->buffer.secure.max_length;
|
*max_length = out_buffer->buffer.secure.max_length;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
case OEMCrypto_BufferType_Direct:
|
case OEMCrypto_BufferType_Direct:
|
||||||
return OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
*destination = NULL;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return OEMCrypto_ERROR_INVALID_CONTEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_buffer->type != OEMCrypto_BufferType_Direct
|
if (out_buffer->type != OEMCrypto_BufferType_Direct
|
||||||
@@ -616,7 +617,7 @@ OEMCryptoResult OEMCrypto_CopyBuffer(const uint8_t *data_addr,
|
|||||||
&max_length);
|
&max_length);
|
||||||
if (sts != OEMCrypto_SUCCESS) return sts;
|
if (sts != OEMCrypto_SUCCESS) return sts;
|
||||||
|
|
||||||
memcpy(destination, data_addr, data_length);
|
if (destination != NULL) memcpy(destination, data_addr, data_length);
|
||||||
return OEMCrypto_SUCCESS;
|
return OEMCrypto_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user