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

Side by Side Diff: crypto/rsa_private_key_nss.cc

Issue 8727014: Implement RSAPrivateKey::Copy() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « crypto/rsa_private_key_mac.cc ('k') | crypto/rsa_private_key_openssl.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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 ck_id.get(), NULL); 131 ck_id.get(), NULL);
132 if (result->key_) 132 if (result->key_)
133 return result.release(); 133 return result.release();
134 } 134 }
135 } 135 }
136 136
137 // We didn't find the key. 137 // We didn't find the key.
138 return NULL; 138 return NULL;
139 } 139 }
140 140
141 RSAPrivateKey* RSAPrivateKey::Copy() const {
142 RSAPrivateKey* copy = new RSAPrivateKey();
143 copy->key_ = SECKEY_CopyPrivateKey(key_);
144 copy->public_key_ = SECKEY_CopyPublicKey(public_key_);
145 return copy;
146 }
141 147
142 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { 148 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const {
143 PrivateKeyInfoCodec private_key_info(true); 149 PrivateKeyInfoCodec private_key_info(true);
144 150
145 // Manually read the component attributes of the private key and build up 151 // Manually read the component attributes of the private key and build up
146 // the PrivateKeyInfo. 152 // the PrivateKeyInfo.
147 if (!ReadAttribute(key_, CKA_MODULUS, private_key_info.modulus()) || 153 if (!ReadAttribute(key_, CKA_MODULUS, private_key_info.modulus()) ||
148 !ReadAttribute(key_, CKA_PUBLIC_EXPONENT, 154 !ReadAttribute(key_, CKA_PUBLIC_EXPONENT,
149 private_key_info.public_exponent()) || 155 private_key_info.public_exponent()) ||
150 !ReadAttribute(key_, CKA_PRIVATE_EXPONENT, 156 !ReadAttribute(key_, CKA_PRIVATE_EXPONENT,
151 private_key_info.private_exponent()) || 157 private_key_info.private_exponent()) ||
152 !ReadAttribute(key_, CKA_PRIME_1, private_key_info.prime1()) || 158 !ReadAttribute(key_, CKA_PRIME_1, private_key_info.prime1()) ||
153 !ReadAttribute(key_, CKA_PRIME_2, private_key_info.prime2()) || 159 !ReadAttribute(key_, CKA_PRIME_2, private_key_info.prime2()) ||
154 !ReadAttribute(key_, CKA_EXPONENT_1, private_key_info.exponent1()) || 160 !ReadAttribute(key_, CKA_EXPONENT_1, private_key_info.exponent1()) ||
155 !ReadAttribute(key_, CKA_EXPONENT_2, private_key_info.exponent2()) || 161 !ReadAttribute(key_, CKA_EXPONENT_2, private_key_info.exponent2()) ||
156 !ReadAttribute(key_, CKA_COEFFICIENT, private_key_info.coefficient())) { 162 !ReadAttribute(key_, CKA_COEFFICIENT, private_key_info.coefficient())) {
157 NOTREACHED(); 163 NOTREACHED();
158 return false; 164 return false;
159 } 165 }
160 166
161 return private_key_info.Export(output); 167 return private_key_info.Export(output);
162 } 168 }
163 169
164 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) { 170 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const {
165 ScopedSECItem der_pubkey(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key_)); 171 ScopedSECItem der_pubkey(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key_));
166 if (!der_pubkey.get()) { 172 if (!der_pubkey.get()) {
167 NOTREACHED(); 173 NOTREACHED();
168 return false; 174 return false;
169 } 175 }
170 176
171 output->assign(der_pubkey->data, der_pubkey->data + der_pubkey->len); 177 output->assign(der_pubkey->data, der_pubkey->data + der_pubkey->len);
172 return true; 178 return true;
173 } 179 }
174 180
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); 242 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_);
237 if (!result->public_key_) { 243 if (!result->public_key_) {
238 NOTREACHED(); 244 NOTREACHED();
239 return NULL; 245 return NULL;
240 } 246 }
241 247
242 return result.release(); 248 return result.release();
243 } 249 }
244 250
245 } // namespace crypto 251 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/rsa_private_key_mac.cc ('k') | crypto/rsa_private_key_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698