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

Unified Diff: content/child/webcrypto/openssl/hmac_openssl.cc

Issue 975273002: Update some comments and code to reflect the fact that HMAC() is no longer hostile to NULL key data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address David's comments Created 5 years, 10 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 | crypto/hmac_openssl.cc » ('j') | crypto/hmac_openssl.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/openssl/hmac_openssl.cc
diff --git a/content/child/webcrypto/openssl/hmac_openssl.cc b/content/child/webcrypto/openssl/hmac_openssl.cc
index 0872390d457a129fea36030889405ae4dbab9271..69b55bf0464979200a41f8bdb37be6aae8950e0a 100644
--- a/content/child/webcrypto/openssl/hmac_openssl.cc
+++ b/content/child/webcrypto/openssl/hmac_openssl.cc
@@ -38,22 +38,14 @@ Status SignHmac(const std::vector<uint8_t>& raw_key,
return Status::ErrorUnsupported();
unsigned int hmac_expected_length = EVP_MD_size(digest_algorithm);
- // OpenSSL wierdness here.
- // First, HMAC() needs a void* for the key data, so make one up front as a
- // cosmetic to avoid a cast. Second, OpenSSL does not like a NULL key,
- // which will result if the raw_key vector is empty; an entirely valid
- // case. Handle this specific case by pointing to a fresh array.
- const unsigned char null_key[] = {0};
- const void* const raw_key_voidp = raw_key.size() ? &raw_key[0] : null_key;
-
buffer->resize(hmac_expected_length);
crypto::ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> hmac_result(
vector_as_array(buffer), hmac_expected_length);
unsigned int hmac_actual_length;
- unsigned char* const success =
- HMAC(digest_algorithm, raw_key_voidp, raw_key.size(), data.bytes(),
- data.byte_length(), hmac_result.safe_buffer(), &hmac_actual_length);
+ unsigned char* const success = HMAC(
+ digest_algorithm, vector_as_array(&raw_key), raw_key.size(), data.bytes(),
+ data.byte_length(), hmac_result.safe_buffer(), &hmac_actual_length);
if (!success || hmac_actual_length != hmac_expected_length)
return Status::OperationError();
« no previous file with comments | « no previous file | crypto/hmac_openssl.cc » ('j') | crypto/hmac_openssl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698