Chromium Code Reviews| Index: crypto/ec_signature_creator_openssl.cc |
| diff --git a/crypto/ec_signature_creator_openssl.cc b/crypto/ec_signature_creator_openssl.cc |
| index 91e8a6a8d330512cb018b2de0c415999e4f15632..8977cdc68cfa9e761e9012739263936bff9daf08 100644 |
| --- a/crypto/ec_signature_creator_openssl.cc |
| +++ b/crypto/ec_signature_creator_openssl.cc |
| @@ -60,24 +60,15 @@ bool ECSignatureCreatorImpl::DecodeSignature(const std::vector<uint8>& der_sig, |
| // The result is made of two 32-byte vectors. |
| const size_t kMaxBytesPerBN = 32; |
| - std::vector<uint8> result; |
| - result.resize(2 * kMaxBytesPerBN); |
| - memset(&result[0], 0, result.size()); |
| + std::vector<uint8> result(2 * kMaxBytesPerBN); |
| - BIGNUM* r = ecdsa_sig.get()->r; |
| - BIGNUM* s = ecdsa_sig.get()->s; |
| - int r_bytes = BN_num_bytes(r); |
| - int s_bytes = BN_num_bytes(s); |
| - // NOTE: Can't really check for equality here since sometimes the value |
| - // returned by BN_num_bytes() will be slightly smaller than kMaxBytesPerBN. |
| - if (r_bytes > static_cast<int>(kMaxBytesPerBN) || |
| - s_bytes > static_cast<int>(kMaxBytesPerBN)) { |
| - DLOG(ERROR) << "Invalid key sizes r(" << r_bytes << ") s(" << s_bytes |
| - << ")"; |
| + 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
|
| + const BIGNUM* s = ecdsa_sig.get()->s; |
| + |
| + if (!BN_bn2bin_padded(&result[0], kMaxBytesPerBN, r) || |
| + !BN_bn2bin_padded(&result[kMaxBytesPerBN], kMaxBytesPerBN, s)) { |
| return false; |
| } |
| - BN_bn2bin(ecdsa_sig.get()->r, &result[kMaxBytesPerBN - r_bytes]); |
| - BN_bn2bin(ecdsa_sig.get()->s, &result[2 * kMaxBytesPerBN - s_bytes]); |
| out_raw_sig->swap(result); |
| return true; |
| } |