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

Side by Side Diff: crypto/signature_creator_openssl.cc

Issue 1441543002: Make vector_as_array use std::vector::data and switch a few directories. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mark comment Created 5 years, 1 month 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
« no previous file with comments | « crypto/nss_key_util.cc ('k') | crypto/signature_verifier_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/signature_creator.h" 5 #include "crypto/signature_creator.h"
6 6
7 #include <openssl/evp.h> 7 #include <openssl/evp.h>
8 #include <openssl/rsa.h> 8 #include <openssl/rsa.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/stl_util.h"
13 #include "crypto/openssl_util.h" 12 #include "crypto/openssl_util.h"
14 #include "crypto/rsa_private_key.h" 13 #include "crypto/rsa_private_key.h"
15 #include "crypto/scoped_openssl_types.h" 14 #include "crypto/scoped_openssl_types.h"
16 15
17 namespace crypto { 16 namespace crypto {
18 17
19 namespace { 18 namespace {
20 19
21 const EVP_MD* ToOpenSSLDigest(SignatureCreator::HashAlgorithm hash_alg) { 20 const EVP_MD* ToOpenSSLDigest(SignatureCreator::HashAlgorithm hash_alg) {
22 switch (hash_alg) { 21 switch (hash_alg) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 const uint8* data, 62 const uint8* data,
64 int data_len, 63 int data_len,
65 std::vector<uint8>* signature) { 64 std::vector<uint8>* signature) {
66 ScopedRSA rsa_key(EVP_PKEY_get1_RSA(key->key())); 65 ScopedRSA rsa_key(EVP_PKEY_get1_RSA(key->key()));
67 if (!rsa_key) 66 if (!rsa_key)
68 return false; 67 return false;
69 signature->resize(RSA_size(rsa_key.get())); 68 signature->resize(RSA_size(rsa_key.get()));
70 69
71 unsigned int len = 0; 70 unsigned int len = 0;
72 if (!RSA_sign(ToOpenSSLDigestType(hash_alg), data, data_len, 71 if (!RSA_sign(ToOpenSSLDigestType(hash_alg), data, data_len,
73 vector_as_array(signature), &len, rsa_key.get())) { 72 signature->data(), &len, rsa_key.get())) {
74 signature->clear(); 73 signature->clear();
75 return false; 74 return false;
76 } 75 }
77 signature->resize(len); 76 signature->resize(len);
78 return true; 77 return true;
79 } 78 }
80 79
81 SignatureCreator::SignatureCreator() 80 SignatureCreator::SignatureCreator()
82 : sign_context_(EVP_MD_CTX_create()) { 81 : sign_context_(EVP_MD_CTX_create()) {
83 } 82 }
(...skipping 12 matching lines...) Expand all
96 95
97 // Determine the maximum length of the signature. 96 // Determine the maximum length of the signature.
98 size_t len = 0; 97 size_t len = 0;
99 if (!EVP_DigestSignFinal(sign_context_, NULL, &len)) { 98 if (!EVP_DigestSignFinal(sign_context_, NULL, &len)) {
100 signature->clear(); 99 signature->clear();
101 return false; 100 return false;
102 } 101 }
103 signature->resize(len); 102 signature->resize(len);
104 103
105 // Sign it. 104 // Sign it.
106 if (!EVP_DigestSignFinal(sign_context_, vector_as_array(signature), &len)) { 105 if (!EVP_DigestSignFinal(sign_context_, signature->data(), &len)) {
107 signature->clear(); 106 signature->clear();
108 return false; 107 return false;
109 } 108 }
110 signature->resize(len); 109 signature->resize(len);
111 return true; 110 return true;
112 } 111 }
113 112
114 } // namespace crypto 113 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/nss_key_util.cc ('k') | crypto/signature_verifier_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698