From 784202a271ae7e303aacbe226bb87fed50a16f81 Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Mon, 20 Sep 2004 16:57:07 +0000 Subject: SHA-1 hashing algorithm Author: jgg Date: 2001-03-06 05:03:49 GMT SHA-1 hashing algorithm --- test/hash.cc | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/makefile | 6 ++++++ 2 files changed, 66 insertions(+) create mode 100644 test/hash.cc (limited to 'test') diff --git a/test/hash.cc b/test/hash.cc new file mode 100644 index 000000000..5c05d9608 --- /dev/null +++ b/test/hash.cc @@ -0,0 +1,60 @@ +#include +#include +#include + +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) + abort(); +} + +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; + } + } + + cout << Sum.Result().Value() << endl; + 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"); + return 0; +} + + diff --git a/test/makefile b/test/makefile index e3b2ac524..541f23834 100644 --- a/test/makefile +++ b/test/makefile @@ -56,3 +56,9 @@ SLIBS = -lapt-pkg -lapt-inst SOURCE = extract-control.cc include $(PROGRAM_H) +# Program for testing hashes +PROGRAM=hash +SLIBS = -lapt-pkg +SOURCE = hash.cc +include $(PROGRAM_H) + -- cgit v1.2.3