Chromium Code Reviews| 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/ec_signature_creator_impl.h" | 5 #include "crypto/ec_signature_creator_impl.h" |
| 6 | 6 |
| 7 #include <openssl/bn.h> | 7 #include <openssl/bn.h> |
| 8 #include <openssl/ec.h> | 8 #include <openssl/ec.h> |
| 9 #include <openssl/ecdsa.h> | 9 #include <openssl/ecdsa.h> |
| 10 #include <openssl/evp.h> | 10 #include <openssl/evp.h> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 OpenSSLErrStackTracer err_tracer(FROM_HERE); | 53 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 54 // Create ECDSA_SIG object from DER-encoded data. | 54 // Create ECDSA_SIG object from DER-encoded data. |
| 55 const unsigned char* der_data = &der_sig.front(); | 55 const unsigned char* der_data = &der_sig.front(); |
| 56 ScopedECDSA_SIG ecdsa_sig( | 56 ScopedECDSA_SIG ecdsa_sig( |
| 57 d2i_ECDSA_SIG(NULL, &der_data, static_cast<long>(der_sig.size()))); | 57 d2i_ECDSA_SIG(NULL, &der_data, static_cast<long>(der_sig.size()))); |
| 58 if (!ecdsa_sig.get()) | 58 if (!ecdsa_sig.get()) |
| 59 return false; | 59 return false; |
| 60 | 60 |
| 61 // The result is made of two 32-byte vectors. | 61 // The result is made of two 32-byte vectors. |
| 62 const size_t kMaxBytesPerBN = 32; | 62 const size_t kMaxBytesPerBN = 32; |
| 63 std::vector<uint8> result; | 63 std::vector<uint8> result(2 * kMaxBytesPerBN); |
| 64 result.resize(2 * kMaxBytesPerBN); | |
| 65 memset(&result[0], 0, result.size()); | |
| 66 | 64 |
| 67 BIGNUM* r = ecdsa_sig.get()->r; | 65 const BIGNUM* r = ecdsa_sig.get()->r; |
|
davidben
2014/11/10 22:37:03
Nit: was there in the original, but doesn't ecdsa_
eroman
2014/11/10 22:42:01
Done: I removed the variables and inlined as ecdsa
| |
| 68 BIGNUM* s = ecdsa_sig.get()->s; | 66 const BIGNUM* s = ecdsa_sig.get()->s; |
| 69 int r_bytes = BN_num_bytes(r); | 67 |
| 70 int s_bytes = BN_num_bytes(s); | 68 if (!BN_bn2bin_padded(&result[0], kMaxBytesPerBN, r) || |
| 71 // NOTE: Can't really check for equality here since sometimes the value | 69 !BN_bn2bin_padded(&result[kMaxBytesPerBN], kMaxBytesPerBN, s)) { |
| 72 // returned by BN_num_bytes() will be slightly smaller than kMaxBytesPerBN. | |
| 73 if (r_bytes > static_cast<int>(kMaxBytesPerBN) || | |
| 74 s_bytes > static_cast<int>(kMaxBytesPerBN)) { | |
| 75 DLOG(ERROR) << "Invalid key sizes r(" << r_bytes << ") s(" << s_bytes | |
| 76 << ")"; | |
| 77 return false; | 70 return false; |
| 78 } | 71 } |
| 79 BN_bn2bin(ecdsa_sig.get()->r, &result[kMaxBytesPerBN - r_bytes]); | |
| 80 BN_bn2bin(ecdsa_sig.get()->s, &result[2 * kMaxBytesPerBN - s_bytes]); | |
| 81 out_raw_sig->swap(result); | 72 out_raw_sig->swap(result); |
| 82 return true; | 73 return true; |
| 83 } | 74 } |
| 84 | 75 |
| 85 } // namespace crypto | 76 } // namespace crypto |
| OLD | NEW |