Index: content/renderer/webcrypto/webcrypto_impl_unittest.cc |
diff --git a/content/renderer/webcrypto/webcrypto_impl_unittest.cc b/content/renderer/webcrypto/webcrypto_impl_unittest.cc |
index bcda603e634b76597d5606c47ccaba2187023031..1e8803b79d1c411eea53794f8d3178423c817330 100644 |
--- a/content/renderer/webcrypto/webcrypto_impl_unittest.cc |
+++ b/content/renderer/webcrypto/webcrypto_impl_unittest.cc |
@@ -697,32 +697,48 @@ TEST_F(WebCryptoImplTest, MAYBE(AesCbcSampleSets)) { |
} |
TEST_F(WebCryptoImplTest, MAYBE(GenerateKeyAes)) { |
- // Generate a small sample of AES keys. |
+ // Check key generation for each of AES-CBC, AES-GCM, and AES-KW, and for each |
+ // allowed key length. |
+ std::vector<blink::WebCryptoAlgorithm> algorithm; |
+ const unsigned short kKeyLength[] = {128, 192, 256}; |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kKeyLength); ++i) { |
+ algorithm.push_back(webcrypto::CreateAesCbcKeyGenAlgorithm(kKeyLength[i])); |
+ algorithm.push_back(webcrypto::CreateAesGcmKeyGenAlgorithm(kKeyLength[i])); |
+ algorithm.push_back(webcrypto::CreateAesKwKeyGenAlgorithm(kKeyLength[i])); |
+ } |
+ blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
std::vector<blink::WebArrayBuffer> keys; |
blink::WebArrayBuffer key_bytes; |
- for (int i = 0; i < 16; ++i) { |
- blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
- ASSERT_TRUE( |
- GenerateKeyInternal(webcrypto::CreateAesCbcKeyGenAlgorithm(128), &key)); |
- EXPECT_TRUE(key.handle()); |
- EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); |
- ASSERT_TRUE( |
- ExportKeyInternal(blink::WebCryptoKeyFormatRaw, key, &key_bytes)); |
- keys.push_back(key_bytes); |
+ for (size_t i = 0; i < algorithm.size(); ++i) { |
+ SCOPED_TRACE(i); |
+ // Generate a small sample of keys. |
+ keys.clear(); |
+ for (int j = 0; j < 16; ++j) { |
+ ASSERT_TRUE(GenerateKeyInternal(algorithm[i], &key)); |
+ EXPECT_TRUE(key.handle()); |
+ EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); |
+ ASSERT_TRUE( |
+ ExportKeyInternal(blink::WebCryptoKeyFormatRaw, key, &key_bytes)); |
+ keys.push_back(key_bytes); |
+ } |
+ // Ensure all entries in the key sample set are unique. This is a simplistic |
+ // estimate of whether the generated keys appear random. |
+ EXPECT_FALSE(CopiesExist(keys)); |
} |
- // Ensure all entries in the key sample set are unique. This is a simplistic |
- // estimate of whether the generated keys appear random. |
- EXPECT_FALSE(CopiesExist(keys)); |
} |
TEST_F(WebCryptoImplTest, MAYBE(GenerateKeyAesBadLength)) { |
+ const unsigned short kKeyLen[] = {0, 127, 257}; |
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
- EXPECT_FALSE( |
- GenerateKeyInternal(webcrypto::CreateAesCbcKeyGenAlgorithm(0), &key)); |
- EXPECT_FALSE( |
- GenerateKeyInternal(webcrypto::CreateAesCbcKeyGenAlgorithm(0), &key)); |
- EXPECT_FALSE( |
- GenerateKeyInternal(webcrypto::CreateAesCbcKeyGenAlgorithm(129), &key)); |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kKeyLen); ++i) { |
+ SCOPED_TRACE(i); |
+ EXPECT_FALSE(GenerateKeyInternal( |
+ webcrypto::CreateAesCbcKeyGenAlgorithm(kKeyLen[i]), &key)); |
+ EXPECT_FALSE(GenerateKeyInternal( |
+ webcrypto::CreateAesGcmKeyGenAlgorithm(kKeyLen[i]), &key)); |
+ EXPECT_FALSE(GenerateKeyInternal( |
+ webcrypto::CreateAesKwKeyGenAlgorithm(kKeyLen[i]), &key)); |
+ } |
} |
TEST_F(WebCryptoImplTest, MAYBE(GenerateKeyHmac)) { |