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

Unified Diff: crypto/hmac_unittest.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 | « crypto/hmac_openssl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/hmac_unittest.cc
diff --git a/crypto/hmac_unittest.cc b/crypto/hmac_unittest.cc
index f0844a9186c9d661273483266408dcb9b2e1a3c1..6bcd1bc2e3a4dda86406c0b6d3620d587126428c 100644
--- a/crypto/hmac_unittest.cc
+++ b/crypto/hmac_unittest.cc
@@ -275,3 +275,21 @@ TEST(HMACTest, Verify) {
base::StringPiece(empty_digest, kSHA1DigestSize)));
}
}
+
+TEST(HMACTest, EmptyKey) {
+ // Test vector from https://en.wikipedia.org/wiki/HMAC
+ const char* kExpectedDigest =
+ "\xFB\xDB\x1D\x1B\x18\xAA\x6C\x08\x32\x4B\x7D\x64\xB7\x1F\xB7\x63"
+ "\x70\x69\x0E\x1D";
+ base::StringPiece data("", 0u);
wtc 2014/04/10 18:43:41 You can also try using a std::string: std::stri
davidben 2014/04/10 18:54:29 Yeah, per C++11, std::string::data and std::string
+
+ crypto::HMAC hmac(crypto::HMAC::SHA1);
+ ASSERT_TRUE(hmac.Init(NULL, 0));
+
+ unsigned char digest[kSHA1DigestSize];
+ EXPECT_TRUE(hmac.Sign(data, digest, kSHA1DigestSize));
+ EXPECT_EQ(0, memcmp(kExpectedDigest, digest, kSHA1DigestSize));
+
+ EXPECT_TRUE(hmac.Verify(
+ data, base::StringPiece(kExpectedDigest, kSHA1DigestSize)));
+}
« no previous file with comments | « crypto/hmac_openssl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698