Commit acbc35cd authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

Use constant-time HMAC comparison in Nigori.

Cryptography is timing-sensitive. MACs should never be compared with usual
string comparison functions, only constant-time checks. Use HMAC::Verify.

Bug: none
Change-Id: Ic1b164441396e4a4a853f1a50d91bc8f5c7fa18e
Reviewed-on: https://chromium-review.googlesource.com/1246323Reviewed-by: default avatarvitaliii <vitaliii@chromium.org>
Commit-Queue: David Benjamin <davidben@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594737}
parent 4f9fb41c
...@@ -334,12 +334,7 @@ bool Nigori::Decrypt(const std::string& encrypted, std::string* value) const { ...@@ -334,12 +334,7 @@ bool Nigori::Decrypt(const std::string& encrypted, std::string* value) const {
if (!hmac.Init(keys_.mac_key->key())) if (!hmac.Init(keys_.mac_key->key()))
return false; return false;
std::vector<unsigned char> expected(kHashSize); if (!hmac.Verify(ciphertext, hash))
if (!hmac.Sign(ciphertext, &expected[0], expected.size()))
return false;
if (hash.compare(0, hash.size(), reinterpret_cast<char*>(&expected[0]),
expected.size()))
return false; return false;
crypto::Encryptor encryptor; crypto::Encryptor encryptor;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment