Merge "Simplify IV Incrementation"
This commit is contained in:
@@ -46,8 +46,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,
|
||||
uint64_t* result);
|
||||
size_t range, const Pattern& pattern, uint64_t* result);
|
||||
static void incrementIV(uint64_t increaseBy, std::vector<uint8_t>* ivPtr);
|
||||
};
|
||||
|
||||
|
||||
@@ -292,8 +292,7 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
kAESBlockSize;
|
||||
} else {
|
||||
res = countEncryptedBlocksInPatternedRange(
|
||||
subSample.mNumBytesOfEncryptedData, blockOffset, pattern,
|
||||
&increment);
|
||||
subSample.mNumBytesOfEncryptedData, pattern, &increment);
|
||||
if (!isCdmResponseTypeSuccess(res)) {
|
||||
// Swallow the specifics of the error to obscure decrypt internals.
|
||||
return kErrorCDMGeneric;
|
||||
@@ -348,32 +347,22 @@ 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,
|
||||
uint64_t* result) {
|
||||
uint64_t blocksPassed = 0;
|
||||
size_t bytesRemaining = range;
|
||||
size_t patternPosition = 0;
|
||||
size_t patternLength = pattern.mEncryptBlocks + pattern.mSkipBlocks;
|
||||
|
||||
if (result == NULL || startingOffset >= kAESBlockSize) {
|
||||
size_t range, const Pattern& pattern, uint64_t* result) {
|
||||
if (result == NULL || range % kAESBlockSize != 0) {
|
||||
return wvcdm::UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
// We may already be partway into a block, so reduce the number of bytes
|
||||
// that must be passed to complete a block if so.
|
||||
size_t bytesNeededToCompleteABlock = kAESBlockSize - startingOffset;
|
||||
while (bytesRemaining >= bytesNeededToCompleteABlock) {
|
||||
bytesRemaining -= bytesNeededToCompleteABlock;
|
||||
const size_t patternLength = pattern.mEncryptBlocks + pattern.mSkipBlocks;
|
||||
uint64_t encryptedBlocksPassed = 0;
|
||||
size_t patternPosition = 0;
|
||||
for (size_t remaining = range / kAESBlockSize; remaining > 0; --remaining) {
|
||||
if (patternPosition < pattern.mEncryptBlocks) {
|
||||
++blocksPassed;
|
||||
++encryptedBlocksPassed;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user