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

Side by Side 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: Test 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 unified diff | Download patch | Annotate | Revision Log
« crypto/hmac_openssl.cc ('K') | « crypto/hmac_openssl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "crypto/hmac.h" 7 #include "crypto/hmac.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 static const size_t kSHA1DigestSize = 20; 10 static const size_t kSHA1DigestSize = 20;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 base::StringPiece(kSimpleHmacCases[i].data, 268 base::StringPiece(kSimpleHmacCases[i].data,
269 kSimpleHmacCases[i].data_len))); 269 kSimpleHmacCases[i].data_len)));
270 270
271 // Expected size, mismatched data 271 // Expected size, mismatched data
272 EXPECT_FALSE(hmac.Verify( 272 EXPECT_FALSE(hmac.Verify(
273 base::StringPiece(kSimpleHmacCases[i].data, 273 base::StringPiece(kSimpleHmacCases[i].data,
274 kSimpleHmacCases[i].data_len), 274 kSimpleHmacCases[i].data_len),
275 base::StringPiece(empty_digest, kSHA1DigestSize))); 275 base::StringPiece(empty_digest, kSHA1DigestSize)));
276 } 276 }
277 } 277 }
278
279 TEST(HMACTest, EmptyKey) {
280 // Test vector from https://en.wikipedia.org/wiki/HMAC
281 const char* kExpectedDigest =
282 "\xFB\xDB\x1D\x1B\x18\xAA\x6C\x08\x32\x4B\x7D\x64\xB7\x1F\xB7\x63"
283 "\x70\x69\x0E\x1D";
284
285 crypto::HMAC hmac(crypto::HMAC::SHA1);
286 ASSERT_TRUE(hmac.Init(NULL, 0));
287
288 unsigned char digest[kSHA1DigestSize];
289 EXPECT_TRUE(hmac.Sign("", digest, kSHA1DigestSize));
wtc 2014/04/09 21:30:58 Please use base::StringPiece() instead of "" here
davidben 2014/04/09 21:44:29 Done. Amusingly, I had to use base::StringPiece(""
290 EXPECT_EQ(0, memcmp(kExpectedDigest, digest, kSHA1DigestSize));
291
292 EXPECT_TRUE(hmac.Verify(
293 "", base::StringPiece(kExpectedDigest, kSHA1DigestSize)));
294 }
OLDNEW
« crypto/hmac_openssl.cc ('K') | « crypto/hmac_openssl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698