Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 } | |
| OLD | NEW |