Sync libmd with FreeBSD:
[dragonfly.git] / lib / libmd / shadriver.c
CommitLineData
984263bc 1/* SHADRIVER.C - test driver for SHA-1 (and SHA-0)
3cd01911
SW
2 * $FreeBSD: src/lib/libmd/shadriver.c,v 1.4 2005/03/09 19:23:04 cperciva Exp $
3 * $DragonFly: src/lib/libmd/shadriver.c,v 1.4 2008/09/11 20:25:34 swildner Exp $
984263bc
MD
4 */
5
6/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
7 rights reserved.
8
9 RSA Data Security, Inc. makes no representations concerning either
10 the merchantability of this software or the suitability of this
11 software for any particular purpose. It is provided "as is"
12 without express or implied warranty of any kind.
13
14 These notices must be retained in any copies of any part of this
15 documentation and/or software.
16 */
17
18/* The following makes SHA default to SHA-1 if it has not already been
19 defined with C compiler flags.
20 */
21#ifndef SHA
22#define SHA 1
23#endif
24
25#include <sys/types.h>
26
27#include <stdio.h>
28#include <time.h>
29#include <string.h>
30#include "sha.h"
39b242ad 31#include "sha256.h"
984263bc
MD
32#if SHA == 1
33#define SHA_Data SHA1_Data
39b242ad
MD
34#elif SHA == 256
35#define SHA_Data SHA256_Data
984263bc
MD
36#endif
37
38/* Digests a string and prints the result.
39 */
40static void SHAString (string)
41char *string;
42{
39b242ad 43 char buf[2*32+1];
984263bc
MD
44
45 printf ("SHA-%d (\"%s\") = %s\n",
46 SHA, string, SHA_Data(string,strlen(string),buf));
47}
48
49/* Digests a reference suite of strings and prints the results.
50 */
51main()
52{
53 printf ("SHA-%d test suite:\n", SHA);
54
55 SHAString ("");
56 SHAString ("abc");
57 SHAString ("message digest");
58 SHAString ("abcdefghijklmnopqrstuvwxyz");
59 SHAString
60 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
61 SHAString
62 ("1234567890123456789012345678901234567890\
631234567890123456789012345678901234567890");
64 return 0;
65}