Simplify IV Incrementation

(This is a merge of go/wvgerrit/22441)

The IV incrementation code in Widevine DRM Plugin includes complexity
for handling partial crypto blocks in "cens" mode, a situation that
cannot actually happen. This commit changes the code to no longer handle
this case specially.

Bug: 28696811
Test: No tests for this code path due to bug 28295739
Change-Id: I77f8434a9785bf028509387c06db217a5de2b91b
This commit is contained in:
John W. Bruce
2016-11-29 18:45:08 -08:00
parent 97c2c74556
commit 3847adb78e
2 changed files with 10 additions and 22 deletions

View File

@@ -46,8 +46,7 @@ class WVCryptoPlugin : public android::CryptoPlugin {
wvcdm::CdmSessionId configureTestMode(const void* data, size_t size); wvcdm::CdmSessionId configureTestMode(const void* data, size_t size);
static wvcdm::CdmResponseType countEncryptedBlocksInPatternedRange( static wvcdm::CdmResponseType countEncryptedBlocksInPatternedRange(
size_t range, size_t startingOffset, const Pattern& pattern, size_t range, const Pattern& pattern, uint64_t* result);
uint64_t* result);
static void incrementIV(uint64_t increaseBy, std::vector<uint8_t>* ivPtr); static void incrementIV(uint64_t increaseBy, std::vector<uint8_t>* ivPtr);
}; };

View File

@@ -292,8 +292,7 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
kAESBlockSize; kAESBlockSize;
} else { } else {
res = countEncryptedBlocksInPatternedRange( res = countEncryptedBlocksInPatternedRange(
subSample.mNumBytesOfEncryptedData, blockOffset, pattern, subSample.mNumBytesOfEncryptedData, pattern, &increment);
&increment);
if (!isCdmResponseTypeSuccess(res)) { if (!isCdmResponseTypeSuccess(res)) {
// Swallow the specifics of the error to obscure decrypt internals. // Swallow the specifics of the error to obscure decrypt internals.
return kErrorCDMGeneric; return kErrorCDMGeneric;
@@ -348,32 +347,22 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
} }
CdmResponseType WVCryptoPlugin::countEncryptedBlocksInPatternedRange( CdmResponseType WVCryptoPlugin::countEncryptedBlocksInPatternedRange(
size_t range, size_t startingOffset, const Pattern& pattern, size_t range, const Pattern& pattern, uint64_t* result) {
uint64_t* result) { if (result == NULL || range % kAESBlockSize != 0) {
uint64_t blocksPassed = 0;
size_t bytesRemaining = range;
size_t patternPosition = 0;
size_t patternLength = pattern.mEncryptBlocks + pattern.mSkipBlocks;
if (result == NULL || startingOffset >= kAESBlockSize) {
return wvcdm::UNKNOWN_ERROR; return wvcdm::UNKNOWN_ERROR;
} }
// We may already be partway into a block, so reduce the number of bytes const size_t patternLength = pattern.mEncryptBlocks + pattern.mSkipBlocks;
// that must be passed to complete a block if so. uint64_t encryptedBlocksPassed = 0;
size_t bytesNeededToCompleteABlock = kAESBlockSize - startingOffset; size_t patternPosition = 0;
while (bytesRemaining >= bytesNeededToCompleteABlock) { for (size_t remaining = range / kAESBlockSize; remaining > 0; --remaining) {
bytesRemaining -= bytesNeededToCompleteABlock;
if (patternPosition < pattern.mEncryptBlocks) { if (patternPosition < pattern.mEncryptBlocks) {
++blocksPassed; ++encryptedBlocksPassed;
} }
patternPosition = (patternPosition + 1) % patternLength; patternPosition = (patternPosition + 1) % patternLength;
// After the first block, we only concern ourselves with complete blocks.
bytesNeededToCompleteABlock = kAESBlockSize;
} }
*result = blocksPassed; *result = encryptedBlocksPassed;
return wvcdm::NO_ERROR; return wvcdm::NO_ERROR;
} }