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

Unified Diff: components/webcrypto/algorithms/hmac.cc

Issue 2202843002: Pass a minimally sized buffer to BoringSSL's HMAC(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address david's feedback Created 4 years, 4 months 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/webcrypto/algorithms/hmac.cc
diff --git a/components/webcrypto/algorithms/hmac.cc b/components/webcrypto/algorithms/hmac.cc
index b02d70c2a9ae1214af6b51e92fb0b916e78b5206..1b4be4a5d4c989e9d52fefdef4b3a7a2b4c6ba74 100644
--- a/components/webcrypto/algorithms/hmac.cc
+++ b/components/webcrypto/algorithms/hmac.cc
@@ -96,15 +96,16 @@ Status SignHmac(const std::vector<uint8_t>& raw_key,
size_t hmac_expected_length = EVP_MD_size(digest_algorithm);
buffer->resize(hmac_expected_length);
- crypto::ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> hmac_result(
- buffer->data(), hmac_expected_length);
unsigned int hmac_actual_length;
- unsigned char* const success =
- HMAC(digest_algorithm, raw_key.data(), raw_key.size(), data.bytes(),
- data.byte_length(), hmac_result.safe_buffer(), &hmac_actual_length);
- if (!success || hmac_actual_length != hmac_expected_length)
+ if (!HMAC(digest_algorithm, raw_key.data(), raw_key.size(), data.bytes(),
+ data.byte_length(), buffer->data(), &hmac_actual_length)) {
return Status::OperationError();
+ }
+
+ // HMAC() promises to use at most EVP_MD_CTX_size(). If this was not the
+ // case then memory corruption may have just occurred.
+ CHECK_EQ(hmac_expected_length, hmac_actual_length);
return Status::Success();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698