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 #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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "crypto/crypto_export.h" | 14 #include "crypto/crypto_export.h" |
15 | 15 |
16 #if defined(USE_OPENSSL) | 16 #if defined(USE_OPENSSL) |
17 // Forward declaration for openssl/*.h | 17 // Forward declaration for openssl/*.h |
18 typedef struct evp_pkey_st EVP_PKEY; | 18 typedef struct evp_pkey_st EVP_PKEY; |
19 #else | 19 #else |
20 // Forward declaration. | 20 // Forward declaration. |
| 21 typedef struct CERTSubjectPublicKeyInfoStr CERTSubjectPublicKeyInfo; |
21 typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey; | 22 typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey; |
22 typedef struct SECKEYPublicKeyStr SECKEYPublicKey; | 23 typedef struct SECKEYPublicKeyStr SECKEYPublicKey; |
23 #endif | 24 #endif |
24 | 25 |
25 namespace crypto { | 26 namespace crypto { |
26 | 27 |
27 // Encapsulates an elliptic curve (EC) private key. Can be used to generate new | 28 // Encapsulates an elliptic curve (EC) private key. Can be used to generate new |
28 // keys, export keys to other formats, or to extract a public key. | 29 // keys, export keys to other formats, or to extract a public key. |
29 // TODO(mattm): make this and RSAPrivateKey implement some PrivateKey interface. | 30 // TODO(mattm): make this and RSAPrivateKey implement some PrivateKey interface. |
30 // (The difference in types of key() and public_key() make this a little | 31 // (The difference in types of key() and public_key() make this a little |
(...skipping 27 matching lines...) Expand all Loading... |
58 // block and an X.509 SubjectPublicKeyInfo block. | 59 // block and an X.509 SubjectPublicKeyInfo block. |
59 // This can return NULL if initialization fails. The created key is permanent | 60 // This can return NULL if initialization fails. The created key is permanent |
60 // and is not exportable in plaintext form. | 61 // and is not exportable in plaintext form. |
61 // | 62 // |
62 // NOTE: Currently only available if USE_NSS is defined. | 63 // NOTE: Currently only available if USE_NSS is defined. |
63 static ECPrivateKey* CreateSensitiveFromEncryptedPrivateKeyInfo( | 64 static ECPrivateKey* CreateSensitiveFromEncryptedPrivateKeyInfo( |
64 const std::string& password, | 65 const std::string& password, |
65 const std::vector<uint8>& encrypted_private_key_info, | 66 const std::vector<uint8>& encrypted_private_key_info, |
66 const std::vector<uint8>& subject_public_key_info); | 67 const std::vector<uint8>& subject_public_key_info); |
67 | 68 |
| 69 #if !defined(USE_OPENSSL) |
| 70 // Imports the key pair and returns in |public_key| and |key|. |
| 71 // Shortcut for code that needs to keep a reference directly to NSS types |
| 72 // without having to create a ECPrivateKey object and make a copy of them. |
| 73 // TODO(mattm): move this function to some NSS util file. |
| 74 static bool ImportFromEncryptedPrivateKeyInfo( |
| 75 const std::string& password, |
| 76 const uint8* encrypted_private_key_info, |
| 77 size_t encrypted_private_key_info_len, |
| 78 CERTSubjectPublicKeyInfo* decoded_spki, |
| 79 bool permanent, |
| 80 bool sensitive, |
| 81 SECKEYPrivateKey** key, |
| 82 SECKEYPublicKey** public_key); |
| 83 #endif |
| 84 |
68 #if defined(USE_OPENSSL) | 85 #if defined(USE_OPENSSL) |
69 EVP_PKEY* key() { return key_; } | 86 EVP_PKEY* key() { return key_; } |
70 #else | 87 #else |
71 SECKEYPrivateKey* key() { return key_; } | 88 SECKEYPrivateKey* key() { return key_; } |
72 SECKEYPublicKey* public_key() { return public_key_; } | 89 SECKEYPublicKey* public_key() { return public_key_; } |
73 #endif | 90 #endif |
74 | 91 |
75 // Exports the private key as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo | 92 // Exports the private key as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo |
76 // block and the public key as an X.509 SubjectPublicKeyInfo block. | 93 // block and the public key as an X.509 SubjectPublicKeyInfo block. |
77 // The |password| and |iterations| are used as inputs to the key derivation | 94 // The |password| and |iterations| are used as inputs to the key derivation |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 SECKEYPublicKey* public_key_; | 132 SECKEYPublicKey* public_key_; |
116 #endif | 133 #endif |
117 | 134 |
118 DISALLOW_COPY_AND_ASSIGN(ECPrivateKey); | 135 DISALLOW_COPY_AND_ASSIGN(ECPrivateKey); |
119 }; | 136 }; |
120 | 137 |
121 | 138 |
122 } // namespace crypto | 139 } // namespace crypto |
123 | 140 |
124 #endif // CRYPTO_EC_PRIVATE_KEY_H_ | 141 #endif // CRYPTO_EC_PRIVATE_KEY_H_ |
OLD | NEW |