1*ebfedea0SLionel Sambuc /* $NetBSD: n-fold-test.c,v 1.1.1.1 2011/04/13 18:15:36 elric Exp $ */
2*ebfedea0SLionel Sambuc
3*ebfedea0SLionel Sambuc /*
4*ebfedea0SLionel Sambuc * Copyright (c) 1999 - 2001 Kungliga Tekniska Högskolan
5*ebfedea0SLionel Sambuc * (Royal Institute of Technology, Stockholm, Sweden).
6*ebfedea0SLionel Sambuc * All rights reserved.
7*ebfedea0SLionel Sambuc *
8*ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
9*ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
10*ebfedea0SLionel Sambuc * are met:
11*ebfedea0SLionel Sambuc *
12*ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
13*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
14*ebfedea0SLionel Sambuc *
15*ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
16*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
17*ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution.
18*ebfedea0SLionel Sambuc *
19*ebfedea0SLionel Sambuc * 3. Neither the name of KTH nor the names of its contributors may be
20*ebfedea0SLionel Sambuc * used to endorse or promote products derived from this software without
21*ebfedea0SLionel Sambuc * specific prior written permission.
22*ebfedea0SLionel Sambuc *
23*ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
24*ebfedea0SLionel Sambuc * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25*ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26*ebfedea0SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
27*ebfedea0SLionel Sambuc * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28*ebfedea0SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29*ebfedea0SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30*ebfedea0SLionel Sambuc * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31*ebfedea0SLionel Sambuc * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32*ebfedea0SLionel Sambuc * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33*ebfedea0SLionel Sambuc * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
34*ebfedea0SLionel Sambuc
35*ebfedea0SLionel Sambuc #include "krb5_locl.h"
36*ebfedea0SLionel Sambuc
37*ebfedea0SLionel Sambuc enum { MAXSIZE = 24 };
38*ebfedea0SLionel Sambuc
39*ebfedea0SLionel Sambuc static struct testcase {
40*ebfedea0SLionel Sambuc const char *str;
41*ebfedea0SLionel Sambuc unsigned n;
42*ebfedea0SLionel Sambuc unsigned char res[MAXSIZE];
43*ebfedea0SLionel Sambuc } tests[] = {
44*ebfedea0SLionel Sambuc {"012345", 8,
45*ebfedea0SLionel Sambuc {0xbe, 0x07, 0x26, 0x31, 0x27, 0x6b, 0x19, 0x55}
46*ebfedea0SLionel Sambuc },
47*ebfedea0SLionel Sambuc {"basch", 24,
48*ebfedea0SLionel Sambuc {0x1a, 0xab, 0x6b, 0x42, 0x96, 0x4b, 0x98, 0xb2, 0x1f, 0x8c, 0xde,
49*ebfedea0SLionel Sambuc 0x2d, 0x24, 0x48, 0xba, 0x34, 0x55, 0xd7, 0x86, 0x2c, 0x97, 0x31,
50*ebfedea0SLionel Sambuc 0x64, 0x3f}
51*ebfedea0SLionel Sambuc },
52*ebfedea0SLionel Sambuc {"eichin", 24,
53*ebfedea0SLionel Sambuc {0x65, 0x69, 0x63, 0x68, 0x69, 0x6e, 0x4b, 0x73, 0x2b, 0x4b,
54*ebfedea0SLionel Sambuc 0x1b, 0x43, 0xda, 0x1a, 0x5b, 0x99, 0x5a, 0x58, 0xd2, 0xc6, 0xd0,
55*ebfedea0SLionel Sambuc 0xd2, 0xdc, 0xca}
56*ebfedea0SLionel Sambuc },
57*ebfedea0SLionel Sambuc {"sommerfeld", 24,
58*ebfedea0SLionel Sambuc {0x2f, 0x7a, 0x98, 0x55, 0x7c, 0x6e, 0xe4, 0xab, 0xad, 0xf4,
59*ebfedea0SLionel Sambuc 0xe7, 0x11, 0x92, 0xdd, 0x44, 0x2b, 0xd4, 0xff, 0x53, 0x25, 0xa5,
60*ebfedea0SLionel Sambuc 0xde, 0xf7, 0x5c}
61*ebfedea0SLionel Sambuc },
62*ebfedea0SLionel Sambuc {"MASSACHVSETTS INSTITVTE OF TECHNOLOGY", 24,
63*ebfedea0SLionel Sambuc {0xdb, 0x3b, 0x0d, 0x8f, 0x0b, 0x06, 0x1e, 0x60, 0x32, 0x82,
64*ebfedea0SLionel Sambuc 0xb3, 0x08, 0xa5, 0x08, 0x41, 0x22, 0x9a, 0xd7, 0x98, 0xfa, 0xb9,
65*ebfedea0SLionel Sambuc 0x54, 0x0c, 0x1b}
66*ebfedea0SLionel Sambuc },
67*ebfedea0SLionel Sambuc {"assar@NADA.KTH.SE", 24,
68*ebfedea0SLionel Sambuc {0x5c, 0x06, 0xc3, 0x4d, 0x2c, 0x89, 0x05, 0xbe, 0x7a, 0x51,
69*ebfedea0SLionel Sambuc 0x83, 0x6c, 0xd6, 0xf8, 0x1c, 0x4b, 0x7a, 0x93, 0x49, 0x16, 0x5a,
70*ebfedea0SLionel Sambuc 0xb3, 0xfa, 0xa9}
71*ebfedea0SLionel Sambuc },
72*ebfedea0SLionel Sambuc {"testKRBTEST.MIT.EDUtestkey", 24,
73*ebfedea0SLionel Sambuc {0x50, 0x2c, 0xf8, 0x29, 0x78, 0xe5, 0xfb, 0x1a, 0x29, 0x06,
74*ebfedea0SLionel Sambuc 0xbd, 0x22, 0x28, 0x91, 0x56, 0xc0, 0x06, 0xa0, 0xdc, 0xf5, 0xb6,
75*ebfedea0SLionel Sambuc 0xc2, 0xda, 0x6c}
76*ebfedea0SLionel Sambuc },
77*ebfedea0SLionel Sambuc {"password", 7,
78*ebfedea0SLionel Sambuc {0x78, 0xa0, 0x7b, 0x6c, 0xaf, 0x85, 0xfa}
79*ebfedea0SLionel Sambuc },
80*ebfedea0SLionel Sambuc {"Rough Consensus, and Running Code", 8,
81*ebfedea0SLionel Sambuc {0xbb, 0x6e, 0xd3, 0x08, 0x70, 0xb7, 0xf0, 0xe0},
82*ebfedea0SLionel Sambuc },
83*ebfedea0SLionel Sambuc {"password", 21,
84*ebfedea0SLionel Sambuc {0x59, 0xe4, 0xa8, 0xca, 0x7c, 0x03, 0x85, 0xc3, 0xc3, 0x7b, 0x3f,
85*ebfedea0SLionel Sambuc 0x6d, 0x20, 0x00, 0x24, 0x7c, 0xb6, 0xe6, 0xbd, 0x5b, 0x3e},
86*ebfedea0SLionel Sambuc },
87*ebfedea0SLionel Sambuc {"MASSACHVSETTS INSTITVTE OF TECHNOLOGY", 24,
88*ebfedea0SLionel Sambuc {0xdb, 0x3b, 0x0d, 0x8f, 0x0b, 0x06, 0x1e, 0x60, 0x32, 0x82, 0xb3,
89*ebfedea0SLionel Sambuc 0x08, 0xa5, 0x08, 0x41, 0x22, 0x9a, 0xd7, 0x98, 0xfa, 0xb9, 0x54,
90*ebfedea0SLionel Sambuc 0x0c, 0x1b}
91*ebfedea0SLionel Sambuc },
92*ebfedea0SLionel Sambuc {NULL, 0}
93*ebfedea0SLionel Sambuc };
94*ebfedea0SLionel Sambuc
95*ebfedea0SLionel Sambuc int
main(int argc,char ** argv)96*ebfedea0SLionel Sambuc main(int argc, char **argv)
97*ebfedea0SLionel Sambuc {
98*ebfedea0SLionel Sambuc unsigned char data[MAXSIZE];
99*ebfedea0SLionel Sambuc struct testcase *t;
100*ebfedea0SLionel Sambuc int ret = 0;
101*ebfedea0SLionel Sambuc
102*ebfedea0SLionel Sambuc for (t = tests; t->str; ++t) {
103*ebfedea0SLionel Sambuc int i;
104*ebfedea0SLionel Sambuc
105*ebfedea0SLionel Sambuc ret = _krb5_n_fold (t->str, strlen(t->str), data, t->n);
106*ebfedea0SLionel Sambuc if (ret)
107*ebfedea0SLionel Sambuc errx(1, "out of memory");
108*ebfedea0SLionel Sambuc if (memcmp (data, t->res, t->n) != 0) {
109*ebfedea0SLionel Sambuc printf ("n-fold(\"%s\", %d) failed\n", t->str, t->n);
110*ebfedea0SLionel Sambuc printf ("should be: ");
111*ebfedea0SLionel Sambuc for (i = 0; i < t->n; ++i)
112*ebfedea0SLionel Sambuc printf ("%02x", t->res[i]);
113*ebfedea0SLionel Sambuc printf ("\nresult was: ");
114*ebfedea0SLionel Sambuc for (i = 0; i < t->n; ++i)
115*ebfedea0SLionel Sambuc printf ("%02x", data[i]);
116*ebfedea0SLionel Sambuc printf ("\n");
117*ebfedea0SLionel Sambuc ret = 1;
118*ebfedea0SLionel Sambuc }
119*ebfedea0SLionel Sambuc }
120*ebfedea0SLionel Sambuc return ret;
121*ebfedea0SLionel Sambuc }
122