OEMCrypto unit test with sample size = 160N+16

Merge from widevine of http://go/wvgerrit/17128

This CL adds a unit test for an edge case that would be handled
differently for HLS and CENC standards.  We enforce the CENC standard.

b/27524491

Change-Id: Ie3cdfaac0fe37dd0eb991179fd84f4e113e07dae
This commit is contained in:
Fred Gylys-Colwell
2016-03-16 11:48:43 -07:00
parent 8186284683
commit 6a10503b61

View File

@@ -2624,6 +2624,42 @@ TEST_P(OEMCryptoSessionTestsDecryptTests, SingleLargeSubsample) {
TestDecryptCENC(key, encryptionIv, encryptedData, unencryptedData); TestDecryptCENC(key, encryptionIv, encryptedData, unencryptedData);
} }
TEST_P(OEMCryptoSessionTestsDecryptTests, PatternPlusOneBlock) {
// When the pattern length is 10 blocks, there is a discrepancy between the
// HLS and the CENC standards for samples of size 160*N+16, for N = 1, 2, 3 ...
// We require the CENC standard for OEMCrypto, and let a layer above us break
// samples into pieces if they wish to use the HLS standard.
subsample_size_.push_back(SampleSize(0, 160+16));
FindTotalSize();
vector<uint8_t> unencryptedData(total_size_);
vector<uint8_t> encryptedData(total_size_);
vector<uint8_t> encryptionIv(AES_BLOCK_SIZE);
vector<uint8_t> key(AES_BLOCK_SIZE);
EXPECT_EQ(OEMCrypto_SUCCESS,
OEMCrypto_GetRandom(&encryptionIv[0], AES_BLOCK_SIZE));
EXPECT_EQ(OEMCrypto_SUCCESS,
OEMCrypto_GetRandom(&key[0], AES_BLOCK_SIZE));
for (size_t i = 0; i < total_size_; i++) unencryptedData[i] = i % 256;
EncryptData(key, encryptionIv, unencryptedData, &encryptedData);
TestDecryptCENC(key, encryptionIv, encryptedData, unencryptedData);
}
TEST_P(OEMCryptoSessionTestsDecryptTests, OneBlock) {
subsample_size_.push_back(SampleSize(0, 16));
FindTotalSize();
vector<uint8_t> unencryptedData(total_size_);
vector<uint8_t> encryptedData(total_size_);
vector<uint8_t> encryptionIv(AES_BLOCK_SIZE);
vector<uint8_t> key(AES_BLOCK_SIZE);
EXPECT_EQ(OEMCrypto_SUCCESS,
OEMCrypto_GetRandom(&encryptionIv[0], AES_BLOCK_SIZE));
EXPECT_EQ(OEMCrypto_SUCCESS,
OEMCrypto_GetRandom(&key[0], AES_BLOCK_SIZE));
for (size_t i = 0; i < total_size_; i++) unencryptedData[i] = i % 256;
EncryptData(key, encryptionIv, unencryptedData, &encryptedData);
TestDecryptCENC(key, encryptionIv, encryptedData, unencryptedData);
}
// This tests the ability to decrypt multiple subsamples with no offset. // This tests the ability to decrypt multiple subsamples with no offset.
// There is no offset within the block, used by CTR mode. However, there might // There is no offset within the block, used by CTR mode. However, there might
// be an offset in the encrypt/skip pattern. // be an offset in the encrypt/skip pattern.
@@ -2873,6 +2909,9 @@ INSTANTIATE_TEST_CASE_P(
PatternTestVariant(3, 7, 0, OEMCrypto_CipherMode_CBC), PatternTestVariant(3, 7, 0, OEMCrypto_CipherMode_CBC),
PatternTestVariant(3, 7, 2, OEMCrypto_CipherMode_CBC), PatternTestVariant(3, 7, 2, OEMCrypto_CipherMode_CBC),
PatternTestVariant(7, 3, 2, OEMCrypto_CipherMode_CBC), PatternTestVariant(7, 3, 2, OEMCrypto_CipherMode_CBC),
// HLS Edge case. We should follow the CENC spec, not HLS spec.
PatternTestVariant(9, 1, 0, OEMCrypto_CipherMode_CBC),
PatternTestVariant(1, 9, 0, OEMCrypto_CipherMode_CBC),
// Pattern length should be 10, but that is not guaranteed. // Pattern length should be 10, but that is not guaranteed.
PatternTestVariant(5, 3, 2, OEMCrypto_CipherMode_CTR), PatternTestVariant(5, 3, 2, OEMCrypto_CipherMode_CTR),
PatternTestVariant(1, 3, 0, OEMCrypto_CipherMode_CTR), PatternTestVariant(1, 3, 0, OEMCrypto_CipherMode_CTR),