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