xref: /freebsd/lib/libmd/skeindriver.c (revision 315ee00f)
1 /* SKEINDRIVER.C - test driver for SKEIN */
2 
3 /*-
4  * SPDX-License-Identifier: RSA-MD
5  *
6  * Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights
7  * reserved.
8  *
9  * RSA Data Security, Inc. makes no representations concerning either the
10  * merchantability of this software or the suitability of this software for
11  * any particular purpose. It is provided "as is" without express or implied
12  * warranty of any kind.
13  *
14  * These notices must be retained in any copies of any part of this
15  * documentation and/or software. */
16 
17 #include <sys/cdefs.h>
18 #include <sys/types.h>
19 
20 #include <stdio.h>
21 #include <time.h>
22 #include <string.h>
23 
24 #include "skein.h"
25 
26 /* The following makes SKEIN default to SKEIN512 if it has not already been
27  * defined with C compiler flags. */
28 #ifndef SKEIN
29 #define SKEIN 512
30 #endif
31 
32 #if SKEIN == 256
33 #undef SKEIN_Data
34 #define SKEIN_Data SKEIN256_Data
35 #elif SKEIN == 512
36 #undef SKEIN_Data
37 #define SKEIN_Data SKEIN512_Data
38 #elif SKEIN == 1024
39 #undef SKEIN_Data
40 #define SKEIN_Data SKEIN1024_Data
41 #endif
42 
43 /* Digests a string and prints the result. */
44 static void
45 SKEINString(char *string)
46 {
47 	char buf[2*128 + 1];
48 
49 	printf("SKEIN%d (\"%s\") = %s\n",
50 	       SKEIN, string, SKEIN_Data(string, strlen(string), buf));
51 }
52 
53 /* Digests a reference suite of strings and prints the results. */
54 int
55 main(void)
56 {
57 	printf("SKEIN%d test suite:\n", SKEIN);
58 
59 	SKEINString("");
60 	SKEINString("abc");
61 	SKEINString("message digest");
62 	SKEINString("abcdefghijklmnopqrstuvwxyz");
63 	SKEINString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
64 		  "abcdefghijklmnopqrstuvwxyz0123456789");
65 	SKEINString("1234567890123456789012345678901234567890"
66 		  "1234567890123456789012345678901234567890");
67 
68 	return 0;
69 }
70