| 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 "content/renderer/webcrypto/webcrypto_impl.h" | 5 #include "content/renderer/webcrypto/webcrypto_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 294 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 295 Status status = crypto_.ImportKeyInternal( | 295 Status status = crypto_.ImportKeyInternal( |
| 296 blink::WebCryptoKeyFormatRaw, | 296 blink::WebCryptoKeyFormatRaw, |
| 297 webcrypto::Uint8VectorStart(key_raw), | 297 webcrypto::Uint8VectorStart(key_raw), |
| 298 key_raw.size(), | 298 key_raw.size(), |
| 299 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm), | 299 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm), |
| 300 true, | 300 true, |
| 301 blink::WebCryptoKeyUsageEncrypt, | 301 blink::WebCryptoKeyUsageEncrypt, |
| 302 &key); | 302 &key); |
| 303 | 303 |
| 304 if (status.IsError()) { | 304 if (status.IsError()) |
| 305 EXPECT_EQ(Status::ErrorUnsupported().ToString(), status.ToString()); | 305 EXPECT_EQ(Status::ErrorUnsupported().ToString(), status.ToString()); |
| 306 } | |
| 307 return status.IsSuccess(); | 306 return status.IsSuccess(); |
| 308 | 307 |
| 309 } | 308 } |
| 310 | 309 |
| 311 Status AesGcmEncrypt(const blink::WebCryptoKey& key, | 310 Status AesGcmEncrypt(const blink::WebCryptoKey& key, |
| 312 const std::vector<uint8>& iv, | 311 const std::vector<uint8>& iv, |
| 313 const std::vector<uint8>& additional_data, | 312 const std::vector<uint8>& additional_data, |
| 314 unsigned tag_length_bits, | 313 unsigned tag_length_bits, |
| 315 const std::vector<uint8>& plain_text, | 314 const std::vector<uint8>& plain_text, |
| 316 std::vector<uint8>* cipher_text, | 315 std::vector<uint8>* cipher_text, |
| 317 std::vector<uint8>* authentication_tag) { | 316 std::vector<uint8>* authentication_tag) { |
| 318 blink::WebCryptoAlgorithm algorithm = CreateAesGcmAlgorithm( | 317 blink::WebCryptoAlgorithm algorithm = CreateAesGcmAlgorithm( |
| 319 iv, additional_data, tag_length_bits); | 318 iv, additional_data, tag_length_bits); |
| 320 | 319 |
| 321 blink::WebArrayBuffer output; | 320 blink::WebArrayBuffer output; |
| 322 Status status = EncryptInternal(algorithm, key, plain_text, &output); | 321 Status status = EncryptInternal(algorithm, key, plain_text, &output); |
| 323 if (status.IsError()) { | 322 if (status.IsError()) |
| 324 return status; | 323 return status; |
| 325 } | |
| 326 | 324 |
| 327 if (output.byteLength() * 8 < tag_length_bits) { | 325 if (output.byteLength() * 8 < tag_length_bits) { |
| 328 EXPECT_TRUE(false); | 326 EXPECT_TRUE(false); |
| 329 return Status::Error(); | 327 return Status::Error(); |
| 330 } | 328 } |
| 331 | 329 |
| 332 // The encryption result is cipher text with authentication tag appended. | 330 // The encryption result is cipher text with authentication tag appended. |
| 333 cipher_text->assign( | 331 cipher_text->assign( |
| 334 static_cast<uint8*>(output.data()), | 332 static_cast<uint8*>(output.data()), |
| 335 static_cast<uint8*>(output.data()) + | 333 static_cast<uint8*>(output.data()) + |
| (...skipping 2243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2579 if (test_tag_size_bits == wrong_tag_size_bits) | 2577 if (test_tag_size_bits == wrong_tag_size_bits) |
| 2580 continue; | 2578 continue; |
| 2581 EXPECT_STATUS_ERROR(AesGcmDecrypt(key, test_iv, test_additional_data, | 2579 EXPECT_STATUS_ERROR(AesGcmDecrypt(key, test_iv, test_additional_data, |
| 2582 wrong_tag_size_bits, test_cipher_text, | 2580 wrong_tag_size_bits, test_cipher_text, |
| 2583 test_authentication_tag, &plain_text)); | 2581 test_authentication_tag, &plain_text)); |
| 2584 } | 2582 } |
| 2585 } | 2583 } |
| 2586 } | 2584 } |
| 2587 | 2585 |
| 2588 } // namespace content | 2586 } // namespace content |
| OLD | NEW |