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; |
} |