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