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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 ScopedPKCS8_PRIV_KEY_INFO pkcs8(EVP_PKEY2PKCS8(key_)); | 169 ScopedPKCS8_PRIV_KEY_INFO pkcs8(EVP_PKEY2PKCS8(key_)); |
170 if (!pkcs8.get()) | 170 if (!pkcs8.get()) |
171 return false; | 171 return false; |
172 | 172 |
173 // Encrypt the object. | 173 // Encrypt the object. |
174 // NOTE: NSS uses SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_3KEY_TRIPLE_DES_CBC | 174 // NOTE: NSS uses SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_3KEY_TRIPLE_DES_CBC |
175 // so use NID_pbe_WithSHA1And3_Key_TripleDES_CBC which should be the OpenSSL | 175 // so use NID_pbe_WithSHA1And3_Key_TripleDES_CBC which should be the OpenSSL |
176 // equivalent. | 176 // equivalent. |
177 ScopedX509_SIG encrypted(PKCS8_encrypt_pbe( | 177 ScopedX509_SIG encrypted(PKCS8_encrypt_pbe( |
178 NID_pbe_WithSHA1And3_Key_TripleDES_CBC, | 178 NID_pbe_WithSHA1And3_Key_TripleDES_CBC, |
| 179 nullptr, |
179 reinterpret_cast<const uint8_t*>(password.data()), | 180 reinterpret_cast<const uint8_t*>(password.data()), |
180 password.size(), | 181 password.size(), |
181 NULL, | 182 nullptr, |
182 0, | 183 0, |
183 iterations, | 184 iterations, |
184 pkcs8.get())); | 185 pkcs8.get())); |
185 if (!encrypted.get()) | 186 if (!encrypted.get()) |
186 return false; | 187 return false; |
187 | 188 |
188 // Write it into |*output| | 189 // Write it into |*output| |
189 return ExportKeyWithBio(encrypted.get(), | 190 return ExportKeyWithBio(encrypted.get(), |
190 reinterpret_cast<ExportBioFunction>(i2d_PKCS8_bio), | 191 reinterpret_cast<ExportBioFunction>(i2d_PKCS8_bio), |
191 output); | 192 output); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 OpenSSLErrStackTracer err_tracer(FROM_HERE); | 230 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
230 ScopedEC_KEY ec_key(EVP_PKEY_get1_EC_KEY(key_)); | 231 ScopedEC_KEY ec_key(EVP_PKEY_get1_EC_KEY(key_)); |
231 return ExportKey(ec_key.get(), | 232 return ExportKey(ec_key.get(), |
232 reinterpret_cast<ExportDataFunction>(i2d_ECParameters), | 233 reinterpret_cast<ExportDataFunction>(i2d_ECParameters), |
233 output); | 234 output); |
234 } | 235 } |
235 | 236 |
236 ECPrivateKey::ECPrivateKey() : key_(NULL) {} | 237 ECPrivateKey::ECPrivateKey() : key_(NULL) {} |
237 | 238 |
238 } // namespace crypto | 239 } // namespace crypto |
OLD | NEW |