Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(775)

Side by Side Diff: crypto/rsa_private_key_nss.cc

Issue 881213004: Support building BoringSSL with NSS certificates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crypto/rsa_private_key.h ('k') | crypto/rsa_private_key_nss_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "crypto/rsa_private_key.h" 5 #include "crypto/rsa_private_key.h"
6 6
7 #include <cryptohi.h> 7 #include <cryptohi.h>
8 #include <keyhi.h> 8 #include <keyhi.h>
9 #include <pk11pub.h> 9 #include <pk11pub.h>
10 #include <secmod.h> 10 #include <secmod.h>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 EnsureNSSInit(); 97 EnsureNSSInit();
98 98
99 ScopedPK11Slot slot(PK11_GetInternalSlot()); 99 ScopedPK11Slot slot(PK11_GetInternalSlot());
100 return CreateFromPrivateKeyInfoWithParams( 100 return CreateFromPrivateKeyInfoWithParams(
101 slot.get(), 101 slot.get(),
102 input, 102 input,
103 false /* not permanent */, 103 false /* not permanent */,
104 false /* not sensitive */); 104 false /* not sensitive */);
105 } 105 }
106 106
107 // static
108 RSAPrivateKey* RSAPrivateKey::CreateFromKey(SECKEYPrivateKey* key) {
109 DCHECK(key);
110 if (SECKEY_GetPrivateKeyType(key) != rsaKey)
111 return NULL;
112 RSAPrivateKey* copy = new RSAPrivateKey();
113 copy->key_ = SECKEY_CopyPrivateKey(key);
114 copy->public_key_ = SECKEY_ConvertToPublicKey(key);
115 if (!copy->key_ || !copy->public_key_) {
116 NOTREACHED();
117 delete copy;
118 return NULL;
119 }
120 return copy;
121 }
122
107 #if defined(USE_NSS_CERTS) 123 #if defined(USE_NSS_CERTS)
108 // static 124 // static
109 RSAPrivateKey* RSAPrivateKey::CreateSensitive(PK11SlotInfo* slot, 125 RSAPrivateKey* RSAPrivateKey::CreateSensitive(PK11SlotInfo* slot,
110 uint16 num_bits) { 126 uint16 num_bits) {
111 return CreateWithParams(slot, 127 return CreateWithParams(slot,
112 num_bits, 128 num_bits,
113 true /* permanent */, 129 true /* permanent */,
114 true /* sensitive */); 130 true /* sensitive */);
115 } 131 }
116 132
117 // static 133 // static
118 RSAPrivateKey* RSAPrivateKey::CreateSensitiveFromPrivateKeyInfo( 134 RSAPrivateKey* RSAPrivateKey::CreateSensitiveFromPrivateKeyInfo(
119 PK11SlotInfo* slot, 135 PK11SlotInfo* slot,
120 const std::vector<uint8>& input) { 136 const std::vector<uint8>& input) {
121 return CreateFromPrivateKeyInfoWithParams(slot, 137 return CreateFromPrivateKeyInfoWithParams(slot,
122 input, 138 input,
123 true /* permanent */, 139 true /* permanent */,
124 true /* sensitive */); 140 true /* sensitive */);
125 } 141 }
126 142
127 // static 143 // static
128 RSAPrivateKey* RSAPrivateKey::CreateFromKey(SECKEYPrivateKey* key) {
129 DCHECK(key);
130 if (SECKEY_GetPrivateKeyType(key) != rsaKey)
131 return NULL;
132 RSAPrivateKey* copy = new RSAPrivateKey();
133 copy->key_ = SECKEY_CopyPrivateKey(key);
134 copy->public_key_ = SECKEY_ConvertToPublicKey(key);
135 if (!copy->key_ || !copy->public_key_) {
136 NOTREACHED();
137 delete copy;
138 return NULL;
139 }
140 return copy;
141 }
142
143 // static
144 RSAPrivateKey* RSAPrivateKey::FindFromPublicKeyInfo( 144 RSAPrivateKey* RSAPrivateKey::FindFromPublicKeyInfo(
145 const std::vector<uint8>& input) { 145 const std::vector<uint8>& input) {
146 scoped_ptr<RSAPrivateKey> result(InitPublicPart(input)); 146 scoped_ptr<RSAPrivateKey> result(InitPublicPart(input));
147 if (!result) 147 if (!result)
148 return NULL; 148 return NULL;
149 149
150 ScopedSECItem ck_id( 150 ScopedSECItem ck_id(
151 PK11_MakeIDFromPubKey(&(result->public_key_->u.rsa.modulus))); 151 PK11_MakeIDFromPubKey(&(result->public_key_->u.rsa.modulus)));
152 if (!ck_id.get()) { 152 if (!ck_id.get()) {
153 NOTREACHED(); 153 NOTREACHED();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 if (!result->public_key_) { 323 if (!result->public_key_) {
324 NOTREACHED(); 324 NOTREACHED();
325 return NULL; 325 return NULL;
326 } 326 }
327 327
328 return result.release(); 328 return result.release();
329 } 329 }
330 #endif // defined(USE_NSS_CERTS) 330 #endif // defined(USE_NSS_CERTS)
331 331
332 } // namespace crypto 332 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/rsa_private_key.h ('k') | crypto/rsa_private_key_nss_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698