Fix cens Mode in Android CDM am: e0f4942b8f am: 442099fb15
am: 67682ddf1a
Change-Id: Idb1f713da3002733152544dd6eae2da06119dbdb
This commit is contained in:
@@ -47,7 +47,7 @@ class WVCryptoPlugin : public android::CryptoPlugin {
|
||||
wvcdm::CdmSessionId configureTestMode(const void* data, size_t size);
|
||||
static wvcdm::CdmResponseType countEncryptedBlocksInPatternedRange(
|
||||
size_t range, size_t startingOffset, const Pattern& pattern,
|
||||
size_t startingPatternOffset, uint64_t* result);
|
||||
uint64_t* result);
|
||||
static void incrementIV(uint64_t increaseBy, std::vector<uint8_t>* ivPtr);
|
||||
};
|
||||
|
||||
|
||||
@@ -146,7 +146,6 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
size_t blockOffset = 0;
|
||||
const size_t patternLengthInBytes =
|
||||
(pattern.mEncryptBlocks + pattern.mSkipBlocks) * kAESBlockSize;
|
||||
size_t patternOffsetInBytes = 0;
|
||||
|
||||
for (size_t i = 0; i < numSubSamples; ++i) {
|
||||
const SubSample& subSample = subSamples[i];
|
||||
@@ -187,7 +186,6 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
params.encrypt_buffer = source + offset;
|
||||
params.encrypt_length = subSample.mNumBytesOfClearData;
|
||||
params.block_offset = 0;
|
||||
params.pattern_descriptor.offset_blocks = 0;
|
||||
params.decrypt_buffer_offset = offset;
|
||||
params.subsample_flags = clearFlags;
|
||||
|
||||
@@ -238,12 +236,6 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
params.encrypt_buffer = source + offset;
|
||||
params.encrypt_length = subSample.mNumBytesOfEncryptedData;
|
||||
params.block_offset = blockOffset;
|
||||
// Note that the pattern offset calculation relies intentionally on
|
||||
// integer division's flooring behavior. If we are partway through a
|
||||
// crypto block, we should return the offset of the pattern block we are
|
||||
// partway through.
|
||||
size_t patternOffsetInBlocks = patternOffsetInBytes / kAESBlockSize;
|
||||
params.pattern_descriptor.offset_blocks = patternOffsetInBlocks;
|
||||
params.decrypt_buffer_offset = offset;
|
||||
params.subsample_flags = encryptedFlags;
|
||||
|
||||
@@ -301,7 +293,7 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
} else {
|
||||
res = countEncryptedBlocksInPatternedRange(
|
||||
subSample.mNumBytesOfEncryptedData, blockOffset, pattern,
|
||||
patternOffsetInBlocks, &increment);
|
||||
&increment);
|
||||
if (!isCdmResponseTypeSuccess(res)) {
|
||||
// Swallow the specifics of the error to obscure decrypt internals.
|
||||
return kErrorCDMGeneric;
|
||||
@@ -312,12 +304,6 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
// Update the block offset
|
||||
blockOffset = (blockOffset + subSample.mNumBytesOfEncryptedData) %
|
||||
kAESBlockSize;
|
||||
|
||||
if (patternLengthInBytes > 0) {
|
||||
patternOffsetInBytes =
|
||||
(patternOffsetInBytes + subSample.mNumBytesOfEncryptedData) %
|
||||
patternLengthInBytes;
|
||||
}
|
||||
} else if (mode == kMode_AES_CBC && patternLengthInBytes == 0) {
|
||||
// If there is no pattern, assume cbc1 mode and update the IV.
|
||||
|
||||
@@ -363,14 +349,13 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
|
||||
CdmResponseType WVCryptoPlugin::countEncryptedBlocksInPatternedRange(
|
||||
size_t range, size_t startingOffset, const Pattern& pattern,
|
||||
size_t startingPatternOffset, uint64_t* result) {
|
||||
uint64_t* result) {
|
||||
uint64_t blocksPassed = 0;
|
||||
size_t bytesRemaining = range;
|
||||
size_t patternOffset = startingPatternOffset;
|
||||
size_t patternPosition = 0;
|
||||
size_t patternLength = pattern.mEncryptBlocks + pattern.mSkipBlocks;
|
||||
|
||||
if (result == NULL || startingOffset >= kAESBlockSize ||
|
||||
startingPatternOffset >= patternLength) {
|
||||
if (result == NULL || startingOffset >= kAESBlockSize) {
|
||||
return wvcdm::UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
@@ -379,10 +364,10 @@ CdmResponseType WVCryptoPlugin::countEncryptedBlocksInPatternedRange(
|
||||
size_t bytesNeededToCompleteABlock = kAESBlockSize - startingOffset;
|
||||
while (bytesRemaining >= bytesNeededToCompleteABlock) {
|
||||
bytesRemaining -= bytesNeededToCompleteABlock;
|
||||
if (patternOffset < pattern.mEncryptBlocks) {
|
||||
if (patternPosition < pattern.mEncryptBlocks) {
|
||||
++blocksPassed;
|
||||
}
|
||||
patternOffset = (patternOffset + 1) % patternLength;
|
||||
patternPosition = (patternPosition + 1) % patternLength;
|
||||
|
||||
// After the first block, we only concern ourselves with complete blocks.
|
||||
bytesNeededToCompleteABlock = kAESBlockSize;
|
||||
|
||||
Reference in New Issue
Block a user