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

Unified Diff: base/sha1_unittest.cc

Issue 6661025: Add base::SHA1HashBytes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing wtc's comments Created 9 years, 9 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 | « base/sha1_portable.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sha1_unittest.cc
diff --git a/base/sha1_unittest.cc b/base/sha1_unittest.cc
index e445e8f0a334ad76717867cbe15297606d45fe61..406150b14d4acb22ba4e69c885bccaf2c55f5e64 100644
--- a/base/sha1_unittest.cc
+++ b/base/sha1_unittest.cc
@@ -54,3 +54,55 @@ TEST(SHA1Test, Test3) {
for (size_t i = 0; i < base::SHA1_LENGTH; i++)
EXPECT_EQ(expected[i], output[i] & 0xFF);
}
+
+TEST(SHA1Test, Test1Bytes) {
+ // Example A.1 from FIPS 180-2: one-block message.
+ std::string input = "abc";
+ unsigned char output[base::SHA1_LENGTH];
+
+ unsigned char expected[] = { 0xa9, 0x99, 0x3e, 0x36,
+ 0x47, 0x06, 0x81, 0x6a,
+ 0xba, 0x3e, 0x25, 0x71,
+ 0x78, 0x50, 0xc2, 0x6c,
+ 0x9c, 0xd0, 0xd8, 0x9d };
+
+ base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()),
+ input.length(), output);
+ for (size_t i = 0; i < base::SHA1_LENGTH; i++)
+ EXPECT_EQ(expected[i], output[i]);
+}
+
+TEST(SHA1Test, Test2Bytes) {
+ // Example A.2 from FIPS 180-2: multi-block message.
+ std::string input =
+ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+ unsigned char output[base::SHA1_LENGTH];
+
+ unsigned char expected[] = { 0x84, 0x98, 0x3e, 0x44,
+ 0x1c, 0x3b, 0xd2, 0x6e,
+ 0xba, 0xae, 0x4a, 0xa1,
+ 0xf9, 0x51, 0x29, 0xe5,
+ 0xe5, 0x46, 0x70, 0xf1 };
+
+ base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()),
+ input.length(), output);
+ for (size_t i = 0; i < base::SHA1_LENGTH; i++)
+ EXPECT_EQ(expected[i], output[i]);
+}
+
+TEST(SHA1Test, Test3Bytes) {
+ // Example A.3 from FIPS 180-2: long message.
+ std::string input(1000000, 'a');
+ unsigned char output[base::SHA1_LENGTH];
+
+ unsigned char expected[] = { 0x34, 0xaa, 0x97, 0x3c,
+ 0xd4, 0xc4, 0xda, 0xa4,
+ 0xf6, 0x1e, 0xeb, 0x2b,
+ 0xdb, 0xad, 0x27, 0x31,
+ 0x65, 0x34, 0x01, 0x6f };
+
+ base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()),
+ input.length(), output);
+ for (size_t i = 0; i < base::SHA1_LENGTH; i++)
+ EXPECT_EQ(expected[i], output[i]);
+}
« no previous file with comments | « base/sha1_portable.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698