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/openssl/rsa_key_openssl.h" | 5 #include "content/child/webcrypto/openssl/rsa_key_openssl.h" |
6 | 6 |
7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
8 #include <openssl/pkcs12.h> | 8 #include <openssl/pkcs12.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 crypto::ScopedRSA rsa(EVP_PKEY_get1_RSA(key)); | 72 crypto::ScopedRSA rsa(EVP_PKEY_get1_RSA(key)); |
73 if (!rsa.get()) | 73 if (!rsa.get()) |
74 return Status::ErrorUnexpected(); | 74 return Status::ErrorUnexpected(); |
75 | 75 |
76 unsigned int modulus_length_bits = BN_num_bits(rsa.get()->n); | 76 unsigned int modulus_length_bits = BN_num_bits(rsa.get()->n); |
77 | 77 |
78 // Convert the public exponent to big-endian representation. | 78 // Convert the public exponent to big-endian representation. |
79 std::vector<uint8_t> e(BN_num_bytes(rsa.get()->e)); | 79 std::vector<uint8_t> e(BN_num_bytes(rsa.get()->e)); |
80 if (e.size() == 0) | 80 if (e.size() == 0) |
81 return Status::ErrorUnexpected(); | 81 return Status::ErrorUnexpected(); |
82 if (static_cast<int>(e.size()) != BN_bn2bin(rsa.get()->e, &e[0])) | 82 if (e.size() != BN_bn2bin(rsa.get()->e, &e[0])) |
83 return Status::ErrorUnexpected(); | 83 return Status::ErrorUnexpected(); |
84 | 84 |
85 *key_algorithm = blink::WebCryptoKeyAlgorithm::createRsaHashed( | 85 *key_algorithm = blink::WebCryptoKeyAlgorithm::createRsaHashed( |
86 rsa_algorithm, modulus_length_bits, &e[0], e.size(), hash_algorithm); | 86 rsa_algorithm, modulus_length_bits, &e[0], e.size(), hash_algorithm); |
87 | 87 |
88 return Status::Success(); | 88 return Status::Success(); |
89 } | 89 } |
90 | 90 |
91 // Verifies that |key| is consistent with the input algorithm id, and creates a | 91 // Verifies that |key| is consistent with the input algorithm id, and creates a |
92 // blink::WebCryptoKeyAlgorithm describing the key. | 92 // blink::WebCryptoKeyAlgorithm describing the key. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 std::vector<uint8_t>* buffer) const { | 223 std::vector<uint8_t>* buffer) const { |
224 if (key.type() != blink::WebCryptoKeyTypePublic) | 224 if (key.type() != blink::WebCryptoKeyTypePublic) |
225 return Status::ErrorUnexpectedKeyType(); | 225 return Status::ErrorUnexpectedKeyType(); |
226 *buffer = AsymKeyOpenSsl::Cast(key)->serialized_key_data(); | 226 *buffer = AsymKeyOpenSsl::Cast(key)->serialized_key_data(); |
227 return Status::Success(); | 227 return Status::Success(); |
228 } | 228 } |
229 | 229 |
230 } // namespace webcrypto | 230 } // namespace webcrypto |
231 | 231 |
232 } // namespace content | 232 } // namespace content |
OLD | NEW |