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

Side by Side Diff: crypto/ec_signature_creator_nss.cc

Issue 9455006: Fix SpdySession::WriteCredentialFrame ECPrivateKey creation args. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: openssl fix Created 8 years, 9 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
« no previous file with comments | « crypto/ec_signature_creator_impl.h ('k') | crypto/ec_signature_creator_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) 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_signature_creator.h" 5 #include "crypto/ec_signature_creator_impl.h"
6 6
7 #include <cryptohi.h> 7 #include <cryptohi.h>
8 #include <pk11pub.h> 8 #include <pk11pub.h>
9 #include <secerr.h> 9 #include <secerr.h>
10 #include <sechash.h> 10 #include <sechash.h>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "crypto/ec_private_key.h" 13 #include "crypto/ec_private_key.h"
14 #include "crypto/nss_util.h" 14 #include "crypto/nss_util.h"
15 #include "crypto/scoped_nss_types.h" 15 #include "crypto/scoped_nss_types.h"
(...skipping 27 matching lines...) Expand all
43 rv = PK11_Sign(key, &sig, &hash); 43 rv = PK11_Sign(key, &sig, &hash);
44 if (rv != SECSuccess) 44 if (rv != SECSuccess)
45 return rv; 45 return rv;
46 46
47 // DER encode the signature. 47 // DER encode the signature.
48 return DSAU_EncodeDerSigWithLen(result, &sig, sig.len); 48 return DSAU_EncodeDerSigWithLen(result, &sig, sig.len);
49 } 49 }
50 50
51 } // namespace 51 } // namespace
52 52
53 // static 53 ECSignatureCreatorImpl::ECSignatureCreatorImpl(ECPrivateKey* key)
54 ECSignatureCreator* ECSignatureCreator::Create(ECPrivateKey* key) {
55 return new ECSignatureCreator(key);
56 }
57
58 ECSignatureCreator::ECSignatureCreator(ECPrivateKey* key)
59 : key_(key) { 54 : key_(key) {
60 EnsureNSSInit(); 55 EnsureNSSInit();
61 } 56 }
62 57
63 ECSignatureCreator::~ECSignatureCreator() { } 58 ECSignatureCreatorImpl::~ECSignatureCreatorImpl() {}
64 59
65 bool ECSignatureCreator::Sign(const uint8* data, 60 bool ECSignatureCreatorImpl::Sign(const uint8* data,
66 int data_len, 61 int data_len,
67 std::vector<uint8>* signature) { 62 std::vector<uint8>* signature) {
68 // Data to be signed 63 // Data to be signed
69 SECItem secret; 64 SECItem secret;
70 secret.type = siBuffer; 65 secret.type = siBuffer;
71 secret.len = data_len; 66 secret.len = data_len;
72 secret.data = const_cast<unsigned char*>(data); 67 secret.data = const_cast<unsigned char*>(data);
73 68
74 // SECItem to receive the output buffer. 69 // SECItem to receive the output buffer.
75 SECItem result; 70 SECItem result;
76 result.type = siBuffer; 71 result.type = siBuffer;
77 result.len = 0; 72 result.len = 0;
78 result.data = NULL; 73 result.data = NULL;
79 74
80 // Sign the secret data and save it to |result|. 75 // Sign the secret data and save it to |result|.
81 SECStatus rv = 76 SECStatus rv =
82 SignData(&result, &secret, key_->key(), HASH_AlgSHA1); 77 SignData(&result, &secret, key_->key(), HASH_AlgSHA1);
83 if (rv != SECSuccess) { 78 if (rv != SECSuccess) {
84 DLOG(ERROR) << "DerSignData: " << PORT_GetError(); 79 DLOG(ERROR) << "DerSignData: " << PORT_GetError();
85 return false; 80 return false;
86 } 81 }
87 82
88 // Copy the signed data into the output vector. 83 // Copy the signed data into the output vector.
89 signature->assign(result.data, result.data + result.len); 84 signature->assign(result.data, result.data + result.len);
90 SECITEM_FreeItem(&result, PR_FALSE /* only free |result.data| */); 85 SECITEM_FreeItem(&result, PR_FALSE /* only free |result.data| */);
91 return true; 86 return true;
92 } 87 }
93 88
94 } // namespace crypto 89 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/ec_signature_creator_impl.h ('k') | crypto/ec_signature_creator_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698