***********************************************************************
** md5driver.c -- sample test routines **
** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
** Created: 2/16/90 RLR **
***********************************************************************
***********************************************************************
** Copyright (C) 1990, RSA Data Security, Inc. 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. **
***********************************************************************
/* Prints message digest buffer in mdContext as 32 hexadecimal digits.
Order is from low-order byte to high-order byte of digest.
Each byte is printed with high-order hexadecimal digit first.
static void MDPrint (mdContext
)
printf ("%02x", mdContext
->digest
[i
]);
#define TEST_BLOCK_SIZE 1000
/* number of blocks to process */
#define TEST_BLOCKS 10000
/* number of test bytes = TEST_BLOCK_SIZE * TEST_BLOCKS */
static long TEST_BYTES
= (long)TEST_BLOCK_SIZE
* (long)TEST_BLOCKS
;
/* A time trial routine, to measure the speed of MD5.
Measures wall time required to digest TEST_BLOCKS * TEST_BLOCK_SIZE
static void MDTimeTrial ()
time_t endTime
, startTime
;
unsigned char data
[TEST_BLOCK_SIZE
];
/* initialize test data */
for (i
= 0; i
< TEST_BLOCK_SIZE
; i
++)
data
[i
] = (unsigned char)(i
& 0xFF);
printf ("MD5 time trial. Processing %ld characters...\n", TEST_BYTES
);
/* digest data in TEST_BLOCK_SIZE byte blocks */
for (i
= TEST_BLOCKS
; i
> 0; i
--)
MD5Update (&mdContext
, data
, TEST_BLOCK_SIZE
);
/* stop timer, get time difference */
printf (" is digest of test input.\n");
("Seconds to process test input: %ld\n", (long)(endTime
-startTime
));
("Characters processed per second: %ld\n",
TEST_BYTES
/(endTime
-startTime
));
/* Computes the message digest for string inString.
Prints out message digest, a space, the string (in quotes) and a
static void MDString (inString
)
unsigned int len
= strlen (inString
);
MD5Update (&mdContext
, inString
, len
);
printf (" \"%s\"\n", inString
);
static void MDFile (filename
)
FILE *inFile
= fopen (filename
, "rb");
unsigned char data
[1024];
printf ("%s can't be opened.\n", filename
);
while ((bytes
= fread (data
, 1, 1024, inFile
)) != 0)
MD5Update (&mdContext
, data
, bytes
);
printf (" %s\n", filename
);
/* Writes the message digest of the data from stdin onto stdout,
followed by a carriage return.
while ((bytes
= fread (data
, 1, 16, stdin
)) != 0)
MD5Update (&mdContext
, data
, bytes
);
/* Runs a standard suite of test data.
static void MDTestSuite ()
printf ("MD5 test suite results:\n");
MDString ("message digest");
MDString ("abcdefghijklmnopqrstuvwxyz");
("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
("1234567890123456789012345678901234567890\
1234567890123456789012345678901234567890");
/* Contents of file foo are "abc" */
/* For each command line argument in turn:
** filename -- prints message digest and name of file
** -sstring -- prints message digest and contents of string
** -t -- prints time trial statistics for 10M
** -x -- execute a standard suite of test data
** (no args) -- writes messages digest of stdin onto stdout
for (i
= 1; i
< argc
; i
++)
if (argv
[i
][0] == '-' && argv
[i
][1] == 's')
else if (strcmp (argv
[i
], "-t") == 0)
else if (strcmp (argv
[i
], "-x") == 0)
***********************************************************************
******************************** (cut) ********************************