OLD | NEW |
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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 HashAlgorithm hash_alg, | 61 HashAlgorithm hash_alg, |
62 const uint8* data, | 62 const uint8* data, |
63 int data_len, | 63 int data_len, |
64 std::vector<uint8>* signature) { | 64 std::vector<uint8>* signature) { |
65 ScopedRSA rsa_key(EVP_PKEY_get1_RSA(key->key())); | 65 ScopedRSA rsa_key(EVP_PKEY_get1_RSA(key->key())); |
66 if (!rsa_key) | 66 if (!rsa_key) |
67 return false; | 67 return false; |
68 signature->resize(RSA_size(rsa_key.get())); | 68 signature->resize(RSA_size(rsa_key.get())); |
69 | 69 |
70 unsigned int len = 0; | 70 unsigned int len = 0; |
71 bool success = RSA_sign(ToOpenSSLDigestType(hash_alg), data, data_len, | 71 if (!RSA_sign(ToOpenSSLDigestType(hash_alg), data, data_len, |
72 vector_as_array(signature), &len, rsa_key.get()); | 72 vector_as_array(signature), &len, rsa_key.get())) { |
73 if (!success) { | |
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 16 matching lines...) Expand all Loading... |
100 int rv = EVP_SignFinal(sign_context_, vector_as_array(signature), &len, key); | 99 int rv = EVP_SignFinal(sign_context_, vector_as_array(signature), &len, key); |
101 if (!rv) { | 100 if (!rv) { |
102 signature->clear(); | 101 signature->clear(); |
103 return false; | 102 return false; |
104 } | 103 } |
105 signature->resize(len); | 104 signature->resize(len); |
106 return true; | 105 return true; |
107 } | 106 } |
108 | 107 |
109 } // namespace crypto | 108 } // namespace crypto |
OLD | NEW |