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