| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "crypto/rsa_private_key.h" | 5 #include "crypto/rsa_private_key.h" |
| 6 | 6 |
| 7 #include <openssl/bio.h> | 7 #include <openssl/bio.h> |
| 8 #include <openssl/bn.h> | 8 #include <openssl/bn.h> |
| 9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
| 10 #include <openssl/pkcs12.h> | 10 #include <openssl/pkcs12.h> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // PKCS#8 decode the input, and then import the EVP_PKEY from Private Key | 84 // PKCS#8 decode the input, and then import the EVP_PKEY from Private Key |
| 85 // Info structure returned. | 85 // Info structure returned. |
| 86 const uint8_t* ptr = &input[0]; | 86 const uint8_t* ptr = &input[0]; |
| 87 ScopedPKCS8_PRIV_KEY_INFO p8inf( | 87 ScopedPKCS8_PRIV_KEY_INFO p8inf( |
| 88 d2i_PKCS8_PRIV_KEY_INFO(nullptr, &ptr, input.size())); | 88 d2i_PKCS8_PRIV_KEY_INFO(nullptr, &ptr, input.size())); |
| 89 if (!p8inf.get() || ptr != &input[0] + input.size()) | 89 if (!p8inf.get() || ptr != &input[0] + input.size()) |
| 90 return NULL; | 90 return NULL; |
| 91 | 91 |
| 92 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); | 92 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); |
| 93 result->key_ = EVP_PKCS82PKEY(p8inf.get()); | 93 result->key_ = EVP_PKCS82PKEY(p8inf.get()); |
| 94 if (!result->key_) | 94 if (!result->key_ || EVP_PKEY_id(result->key_) != EVP_PKEY_RSA) |
| 95 return NULL; | 95 return NULL; |
| 96 | 96 |
| 97 return result.release(); | 97 return result.release(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // static | 100 // static |
| 101 RSAPrivateKey* RSAPrivateKey::CreateFromKey(EVP_PKEY* key) { | 101 RSAPrivateKey* RSAPrivateKey::CreateFromKey(EVP_PKEY* key) { |
| 102 DCHECK(key); | 102 DCHECK(key); |
| 103 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA) | 103 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA) |
| 104 return NULL; | 104 return NULL; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 129 | 129 |
| 130 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { | 130 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { |
| 131 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); | 131 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { | 134 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { |
| 135 return ExportKey(key_, i2d_PUBKEY_bio, output); | 135 return ExportKey(key_, i2d_PUBKEY_bio, output); |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace crypto | 138 } // namespace crypto |
| OLD | NEW |