| 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 #ifndef CRYPTO_EC_PRIVATE_KEY_H_ | 5 #ifndef CRYPTO_EC_PRIVATE_KEY_H_ |
| 6 #define CRYPTO_EC_PRIVATE_KEY_H_ | 6 #define CRYPTO_EC_PRIVATE_KEY_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // Encapsulates an elliptic curve (EC) private key. Can be used to generate new | 24 // Encapsulates an elliptic curve (EC) private key. Can be used to generate new |
| 25 // keys, export keys to other formats, or to extract a public key. | 25 // keys, export keys to other formats, or to extract a public key. |
| 26 // TODO(mattm): make this and RSAPrivateKey implement some PrivateKey interface. | 26 // TODO(mattm): make this and RSAPrivateKey implement some PrivateKey interface. |
| 27 // (The difference in types of key() and public_key() make this a little | 27 // (The difference in types of key() and public_key() make this a little |
| 28 // tricky.) | 28 // tricky.) |
| 29 class CRYPTO_EXPORT ECPrivateKey { | 29 class CRYPTO_EXPORT ECPrivateKey { |
| 30 public: | 30 public: |
| 31 ~ECPrivateKey(); | 31 ~ECPrivateKey(); |
| 32 | 32 |
| 33 // Creates a new random instance. Can return NULL if initialization fails. | 33 // Creates a new random instance. Can return nullptr if initialization fails. |
| 34 // The created key will use the NIST P-256 curve. | 34 // The created key will use the NIST P-256 curve. |
| 35 // TODO(mattm): Add a curve parameter. | 35 // TODO(mattm): Add a curve parameter. |
| 36 static ECPrivateKey* Create(); | 36 static std::unique_ptr<ECPrivateKey> Create(); |
| 37 | 37 |
| 38 // Create a new instance by importing an existing private key. The format is | 38 // Create a new instance by importing an existing private key. The format is |
| 39 // an ASN.1-encoded PrivateKeyInfo block from PKCS #8. This can return | 39 // an ASN.1-encoded PrivateKeyInfo block from PKCS #8. This can return |
| 40 // nullptr if initialization fails. | 40 // nullptr if initialization fails. |
| 41 static std::unique_ptr<ECPrivateKey> CreateFromPrivateKeyInfo( | 41 static std::unique_ptr<ECPrivateKey> CreateFromPrivateKeyInfo( |
| 42 const std::vector<uint8_t>& input); | 42 const std::vector<uint8_t>& input); |
| 43 | 43 |
| 44 // Creates a new instance by importing an existing key pair. | 44 // Creates a new instance by importing an existing key pair. |
| 45 // The key pair is given as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo | 45 // The key pair is given as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo |
| 46 // block and an X.509 SubjectPublicKeyInfo block. | 46 // block and an X.509 SubjectPublicKeyInfo block. |
| 47 // Returns NULL if initialization fails. | 47 // Returns nullptr if initialization fails. |
| 48 // | 48 // |
| 49 // This function is deprecated. Use CreateFromPrivateKeyInfo for new code. | 49 // This function is deprecated. Use CreateFromPrivateKeyInfo for new code. |
| 50 // See https://crbug.com/603319. | 50 // See https://crbug.com/603319. |
| 51 static ECPrivateKey* CreateFromEncryptedPrivateKeyInfo( | 51 static std::unique_ptr<ECPrivateKey> CreateFromEncryptedPrivateKeyInfo( |
| 52 const std::string& password, | 52 const std::string& password, |
| 53 const std::vector<uint8_t>& encrypted_private_key_info, | 53 const std::vector<uint8_t>& encrypted_private_key_info, |
| 54 const std::vector<uint8_t>& subject_public_key_info); | 54 const std::vector<uint8_t>& subject_public_key_info); |
| 55 | 55 |
| 56 // Returns a copy of the object. | 56 // Returns a copy of the object. |
| 57 ECPrivateKey* Copy() const; | 57 std::unique_ptr<ECPrivateKey> Copy() const; |
| 58 | 58 |
| 59 EVP_PKEY* key() { return key_; } | 59 EVP_PKEY* key() { return key_; } |
| 60 | 60 |
| 61 // Exports the private key to a PKCS #8 PrivateKeyInfo block. | 61 // Exports the private key to a PKCS #8 PrivateKeyInfo block. |
| 62 bool ExportPrivateKey(std::vector<uint8_t>* output) const; | 62 bool ExportPrivateKey(std::vector<uint8_t>* output) const; |
| 63 | 63 |
| 64 // Exports the private key as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo | 64 // Exports the private key as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo |
| 65 // block and the public key as an X.509 SubjectPublicKeyInfo block. | 65 // block and the public key as an X.509 SubjectPublicKeyInfo block. |
| 66 // The |password| and |iterations| are used as inputs to the key derivation | 66 // The |password| and |iterations| are used as inputs to the key derivation |
| 67 // function for generating the encryption key. PKCS #5 recommends a minimum | 67 // function for generating the encryption key. PKCS #5 recommends a minimum |
| (...skipping 17 matching lines...) Expand all Loading... |
| 85 | 85 |
| 86 EVP_PKEY* key_; | 86 EVP_PKEY* key_; |
| 87 | 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(ECPrivateKey); | 88 DISALLOW_COPY_AND_ASSIGN(ECPrivateKey); |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 | 91 |
| 92 } // namespace crypto | 92 } // namespace crypto |
| 93 | 93 |
| 94 #endif // CRYPTO_EC_PRIVATE_KEY_H_ | 94 #endif // CRYPTO_EC_PRIVATE_KEY_H_ |
| OLD | NEW |