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/bn.h> | 7 #include <openssl/bn.h> |
8 #include <openssl/bytestring.h> | 8 #include <openssl/bytestring.h> |
9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
10 #include <openssl/mem.h> | 10 #include <openssl/mem.h> |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 ScopedRSA rsa(EVP_PKEY_get1_RSA(key_)); | 80 ScopedRSA rsa(EVP_PKEY_get1_RSA(key_)); |
81 if (!rsa) | 81 if (!rsa) |
82 return NULL; | 82 return NULL; |
83 copy->key_ = EVP_PKEY_new(); | 83 copy->key_ = EVP_PKEY_new(); |
84 if (!EVP_PKEY_set1_RSA(copy->key_, rsa.get())) | 84 if (!EVP_PKEY_set1_RSA(copy->key_, rsa.get())) |
85 return NULL; | 85 return NULL; |
86 return copy.release(); | 86 return copy.release(); |
87 } | 87 } |
88 | 88 |
89 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8_t>* output) const { | 89 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8_t>* output) const { |
| 90 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
90 uint8_t *der; | 91 uint8_t *der; |
91 size_t der_len; | 92 size_t der_len; |
92 AutoCBB cbb; | 93 AutoCBB cbb; |
93 if (!CBB_init(cbb.get(), 0) || | 94 if (!CBB_init(cbb.get(), 0) || |
94 !EVP_marshal_private_key(cbb.get(), key_) || | 95 !EVP_marshal_private_key(cbb.get(), key_) || |
95 !CBB_finish(cbb.get(), &der, &der_len)) { | 96 !CBB_finish(cbb.get(), &der, &der_len)) { |
96 return false; | 97 return false; |
97 } | 98 } |
98 output->assign(der, der + der_len); | 99 output->assign(der, der + der_len); |
99 OPENSSL_free(der); | 100 OPENSSL_free(der); |
100 return true; | 101 return true; |
101 } | 102 } |
102 | 103 |
103 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8_t>* output) const { | 104 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8_t>* output) const { |
| 105 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
104 uint8_t *der; | 106 uint8_t *der; |
105 size_t der_len; | 107 size_t der_len; |
106 AutoCBB cbb; | 108 AutoCBB cbb; |
107 if (!CBB_init(cbb.get(), 0) || | 109 if (!CBB_init(cbb.get(), 0) || |
108 !EVP_marshal_public_key(cbb.get(), key_) || | 110 !EVP_marshal_public_key(cbb.get(), key_) || |
109 !CBB_finish(cbb.get(), &der, &der_len)) { | 111 !CBB_finish(cbb.get(), &der, &der_len)) { |
110 return false; | 112 return false; |
111 } | 113 } |
112 output->assign(der, der + der_len); | 114 output->assign(der, der + der_len); |
113 OPENSSL_free(der); | 115 OPENSSL_free(der); |
114 return true; | 116 return true; |
115 } | 117 } |
116 | 118 |
117 } // namespace crypto | 119 } // namespace crypto |
OLD | NEW |