Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/stl_util.h" | 5 #include "base/stl_util.h" |
| 6 #include "content/child/webcrypto/algorithm_dispatch.h" | 6 #include "content/child/webcrypto/algorithm_dispatch.h" |
| 7 #include "content/child/webcrypto/crypto_data.h" | 7 #include "content/child/webcrypto/crypto_data.h" |
| 8 #include "content/child/webcrypto/jwk.h" | 8 #include "content/child/webcrypto/jwk.h" |
| 9 #include "content/child/webcrypto/status.h" | 9 #include "content/child/webcrypto/status.h" |
| 10 #include "content/child/webcrypto/test/test_helpers.h" | 10 #include "content/child/webcrypto/test/test_helpers.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 | 121 |
| 122 EXPECT_EQ(CryptoData(expected_bytes), CryptoData(derived_bytes)); | 122 EXPECT_EQ(CryptoData(expected_bytes), CryptoData(derived_bytes)); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Loads up a test ECDH public and private key for P-521. The keys | 126 // Loads up a test ECDH public and private key for P-521. The keys |
| 127 // come from different key pairs, and can be used for key derivation of up to | 127 // come from different key pairs, and can be used for key derivation of up to |
| 128 // 528 bits. | 128 // 528 bits. |
| 129 void LoadTestKeys(blink::WebCryptoKey* public_key, | 129 void LoadTestKeys(blink::WebCryptoKey* public_key, |
| 130 blink::WebCryptoKey* private_key) { | 130 blink::WebCryptoKey* private_key) { |
| 131 // Assume that the 7th key in the test data is for P-521. | |
| 132 scoped_ptr<base::ListValue> tests; | 131 scoped_ptr<base::ListValue> tests; |
| 133 ASSERT_TRUE(ReadJsonTestFileToList("ecdh.json", &tests)); | 132 ASSERT_TRUE(ReadJsonTestFileToList("ecdh.json", &tests)); |
| 134 | 133 |
| 135 const base::DictionaryValue* test; | 134 const base::DictionaryValue* test; |
|
eroman
2014/12/22 17:56:07
This does not handle the case where the property i
Habib Virji
2014/12/23 10:59:05
I have added now, assert failure if it fails to fi
| |
| 136 ASSERT_TRUE(tests->GetDictionary(6, &test)); | 135 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { |
| 136 SCOPED_TRACE(test_index); | |
| 137 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); | |
| 138 int result = 0; | |
| 139 test->GetInteger("load_p521_test_keys", &result); | |
| 140 if (result) | |
| 141 break; | |
| 142 } | |
| 137 | 143 |
| 138 ImportKeysFromTest(test, public_key, private_key); | 144 ImportKeysFromTest(test, public_key, private_key); |
| 139 | 145 |
| 140 ASSERT_EQ(blink::WebCryptoNamedCurveP521, | 146 ASSERT_EQ(blink::WebCryptoNamedCurveP521, |
| 141 public_key->algorithm().ecParams()->namedCurve()); | 147 public_key->algorithm().ecParams()->namedCurve()); |
| 142 } | 148 } |
| 143 | 149 |
| 144 // Try deriving an AES key of length 129 bits. | 150 // Try deriving an AES key of length 129 bits. |
| 145 TEST(WebCryptoEcdhTest, DeriveKeyBadAesLength) { | 151 TEST(WebCryptoEcdhTest, DeriveKeyBadAesLength) { |
| 146 if (!SupportsEcdh()) | 152 if (!SupportsEcdh()) |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 CryptoData(MakeJsonVector(*private_key_json)), | 354 CryptoData(MakeJsonVector(*private_key_json)), |
| 349 CreateEcdhImportAlgorithm(curve), true, | 355 CreateEcdhImportAlgorithm(curve), true, |
| 350 0, &key)); | 356 0, &key)); |
| 351 } | 357 } |
| 352 | 358 |
| 353 } // namespace | 359 } // namespace |
| 354 | 360 |
| 355 } // namespace webcrypto | 361 } // namespace webcrypto |
| 356 | 362 |
| 357 } // namespace content | 363 } // namespace content |
| OLD | NEW |