aboutsummaryrefslogtreecommitdiff
path: root/src/unit/md5.unit
diff options
context:
space:
mode:
Diffstat (limited to 'src/unit/md5.unit')
-rw-r--r--src/unit/md5.unit82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/unit/md5.unit b/src/unit/md5.unit
new file mode 100644
index 0000000..248aaaf
--- /dev/null
+++ b/src/unit/md5.unit
@@ -0,0 +1,82 @@
1// vim: syntax=cpp
2/*
3 * Copyright (C) 2007-2010 Xagasoft, All rights reserved.
4 *
5 * This file is part of the libbu++ library and is released under the
6 * terms of the license contained in the file LICENSE.
7 */
8
9#include "bu/md5.h"
10
11#include <stdlib.h>
12
13suite Md5
14{
15 test basics
16 {
17#define tryStr( a, b ) \
18 { Bu::Md5 m; m.addData(a); unitTest( m.getHexResult() == b ); } (void)0
19 tryStr("", "d41d8cd98f00b204e9800998ecf8427e");
20 tryStr("a", "0cc175b9c0f1b6a831c399e269772661");
21 tryStr("abc", "900150983cd24fb0d6963f7d28e17f72");
22 tryStr("message digest", "f96b697d7cb7938d525a2f31aaf161d0");
23 tryStr("abcdefghijklmnopqrstuvwxyz",
24 "c3fcd3d76192e4007dfb496cca67e13b");
25 tryStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
26 "d174ab98d277d9f5a5611c2c9f419d9f");
27 tryStr("12345678901234567890123456789012345"
28 "678901234567890123456789012345678901234567890",
29 "57edf4a22be3c955ac49da2e2107b67a");
30 }
31
32 test twoChunks
33 {
34 Bu::Md5 m;
35 m.addData("12345678901234567890123456789012345");
36 m.addData("678901234567890123456789012345678901234567890");
37 unitTest( m.getHexResult() == "57edf4a22be3c955ac49da2e2107b67a" );
38 }
39
40 test biggerBlocks
41 {
42 const char *sums[33] = {
43 "75fcf199abe516903321095a588b938d",
44 "e26a863c96d6bdba6601175aedaae108",
45 "2b207fdcb222078d3ebfeb8d5e7c9315",
46 "b08683aaa465add72cc2b43ae42f4f70",
47 "638bb73963b2d925771c3579ccb5e879",
48 "c727bd4b48a88e3df5924a2604de0790",
49 "f33d21203c80490f7342e5853c5550eb",
50 "db449faca66a177aae59b1e36a19d053",
51 "c800d429afb5f5c820f75c2c94e2e2bb",
52 "43b79c70b9a6a11e823ffbfa0f45a4db",
53 "0177ffc483cf598ae3966b3a5ae00c8c",
54 "1a68fdf4b17a3820d48d101e9355a818"
55 };
56
57 char block[128];
58 for( int i = 0; i < 128; i++ )
59 block[i] = i*2;
60
61 const char **curSum = sums;
62 for( int j = 1; j < 4096; j*=2 )
63 {
64 /*
65 Bu::File fOut("temp", Bu::File::WriteNew );
66 for( int b = 0; b < j; b++ )
67 {
68 fOut.write( block, 128 );
69 }
70 fOut.close();
71 system("md5sum -b temp");
72 */
73 Bu::Md5 m;
74 for( int b = 0; b < j; b++ )
75 {
76 m.addData( block, 128 );
77 }
78 unitTest( m.getHexResult() == *curSum );
79 curSum++;
80 }
81 }
82}