| 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/child/webcrypto/platform_crypto.h" | 5 #include "content/child/webcrypto/platform_crypto.h" |
| 6 | 6 |
| 7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
| 8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
| 9 #include <secerr.h> | 9 #include <secerr.h> |
| 10 #include <sechash.h> | 10 #include <sechash.h> |
| (...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 return AesGcmEncryptDecrypt( | 1433 return AesGcmEncryptDecrypt( |
| 1434 mode, key, data, iv, additional_data, tag_length_bits, buffer); | 1434 mode, key, data, iv, additional_data, tag_length_bits, buffer); |
| 1435 } | 1435 } |
| 1436 | 1436 |
| 1437 // ----------------------------------- | 1437 // ----------------------------------- |
| 1438 // Key generation | 1438 // Key generation |
| 1439 // ----------------------------------- | 1439 // ----------------------------------- |
| 1440 | 1440 |
| 1441 Status GenerateRsaKeyPair(const blink::WebCryptoAlgorithm& algorithm, | 1441 Status GenerateRsaKeyPair(const blink::WebCryptoAlgorithm& algorithm, |
| 1442 bool extractable, | 1442 bool extractable, |
| 1443 blink::WebCryptoKeyUsageMask usage_mask, | 1443 blink::WebCryptoKeyUsageMask public_key_usage_mask, |
| 1444 blink::WebCryptoKeyUsageMask private_key_usage_mask, |
| 1444 unsigned int modulus_length_bits, | 1445 unsigned int modulus_length_bits, |
| 1445 const CryptoData& public_exponent, | 1446 const CryptoData& public_exponent, |
| 1446 blink::WebCryptoKey* public_key, | 1447 blink::WebCryptoKey* public_key, |
| 1447 blink::WebCryptoKey* private_key) { | 1448 blink::WebCryptoKey* private_key) { |
| 1448 if (algorithm.id() == blink::WebCryptoAlgorithmIdRsaOaep && | 1449 if (algorithm.id() == blink::WebCryptoAlgorithmIdRsaOaep && |
| 1449 !g_nss_runtime_support.Get().IsRsaOaepSupported()) { | 1450 !g_nss_runtime_support.Get().IsRsaOaepSupported()) { |
| 1450 return Status::ErrorUnsupported(); | 1451 return Status::ErrorUnsupported(); |
| 1451 } | 1452 } |
| 1452 | 1453 |
| 1453 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot()); | 1454 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 scoped_ptr<PrivateKey> private_key_handle; | 1517 scoped_ptr<PrivateKey> private_key_handle; |
| 1517 status = PrivateKey::Create( | 1518 status = PrivateKey::Create( |
| 1518 scoped_sec_private_key.Pass(), key_algorithm, &private_key_handle); | 1519 scoped_sec_private_key.Pass(), key_algorithm, &private_key_handle); |
| 1519 if (status.IsError()) | 1520 if (status.IsError()) |
| 1520 return status; | 1521 return status; |
| 1521 | 1522 |
| 1522 *public_key = blink::WebCryptoKey::create(public_key_handle.release(), | 1523 *public_key = blink::WebCryptoKey::create(public_key_handle.release(), |
| 1523 blink::WebCryptoKeyTypePublic, | 1524 blink::WebCryptoKeyTypePublic, |
| 1524 true, | 1525 true, |
| 1525 key_algorithm, | 1526 key_algorithm, |
| 1526 usage_mask); | 1527 public_key_usage_mask); |
| 1527 *private_key = blink::WebCryptoKey::create(private_key_handle.release(), | 1528 *private_key = blink::WebCryptoKey::create(private_key_handle.release(), |
| 1528 blink::WebCryptoKeyTypePrivate, | 1529 blink::WebCryptoKeyTypePrivate, |
| 1529 extractable, | 1530 extractable, |
| 1530 key_algorithm, | 1531 key_algorithm, |
| 1531 usage_mask); | 1532 private_key_usage_mask); |
| 1532 | 1533 |
| 1533 return Status::Success(); | 1534 return Status::Success(); |
| 1534 } | 1535 } |
| 1535 | 1536 |
| 1536 void Init() { | 1537 void Init() { |
| 1537 crypto::EnsureNSSInit(); | 1538 crypto::EnsureNSSInit(); |
| 1538 } | 1539 } |
| 1539 | 1540 |
| 1540 Status DigestSha(blink::WebCryptoAlgorithmId algorithm, | 1541 Status DigestSha(blink::WebCryptoAlgorithmId algorithm, |
| 1541 const CryptoData& data, | 1542 const CryptoData& data, |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1862 buffer->assign(key_data->data, key_data->data + key_data->len); | 1863 buffer->assign(key_data->data, key_data->data + key_data->len); |
| 1863 | 1864 |
| 1864 return Status::Success(); | 1865 return Status::Success(); |
| 1865 } | 1866 } |
| 1866 | 1867 |
| 1867 } // namespace platform | 1868 } // namespace platform |
| 1868 | 1869 |
| 1869 } // namespace webcrypto | 1870 } // namespace webcrypto |
| 1870 | 1871 |
| 1871 } // namespace content | 1872 } // namespace content |
| OLD | NEW |