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