]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libmd/shadriver.c
Remove spurious newline
[FreeBSD/FreeBSD.git] / lib / libmd / shadriver.c
1 /* SHADRIVER.C - test driver for SHA-1 (and SHA-2) */
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 __FBSDID("$FreeBSD$");
19
20 #include <sys/types.h>
21
22 #include <stdio.h>
23 #include <time.h>
24 #include <string.h>
25
26 #include "sha.h"
27 #include "sha224.h"
28 #include "sha256.h"
29 #include "sha384.h"
30 #include "sha512.h"
31 #include "sha512t.h"
32
33 /* The following makes SHA default to SHA-1 if it has not already been
34  * defined with C compiler flags. */
35 #ifndef SHA
36 #define SHA 1
37 #endif
38
39 #if SHA == 1
40 #undef SHA_Data
41 #define SHA_Data SHA1_Data
42 #elif SHA == 224
43 #undef SHA_Data
44 #define SHA_Data SHA224_Data
45 #elif SHA == 256
46 #undef SHA_Data
47 #define SHA_Data SHA256_Data
48 #elif SHA == 384
49 #undef SHA_Data
50 #define SHA_Data SHA384_Data
51 #elif SHA == 512
52 #undef SHA_Data
53 #define SHA_Data SHA512_Data
54 #elif SHA == 512256
55 #undef SHA_Data
56 #define SHA_Data SHA512_256_Data
57 #endif
58
59 /* Digests a string and prints the result. */
60 static void
61 SHAString(char *string)
62 {
63         char buf[2*64 + 1];
64
65         printf("SHA-%d (\"%s\") = %s\n",
66                SHA, string, SHA_Data(string, strlen(string), buf));
67 }
68
69 /* Digests a reference suite of strings and prints the results. */
70 int
71 main(void)
72 {
73         printf("SHA-%d test suite:\n", SHA);
74
75         SHAString("");
76         SHAString("abc");
77         SHAString("message digest");
78         SHAString("abcdefghijklmnopqrstuvwxyz");
79         SHAString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
80                   "abcdefghijklmnopqrstuvwxyz0123456789");
81         SHAString("1234567890123456789012345678901234567890"
82                   "1234567890123456789012345678901234567890");
83
84         return 0;
85 }