From 54ce88fd2669a729c89c940be3abc9456d19d542 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Feb 2011 21:53:23 +0100 Subject: add sha512 interface based on sha2 by aaron gifford --- test/hash.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'test/hash.cc') diff --git a/test/hash.cc b/test/hash.cc index cfdb4ea9d..259aa4e9a 100644 --- a/test/hash.cc +++ b/test/hash.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -10,9 +11,17 @@ template void Test(const char *In,const char *Out) { T Sum; Sum.Add(In); - cout << Sum.Result().Value() << endl; - if (stringcasecmp(Sum.Result().Value(),Out) != 0) + + cout << "expected: '" << Out << "'" << endl; + cout << "got : '" << Sum.Result().Value() << "'" << endl; + cout << "got : '" << Sum.Result().Value() << "'" << endl; + cout << "got : '" << Sum.Result().Value() << "'" << endl; + if (stringcasecmp(Sum.Result().Value(), Out) != 0) { + cout << "FAIL" << endl << endl; abort(); + } else { + cout << "PASS" << endl << endl; + } } template void TestMill(const char *Out) @@ -34,9 +43,8 @@ template void TestMill(const char *Out) Count = 0; } } - - cout << Sum.Result().Value() << endl; - if (stringcasecmp(Sum.Result().Value(),Out) != 0) + + if (stringcasecmp(Sum.Result().Value(), Out) != 0) abort(); } @@ -62,8 +70,13 @@ int main() // SHA-256, From FIPS 180-2 Test("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); - + // SHA-512, From + Test( + "abc", + "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" + "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"); + return 0; } -- cgit v1.2.3 From 84a0890e6ef49b5d41a0b9ff0b5a5fe95cca6f3e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 25 Feb 2011 14:16:35 +0100 Subject: move sha512,256 into apt-pkg/sha2.{cc,h}, move gifford implementation to sha2_internal.{cc,h} --- test/hash.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/hash.cc') diff --git a/test/hash.cc b/test/hash.cc index 259aa4e9a..88f09fca0 100644 --- a/test/hash.cc +++ b/test/hash.cc @@ -1,7 +1,6 @@ #include #include -#include -#include +#include #include #include -- cgit v1.2.3 From 67dc3830798e6b59a9fce03682c9802233b0a1fe Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Jul 2011 19:34:11 +0200 Subject: move hash test to libapt-testcases and add a few more tests --- test/hash.cc | 82 ------------------------------------------------------------ 1 file changed, 82 deletions(-) delete mode 100644 test/hash.cc (limited to 'test/hash.cc') diff --git a/test/hash.cc b/test/hash.cc deleted file mode 100644 index 88f09fca0..000000000 --- a/test/hash.cc +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include -#include -#include - -using namespace std; - -template void Test(const char *In,const char *Out) -{ - T Sum; - Sum.Add(In); - - cout << "expected: '" << Out << "'" << endl; - cout << "got : '" << Sum.Result().Value() << "'" << endl; - cout << "got : '" << Sum.Result().Value() << "'" << endl; - cout << "got : '" << Sum.Result().Value() << "'" << endl; - if (stringcasecmp(Sum.Result().Value(), Out) != 0) { - cout << "FAIL" << endl << endl; - abort(); - } else { - cout << "PASS" << endl << endl; - } -} - -template void TestMill(const char *Out) -{ - T Sum; - - const unsigned char As[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - unsigned Count = 1000000; - for (; Count != 0;) - { - if (Count >= 64) - { - Sum.Add(As,64); - Count -= 64; - } - else - { - Sum.Add(As,Count); - Count = 0; - } - } - - if (stringcasecmp(Sum.Result().Value(), Out) != 0) - abort(); -} - -int main() -{ - // From FIPS PUB 180-1 - Test("abc","A9993E364706816ABA3E25717850C26C9CD0D89D"); - Test("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "84983E441C3BD26EBAAE4AA1F95129E5E54670F1"); - TestMill("34AA973CD4C4DAA4F61EEB2BDBAD27316534016F"); - - // MD5 tests from RFC 1321 - Test("","d41d8cd98f00b204e9800998ecf8427e"); - Test("a","0cc175b9c0f1b6a831c399e269772661"); - Test("abc","900150983cd24fb0d6963f7d28e17f72"); - Test("message digest","f96b697d7cb7938d525a2f31aaf161d0"); - Test("abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b"); - Test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "d174ab98d277d9f5a5611c2c9f419d9f"); - Test("12345678901234567890123456789012345678901234567890123456789012345678901234567890", - "57edf4a22be3c955ac49da2e2107b67a"); - - // SHA-256, From FIPS 180-2 - Test("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); - - // SHA-512, From - Test( - "abc", - "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" - "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"); - - return 0; -} - - -- cgit v1.2.3