Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: content/child/webcrypto/shared_crypto_unittest.cc

Issue 203303006: [webcrypto] Add length parameter to HmacKeyAlgorithm. (chromium) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add bound check Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/shared_crypto_unittest.cc
diff --git a/content/child/webcrypto/shared_crypto_unittest.cc b/content/child/webcrypto/shared_crypto_unittest.cc
index 55c3bb7a57a75a35305d7f46148e27ed28001044..814a26fb45ff31d140754e9e2ac4a3504cf9fdab 100644
--- a/content/child/webcrypto/shared_crypto_unittest.cc
+++ b/content/child/webcrypto/shared_crypto_unittest.cc
@@ -675,6 +675,9 @@ TEST_F(SharedCryptoTest, HMACSampleSets) {
blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify);
EXPECT_EQ(test_hash.id(), key.algorithm().hmacParams()->hash().id());
+#if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH)
+ EXPECT_EQ(test_key.size() * 8, key.algorithm().hmacParams()->lengthBits());
+#endif
// Verify exported raw key is identical to the imported data
blink::WebArrayBuffer raw_key;
@@ -955,6 +958,9 @@ TEST_F(SharedCryptoTest, MAYBE(GenerateKeyHmac)) {
EXPECT_EQ(blink::WebCryptoAlgorithmIdHmac, key.algorithm().id());
EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1,
key.algorithm().hmacParams()->hash().id());
+#if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH)
+ EXPECT_EQ(512u, key.algorithm().hmacParams()->lengthBits());
+#endif
blink::WebArrayBuffer raw_key;
ASSERT_STATUS_SUCCESS(
@@ -975,6 +981,12 @@ TEST_F(SharedCryptoTest, MAYBE(GenerateKeyHmacNoLength)) {
ASSERT_STATUS_SUCCESS(GenerateSecretKey(algorithm, true, 0, &key));
EXPECT_TRUE(key.handle());
EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type());
+ EXPECT_EQ(blink::WebCryptoAlgorithmIdHmac, key.algorithm().id());
+ EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1,
+ key.algorithm().hmacParams()->hash().id());
+#if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH)
+ EXPECT_EQ(512u, key.algorithm().hmacParams()->lengthBits());
+#endif
blink::WebArrayBuffer raw_key;
ASSERT_STATUS_SUCCESS(ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key));
EXPECT_EQ(64U, raw_key.byteLength());
@@ -982,8 +994,12 @@ TEST_F(SharedCryptoTest, MAYBE(GenerateKeyHmacNoLength)) {
// The block size for HMAC SHA-512 is larger.
algorithm = CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha512, 0);
ASSERT_STATUS_SUCCESS(GenerateSecretKey(algorithm, true, 0, &key));
+ EXPECT_EQ(blink::WebCryptoAlgorithmIdHmac, key.algorithm().id());
EXPECT_EQ(blink::WebCryptoAlgorithmIdSha512,
key.algorithm().hmacParams()->hash().id());
+#if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH)
+ EXPECT_EQ(1024u, key.algorithm().hmacParams()->lengthBits());
+#endif
ASSERT_STATUS_SUCCESS(ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key));
EXPECT_EQ(128U, raw_key.byteLength());
}
@@ -1360,6 +1376,9 @@ TEST_F(SharedCryptoTest, MAYBE(ImportJwkInputConsistency)) {
EXPECT_EQ(blink::WebCryptoAlgorithmIdHmac, key.algorithm().id());
EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256,
key.algorithm().hmacParams()->hash().id());
+#if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH)
+ EXPECT_EQ(320u, key.algorithm().hmacParams()->lengthBits());
+#endif
EXPECT_EQ(blink::WebCryptoKeyUsageVerify, key.usages());
key = blink::WebCryptoKey::createNull();
@@ -2618,6 +2637,9 @@ TEST_F(SharedCryptoTest, MAYBE(AesKwJwkSymkeyUnwrapKnownData)) {
EXPECT_EQ(blink::WebCryptoAlgorithmIdHmac, unwrapped_key.algorithm().id());
EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256,
unwrapped_key.algorithm().hmacParams()->hash().id());
+#if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH)
+ EXPECT_EQ(256u, unwrapped_key.algorithm().hmacParams()->lengthBits());
+#endif
EXPECT_EQ(true, unwrapped_key.extractable());
EXPECT_EQ(blink::WebCryptoKeyUsageVerify, unwrapped_key.usages());
« no previous file with comments | « no previous file | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698