Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/vczip/tests/tvcsum.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2003-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Phong Vo <[email protected]> *
18
* Glenn Fowler <[email protected]> *
19
* *
20
***********************************************************************/
21
#include "vctest.h"
22
#include "vccrypto.h"
23
24
/* hold test strings */
25
typedef struct _pair_s
26
{ Vcchar_t* str;
27
Vcchar_t* sum;
28
} Pair_t;
29
30
static Pair_t Md5[] =
31
{ { "0123456789", "781E5E245D69B566979B86E28D23F2C7" },
32
{ "abcdefghij", "A925576942E94B2EF57A066101B48876" },
33
{ 0, 0 }
34
};
35
36
int main()
37
{
38
ssize_t k, n;
39
Vcchar_t *sum, hex[1024];
40
Vcx_t xx;
41
42
if(vcxinit(&xx, Vcxmd5sum, 0, 0) < 0)
43
terror("Initializing md5 handle");
44
for(k = 0; Md5[k].str; ++k)
45
{ if((n = vcxencode(&xx, Md5[k].str, strlen((char*)Md5[k].str), &sum)) < 0 )
46
terror("Encoding data");
47
if(n != 16)
48
terror("Bad md5 digest length");
49
if(vchexcode(sum, n, hex, sizeof(hex), 1) != 32)
50
terror("Bad md5 hex coding length");
51
if(strcmp((char*)Md5[k].sum, (char*)hex) != 0)
52
terror("Bad md5 digest");
53
}
54
vcxstop(&xx);
55
56
exit(0);
57
}
58
59