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

Side by Side Diff: content/renderer/webcrypto/shared_crypto_unittest.cc

Issue 187103003: [webcrypto] Change HMAC key generation length from bytes to bits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/webcrypto/shared_crypto.h" 5 #include "content/renderer/webcrypto/shared_crypto.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 iv.size(), 101 iv.size(),
102 true, 102 true,
103 Uint8VectorStart(additional_data), 103 Uint8VectorStart(additional_data),
104 additional_data.size(), 104 additional_data.size(),
105 true, 105 true,
106 tag_length_bits)); 106 tag_length_bits));
107 } 107 }
108 108
109 // Creates an HMAC algorithm whose parameters struct is compatible with key 109 // Creates an HMAC algorithm whose parameters struct is compatible with key
110 // generation. It is an error to call this with a hash_id that is not a SHA*. 110 // generation. It is an error to call this with a hash_id that is not a SHA*.
111 // The key_length_bytes parameter is optional, with zero meaning unspecified. 111 // The key_length_bits parameter is optional, with zero meaning unspecified.
112 blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm( 112 blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm(
113 blink::WebCryptoAlgorithmId hash_id, 113 blink::WebCryptoAlgorithmId hash_id,
114 unsigned int key_length_bytes) { 114 unsigned int key_length_bits) {
115 #ifndef WEBCRYPTO_HMAC_BITS
Ryan Sleevi 2014/03/06 21:51:37 !defined
eroman 2014/03/06 21:54:18 Done.
116 // TODO(eroman): Delete
117 key_length_bits /= 8;
118 #endif
115 DCHECK(IsHashAlgorithm(hash_id)); 119 DCHECK(IsHashAlgorithm(hash_id));
116 // key_length_bytes == 0 means unspecified 120 // key_length_bytes == 0 means unspecified
117 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( 121 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
118 blink::WebCryptoAlgorithmIdHmac, 122 blink::WebCryptoAlgorithmIdHmac,
119 new blink::WebCryptoHmacKeyGenParams( 123 new blink::WebCryptoHmacKeyGenParams(
120 CreateAlgorithm(hash_id), (key_length_bytes != 0), key_length_bytes)); 124 CreateAlgorithm(hash_id), (key_length_bits != 0), key_length_bits));
121 } 125 }
122 126
123 // Returns a slightly modified version of the input vector. 127 // Returns a slightly modified version of the input vector.
124 // 128 //
125 // - For non-empty inputs a single bit is inverted. 129 // - For non-empty inputs a single bit is inverted.
126 // - For empty inputs, a byte is added. 130 // - For empty inputs, a byte is added.
127 std::vector<uint8> Corrupted(const std::vector<uint8>& input) { 131 std::vector<uint8> Corrupted(const std::vector<uint8>& input) {
128 std::vector<uint8> corrupted_data(input); 132 std::vector<uint8> corrupted_data(input);
129 if (corrupted_data.empty()) 133 if (corrupted_data.empty())
130 corrupted_data.push_back(0); 134 corrupted_data.push_back(0);
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 } 862 }
859 } 863 }
860 864
861 TEST_F(SharedCryptoTest, MAYBE(GenerateKeyHmac)) { 865 TEST_F(SharedCryptoTest, MAYBE(GenerateKeyHmac)) {
862 // Generate a small sample of HMAC keys. 866 // Generate a small sample of HMAC keys.
863 std::vector<blink::WebArrayBuffer> keys; 867 std::vector<blink::WebArrayBuffer> keys;
864 for (int i = 0; i < 16; ++i) { 868 for (int i = 0; i < 16; ++i) {
865 blink::WebArrayBuffer key_bytes; 869 blink::WebArrayBuffer key_bytes;
866 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); 870 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
867 blink::WebCryptoAlgorithm algorithm = 871 blink::WebCryptoAlgorithm algorithm =
868 CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha1, 64); 872 CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha1, 512);
869 ASSERT_STATUS_SUCCESS(GenerateSecretKey(algorithm, true, 0, &key)); 873 ASSERT_STATUS_SUCCESS(GenerateSecretKey(algorithm, true, 0, &key));
870 EXPECT_FALSE(key.isNull()); 874 EXPECT_FALSE(key.isNull());
871 EXPECT_TRUE(key.handle()); 875 EXPECT_TRUE(key.handle());
872 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); 876 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type());
873 EXPECT_EQ(blink::WebCryptoAlgorithmIdHmac, key.algorithm().id()); 877 EXPECT_EQ(blink::WebCryptoAlgorithmIdHmac, key.algorithm().id());
874 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, 878 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1,
875 key.algorithm().hmacParams()->hash().id()); 879 key.algorithm().hmacParams()->hash().id());
876 880
877 blink::WebArrayBuffer raw_key; 881 blink::WebArrayBuffer raw_key;
878 ASSERT_STATUS_SUCCESS( 882 ASSERT_STATUS_SUCCESS(
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
2136 test_cipher_text, 2140 test_cipher_text,
2137 test_authentication_tag, 2141 test_authentication_tag,
2138 &plain_text)); 2142 &plain_text));
2139 } 2143 }
2140 } 2144 }
2141 } 2145 }
2142 2146
2143 } // namespace webcrypto 2147 } // namespace webcrypto
2144 2148
2145 } // namespace content 2149 } // namespace content
OLDNEW
« content/renderer/webcrypto/shared_crypto.cc ('K') | « content/renderer/webcrypto/shared_crypto.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698