1e0c51286SKyle Evans /* SHADRIVER.C - test driver for SHA-1 (and SHA-2) */ 2e0c51286SKyle Evans 3e0c51286SKyle Evans /*- 4e0c51286SKyle Evans * SPDX-License-Identifier: RSA-MD 5e0c51286SKyle Evans * 6e0c51286SKyle Evans * Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights 7e0c51286SKyle Evans * reserved. 8e0c51286SKyle Evans * 9e0c51286SKyle Evans * RSA Data Security, Inc. makes no representations concerning either the 10e0c51286SKyle Evans * merchantability of this software or the suitability of this software for 11e0c51286SKyle Evans * any particular purpose. It is provided "as is" without express or implied 12e0c51286SKyle Evans * warranty of any kind. 13e0c51286SKyle Evans * 14e0c51286SKyle Evans * These notices must be retained in any copies of any part of this 15e0c51286SKyle Evans * documentation and/or software. */ 16e0c51286SKyle Evans 17e0c51286SKyle Evans #include <sys/types.h> 18e0c51286SKyle Evans 19e0c51286SKyle Evans #include <stdio.h> 20e0c51286SKyle Evans #include <time.h> 21e0c51286SKyle Evans #include <string.h> 22e0c51286SKyle Evans 23e0c51286SKyle Evans #include "sha.h" 24e0c51286SKyle Evans #include "sha224.h" 25e0c51286SKyle Evans #include "sha256.h" 26e0c51286SKyle Evans #include "sha384.h" 27e0c51286SKyle Evans #include "sha512.h" 28e0c51286SKyle Evans #include "sha512t.h" 29e0c51286SKyle Evans 30e0c51286SKyle Evans /* The following makes SHA default to SHA-1 if it has not already been 31e0c51286SKyle Evans * defined with C compiler flags. */ 32e0c51286SKyle Evans #ifndef SHA 33e0c51286SKyle Evans #define SHA 1 34e0c51286SKyle Evans #endif 35e0c51286SKyle Evans 36e0c51286SKyle Evans #if SHA == 1 37e0c51286SKyle Evans #undef SHA_Data 38e0c51286SKyle Evans #define SHA_Data SHA1_Data 39e0c51286SKyle Evans #elif SHA == 224 40e0c51286SKyle Evans #undef SHA_Data 41e0c51286SKyle Evans #define SHA_Data SHA224_Data 42e0c51286SKyle Evans #elif SHA == 256 43e0c51286SKyle Evans #undef SHA_Data 44e0c51286SKyle Evans #define SHA_Data SHA256_Data 45e0c51286SKyle Evans #elif SHA == 384 46e0c51286SKyle Evans #undef SHA_Data 47e0c51286SKyle Evans #define SHA_Data SHA384_Data 48e0c51286SKyle Evans #elif SHA == 512 49e0c51286SKyle Evans #undef SHA_Data 50e0c51286SKyle Evans #define SHA_Data SHA512_Data 51e0c51286SKyle Evans #elif SHA == 512224 52e0c51286SKyle Evans #undef SHA_Data 53e0c51286SKyle Evans #define SHA_Data SHA512_224_Data 54e0c51286SKyle Evans #elif SHA == 512256 55e0c51286SKyle Evans #undef SHA_Data 56e0c51286SKyle Evans #define SHA_Data SHA512_256_Data 57e0c51286SKyle Evans #endif 58e0c51286SKyle Evans 59e0c51286SKyle Evans /* Digests a string and prints the result. */ 60e0c51286SKyle Evans static void SHAString(const char * string)61*01112a17SKyle EvansSHAString(const char *string) 62e0c51286SKyle Evans { 63e0c51286SKyle Evans char buf[2*64 + 1]; 64e0c51286SKyle Evans 65e0c51286SKyle Evans printf("SHA-%d (\"%s\") = %s\n", 66e0c51286SKyle Evans SHA, string, SHA_Data(string, strlen(string), buf)); 67e0c51286SKyle Evans } 68e0c51286SKyle Evans 69e0c51286SKyle Evans /* Digests a reference suite of strings and prints the results. */ 70e0c51286SKyle Evans int main(void)71e0c51286SKyle Evansmain(void) 72e0c51286SKyle Evans { 73e0c51286SKyle Evans printf("SHA-%d test suite:\n", SHA); 74e0c51286SKyle Evans 75e0c51286SKyle Evans SHAString(""); 76e0c51286SKyle Evans SHAString("abc"); 77e0c51286SKyle Evans SHAString("message digest"); 78e0c51286SKyle Evans SHAString("abcdefghijklmnopqrstuvwxyz"); 79e0c51286SKyle Evans SHAString("ABCDEFGHIJKLMNOPQRSTUVWXYZ" 80e0c51286SKyle Evans "abcdefghijklmnopqrstuvwxyz0123456789"); 81e0c51286SKyle Evans SHAString("1234567890123456789012345678901234567890" 82e0c51286SKyle Evans "1234567890123456789012345678901234567890"); 83e0c51286SKyle Evans 84e0c51286SKyle Evans return 0; 85e0c51286SKyle Evans } 86