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