xref: /freebsd-src/contrib/netbsd-tests/lib/libskey/t_algorithms.c (revision 9268022b74279434ed6300244e3f977e56a8ceb5)
1*57718be8SEnji Cooper /* $NetBSD: t_algorithms.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $ */
2*57718be8SEnji Cooper 
3*57718be8SEnji Cooper /*
4*57718be8SEnji Cooper  * Copyright (c) 2000, 2008, 2010 The NetBSD Foundation, Inc.
5*57718be8SEnji Cooper  * All rights reserved.
6*57718be8SEnji Cooper  *
7*57718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
8*57718be8SEnji Cooper  * modification, are permitted provided that the following conditions
9*57718be8SEnji Cooper  * are met:
10*57718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
11*57718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
12*57718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
13*57718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
14*57718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
15*57718be8SEnji Cooper  *
16*57718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17*57718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18*57718be8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19*57718be8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20*57718be8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*57718be8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*57718be8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*57718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*57718be8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*57718be8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*57718be8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
27*57718be8SEnji Cooper  */
28*57718be8SEnji Cooper 
29*57718be8SEnji Cooper #include <sys/cdefs.h>
30*57718be8SEnji Cooper __COPYRIGHT("@(#) Copyright (c) 2008, 2010\
31*57718be8SEnji Cooper  The NetBSD Foundation, inc. All rights reserved.");
32*57718be8SEnji Cooper __RCSID("$NetBSD: t_algorithms.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $");
33*57718be8SEnji Cooper 
34*57718be8SEnji Cooper #include <stdio.h>
35*57718be8SEnji Cooper #include <strings.h>
36*57718be8SEnji Cooper #include <skey.h>
37*57718be8SEnji Cooper 
38*57718be8SEnji Cooper #include <atf-c.h>
39*57718be8SEnji Cooper 
40*57718be8SEnji Cooper #define H_REQUIRE(x, y) \
41*57718be8SEnji Cooper 	ATF_REQUIRE_MSG(strcasecmp((x), (y)) == 0, "\"%s\" != \"%s\"", (x), (y))
42*57718be8SEnji Cooper 
43*57718be8SEnji Cooper static void
h_check(const char * pass,const char * seed,const char * algo,const char * zero,const char * one,const char * nine)44*57718be8SEnji Cooper h_check(const char *pass, const char *seed,
45*57718be8SEnji Cooper         const char *algo, const char *zero,
46*57718be8SEnji Cooper         const char *one,  const char *nine)
47*57718be8SEnji Cooper {
48*57718be8SEnji Cooper 	char prn[64];
49*57718be8SEnji Cooper 	char data[16];
50*57718be8SEnji Cooper 	int i;
51*57718be8SEnji Cooper 
52*57718be8SEnji Cooper 	skey_set_algorithm(algo);
53*57718be8SEnji Cooper 
54*57718be8SEnji Cooper 	keycrunch(data, seed, pass);
55*57718be8SEnji Cooper 	btoa8(prn, data);
56*57718be8SEnji Cooper 	H_REQUIRE(prn, zero);
57*57718be8SEnji Cooper 
58*57718be8SEnji Cooper 	f(data);
59*57718be8SEnji Cooper 	btoa8(prn, data);
60*57718be8SEnji Cooper 	H_REQUIRE(prn, one);
61*57718be8SEnji Cooper 
62*57718be8SEnji Cooper 	for(i = 1; i < 99; ++i)
63*57718be8SEnji Cooper 		f(data);
64*57718be8SEnji Cooper 	btoa8(prn, data);
65*57718be8SEnji Cooper 	H_REQUIRE(prn, nine);
66*57718be8SEnji Cooper }
67*57718be8SEnji Cooper 
68*57718be8SEnji Cooper ATF_TC(md4);
ATF_TC_HEAD(md4,tc)69*57718be8SEnji Cooper ATF_TC_HEAD(md4, tc)
70*57718be8SEnji Cooper {
71*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Checks MD4 algorithm");
72*57718be8SEnji Cooper }
ATF_TC_BODY(md4,tc)73*57718be8SEnji Cooper ATF_TC_BODY(md4, tc)
74*57718be8SEnji Cooper {
75*57718be8SEnji Cooper 	h_check("This is a test.", "TeSt", "md4", "D1854218EBBB0B51",
76*57718be8SEnji Cooper 		"63473EF01CD0B444", "C5E612776E6C237A");
77*57718be8SEnji Cooper 	h_check("AbCdEfGhIjK", "alpha1", "md4", "50076F47EB1ADE4E",
78*57718be8SEnji Cooper 		"65D20D1949B5F7AB", "D150C82CCE6F62D1");
79*57718be8SEnji Cooper 	h_check("OTP's are good", "correct", "md4", "849C79D4F6F55388",
80*57718be8SEnji Cooper 		"8C0992FB250847B1", "3F3BF4B4145FD74B");
81*57718be8SEnji Cooper }
82*57718be8SEnji Cooper 
83*57718be8SEnji Cooper ATF_TC(md5);
ATF_TC_HEAD(md5,tc)84*57718be8SEnji Cooper ATF_TC_HEAD(md5, tc)
85*57718be8SEnji Cooper {
86*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Checks MD5 algorithm");
87*57718be8SEnji Cooper }
ATF_TC_BODY(md5,tc)88*57718be8SEnji Cooper ATF_TC_BODY(md5, tc)
89*57718be8SEnji Cooper {
90*57718be8SEnji Cooper 	h_check("This is a test.", "TeSt", "md5", "9E876134D90499DD",
91*57718be8SEnji Cooper 		"7965E05436F5029F", "50FE1962C4965880");
92*57718be8SEnji Cooper 	h_check("AbCdEfGhIjK", "alpha1", "md5", "87066DD9644BF206",
93*57718be8SEnji Cooper 		"7CD34C1040ADD14B", "5AA37A81F212146C");
94*57718be8SEnji Cooper 	h_check("OTP's are good", "correct", "md5", "F205753943DE4CF9",
95*57718be8SEnji Cooper 		"DDCDAC956F234937", "B203E28FA525BE47");
96*57718be8SEnji Cooper }
97*57718be8SEnji Cooper 
98*57718be8SEnji Cooper ATF_TC(sha1);
ATF_TC_HEAD(sha1,tc)99*57718be8SEnji Cooper ATF_TC_HEAD(sha1, tc)
100*57718be8SEnji Cooper {
101*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Checks SHA1 algorithm");
102*57718be8SEnji Cooper }
ATF_TC_BODY(sha1,tc)103*57718be8SEnji Cooper ATF_TC_BODY(sha1, tc)
104*57718be8SEnji Cooper {
105*57718be8SEnji Cooper 	h_check("This is a test.", "TeSt", "sha1","BB9E6AE1979D8FF4",
106*57718be8SEnji Cooper 		"63D936639734385B", "87FEC7768B73CCF9");
107*57718be8SEnji Cooper 	h_check("AbCdEfGhIjK", "alpha1", "sha1","AD85F658EBE383C9",
108*57718be8SEnji Cooper 		"D07CE229B5CF119B", "27BC71035AAF3DC6");
109*57718be8SEnji Cooper 	h_check("OTP's are good", "correct", "sha1","D51F3E99BF8E6F0B",
110*57718be8SEnji Cooper 		"82AEB52D943774E4", "4F296A74FE1567EC");
111*57718be8SEnji Cooper }
112*57718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)113*57718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
114*57718be8SEnji Cooper {
115*57718be8SEnji Cooper 
116*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, md4);
117*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, md5);
118*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, sha1);
119*57718be8SEnji Cooper 
120*57718be8SEnji Cooper 	return atf_no_error();
121*57718be8SEnji Cooper }
122