1/* SHADRIVER.C - test driver for SHA-1 (and SHA-2) */ 2 3/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights 4 * reserved. 5 * 6 * RSA Data Security, Inc. makes no representations concerning either the 7 * merchantability of this software or the suitability of this software for 8 * any particular purpose. It is provided "as is" without express or implied 9 * warranty of any kind. 10 * 11 * These notices must be retained in any copies of any part of this 12 * documentation and/or software. */ 13 14#include <sys/cdefs.h> 15__FBSDID("$FreeBSD: releng/11.0/lib/libmd/shadriver.c 300903 2016-05-28 16:06:07Z allanjude $"); 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 "sha256.h" 25#include "sha384.h" 26#include "sha512.h" 27#include "sha512t.h" 28 29/* The following makes SHA default to SHA-1 if it has not already been 30 * defined with C compiler flags. */ 31#ifndef SHA 32#define SHA 1 33#endif 34 35#if SHA == 1 36#undef SHA_Data 37#define SHA_Data SHA1_Data 38#elif SHA == 256 39#undef SHA_Data 40#define SHA_Data SHA256_Data 41#elif SHA == 384 42#undef SHA_Data 43#define SHA_Data SHA384_Data 44#elif SHA == 512 45#undef SHA_Data 46#define SHA_Data SHA512_Data 47#elif SHA == 512256 48#undef SHA_Data 49#define SHA_Data SHA512_256_Data 50#endif 51 52/* Digests a string and prints the result. */ 53static void 54SHAString(char *string) 55{ 56 char buf[2*64 + 1]; 57 58 printf("SHA-%d (\"%s\") = %s\n", 59 SHA, string, SHA_Data(string, strlen(string), buf)); 60} 61 62/* Digests a reference suite of strings and prints the results. */ 63int 64main(void) 65{ 66 printf("SHA-%d test suite:\n", SHA); 67 68 SHAString(""); 69 SHAString("abc"); 70 SHAString("message digest"); 71 SHAString("abcdefghijklmnopqrstuvwxyz"); 72 SHAString("ABCDEFGHIJKLMNOPQRSTUVWXYZ" 73 "abcdefghijklmnopqrstuvwxyz0123456789"); 74 SHAString("1234567890123456789012345678901234567890" 75 "1234567890123456789012345678901234567890"); 76 77 return 0; 78} 79