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