From 0e83fe8c8551c7695af31d06f1e369c28a0f46b2 Mon Sep 17 00:00:00 2001 From: "davidben@chromium.org" Date: Thu, 10 Apr 2014 21:16:59 +0000 Subject: 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 --- crypto/hmac_openssl.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'crypto/hmac_openssl.cc') 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; } -- cgit v1.1