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