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

Unified Diff: crypto/ec_signature_creator_openssl.cc

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/BUILD.gn ('k') | crypto/nss_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c422cef5f275a2d6cf711d78affc31fb6e00d411 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;
}
« no previous file with comments | « crypto/BUILD.gn ('k') | crypto/nss_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698