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

Side by Side Diff: crypto/signature_verifier_nss.cc

Issue 18181018: Use the HASH_ResultLenContext and HASH_GetType functions, now that they (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
« no previous file with comments | « no previous file | no next file » | 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/signature_verifier.h" 5 #include "crypto/signature_verifier.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 <secerr.h> 10 #include <secerr.h>
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 return HASH_AlgNULL; 29 return HASH_AlgNULL;
30 } 30 }
31 31
32 SECStatus VerifyRSAPSS_End(SECKEYPublicKey* public_key, 32 SECStatus VerifyRSAPSS_End(SECKEYPublicKey* public_key,
33 HASHContext* hash_context, 33 HASHContext* hash_context,
34 HASH_HashType mask_hash_alg, 34 HASH_HashType mask_hash_alg,
35 unsigned int salt_len, 35 unsigned int salt_len,
36 const unsigned char* signature, 36 const unsigned char* signature,
37 unsigned int signature_len) { 37 unsigned int signature_len) {
38 unsigned int hash_len = hash_context->hashobj->length; 38 unsigned int hash_len = HASH_ResultLenContext(hash_context);
39 std::vector<unsigned char> hash(hash_len); 39 std::vector<unsigned char> hash(hash_len);
40 HASH_End(hash_context, &hash[0], &hash_len, hash.size()); 40 HASH_End(hash_context, &hash[0], &hash_len, hash.size());
41 41
42 unsigned int modulus_len = SECKEY_PublicKeyStrength(public_key); 42 unsigned int modulus_len = SECKEY_PublicKeyStrength(public_key);
43 if (signature_len != modulus_len) { 43 if (signature_len != modulus_len) {
44 PORT_SetError(SEC_ERROR_BAD_SIGNATURE); 44 PORT_SetError(SEC_ERROR_BAD_SIGNATURE);
45 return SECFailure; 45 return SECFailure;
46 } 46 }
47 std::vector<unsigned char> enc(signature_len); 47 std::vector<unsigned char> enc(signature_len);
48 SECStatus rv = PK11_PubEncryptRaw(public_key, &enc[0], 48 SECStatus rv = PK11_PubEncryptRaw(public_key, &enc[0],
49 const_cast<unsigned char*>(signature), 49 const_cast<unsigned char*>(signature),
50 signature_len, NULL); 50 signature_len, NULL);
51 if (rv != SECSuccess) { 51 if (rv != SECSuccess) {
52 LOG(WARNING) << "PK11_PubEncryptRaw failed"; 52 LOG(WARNING) << "PK11_PubEncryptRaw failed";
53 return rv; 53 return rv;
54 } 54 }
55 return emsa_pss_verify(&hash[0], &enc[0], enc.size(), 55 return emsa_pss_verify(&hash[0], &enc[0], enc.size(),
56 hash_context->hashobj->type, mask_hash_alg, 56 HASH_GetType(hash_context), mask_hash_alg,
57 salt_len); 57 salt_len);
58 } 58 }
59 59
60 } // namespace 60 } // namespace
61 61
62 SignatureVerifier::SignatureVerifier() 62 SignatureVerifier::SignatureVerifier()
63 : vfy_context_(NULL), 63 : vfy_context_(NULL),
64 hash_alg_(SHA1), 64 hash_alg_(SHA1),
65 mask_hash_alg_(SHA1), 65 mask_hash_alg_(SHA1),
66 salt_len_(0), 66 salt_len_(0),
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 hash_context_ = NULL; 217 hash_context_ = NULL;
218 } 218 }
219 if (public_key_) { 219 if (public_key_) {
220 SECKEY_DestroyPublicKey(public_key_); 220 SECKEY_DestroyPublicKey(public_key_);
221 public_key_ = NULL; 221 public_key_ = NULL;
222 } 222 }
223 signature_.clear(); 223 signature_.clear();
224 } 224 }
225 225
226 } // namespace crypto 226 } // namespace crypto
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698