Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: crypto/ec_private_key.cc

Issue 2113143004: Switch to OpenSSL's |EVP_PKEY_up_ref| signature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | crypto/rsa_private_key.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ec_private_key.h" 5 #include "crypto/ec_private_key.h"
6 6
7 #include <openssl/bytestring.h> 7 #include <openssl/bytestring.h>
8 #include <openssl/ec.h> 8 #include <openssl/ec.h>
9 #include <openssl/evp.h> 9 #include <openssl/evp.h>
10 #include <openssl/mem.h> 10 #include <openssl/mem.h>
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 std::unique_ptr<ECPrivateKey> result(new ECPrivateKey()); 139 std::unique_ptr<ECPrivateKey> result(new ECPrivateKey());
140 result->key_ = EVP_PKCS82PKEY(p8_decrypted.get()); 140 result->key_ = EVP_PKCS82PKEY(p8_decrypted.get());
141 if (!result->key_ || EVP_PKEY_id(result->key_) != EVP_PKEY_EC) 141 if (!result->key_ || EVP_PKEY_id(result->key_) != EVP_PKEY_EC)
142 return nullptr; 142 return nullptr;
143 143
144 return result; 144 return result;
145 } 145 }
146 146
147 std::unique_ptr<ECPrivateKey> ECPrivateKey::Copy() const { 147 std::unique_ptr<ECPrivateKey> ECPrivateKey::Copy() const {
148 std::unique_ptr<ECPrivateKey> copy(new ECPrivateKey()); 148 std::unique_ptr<ECPrivateKey> copy(new ECPrivateKey());
149 if (key_) 149 if (key_) {
150 copy->key_ = EVP_PKEY_up_ref(key_); 150 EVP_PKEY_up_ref(key_);
151 copy->key_ = key_;
152 }
151 return copy; 153 return copy;
152 } 154 }
153 155
154 bool ECPrivateKey::ExportPrivateKey(std::vector<uint8_t>* output) const { 156 bool ECPrivateKey::ExportPrivateKey(std::vector<uint8_t>* output) const {
155 OpenSSLErrStackTracer err_tracer(FROM_HERE); 157 OpenSSLErrStackTracer err_tracer(FROM_HERE);
156 uint8_t* der; 158 uint8_t* der;
157 size_t der_len; 159 size_t der_len;
158 AutoCBB cbb; 160 AutoCBB cbb;
159 if (!CBB_init(cbb.get(), 0) || !EVP_marshal_private_key(cbb.get(), key_) || 161 if (!CBB_init(cbb.get(), 0) || !EVP_marshal_private_key(cbb.get(), key_) ||
160 !CBB_finish(cbb.get(), &der, &der_len)) { 162 !CBB_finish(cbb.get(), &der, &der_len)) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 return false; 232 return false;
231 } 233 }
232 234
233 output->assign(reinterpret_cast<const char*>(buf), sizeof(buf)); 235 output->assign(reinterpret_cast<const char*>(buf), sizeof(buf));
234 return true; 236 return true;
235 } 237 }
236 238
237 ECPrivateKey::ECPrivateKey() : key_(nullptr) {} 239 ECPrivateKey::ECPrivateKey() : key_(nullptr) {}
238 240
239 } // namespace crypto 241 } // namespace crypto
OLDNEW
« no previous file with comments | « no previous file | crypto/rsa_private_key.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698