shadriver.c revision 143334
144290Swollman/* SHADRIVER.C - test driver for SHA-1 (and SHA-0) 244290Swollman */ 344290Swollman 484211Sdillon#include <sys/cdefs.h> 584211Sdillon__FBSDID("$FreeBSD: head/lib/libmd/shadriver.c 143334 2005-03-09 19:23:04Z cperciva $"); 684211Sdillon 744290Swollman/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All 844290Swollman rights reserved. 944290Swollman 1044290Swollman RSA Data Security, Inc. makes no representations concerning either 1144290Swollman the merchantability of this software or the suitability of this 1244290Swollman software for any particular purpose. It is provided "as is" 1344290Swollman without express or implied warranty of any kind. 1444290Swollman 1544290Swollman These notices must be retained in any copies of any part of this 1644290Swollman documentation and/or software. 1744290Swollman */ 1844290Swollman 1944290Swollman/* The following makes SHA default to SHA-1 if it has not already been 2044290Swollman defined with C compiler flags. 2144290Swollman */ 2244290Swollman#ifndef SHA 2344290Swollman#define SHA 1 2444290Swollman#endif 2544290Swollman 2644290Swollman#include <sys/types.h> 2744290Swollman 2844290Swollman#include <stdio.h> 2944290Swollman#include <time.h> 3044290Swollman#include <string.h> 3144290Swollman#include "sha.h" 32143334Scperciva#include "sha256.h" 3344290Swollman#if SHA == 1 3444290Swollman#define SHA_Data SHA1_Data 35143334Scperciva#elif SHA == 256 36143334Scperciva#define SHA_Data SHA256_Data 3744290Swollman#endif 3844290Swollman 3944290Swollman/* Digests a string and prints the result. 4044290Swollman */ 4144290Swollmanstatic void SHAString (string) 4244290Swollmanchar *string; 4344290Swollman{ 44143334Scperciva char buf[2*32+1]; 4544290Swollman 4644290Swollman printf ("SHA-%d (\"%s\") = %s\n", 4744290Swollman SHA, string, SHA_Data(string,strlen(string),buf)); 4844290Swollman} 4944290Swollman 5044290Swollman/* Digests a reference suite of strings and prints the results. 5144290Swollman */ 5244290Swollmanmain() 5344290Swollman{ 5444290Swollman printf ("SHA-%d test suite:\n", SHA); 5544290Swollman 5644290Swollman SHAString (""); 5744290Swollman SHAString ("abc"); 5844290Swollman SHAString ("message digest"); 5944290Swollman SHAString ("abcdefghijklmnopqrstuvwxyz"); 6044290Swollman SHAString 6144290Swollman ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); 6244290Swollman SHAString 6344290Swollman ("1234567890123456789012345678901234567890\ 6444290Swollman1234567890123456789012345678901234567890"); 6544290Swollman return 0; 6644290Swollman} 67