diff options
author | eroman <eroman@chromium.org> | 2014-11-10 15:43:38 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-10 23:44:02 +0000 |
commit | 0f4b2770055c29a698a0daaad87c57fe7f2169b5 (patch) | |
tree | 37f6be66cd757c1574e81ecd46e6d4f8c9dcde9a /crypto | |
parent | 1867afc9d14407dfc3e820236b82421f356fa2c0 (diff) | |
download | chromium_src-0f4b2770055c29a698a0daaad87c57fe7f2169b5.zip chromium_src-0f4b2770055c29a698a0daaad87c57fe7f2169b5.tar.gz chromium_src-0f4b2770055c29a698a0daaad87c57fe7f2169b5.tar.bz2 |
Cleanup: Use BN_bn2bin_padded() for zero-padding rather than custom code.
Review URL: https://codereview.chromium.org/711113003
Cr-Commit-Position: refs/heads/master@{#303535}
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/ec_signature_creator_openssl.cc | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/crypto/ec_signature_creator_openssl.cc b/crypto/ec_signature_creator_openssl.cc index 91e8a6a8..c422cef 100644 --- a/crypto/ec_signature_creator_openssl.cc +++ b/crypto/ec_signature_creator_openssl.cc @@ -60,24 +60,13 @@ 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 - << ")"; + if (!BN_bn2bin_padded(&result[0], kMaxBytesPerBN, ecdsa_sig->r) || + !BN_bn2bin_padded(&result[kMaxBytesPerBN], kMaxBytesPerBN, + ecdsa_sig->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; } |