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 extern "C" { | 7 extern "C" { |
8 // Work around NSS missing SEC_BEGIN_PROTOS in secmodt.h. This must come before | 8 // Work around NSS missing SEC_BEGIN_PROTOS in secmodt.h. This must come before |
9 // other NSS headers. | 9 // other NSS headers. |
10 #include <secmodt.h> | 10 #include <secmodt.h> |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // static | 89 // static |
90 ECPrivateKey* ECPrivateKey::Create() { | 90 ECPrivateKey* ECPrivateKey::Create() { |
91 EnsureNSSInit(); | 91 EnsureNSSInit(); |
92 | 92 |
93 ScopedPK11Slot slot(GetTempKeySlot()); | 93 ScopedPK11Slot slot(GetTempKeySlot()); |
94 return CreateWithParams(slot.get(), | 94 return CreateWithParams(slot.get(), |
95 false /* not permanent */, | 95 false /* not permanent */, |
96 false /* not sensitive */); | 96 false /* not sensitive */); |
97 } | 97 } |
98 | 98 |
99 #if defined(USE_NSS) | |
100 // static | |
101 ECPrivateKey* ECPrivateKey::CreateSensitive(PK11SlotInfo* slot) { | |
102 return CreateWithParams( | |
103 slot, true /* permanent */, true /* sensitive */); | |
104 } | |
105 #endif | |
106 | |
107 // static | 99 // static |
108 ECPrivateKey* ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( | 100 ECPrivateKey* ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( |
109 const std::string& password, | 101 const std::string& password, |
110 const std::vector<uint8>& encrypted_private_key_info, | 102 const std::vector<uint8>& encrypted_private_key_info, |
111 const std::vector<uint8>& subject_public_key_info) { | 103 const std::vector<uint8>& subject_public_key_info) { |
112 EnsureNSSInit(); | 104 EnsureNSSInit(); |
113 | 105 |
114 ScopedPK11Slot slot(GetTempKeySlot()); | 106 ScopedPK11Slot slot(GetTempKeySlot()); |
115 return CreateFromEncryptedPrivateKeyInfoWithParams( | 107 return CreateFromEncryptedPrivateKeyInfoWithParams( |
116 slot.get(), | 108 slot.get(), |
117 password, | 109 password, |
118 encrypted_private_key_info, | 110 encrypted_private_key_info, |
119 subject_public_key_info, | 111 subject_public_key_info, |
120 false /* not permanent */, | 112 false /* not permanent */, |
121 false /* not sensitive */); | 113 false /* not sensitive */); |
122 } | 114 } |
123 | 115 |
124 #if defined(USE_NSS) | |
125 // static | |
126 ECPrivateKey* ECPrivateKey::CreateSensitiveFromEncryptedPrivateKeyInfo( | |
127 PK11SlotInfo* slot, | |
128 const std::string& password, | |
129 const std::vector<uint8>& encrypted_private_key_info, | |
130 const std::vector<uint8>& subject_public_key_info) { | |
131 return CreateFromEncryptedPrivateKeyInfoWithParams( | |
132 slot, | |
133 password, | |
134 encrypted_private_key_info, | |
135 subject_public_key_info, | |
136 true /* permanent */, | |
137 true /* sensitive */); | |
138 } | |
139 #endif | |
140 | |
141 // static | 116 // static |
142 bool ECPrivateKey::ImportFromEncryptedPrivateKeyInfo( | 117 bool ECPrivateKey::ImportFromEncryptedPrivateKeyInfo( |
143 PK11SlotInfo* slot, | 118 PK11SlotInfo* slot, |
144 const std::string& password, | 119 const std::string& password, |
145 const uint8* encrypted_private_key_info, | 120 const uint8* encrypted_private_key_info, |
146 size_t encrypted_private_key_info_len, | 121 size_t encrypted_private_key_info_len, |
147 CERTSubjectPublicKeyInfo* decoded_spki, | 122 CERTSubjectPublicKeyInfo* decoded_spki, |
148 bool permanent, | 123 bool permanent, |
149 bool sensitive, | 124 bool sensitive, |
150 SECKEYPrivateKey** key, | 125 SECKEYPrivateKey** key, |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 371 |
397 if (success) { | 372 if (success) { |
398 CHECK_EQ(ecKey, SECKEY_GetPublicKeyType(result->public_key_)); | 373 CHECK_EQ(ecKey, SECKEY_GetPublicKeyType(result->public_key_)); |
399 return result.release(); | 374 return result.release(); |
400 } | 375 } |
401 | 376 |
402 return NULL; | 377 return NULL; |
403 } | 378 } |
404 | 379 |
405 } // namespace crypto | 380 } // namespace crypto |
OLD | NEW |