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

Side by Side Diff: crypto/ec_signature_creator_nss.cc

Issue 10451068: Fixing gcc 4.7 building problems. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Modified per Adam's comments Created 8 years, 6 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
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_impl.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 #include <unistd.h>
11 12
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "crypto/ec_private_key.h" 14 #include "crypto/ec_private_key.h"
14 #include "crypto/nss_util.h" 15 #include "crypto/nss_util.h"
15 #include "crypto/scoped_nss_types.h" 16 #include "crypto/scoped_nss_types.h"
16 17
17 namespace crypto { 18 namespace crypto {
18 19
19 namespace { 20 namespace {
20 21
21 SECStatus SignData(SECItem* result, 22 SECStatus SignData(SECItem* result,
22 SECItem* input, 23 SECItem* input,
23 SECKEYPrivateKey* key, 24 SECKEYPrivateKey* key,
24 HASH_HashType hash_type) { 25 HASH_HashType hash_type) {
25 if (key->keyType != ecKey) { 26 if (key->keyType != ecKey) {
26 DLOG(FATAL) << "Should be using an EC key."; 27 DLOG(FATAL) << "Should be using an EC key.";
27 PORT_SetError(SEC_ERROR_INVALID_ARGS); 28 PORT_SetError(SEC_ERROR_INVALID_ARGS);
28 return SECFailure; 29 return SECFailure;
29 } 30 }
30 31
31 // Hash the input. 32 // Hash the input.
32 std::vector<uint8> hash_data(HASH_ResultLen(hash_type)); 33 std::vector<uint8> hash_data(HASH_ResultLen(hash_type));
33 SECStatus rv = HASH_HashBuf( 34 SECStatus rv = HASH_HashBuf(
34 hash_type, &hash_data[0], input->data, input->len); 35 hash_type, &hash_data[0], input->data, input->len);
35 if (rv != SECSuccess) 36 if (rv != SECSuccess)
36 return rv; 37 return rv;
37 SECItem hash = {siBuffer, &hash_data[0], hash_data.size()}; 38 SECItem hash = {siBuffer, &hash_data[0],
39 static_cast<unsigned int>(hash_data.size())};
38 40
39 // Compute signature of hash. 41 // Compute signature of hash.
40 int signature_len = PK11_SignatureLen(key); 42 int signature_len = PK11_SignatureLen(key);
41 std::vector<uint8> signature_data(signature_len); 43 std::vector<uint8> signature_data(signature_len);
42 SECItem sig = {siBuffer, &signature_data[0], signature_len}; 44 SECItem sig = {siBuffer, &signature_data[0],
45 static_cast<unsigned int>(signature_len)};
43 rv = PK11_Sign(key, &sig, &hash); 46 rv = PK11_Sign(key, &sig, &hash);
44 if (rv != SECSuccess) 47 if (rv != SECSuccess)
45 return rv; 48 return rv;
46 49
47 // DER encode the signature. 50 // DER encode the signature.
48 return DSAU_EncodeDerSigWithLen(result, &sig, sig.len); 51 return DSAU_EncodeDerSigWithLen(result, &sig, sig.len);
49 } 52 }
50 53
51 } // namespace 54 } // namespace
52 55
(...skipping 27 matching lines...) Expand all
80 return false; 83 return false;
81 } 84 }
82 85
83 // Copy the signed data into the output vector. 86 // Copy the signed data into the output vector.
84 signature->assign(result.data, result.data + result.len); 87 signature->assign(result.data, result.data + result.len);
85 SECITEM_FreeItem(&result, PR_FALSE /* only free |result.data| */); 88 SECITEM_FreeItem(&result, PR_FALSE /* only free |result.data| */);
86 return true; 89 return true;
87 } 90 }
88 91
89 } // namespace crypto 92 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698