Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / lib / libskey / skeytest.c
blob890b1463e5f06909cf9ca736b3804d3822cd5bbb
1 /* $NetBSD: skeytest.c,v 1.3 2002/02/21 07:38:18 itojun Exp $ */
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 /* This is a regression test for the S/Key implementation
30 against the data set from Appendix C of RFC2289 */
32 #include <stdio.h>
33 #include <string.h>
34 #include "skey.h"
36 struct regRes {
37 char *algo, *zero, *one, *nine;
40 struct regPass {
41 char *passphrase, *seed;
42 struct regRes res[4];
43 } regPass[] = {
44 { "This is a test.", "TeSt", {
45 { "md4", "D1854218EBBB0B51", "63473EF01CD0B444", "C5E612776E6C237A" },
46 { "md5", "9E876134D90499DD", "7965E05436F5029F", "50FE1962C4965880" },
47 { "sha1","BB9E6AE1979D8FF4", "63D936639734385B", "87FEC7768B73CCF9" },
48 { NULL } } },
49 { "AbCdEfGhIjK", "alpha1", {
50 { "md4", "50076F47EB1ADE4E", "65D20D1949B5F7AB", "D150C82CCE6F62D1" },
51 { "md5", "87066DD9644BF206", "7CD34C1040ADD14B", "5AA37A81F212146C" },
52 { "sha1","AD85F658EBE383C9", "D07CE229B5CF119B", "27BC71035AAF3DC6" },
53 { NULL } } },
54 { "OTP's are good", "correct", {
55 { "md4", "849C79D4F6F55388", "8C0992FB250847B1", "3F3BF4B4145FD74B" },
56 { "md5", "F205753943DE4CF9", "DDCDAC956F234937", "B203E28FA525BE47" },
57 { "sha1","D51F3E99BF8E6F0B", "82AEB52D943774E4", "4F296A74FE1567EC" },
58 { NULL } } },
59 { NULL }
62 int main()
64 char data[16], prn[64];
65 struct regPass *rp;
66 int i = 0;
67 int errors = 0;
68 int j;
70 for(rp = regPass; rp->passphrase; rp++)
72 struct regRes *rr;
74 i++;
75 for(rr = rp->res; rr->algo; rr++)
77 skey_set_algorithm(rr->algo);
79 keycrunch(data, rp->seed, rp->passphrase);
80 btoa8(prn, data);
82 if(strcasecmp(prn, rr->zero))
84 errors++;
85 printf("Set %d, round 0, %s: Expected %s and got %s\n", i, rr->algo, rr->zero, prn);
88 f(data);
89 btoa8(prn, data);
91 if(strcasecmp(prn, rr->one))
93 errors++;
94 printf("Set %d, round 1, %s: Expected %s and got %s\n", i, rr->algo, rr->one, prn);
97 for(j=1; j<99; j++)
98 f(data);
99 btoa8(prn, data);
101 if(strcasecmp(prn, rr->nine))
103 errors++;
104 printf("Set %d, round 99, %s: Expected %s and got %s\n", i, rr->algo, rr->nine, prn);
110 printf("%d errors\n", errors);
111 return(errors ? 1 : 0);