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 CERTSubjectPublicKeyInfoStr CERTSubjectPublicKeyInfo; |
22 typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey; | 22 typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey; |
23 typedef struct SECKEYPublicKeyStr SECKEYPublicKey; | 23 typedef struct SECKEYPublicKeyStr SECKEYPublicKey; |
| 24 typedef struct PK11SlotInfoStr PK11SlotInfo; |
24 #endif | 25 #endif |
25 | 26 |
26 namespace crypto { | 27 namespace crypto { |
27 | 28 |
28 // Encapsulates an elliptic curve (EC) private key. Can be used to generate new | 29 // Encapsulates an elliptic curve (EC) private key. Can be used to generate new |
29 // keys, export keys to other formats, or to extract a public key. | 30 // keys, export keys to other formats, or to extract a public key. |
30 // TODO(mattm): make this and RSAPrivateKey implement some PrivateKey interface. | 31 // TODO(mattm): make this and RSAPrivateKey implement some PrivateKey interface. |
31 // (The difference in types of key() and public_key() make this a little | 32 // (The difference in types of key() and public_key() make this a little |
32 // tricky.) | 33 // tricky.) |
33 class CRYPTO_EXPORT ECPrivateKey { | 34 class CRYPTO_EXPORT ECPrivateKey { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // TODO(mattm): move this function to some NSS util file. | 74 // TODO(mattm): move this function to some NSS util file. |
74 static bool ImportFromEncryptedPrivateKeyInfo( | 75 static bool ImportFromEncryptedPrivateKeyInfo( |
75 const std::string& password, | 76 const std::string& password, |
76 const uint8* encrypted_private_key_info, | 77 const uint8* encrypted_private_key_info, |
77 size_t encrypted_private_key_info_len, | 78 size_t encrypted_private_key_info_len, |
78 CERTSubjectPublicKeyInfo* decoded_spki, | 79 CERTSubjectPublicKeyInfo* decoded_spki, |
79 bool permanent, | 80 bool permanent, |
80 bool sensitive, | 81 bool sensitive, |
81 SECKEYPrivateKey** key, | 82 SECKEYPrivateKey** key, |
82 SECKEYPublicKey** public_key); | 83 SECKEYPublicKey** public_key); |
| 84 |
| 85 // Returns a reference to the NSS slot that will be used to generate / store |
| 86 // the private key. |
| 87 static PK11SlotInfo* GetKeySlot(); |
83 #endif | 88 #endif |
84 | 89 |
85 #if defined(USE_OPENSSL) | 90 #if defined(USE_OPENSSL) |
86 EVP_PKEY* key() { return key_; } | 91 EVP_PKEY* key() { return key_; } |
87 #else | 92 #else |
88 SECKEYPrivateKey* key() { return key_; } | 93 SECKEYPrivateKey* key() { return key_; } |
89 SECKEYPublicKey* public_key() { return public_key_; } | 94 SECKEYPublicKey* public_key() { return public_key_; } |
90 #endif | 95 #endif |
91 | 96 |
92 // Exports the private key as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo | 97 // Exports the private key as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 SECKEYPublicKey* public_key_; | 137 SECKEYPublicKey* public_key_; |
133 #endif | 138 #endif |
134 | 139 |
135 DISALLOW_COPY_AND_ASSIGN(ECPrivateKey); | 140 DISALLOW_COPY_AND_ASSIGN(ECPrivateKey); |
136 }; | 141 }; |
137 | 142 |
138 | 143 |
139 } // namespace crypto | 144 } // namespace crypto |
140 | 145 |
141 #endif // CRYPTO_EC_PRIVATE_KEY_H_ | 146 #endif // CRYPTO_EC_PRIVATE_KEY_H_ |
OLD | NEW |