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