]>
Commit | Line | Data |
---|---|---|
784202a2 AL |
1 | #include <apt-pkg/md5.h> |
2 | #include <apt-pkg/sha1.h> | |
84a0890e | 3 | #include <apt-pkg/sha2.h> |
784202a2 | 4 | #include <apt-pkg/strutl.h> |
aebbb9d0 AL |
5 | #include <iostream> |
6 | ||
7 | using namespace std; | |
784202a2 AL |
8 | |
9 | template <class T> void Test(const char *In,const char *Out) | |
10 | { | |
11 | T Sum; | |
12 | Sum.Add(In); | |
54ce88fd MV |
13 | |
14 | cout << "expected: '" << Out << "'" << endl; | |
15 | cout << "got : '" << Sum.Result().Value() << "'" << endl; | |
16 | cout << "got : '" << Sum.Result().Value() << "'" << endl; | |
17 | cout << "got : '" << Sum.Result().Value() << "'" << endl; | |
18 | if (stringcasecmp(Sum.Result().Value(), Out) != 0) { | |
19 | cout << "FAIL" << endl << endl; | |
784202a2 | 20 | abort(); |
54ce88fd MV |
21 | } else { |
22 | cout << "PASS" << endl << endl; | |
23 | } | |
784202a2 AL |
24 | } |
25 | ||
26 | template <class T> void TestMill(const char *Out) | |
27 | { | |
28 | T Sum; | |
29 | ||
30 | const unsigned char As[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | |
31 | unsigned Count = 1000000; | |
32 | for (; Count != 0;) | |
33 | { | |
34 | if (Count >= 64) | |
35 | { | |
36 | Sum.Add(As,64); | |
37 | Count -= 64; | |
38 | } | |
39 | else | |
40 | { | |
41 | Sum.Add(As,Count); | |
42 | Count = 0; | |
43 | } | |
44 | } | |
54ce88fd MV |
45 | |
46 | if (stringcasecmp(Sum.Result().Value(), Out) != 0) | |
784202a2 AL |
47 | abort(); |
48 | } | |
49 | ||
50 | int main() | |
51 | { | |
52 | // From FIPS PUB 180-1 | |
53 | Test<SHA1Summation>("abc","A9993E364706816ABA3E25717850C26C9CD0D89D"); | |
54 | Test<SHA1Summation>("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | |
55 | "84983E441C3BD26EBAAE4AA1F95129E5E54670F1"); | |
56 | TestMill<SHA1Summation>("34AA973CD4C4DAA4F61EEB2BDBAD27316534016F"); | |
57 | ||
58 | // MD5 tests from RFC 1321 | |
59 | Test<MD5Summation>("","d41d8cd98f00b204e9800998ecf8427e"); | |
60 | Test<MD5Summation>("a","0cc175b9c0f1b6a831c399e269772661"); | |
61 | Test<MD5Summation>("abc","900150983cd24fb0d6963f7d28e17f72"); | |
62 | Test<MD5Summation>("message digest","f96b697d7cb7938d525a2f31aaf161d0"); | |
63 | Test<MD5Summation>("abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b"); | |
64 | Test<MD5Summation>("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | |
65 | "d174ab98d277d9f5a5611c2c9f419d9f"); | |
66 | Test<MD5Summation>("12345678901234567890123456789012345678901234567890123456789012345678901234567890", | |
67 | "57edf4a22be3c955ac49da2e2107b67a"); | |
fab58e35 MV |
68 | |
69 | // SHA-256, From FIPS 180-2 | |
70 | Test<SHA256Summation>("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | |
71 | "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); | |
fab58e35 | 72 | |
54ce88fd MV |
73 | // SHA-512, From |
74 | Test<SHA512Summation>( | |
75 | "abc", | |
76 | "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" | |
77 | "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"); | |
78 | ||
784202a2 AL |
79 | return 0; |
80 | } | |
81 | ||
82 |