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

Unified Diff: crypto/hmac_openssl.cc

Issue 231603002: Allow empty keys in hmac_openssl.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 0 -> 0u in hopes that appeases Android's STL Created 6 years, 8 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_unittest.cc » ('j') | crypto/hmac_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/hmac_openssl.cc
diff --git a/crypto/hmac_openssl.cc b/crypto/hmac_openssl.cc
index f7010c81bc651a562996b788645352b6cb2a3e1b..46bfbaefbeff7acdcf1fcbc2c925ed1a77d93e64 100644
--- a/crypto/hmac_openssl.cc
+++ b/crypto/hmac_openssl.cc
@@ -31,6 +31,14 @@ bool HMAC::Init(const unsigned char* key, size_t key_length) {
DCHECK(plat_->key.empty());
plat_->key.assign(key, key + key_length);
+ if (key_length == 0) {
+ // Special-case: if the key is empty, use a key with one zero
+ // byte. OpenSSL's HMAC function breaks when passed a NULL key. (It calls
+ // HMAC_Init_ex which treats a NULL key as having already been initialized
+ // with a key previously.) HMAC pads keys with zeros, so this key is
+ // equivalent.
+ plat_->key.push_back(0);
+ }
return true;
}
« no previous file with comments | « no previous file | crypto/hmac_unittest.cc » ('j') | crypto/hmac_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698