Specify generic encryption buffer sizes
Merge from widevine repo of http://go/wvgerrit/17463 This CL updates the unit tests to verify that OEMCrypto_Generic_Encrypt and OEMCrypto_Generic_Decrypt can handle a buffer size of at least 100k. It also adds code to the oemcrypto_dynamic_adapter so that buffer sizes that are larger than 100k are broken into chunks of 100k. All Nexus devices targeted for N pass these tests. b/27040752 Change-Id: Iaf5c65d2f0b69e60f03cc99732d1ecab60658049
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "log.h"
|
||||
#include "profiled_scope.h"
|
||||
#include "properties.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
|
||||
using namespace wvoec3;
|
||||
using wvcdm::kLevelDefault;
|
||||
@@ -31,6 +32,8 @@ using wvcdm::kLevel3;
|
||||
|
||||
namespace {
|
||||
|
||||
static const size_t kMaxGenericEncryptChunkSize = 100*1024;
|
||||
|
||||
typedef struct {
|
||||
const uint8_t* key_id;
|
||||
size_t key_id_length;
|
||||
@@ -1107,8 +1110,23 @@ extern "C" OEMCryptoResult OEMCrypto_Generic_Encrypt(
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
return pair.fcn->Generic_Encrypt(pair.session, in_buffer, buffer_length, iv,
|
||||
algorithm, out_buffer);
|
||||
OEMCryptoResult status = OEMCrypto_SUCCESS;
|
||||
std::vector<uint8_t> current_iv(iv, iv + wvcdm::KEY_IV_SIZE);
|
||||
while (buffer_length > 0 && status == OEMCrypto_SUCCESS) {
|
||||
const size_t chunk_size = std::min(buffer_length,
|
||||
kMaxGenericEncryptChunkSize);
|
||||
status = pair.fcn->Generic_Encrypt(pair.session, in_buffer, chunk_size,
|
||||
¤t_iv[0],
|
||||
algorithm, out_buffer);
|
||||
buffer_length -= chunk_size;
|
||||
in_buffer += chunk_size;
|
||||
out_buffer += chunk_size;
|
||||
if (buffer_length > 0) {
|
||||
current_iv.assign(out_buffer - wvcdm::KEY_IV_SIZE,
|
||||
out_buffer);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
extern "C" OEMCryptoResult OEMCrypto_Generic_Decrypt(
|
||||
@@ -1121,8 +1139,23 @@ extern "C" OEMCryptoResult OEMCrypto_Generic_Decrypt(
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
return pair.fcn->Generic_Decrypt(pair.session, in_buffer, buffer_length, iv,
|
||||
algorithm, out_buffer);
|
||||
OEMCryptoResult status = OEMCrypto_SUCCESS;
|
||||
std::vector<uint8_t> current_iv(iv, iv + wvcdm::KEY_IV_SIZE);
|
||||
while (buffer_length > 0 && status == OEMCrypto_SUCCESS) {
|
||||
const size_t chunk_size = std::min(buffer_length,
|
||||
kMaxGenericEncryptChunkSize);
|
||||
status = pair.fcn->Generic_Decrypt(pair.session, in_buffer, chunk_size,
|
||||
¤t_iv[0],
|
||||
algorithm, out_buffer);
|
||||
buffer_length -= chunk_size;
|
||||
in_buffer += chunk_size;
|
||||
out_buffer += chunk_size;
|
||||
if (buffer_length > 0) {
|
||||
current_iv.assign(in_buffer - wvcdm::KEY_IV_SIZE,
|
||||
in_buffer);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
extern "C" OEMCryptoResult OEMCrypto_Generic_Sign(OEMCrypto_SESSION session,
|
||||
|
||||
Reference in New Issue
Block a user