| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "webcrypto_impl.h" | 5 #include "webcrypto_impl.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 const std::vector<uint8>& data, | 173 const std::vector<uint8>& data, |
| 174 WebKit::WebArrayBuffer* buffer) { | 174 WebKit::WebArrayBuffer* buffer) { |
| 175 return crypto_.DecryptInternal( | 175 return crypto_.DecryptInternal( |
| 176 algorithm, key, Start(data), data.size(), buffer); | 176 algorithm, key, Start(data), data.size(), buffer); |
| 177 } | 177 } |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 WebCryptoImpl crypto_; | 180 WebCryptoImpl crypto_; |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 // TODO(padolph) Enable these tests for OpenSSL once matching impl is available |
| 184 #if !defined(USE_OPENSSL) |
| 185 |
| 183 TEST_F(WebCryptoImplTest, DigestSampleSets) { | 186 TEST_F(WebCryptoImplTest, DigestSampleSets) { |
| 184 // The results are stored here in hex format for readability. | 187 // The results are stored here in hex format for readability. |
| 185 // | 188 // |
| 186 // TODO(bryaneyler): Eventually, all these sample test sets should be replaced | 189 // TODO(bryaneyler): Eventually, all these sample test sets should be replaced |
| 187 // with the sets here: http://csrc.nist.gov/groups/STM/cavp/index.html#03 | 190 // with the sets here: http://csrc.nist.gov/groups/STM/cavp/index.html#03 |
| 188 // | 191 // |
| 189 // Results were generated using the command sha{1,224,256,384,512}sum. | 192 // Results were generated using the command sha{1,224,256,384,512}sum. |
| 190 struct TestCase { | 193 struct TestCase { |
| 191 WebKit::WebCryptoAlgorithmId algorithm; | 194 WebKit::WebCryptoAlgorithmId algorithm; |
| 192 const std::string hex_input; | 195 const std::string hex_input; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 257 |
| 255 WebKit::WebCryptoAlgorithm algorithm = CreateAlgorithm(test.algorithm); | 258 WebKit::WebCryptoAlgorithm algorithm = CreateAlgorithm(test.algorithm); |
| 256 std::vector<uint8> input = HexStringToBytes(test.hex_input); | 259 std::vector<uint8> input = HexStringToBytes(test.hex_input); |
| 257 | 260 |
| 258 WebKit::WebArrayBuffer output; | 261 WebKit::WebArrayBuffer output; |
| 259 ASSERT_TRUE(DigestInternal(algorithm, input, &output)); | 262 ASSERT_TRUE(DigestInternal(algorithm, input, &output)); |
| 260 ExpectArrayBufferMatchesHex(test.hex_result, output); | 263 ExpectArrayBufferMatchesHex(test.hex_result, output); |
| 261 } | 264 } |
| 262 } | 265 } |
| 263 | 266 |
| 267 #endif // #if !defined(USE_OPENSSL) |
| 268 |
| 264 TEST_F(WebCryptoImplTest, HMACSampleSets) { | 269 TEST_F(WebCryptoImplTest, HMACSampleSets) { |
| 265 struct TestCase { | 270 struct TestCase { |
| 266 WebKit::WebCryptoAlgorithmId algorithm; | 271 WebKit::WebCryptoAlgorithmId algorithm; |
| 267 const char* key; | 272 const char* key; |
| 268 const char* message; | 273 const char* message; |
| 269 const char* mac; | 274 const char* mac; |
| 270 }; | 275 }; |
| 271 | 276 |
| 272 const TestCase kTests[] = { | 277 const TestCase kTests[] = { |
| 273 // Empty sets. Result generated via OpenSSL commandline tool. These | 278 // Empty sets. Result generated via OpenSSL commandline tool. These |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 algorithm, | 398 algorithm, |
| 394 key, | 399 key, |
| 395 kLongSignature, | 400 kLongSignature, |
| 396 sizeof(kLongSignature), | 401 sizeof(kLongSignature), |
| 397 message_raw, | 402 message_raw, |
| 398 &signature_match)); | 403 &signature_match)); |
| 399 EXPECT_FALSE(signature_match); | 404 EXPECT_FALSE(signature_match); |
| 400 } | 405 } |
| 401 } | 406 } |
| 402 | 407 |
| 408 // TODO(padolph) Enable these tests for OpenSSL once matching impl is available |
| 409 #if !defined(USE_OPENSSL) |
| 410 |
| 403 TEST_F(WebCryptoImplTest, AesCbcFailures) { | 411 TEST_F(WebCryptoImplTest, AesCbcFailures) { |
| 404 WebKit::WebCryptoKey key = ImportSecretKeyFromRawHexString( | 412 WebKit::WebCryptoKey key = ImportSecretKeyFromRawHexString( |
| 405 "2b7e151628aed2a6abf7158809cf4f3c", | 413 "2b7e151628aed2a6abf7158809cf4f3c", |
| 406 CreateAlgorithm(WebKit::WebCryptoAlgorithmIdAesCbc), | 414 CreateAlgorithm(WebKit::WebCryptoAlgorithmIdAesCbc), |
| 407 WebKit::WebCryptoKeyUsageEncrypt | WebKit::WebCryptoKeyUsageDecrypt); | 415 WebKit::WebCryptoKeyUsageEncrypt | WebKit::WebCryptoKeyUsageDecrypt); |
| 408 | 416 |
| 409 WebKit::WebArrayBuffer output; | 417 WebKit::WebArrayBuffer output; |
| 410 | 418 |
| 411 // Use an invalid |iv| (fewer than 16 bytes) | 419 // Use an invalid |iv| (fewer than 16 bytes) |
| 412 { | 420 { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 if (cipher_text.size() > 3) { | 594 if (cipher_text.size() > 3) { |
| 587 EXPECT_FALSE(DecryptInternal(CreateAesCbcAlgorithm(iv), | 595 EXPECT_FALSE(DecryptInternal(CreateAesCbcAlgorithm(iv), |
| 588 key, | 596 key, |
| 589 &cipher_text[0], | 597 &cipher_text[0], |
| 590 cipher_text.size() - 3, | 598 cipher_text.size() - 3, |
| 591 &output)); | 599 &output)); |
| 592 } | 600 } |
| 593 } | 601 } |
| 594 } | 602 } |
| 595 | 603 |
| 604 #endif // !defined(USE_OPENSSL) |
| 605 |
| 596 } // namespace content | 606 } // namespace content |
| OLD | NEW |