OLD | NEW |
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/ec.h> | 7 #include <openssl/ec.h> |
8 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
9 #include <openssl/pkcs12.h> | 9 #include <openssl/pkcs12.h> |
10 #include <openssl/x509.h> | 10 #include <openssl/x509.h> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 86 } |
87 | 87 |
88 ECPrivateKey* ECPrivateKey::Copy() const { | 88 ECPrivateKey* ECPrivateKey::Copy() const { |
89 scoped_ptr<ECPrivateKey> copy(new ECPrivateKey); | 89 scoped_ptr<ECPrivateKey> copy(new ECPrivateKey); |
90 if (key_) | 90 if (key_) |
91 copy->key_ = EVP_PKEY_up_ref(key_); | 91 copy->key_ = EVP_PKEY_up_ref(key_); |
92 return copy.release(); | 92 return copy.release(); |
93 } | 93 } |
94 | 94 |
95 // static | 95 // static |
96 bool ECPrivateKey::IsSupported() { return true; } | |
97 | |
98 // static | |
99 ECPrivateKey* ECPrivateKey::Create() { | 96 ECPrivateKey* ECPrivateKey::Create() { |
100 OpenSSLErrStackTracer err_tracer(FROM_HERE); | 97 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
101 | 98 |
102 ScopedEC_KEY ec_key(EC_KEY_new_by_curve_name(NID_X9_62_prime256v1)); | 99 ScopedEC_KEY ec_key(EC_KEY_new_by_curve_name(NID_X9_62_prime256v1)); |
103 if (!ec_key.get() || !EC_KEY_generate_key(ec_key.get())) | 100 if (!ec_key.get() || !EC_KEY_generate_key(ec_key.get())) |
104 return NULL; | 101 return NULL; |
105 | 102 |
106 scoped_ptr<ECPrivateKey> result(new ECPrivateKey()); | 103 scoped_ptr<ECPrivateKey> result(new ECPrivateKey()); |
107 result->key_ = EVP_PKEY_new(); | 104 result->key_ = EVP_PKEY_new(); |
108 if (!result->key_ || !EVP_PKEY_set1_EC_KEY(result->key_, ec_key.get())) | 105 if (!result->key_ || !EVP_PKEY_set1_EC_KEY(result->key_, ec_key.get())) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 OpenSSLErrStackTracer err_tracer(FROM_HERE); | 227 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
231 ScopedEC_KEY ec_key(EVP_PKEY_get1_EC_KEY(key_)); | 228 ScopedEC_KEY ec_key(EVP_PKEY_get1_EC_KEY(key_)); |
232 return ExportKey(ec_key.get(), | 229 return ExportKey(ec_key.get(), |
233 reinterpret_cast<ExportDataFunction>(i2d_ECParameters), | 230 reinterpret_cast<ExportDataFunction>(i2d_ECParameters), |
234 output); | 231 output); |
235 } | 232 } |
236 | 233 |
237 ECPrivateKey::ECPrivateKey() : key_(NULL) {} | 234 ECPrivateKey::ECPrivateKey() : key_(NULL) {} |
238 | 235 |
239 } // namespace crypto | 236 } // namespace crypto |
OLD | NEW |