summaryrefslogtreecommitdiffstats
path: root/crypto/hmac_openssl.cc
diff options
context:
space:
mode:
authordavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-10 21:16:59 +0000
committerdavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-10 21:16:59 +0000
commit0e83fe8c8551c7695af31d06f1e369c28a0f46b2 (patch)
tree0b6885638a3f88059e6bf5391064d3bb31b2609f /crypto/hmac_openssl.cc
parent852af4dd6de75142822632c95fe840562b0d5a9a (diff)
downloadchromium_src-0e83fe8c8551c7695af31d06f1e369c28a0f46b2.zip
chromium_src-0e83fe8c8551c7695af31d06f1e369c28a0f46b2.tar.gz
chromium_src-0e83fe8c8551c7695af31d06f1e369c28a0f46b2.tar.bz2
Allow empty keys in hmac_openssl.cc.
PrefHashCalculator uses empty keys in developer builds. This fixes Chrome startup in debug builds. BUG=none Review URL: https://codereview.chromium.org/231603002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263085 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/hmac_openssl.cc')
-rw-r--r--crypto/hmac_openssl.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/crypto/hmac_openssl.cc b/crypto/hmac_openssl.cc
index f7010c8..46bfbae 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;
}