1220496Smarkm/* SHADRIVER.C - test driver for SHA-1 (and SHA-2) */
244290Swollman
3220496Smarkm/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights
4220496Smarkm * reserved.
5220496Smarkm *
6220496Smarkm * RSA Data Security, Inc. makes no representations concerning either the
7220496Smarkm * merchantability of this software or the suitability of this software for
8220496Smarkm * any particular purpose. It is provided "as is" without express or implied
9220496Smarkm * warranty of any kind.
10220496Smarkm *
11220496Smarkm * These notices must be retained in any copies of any part of this
12220496Smarkm * documentation and/or software. */
13220496Smarkm
1484211Sdillon#include <sys/cdefs.h>
1584211Sdillon__FBSDID("$FreeBSD$");
1684211Sdillon
17220496Smarkm#include <sys/types.h>
1844290Swollman
19220496Smarkm#include <stdio.h>
20220496Smarkm#include <time.h>
21220496Smarkm#include <string.h>
2244290Swollman
23220496Smarkm#include "sha.h"
24220496Smarkm#include "sha256.h"
25220496Smarkm#include "sha512.h"
2644290Swollman
2744290Swollman/* The following makes SHA default to SHA-1 if it has not already been
28220496Smarkm * defined with C compiler flags. */
2944290Swollman#ifndef SHA
3044290Swollman#define SHA 1
3144290Swollman#endif
3244290Swollman
3344290Swollman#if SHA == 1
3444290Swollman#define SHA_Data SHA1_Data
35143334Scperciva#elif SHA == 256
36143334Scperciva#define SHA_Data SHA256_Data
37220496Smarkm#elif SHA == 512
38220496Smarkm#define SHA_Data SHA512_Data
3944290Swollman#endif
4044290Swollman
41220496Smarkm/* Digests a string and prints the result. */
42220496Smarkmstatic void
43220496SmarkmSHAString(char *string)
4444290Swollman{
45220496Smarkm	char buf[2*64 + 1];
4644290Swollman
47220496Smarkm	printf("SHA-%d (\"%s\") = %s\n",
48220496Smarkm	       SHA, string, SHA_Data(string, strlen(string), buf));
4944290Swollman}
5044290Swollman
51220496Smarkm/* Digests a reference suite of strings and prints the results. */
52220496Smarkmint
53220496Smarkmmain(void)
5444290Swollman{
55220496Smarkm	printf("SHA-%d test suite:\n", SHA);
5644290Swollman
57220496Smarkm	SHAString("");
58220496Smarkm	SHAString("abc");
59220496Smarkm	SHAString("message digest");
60220496Smarkm	SHAString("abcdefghijklmnopqrstuvwxyz");
61220496Smarkm	SHAString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
62220496Smarkm		  "abcdefghijklmnopqrstuvwxyz0123456789");
63220496Smarkm	SHAString("1234567890123456789012345678901234567890"
64220496Smarkm		  "1234567890123456789012345678901234567890");
65220496Smarkm
66220496Smarkm	return 0;
6744290Swollman}
68