]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - lib/libmd/shadriver.c
MFC r285417: Add new include path for sha256.h
[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 "sha384.h"
26 #include "sha512.h"
27
28 /* The following makes SHA default to SHA-1 if it has not already been
29  * defined with C compiler flags. */
30 #ifndef SHA
31 #define SHA 1
32 #endif
33
34 #if SHA == 1
35 #undef SHA_Data
36 #define SHA_Data SHA1_Data
37 #elif SHA == 256
38 #undef SHA_Data
39 #define SHA_Data SHA256_Data
40 #elif SHA == 384
41 #undef SHA_Data
42 #define SHA_Data SHA384_Data
43 #elif SHA == 512
44 #undef SHA_Data
45 #define SHA_Data SHA512_Data
46 #endif
47
48 /* Digests a string and prints the result. */
49 static void
50 SHAString(char *string)
51 {
52         char buf[2*64 + 1];
53
54         printf("SHA-%d (\"%s\") = %s\n",
55                SHA, string, SHA_Data(string, strlen(string), buf));
56 }
57
58 /* Digests a reference suite of strings and prints the results. */
59 int
60 main(void)
61 {
62         printf("SHA-%d test suite:\n", SHA);
63
64         SHAString("");
65         SHAString("abc");
66         SHAString("message digest");
67         SHAString("abcdefghijklmnopqrstuvwxyz");
68         SHAString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
69                   "abcdefghijklmnopqrstuvwxyz0123456789");
70         SHAString("1234567890123456789012345678901234567890"
71                   "1234567890123456789012345678901234567890");
72
73         return 0;
74 }