| 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 | |
| 186 TEST_F(WebCryptoImplTest, DigestSampleSets) { | 183 TEST_F(WebCryptoImplTest, DigestSampleSets) { |
| 187 // The results are stored here in hex format for readability. | 184 // The results are stored here in hex format for readability. |
| 188 // | 185 // |
| 189 // TODO(bryaneyler): Eventually, all these sample test sets should be replaced | 186 // TODO(bryaneyler): Eventually, all these sample test sets should be replaced |
| 190 // with the sets here: http://csrc.nist.gov/groups/STM/cavp/index.html#03 | 187 // with the sets here: http://csrc.nist.gov/groups/STM/cavp/index.html#03 |
| 191 // | 188 // |
| 192 // Results were generated using the command sha{1,224,256,384,512}sum. | 189 // Results were generated using the command sha{1,224,256,384,512}sum. |
| 193 struct TestCase { | 190 struct TestCase { |
| 194 WebKit::WebCryptoAlgorithmId algorithm; | 191 WebKit::WebCryptoAlgorithmId algorithm; |
| 195 const std::string hex_input; | 192 const std::string hex_input; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 254 |
| 258 WebKit::WebCryptoAlgorithm algorithm = CreateAlgorithm(test.algorithm); | 255 WebKit::WebCryptoAlgorithm algorithm = CreateAlgorithm(test.algorithm); |
| 259 std::vector<uint8> input = HexStringToBytes(test.hex_input); | 256 std::vector<uint8> input = HexStringToBytes(test.hex_input); |
| 260 | 257 |
| 261 WebKit::WebArrayBuffer output; | 258 WebKit::WebArrayBuffer output; |
| 262 ASSERT_TRUE(DigestInternal(algorithm, input, &output)); | 259 ASSERT_TRUE(DigestInternal(algorithm, input, &output)); |
| 263 ExpectArrayBufferMatchesHex(test.hex_result, output); | 260 ExpectArrayBufferMatchesHex(test.hex_result, output); |
| 264 } | 261 } |
| 265 } | 262 } |
| 266 | 263 |
| 267 #endif // #if !defined(USE_OPENSSL) | 264 // TODO(padolph) Enable these tests for OpenSSL once matching impl is available |
| 265 #if !defined(USE_OPENSSL) |
| 268 | 266 |
| 269 TEST_F(WebCryptoImplTest, HMACSampleSets) { | 267 TEST_F(WebCryptoImplTest, HMACSampleSets) { |
| 270 struct TestCase { | 268 struct TestCase { |
| 271 WebKit::WebCryptoAlgorithmId algorithm; | 269 WebKit::WebCryptoAlgorithmId algorithm; |
| 272 const char* key; | 270 const char* key; |
| 273 const char* message; | 271 const char* message; |
| 274 const char* mac; | 272 const char* mac; |
| 275 }; | 273 }; |
| 276 | 274 |
| 277 const TestCase kTests[] = { | 275 const TestCase kTests[] = { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 algorithm, | 396 algorithm, |
| 399 key, | 397 key, |
| 400 kLongSignature, | 398 kLongSignature, |
| 401 sizeof(kLongSignature), | 399 sizeof(kLongSignature), |
| 402 message_raw, | 400 message_raw, |
| 403 &signature_match)); | 401 &signature_match)); |
| 404 EXPECT_FALSE(signature_match); | 402 EXPECT_FALSE(signature_match); |
| 405 } | 403 } |
| 406 } | 404 } |
| 407 | 405 |
| 408 // TODO(padolph) Enable these tests for OpenSSL once matching impl is available | |
| 409 #if !defined(USE_OPENSSL) | |
| 410 | |
| 411 TEST_F(WebCryptoImplTest, AesCbcFailures) { | 406 TEST_F(WebCryptoImplTest, AesCbcFailures) { |
| 412 WebKit::WebCryptoKey key = ImportSecretKeyFromRawHexString( | 407 WebKit::WebCryptoKey key = ImportSecretKeyFromRawHexString( |
| 413 "2b7e151628aed2a6abf7158809cf4f3c", | 408 "2b7e151628aed2a6abf7158809cf4f3c", |
| 414 CreateAlgorithm(WebKit::WebCryptoAlgorithmIdAesCbc), | 409 CreateAlgorithm(WebKit::WebCryptoAlgorithmIdAesCbc), |
| 415 WebKit::WebCryptoKeyUsageEncrypt | WebKit::WebCryptoKeyUsageDecrypt); | 410 WebKit::WebCryptoKeyUsageEncrypt | WebKit::WebCryptoKeyUsageDecrypt); |
| 416 | 411 |
| 417 WebKit::WebArrayBuffer output; | 412 WebKit::WebArrayBuffer output; |
| 418 | 413 |
| 419 // Use an invalid |iv| (fewer than 16 bytes) | 414 // Use an invalid |iv| (fewer than 16 bytes) |
| 420 { | 415 { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 &cipher_text[0], | 592 &cipher_text[0], |
| 598 cipher_text.size() - 3, | 593 cipher_text.size() - 3, |
| 599 &output)); | 594 &output)); |
| 600 } | 595 } |
| 601 } | 596 } |
| 602 } | 597 } |
| 603 | 598 |
| 604 #endif // !defined(USE_OPENSSL) | 599 #endif // !defined(USE_OPENSSL) |
| 605 | 600 |
| 606 } // namespace content | 601 } // namespace content |
| OLD | NEW |