shadriver.c revision 220496
192108Sphk/* SHADRIVER.C - test driver for SHA-1 (and SHA-2) */
292108Sphk
392108Sphk/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights
492108Sphk * reserved.
592108Sphk *
692108Sphk * RSA Data Security, Inc. makes no representations concerning either the
792108Sphk * merchantability of this software or the suitability of this software for
892108Sphk * any particular purpose. It is provided "as is" without express or implied
992108Sphk * warranty of any kind.
1092108Sphk *
1192108Sphk * These notices must be retained in any copies of any part of this
1292108Sphk * documentation and/or software. */
1392108Sphk
1492108Sphk#include <sys/cdefs.h>
1592108Sphk__FBSDID("$FreeBSD: head/lib/libmd/shadriver.c 220496 2011-04-09 13:56:29Z markm $");
1692108Sphk
1792108Sphk#include <sys/types.h>
1892108Sphk
1992108Sphk#include <stdio.h>
2092108Sphk#include <time.h>
2192108Sphk#include <string.h>
2292108Sphk
2392108Sphk#include "sha.h"
2492108Sphk#include "sha256.h"
2592108Sphk#include "sha512.h"
2692108Sphk
2792108Sphk/* The following makes SHA default to SHA-1 if it has not already been
2892108Sphk * defined with C compiler flags. */
2992108Sphk#ifndef SHA
3092108Sphk#define SHA 1
3192108Sphk#endif
3292108Sphk
3392108Sphk#if SHA == 1
3492108Sphk#define SHA_Data SHA1_Data
3592108Sphk#elif SHA == 256
3692108Sphk#define SHA_Data SHA256_Data
3792108Sphk#elif SHA == 512
3892108Sphk#define SHA_Data SHA512_Data
3992108Sphk#endif
4092108Sphk
4192108Sphk/* Digests a string and prints the result. */
4292108Sphkstatic void
4392108SphkSHAString(char *string)
4492108Sphk{
4592108Sphk	char buf[2*64 + 1];
4692108Sphk
4792108Sphk	printf("SHA-%d (\"%s\") = %s\n",
4892108Sphk	       SHA, string, SHA_Data(string, strlen(string), buf));
4992108Sphk}
5092108Sphk
5192108Sphk/* Digests a reference suite of strings and prints the results. */
5292108Sphkint
5392108Sphkmain(void)
5492108Sphk{
5592108Sphk	printf("SHA-%d test suite:\n", SHA);
5692108Sphk
57104054Sphk	SHAString("");
58112988Sphk	SHAString("abc");
5992108Sphk	SHAString("message digest");
6092108Sphk	SHAString("abcdefghijklmnopqrstuvwxyz");
6192108Sphk	SHAString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6292108Sphk		  "abcdefghijklmnopqrstuvwxyz0123456789");
6393250Sphk	SHAString("1234567890123456789012345678901234567890"
6492108Sphk		  "1234567890123456789012345678901234567890");
6592108Sphk
66109170Sphk	return 0;
6793250Sphk}
6892108Sphk