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

Side by Side Diff: crypto/rsa_private_key_nss.cc

Issue 18697003: Introduce RSAPrivateKey::SignDigest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 ScopedSECItem der_pubkey(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key_)); 188 ScopedSECItem der_pubkey(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key_));
189 if (!der_pubkey.get()) { 189 if (!der_pubkey.get()) {
190 NOTREACHED(); 190 NOTREACHED();
191 return false; 191 return false;
192 } 192 }
193 193
194 output->assign(der_pubkey->data, der_pubkey->data + der_pubkey->len); 194 output->assign(der_pubkey->data, der_pubkey->data + der_pubkey->len);
195 return true; 195 return true;
196 } 196 }
197 197
198 bool RSAPrivateKey::SignDigest(const std::vector<uint8>& digest,
199 std::vector<uint8>* output) const {
200 size_t signature_len = PK11_SignatureLen(key_);
201
202 SECItem digest_item;
203 digest_item.type = siBuffer;
204 digest_item.data = const_cast<unsigned char*>(&digest[0]);
205 digest_item.len = digest.size();
206
207 SECItem signature_item;
208 signature_item.len = signature_len;
209 signature_item.data = (unsigned char*) PORT_Alloc(signature_len);
210 SECStatus rv = PK11_Sign(key_, &signature_item, &digest_item);
211 if (rv != SECSuccess) {
212 NOTREACHED();
213 SECITEM_FreeItem(&signature_item, PR_FALSE);
214 return false;
215 }
216
217 output->assign(signature_item.data,
218 signature_item.data + signature_item.len);
219 SECITEM_FreeItem(&signature_item, PR_FALSE);
220 return true;
221 }
222
198 RSAPrivateKey::RSAPrivateKey() : key_(NULL), public_key_(NULL) { 223 RSAPrivateKey::RSAPrivateKey() : key_(NULL), public_key_(NULL) {
199 EnsureNSSInit(); 224 EnsureNSSInit();
200 } 225 }
201 226
202 // static 227 // static
203 RSAPrivateKey* RSAPrivateKey::CreateWithParams(uint16 num_bits, 228 RSAPrivateKey* RSAPrivateKey::CreateWithParams(uint16 num_bits,
204 bool permanent, 229 bool permanent,
205 bool sensitive) { 230 bool sensitive) {
206 #if !defined(USE_NSS) 231 #if !defined(USE_NSS)
207 if (permanent) { 232 if (permanent) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); 300 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_);
276 if (!result->public_key_) { 301 if (!result->public_key_) {
277 NOTREACHED(); 302 NOTREACHED();
278 return NULL; 303 return NULL;
279 } 304 }
280 305
281 return result.release(); 306 return result.release();
282 } 307 }
283 308
284 } // namespace crypto 309 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698