1*40b1a6e6Sjoerg /*-
2*40b1a6e6Sjoerg * Copyright (c) 2003-2007 Tim Kientzle
3*40b1a6e6Sjoerg * Copyright (c) 2011 Andres Mejia
4*40b1a6e6Sjoerg * All rights reserved.
5*40b1a6e6Sjoerg *
6*40b1a6e6Sjoerg * Redistribution and use in source and binary forms, with or without
7*40b1a6e6Sjoerg * modification, are permitted provided that the following conditions
8*40b1a6e6Sjoerg * are met:
9*40b1a6e6Sjoerg * 1. Redistributions of source code must retain the above copyright
10*40b1a6e6Sjoerg * notice, this list of conditions and the following disclaimer.
11*40b1a6e6Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
12*40b1a6e6Sjoerg * notice, this list of conditions and the following disclaimer in the
13*40b1a6e6Sjoerg * documentation and/or other materials provided with the distribution.
14*40b1a6e6Sjoerg *
15*40b1a6e6Sjoerg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16*40b1a6e6Sjoerg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*40b1a6e6Sjoerg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*40b1a6e6Sjoerg * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19*40b1a6e6Sjoerg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*40b1a6e6Sjoerg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*40b1a6e6Sjoerg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*40b1a6e6Sjoerg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*40b1a6e6Sjoerg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*40b1a6e6Sjoerg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*40b1a6e6Sjoerg */
26*40b1a6e6Sjoerg #include "test.h"
27*40b1a6e6Sjoerg
28*40b1a6e6Sjoerg /* Sanity test of internal digest functionality */
29*40b1a6e6Sjoerg
30*40b1a6e6Sjoerg #define __LIBARCHIVE_BUILD 1
31*40b1a6e6Sjoerg #include "archive_digest_private.h"
32*40b1a6e6Sjoerg
DEFINE_TEST(test_archive_md5)33*40b1a6e6Sjoerg DEFINE_TEST(test_archive_md5)
34*40b1a6e6Sjoerg {
35*40b1a6e6Sjoerg archive_md5_ctx ctx;
36*40b1a6e6Sjoerg unsigned char buf[] = "";
37*40b1a6e6Sjoerg unsigned char md[16];
38*40b1a6e6Sjoerg unsigned char actualmd[] = "\x93\xb8\x85\xad\xfe\x0d\xa0\x89"
39*40b1a6e6Sjoerg "\xcd\xf6\x34\x90\x4f\xd5\x9f\x71";
40*40b1a6e6Sjoerg
41*40b1a6e6Sjoerg if (ARCHIVE_OK != archive_md5_init(&ctx)) {
42*40b1a6e6Sjoerg skipping("This platform does not support MD5");
43*40b1a6e6Sjoerg return;
44*40b1a6e6Sjoerg }
45*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_md5_update(&ctx, buf, sizeof(buf)));
46*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_md5_final(&ctx, md));
47*40b1a6e6Sjoerg assertEqualMem(md, actualmd, sizeof(md));
48*40b1a6e6Sjoerg }
49*40b1a6e6Sjoerg
DEFINE_TEST(test_archive_rmd160)50*40b1a6e6Sjoerg DEFINE_TEST(test_archive_rmd160)
51*40b1a6e6Sjoerg {
52*40b1a6e6Sjoerg archive_rmd160_ctx ctx;
53*40b1a6e6Sjoerg unsigned char buf[] = "";
54*40b1a6e6Sjoerg unsigned char md[20];
55*40b1a6e6Sjoerg unsigned char actualmd[] = "\xc8\x1b\x94\x93\x34\x20\x22\x1a\x7a\xc0"
56*40b1a6e6Sjoerg "\x04\xa9\x02\x42\xd8\xb1\xd3\xe5\x07\x0d";
57*40b1a6e6Sjoerg
58*40b1a6e6Sjoerg if (ARCHIVE_OK != archive_rmd160_init(&ctx)) {
59*40b1a6e6Sjoerg skipping("This platform does not support RMD160");
60*40b1a6e6Sjoerg return;
61*40b1a6e6Sjoerg }
62*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_rmd160_update(&ctx, buf, sizeof(buf)));
63*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_rmd160_final(&ctx, md));
64*40b1a6e6Sjoerg assertEqualMem(md, actualmd, sizeof(md));
65*40b1a6e6Sjoerg }
66*40b1a6e6Sjoerg
DEFINE_TEST(test_archive_sha1)67*40b1a6e6Sjoerg DEFINE_TEST(test_archive_sha1)
68*40b1a6e6Sjoerg {
69*40b1a6e6Sjoerg archive_sha1_ctx ctx;
70*40b1a6e6Sjoerg unsigned char buf[] = "";
71*40b1a6e6Sjoerg unsigned char md[20];
72*40b1a6e6Sjoerg unsigned char actualmd[] = "\x5b\xa9\x3c\x9d\xb0\xcf\xf9\x3f\x52\xb5"
73*40b1a6e6Sjoerg "\x21\xd7\x42\x0e\x43\xf6\xed\xa2\x78\x4f";
74*40b1a6e6Sjoerg
75*40b1a6e6Sjoerg if (ARCHIVE_OK != archive_sha1_init(&ctx)) {
76*40b1a6e6Sjoerg skipping("This platform does not support SHA1");
77*40b1a6e6Sjoerg return;
78*40b1a6e6Sjoerg }
79*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_sha1_update(&ctx, buf, sizeof(buf)));
80*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_sha1_final(&ctx, md));
81*40b1a6e6Sjoerg assertEqualMem(md, actualmd, sizeof(md));
82*40b1a6e6Sjoerg }
83*40b1a6e6Sjoerg
DEFINE_TEST(test_archive_sha256)84*40b1a6e6Sjoerg DEFINE_TEST(test_archive_sha256)
85*40b1a6e6Sjoerg {
86*40b1a6e6Sjoerg archive_sha256_ctx ctx;
87*40b1a6e6Sjoerg unsigned char buf[] = "";
88*40b1a6e6Sjoerg unsigned char md[32];
89*40b1a6e6Sjoerg unsigned char actualmd[] = "\x6e\x34\x0b\x9c\xff\xb3\x7a\x98"
90*40b1a6e6Sjoerg "\x9c\xa5\x44\xe6\xbb\x78\x0a\x2c"
91*40b1a6e6Sjoerg "\x78\x90\x1d\x3f\xb3\x37\x38\x76"
92*40b1a6e6Sjoerg "\x85\x11\xa3\x06\x17\xaf\xa0\x1d";
93*40b1a6e6Sjoerg
94*40b1a6e6Sjoerg if (ARCHIVE_OK != archive_sha256_init(&ctx)) {
95*40b1a6e6Sjoerg skipping("This platform does not support SHA256");
96*40b1a6e6Sjoerg return;
97*40b1a6e6Sjoerg }
98*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_sha256_update(&ctx, buf, sizeof(buf)));
99*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_sha256_final(&ctx, md));
100*40b1a6e6Sjoerg assertEqualMem(md, actualmd, sizeof(md));
101*40b1a6e6Sjoerg }
102*40b1a6e6Sjoerg
DEFINE_TEST(test_archive_sha384)103*40b1a6e6Sjoerg DEFINE_TEST(test_archive_sha384)
104*40b1a6e6Sjoerg {
105*40b1a6e6Sjoerg archive_sha384_ctx ctx;
106*40b1a6e6Sjoerg unsigned char buf[] = "";
107*40b1a6e6Sjoerg unsigned char md[48];
108*40b1a6e6Sjoerg unsigned char actualmd[] = "\xbe\xc0\x21\xb4\xf3\x68\xe3\x06"
109*40b1a6e6Sjoerg "\x91\x34\xe0\x12\xc2\xb4\x30\x70"
110*40b1a6e6Sjoerg "\x83\xd3\xa9\xbd\xd2\x06\xe2\x4e"
111*40b1a6e6Sjoerg "\x5f\x0d\x86\xe1\x3d\x66\x36\x65"
112*40b1a6e6Sjoerg "\x59\x33\xec\x2b\x41\x34\x65\x96"
113*40b1a6e6Sjoerg "\x68\x17\xa9\xc2\x08\xa1\x17\x17";
114*40b1a6e6Sjoerg
115*40b1a6e6Sjoerg if (ARCHIVE_OK != archive_sha384_init(&ctx)) {
116*40b1a6e6Sjoerg skipping("This platform does not support SHA384");
117*40b1a6e6Sjoerg return;
118*40b1a6e6Sjoerg }
119*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_sha384_update(&ctx, buf, sizeof(buf)));
120*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_sha384_final(&ctx, md));
121*40b1a6e6Sjoerg assertEqualMem(md, actualmd, sizeof(md));
122*40b1a6e6Sjoerg }
123*40b1a6e6Sjoerg
DEFINE_TEST(test_archive_sha512)124*40b1a6e6Sjoerg DEFINE_TEST(test_archive_sha512)
125*40b1a6e6Sjoerg {
126*40b1a6e6Sjoerg archive_sha512_ctx ctx;
127*40b1a6e6Sjoerg unsigned char buf[] = "";
128*40b1a6e6Sjoerg unsigned char md[64];
129*40b1a6e6Sjoerg unsigned char actualmd[] = "\xb8\x24\x4d\x02\x89\x81\xd6\x93"
130*40b1a6e6Sjoerg "\xaf\x7b\x45\x6a\xf8\xef\xa4\xca"
131*40b1a6e6Sjoerg "\xd6\x3d\x28\x2e\x19\xff\x14\x94"
132*40b1a6e6Sjoerg "\x2c\x24\x6e\x50\xd9\x35\x1d\x22"
133*40b1a6e6Sjoerg "\x70\x4a\x80\x2a\x71\xc3\x58\x0b"
134*40b1a6e6Sjoerg "\x63\x70\xde\x4c\xeb\x29\x3c\x32"
135*40b1a6e6Sjoerg "\x4a\x84\x23\x34\x25\x57\xd4\xe5"
136*40b1a6e6Sjoerg "\xc3\x84\x38\xf0\xe3\x69\x10\xee";
137*40b1a6e6Sjoerg
138*40b1a6e6Sjoerg if (ARCHIVE_OK != archive_sha512_init(&ctx)) {
139*40b1a6e6Sjoerg skipping("This platform does not support SHA512");
140*40b1a6e6Sjoerg return;
141*40b1a6e6Sjoerg }
142*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_sha512_update(&ctx, buf, sizeof(buf)));
143*40b1a6e6Sjoerg assertEqualInt(ARCHIVE_OK, archive_sha512_final(&ctx, md));
144*40b1a6e6Sjoerg assertEqualMem(md, actualmd, sizeof(md));
145*40b1a6e6Sjoerg }
146