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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 bool SignInternal( | 99 bool SignInternal( |
100 const WebKit::WebCryptoAlgorithm& algorithm, | 100 const WebKit::WebCryptoAlgorithm& algorithm, |
101 const WebKit::WebCryptoKey& key, | 101 const WebKit::WebCryptoKey& key, |
102 const unsigned char* data, | 102 const unsigned char* data, |
103 unsigned data_size, | 103 unsigned data_size, |
104 WebKit::WebArrayBuffer* buffer) { | 104 WebKit::WebArrayBuffer* buffer) { |
105 return crypto_.SignInternal(algorithm, key, data, data_size, buffer); | 105 return crypto_.SignInternal(algorithm, key, data, data_size, buffer); |
106 } | 106 } |
107 | 107 |
| 108 bool VerifySignatureInternal( |
| 109 const WebKit::WebCryptoAlgorithm& algorithm, |
| 110 const WebKit::WebCryptoKey& key, |
| 111 const unsigned char* signature, |
| 112 unsigned signature_size, |
| 113 const unsigned char* data, |
| 114 unsigned data_size, |
| 115 bool* signature_match) { |
| 116 return crypto_.VerifySignatureInternal(algorithm, |
| 117 key, |
| 118 signature, |
| 119 signature_size, |
| 120 data, |
| 121 data_size, |
| 122 signature_match); |
| 123 } |
| 124 |
108 private: | 125 private: |
109 WebCryptoImpl crypto_; | 126 WebCryptoImpl crypto_; |
110 }; | 127 }; |
111 | 128 |
112 TEST_F(WebCryptoImplTest, DigestSampleSets) { | 129 TEST_F(WebCryptoImplTest, DigestSampleSets) { |
113 // The results are stored here in hex format for readability. | 130 // The results are stored here in hex format for readability. |
114 // | 131 // |
115 // TODO(bryaneyler): Eventually, all these sample test sets should be replaced | 132 // TODO(bryaneyler): Eventually, all these sample test sets should be replaced |
116 // with the sets here: http://csrc.nist.gov/groups/STM/cavp/index.html#03 | 133 // with the sets here: http://csrc.nist.gov/groups/STM/cavp/index.html#03 |
117 // | 134 // |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 test.key, algorithm, WebKit::WebCryptoKeyUsageSign); | 306 test.key, algorithm, WebKit::WebCryptoKeyUsageSign); |
290 | 307 |
291 std::vector<uint8> message_raw = HexStringToBytes(test.message); | 308 std::vector<uint8> message_raw = HexStringToBytes(test.message); |
292 | 309 |
293 WebKit::WebArrayBuffer output; | 310 WebKit::WebArrayBuffer output; |
294 | 311 |
295 ASSERT_TRUE(SignInternal( | 312 ASSERT_TRUE(SignInternal( |
296 algorithm, key, message_raw.data(), message_raw.size(), &output)); | 313 algorithm, key, message_raw.data(), message_raw.size(), &output)); |
297 | 314 |
298 ExpectArrayBufferMatchesHex(test.mac, output); | 315 ExpectArrayBufferMatchesHex(test.mac, output); |
| 316 |
| 317 bool signature_match = false; |
| 318 EXPECT_TRUE(VerifySignatureInternal( |
| 319 algorithm, |
| 320 key, |
| 321 static_cast<const unsigned char*>(output.data()), |
| 322 output.byteLength(), |
| 323 message_raw.data(), |
| 324 message_raw.size(), |
| 325 &signature_match)); |
| 326 EXPECT_TRUE(signature_match); |
| 327 |
| 328 // Ensure truncated signature does not verify by passing one less byte. |
| 329 EXPECT_TRUE(VerifySignatureInternal( |
| 330 algorithm, |
| 331 key, |
| 332 static_cast<const unsigned char*>(output.data()), |
| 333 output.byteLength() - 1, |
| 334 message_raw.data(), |
| 335 message_raw.size(), |
| 336 &signature_match)); |
| 337 EXPECT_FALSE(signature_match); |
| 338 |
| 339 // Ensure extra long signature does not cause issues and fails. |
| 340 const unsigned char kLongSignature[1024] = { 0 }; |
| 341 EXPECT_TRUE(VerifySignatureInternal( |
| 342 algorithm, |
| 343 key, |
| 344 kLongSignature, |
| 345 sizeof(kLongSignature), |
| 346 message_raw.data(), |
| 347 message_raw.size(), |
| 348 &signature_match)); |
| 349 EXPECT_FALSE(signature_match); |
299 } | 350 } |
300 } | 351 } |
301 | 352 |
302 } // namespace content | 353 } // namespace content |
OLD | NEW |