From 6a10503b61f0585e996d01a80b569d75082b1083 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Wed, 16 Mar 2016 11:48:43 -0700 Subject: [PATCH] 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 --- .../oemcrypto/test/oemcrypto_test.cpp | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index 356a8745..52aa92d1 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -2624,6 +2624,42 @@ TEST_P(OEMCryptoSessionTestsDecryptTests, SingleLargeSubsample) { 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 unencryptedData(total_size_); + vector encryptedData(total_size_); + vector encryptionIv(AES_BLOCK_SIZE); + vector 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 unencryptedData(total_size_); + vector encryptedData(total_size_); + vector encryptionIv(AES_BLOCK_SIZE); + vector 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. // There is no offset within the block, used by CTR mode. However, there might // 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, 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. PatternTestVariant(5, 3, 2, OEMCrypto_CipherMode_CTR), PatternTestVariant(1, 3, 0, OEMCrypto_CipherMode_CTR),