1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/* MDDRIVER.C - test driver for MD2, MD4 and MD5
*/
/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
rights reserved.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
/******************************************************************
The return value structure has been altered by Mark to fit into
cfengine instead of printing out strings on the console. Also
cf appended to the names to counteract buggy library functions in
solaris and maybe other systems which invade the name space!!!
*******************************************************************/
/* The following makes MD default to MD5 if it has not already been
defined with C compiler flags.
*/
#ifndef MD
#define MD 5
#endif
#include <stdio.h>
#include <string.h>
#include "global.h"
#include "../src/cf.defs.h"
#include "../src/cf.extern.h"
#if MD == 5
#include "md5.h"
#endif
/* Length of test block, number of test blocks.
*/
#define TEST_BLOCK_LEN 1000
#define TEST_BLOCK_COUNT 1000
void MDFile PROTO_LIST ((char *));
void MDFilter PROTO_LIST ((void));
void MDPrint PROTO_LIST ((unsigned char [16]));
#if MD == 2
#define MD_CTX MD2_CTX
#define MDInit MD2Init
#define MDUpdate MD2Update
#define MDFinal MD2Final
#endif
#if MD == 4
#define MD_CTX MD4_CTX
#define MDInit MD4Init
#define MDUpdate MD4Update
#define MDFinal MD4Final
#endif
#if MD == 5
#define MD_CTX MD5_CTX
#define MDInit MD5Init
#define MDUpdate MD5Update
#define MDFinal MD5Final
#endif
/**************************************************************/
/* Digests a file and prints the result.
*/
void cfMDFile (filename,digest)
char *filename;
unsigned char digest[16];
{ FILE *file;
MD_CTX context;
int len;
unsigned char buffer[1024];
Debug2("MDFile(%s)\n",filename);
if ((file = fopen (filename, "rb")) == NULL)
{
printf ("%s can't be opened\n", filename);
}
else
{
cfMD5Init (&context);
while (len = fread (buffer, 1, 1024, file))
{
cfMD5Update (&context, buffer, len);
}
cfMD5Final (digest, &context);
fclose (file);
}
}
|