From 6c683f09fd3c1e0b7565b6c93d639b9840e7c1f8 Mon Sep 17 00:00:00 2001 From: "bryner@chromium.org" Date: Fri, 24 Sep 2010 17:45:21 +0000 Subject: Fix a bug in the string wrapper for SHA256HashString. The wrapper was using the size of the input string as the number of hash bytes to compute, rather than the size of the output string (SHA256_LENGTH). Added a test for this. BUG=none TEST=Sha256Test.Test1_String Review URL: http://codereview.chromium.org/3492008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60491 0039d316-1c4b-4281-b951-d872f2087c98 --- base/sha2_unittest.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'base/sha2_unittest.cc') diff --git a/base/sha2_unittest.cc b/base/sha2_unittest.cc index a6844dd..b0321e8 100644 --- a/base/sha2_unittest.cc +++ b/base/sha2_unittest.cc @@ -30,6 +30,25 @@ TEST(Sha256Test, Test1) { EXPECT_EQ(expected1[i], static_cast(output_truncated1[i])); } +TEST(Sha256Test, Test1_String) { + // Same as the above, but using the wrapper that returns a std::string. + // Example B.1 from FIPS 180-2: one-block message. + std::string input1 = "abc"; + int expected1[] = { 0xba, 0x78, 0x16, 0xbf, + 0x8f, 0x01, 0xcf, 0xea, + 0x41, 0x41, 0x40, 0xde, + 0x5d, 0xae, 0x22, 0x23, + 0xb0, 0x03, 0x61, 0xa3, + 0x96, 0x17, 0x7a, 0x9c, + 0xb4, 0x10, 0xff, 0x61, + 0xf2, 0x00, 0x15, 0xad }; + + std::string output1 = base::SHA256HashString(input1); + ASSERT_EQ(base::SHA256_LENGTH, output1.size()); + for (size_t i = 0; i < base::SHA256_LENGTH; i++) + EXPECT_EQ(expected1[i], static_cast(output1[i])); +} + TEST(Sha256Test, Test2) { // Example B.2 from FIPS 180-2: multi-block message. std::string input2 = -- cgit v1.1