Commit ca64db01 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Add md5 utility A port of the FreeBSD tool of the same name, md5 calculates a...

Add md5 utility A port of the FreeBSD tool of the same name, md5 calculates a long check sequence to see if the file has been transported across the internet without error.

Specifically, this is a snapshot of
  /lib/libmd/md5c.c revision 154479
  /lib/libmd/mdXhl.c revision 154479
  /sbin/md5/md5.c revision 238964
with a few tweaks for RISC OS.
Tested by comparing the MD5 sum of a few downloads from the downloads page.

Version 5.55. Tagged as 'Internet-5_55'
parent fe633ca0
......@@ -70,6 +70,7 @@ DISCFILES= ${RDIR}.!Boot\
${SDIR}.gethost.GetHost\
${SDIR}.ifrconfig.IfRConfig\
${SDIR}.map-mbone.Map-MBone\
${SDIR}.md5.MD5\
${SDIR}.mrinfo.MRInfo\
${SDIR}.mtrace.MTrace\
${SDIR}.pong.Pong\
......@@ -89,7 +90,7 @@ DISCFILES= ${RDIR}.!Boot\
FILES=\
${COMMONFILES} \
${DISCFILES} \
${STBFILE}
${STBFILES}
BAREMINUTILS = \
${SDIR}.ifconfig.IfConfig \
......@@ -100,7 +101,6 @@ EMERGENCYUTILS = \
${SDIR}.arp.ARP \
${SDIR}.ifconfig.IfConfig \
${SDIR}.ping.Ping \
${SDIR}.pong.Pong \
${SDIR}.utils.utl.CheckMem \
${SDIR}.newfiler.NewFiler \
${SDIR}.sysctl.SysCtl \
......@@ -113,6 +113,7 @@ NETUTILS = \
${SDIR}.inetstat.InetStat \
${SDIR}.ipvars.IPVars \
${SDIR}.map-mbone.Map-MBone \
${SDIR}.md5.MD5 \
${SDIR}.mrinfo.MRInfo \
${SDIR}.mtrace.MTrace \
${SDIR}.ping.Ping \
......@@ -185,9 +186,10 @@ install_: ${DISCFILES} dirs
SetType ${INSTAPP}.files.AUNMap Obey
${CP} ${RDIR}.utils ${INSTAPP}.utils ${CPFLAGS}
|
${CP} ${SDIR}.map-mbone.Map-MBone ${INSTAPP}.bin.Map-MBone ${CPFLAGS}
${CP} ${SDIR}.gethost.GetHost ${INSTAPP}.bin.GetHost ${CPFLAGS}
${CP} ${SDIR}.ifrconfig.IfRConfig ${INSTAPP}.bin.IfRConfig ${CPFLAGS}
${CP} ${SDIR}.map-mbone.Map-MBone ${INSTAPP}.bin.Map-MBone ${CPFLAGS}
${CP} ${SDIR}.md5.MD5 ${INSTAPP}.bin.MD5 ${CPFLAGS}
${CP} ${SDIR}.mrinfo.MRInfo ${INSTAPP}.bin.MRInfo ${CPFLAGS}
${CP} ${SDIR}.mtrace.MTrace ${INSTAPP}.bin.MTrace ${CPFLAGS}
${CP} ${SDIR}.pong.Pong ${INSTAPP}.bin.Pong ${CPFLAGS}
......@@ -222,6 +224,7 @@ resources-NetUtils: ${NETUTILS}
${CP} ${SDIR}.ipvars.IPVars ${RESD}.bin.IPVars ${CPFLAGS}
${CP} ${SDIR}.inetstat.InetStat ${RESD}.bin.InetStat ${CPFLAGS}
${CP} ${SDIR}.map-mbone.Map-MBone ${RESD}.bin.Map-MBone ${CPFLAGS}
${CP} ${SDIR}.md5.MD5 ${RESD}.bin.MD5 ${CPFLAGS}
${CP} ${SDIR}.mrinfo.MRInfo ${RESD}.bin.MRInfo ${CPFLAGS}
${CP} ${SDIR}.mtrace.MTrace ${RESD}.bin.MTrace ${CPFLAGS}
${CP} ${SDIR}.ping.Ping ${RESD}.bin.Ping ${CPFLAGS}
......@@ -252,7 +255,6 @@ resources-EmergencyUtils: ${EMERGENCYUTILS}
${CP} ${SDIR}.arp.ARP ${RESD}.bin.ARP ${CPFLAGS}
${CP} ${SDIR}.ifconfig.IfConfig ${RESD}.bin.IfConfig ${CPFLAGS}
${CP} ${SDIR}.ping.Ping ${RESD}.bin.Ping ${CPFLAGS}
${CP} ${SDIR}.pong.Pong ${RESD}.bin.Pong ${CPFLAGS}
${CP} ${SDIR}.utils.utl.CheckMem ${RESD}.utils.CheckMem ${CPFLAGS}
${CP} ${SDIR}.newfiler.NewFiler ${RESD}.utils.NewFiler ${CPFLAGS}
${CP} ${SDIR}.sysctl.SysCtl ${RESD}.bin.SysCtl ${CPFLAGS}
......@@ -326,6 +328,14 @@ ${SDIR}.map-mbone.Map-MBone: ${SDIR}.map-mbone.c.Map-MBone \
@up
@up
${SDIR}.md5.MD5: ${SDIR}.md5.c.md5 \
${SDIR}.md5.c.md5c \
${SDIR}.md5.c.mdXhl
dir ${SDIR}.md5
@amu_machine
@up
@up
${SDIR}.mrinfo.MRInfo: ${SDIR}.mrinfo.c.MRInfo \
${SDIR}.mrinfo.c.igmp \
${SDIR}.mrinfo.c.inet \
......@@ -413,90 +423,4 @@ ${SDIR}.utils.utl.X: ${SDIR}.utils.s.X
@up
@up
BBETYPE = internet
bbe-internet: bbe-internet-${OPTIONS}-${TYPE} bbe-generic
${NOP}
bbe-internet-install_common:
BBE_Export_File_In_Dir Sources.arp ARP
BBE_Export_File_In_Dir Sources.ifconfig IfConfig
BBE_Export_File_In_Dir Sources.inetstat InetStat
BBE_Export_File_In_Dir Sources.ipvars IPVars
BBE_Export_File_In_Dir Sources.ping Ping
BBE_Export_File_In_Dir Sources.route Route
BBE_Export_File_In_Dir Sources.showstat ShowStat
BBE_Export_File_In_Dir Sources.sysctl SysCtl
BBE_Export_File_In_Dir Sources.traceroute TraceRoute
bbe-internet-STB-: bbe-internet-install_common
BBE_Export_File_In_Dir awk Version
BBE_Export_File_In_Dir Resources !Boot
BBE_Export_File_In_Dir Sources.pong Pong
BBE_Export_Dir Resources.files
# assume if neither OPTIONS nor TYPE was set that it's an install build
bbe-internet--: bbe-internet-install_common
BBE_Export_File_In_Dir awk Version
BBE_Export_File_In_Dir Resources !Boot
BBE_Export_File_In_Dir Resources !Run
BBE_Export_File_In_Dir Resources !Sprites
BBE_Export_File_In_Dir Resources !Sprites22
BBE_Export_Dir Resources.files
BBE_Export_Dir Resources.utils
BBE_Export_File_In_Dir Sources.map-mbone Map-MBone
BBE_Export_File_In_Dir Sources.gethost GetHost
BBE_Export_File_In_Dir Sources.ifrconfig IfRConfig
BBE_Export_File_In_Dir Sources.mrinfo MRInfo
BBE_Export_File_In_Dir Sources.mtrace MTrace
BBE_Export_File_In_Dir Sources.pong Pong
BBE_Export_File_In_Dir Sources.utils.utl RMFind
BBE_Export_File_In_Dir Sources.utils.utl CheckMem
BBE_Export_File_In_Dir Sources.newfiler NewFiler
BBE_Export_File_In_Dir Sources.utils.utl ReadCMOSIP
BBE_Export_File_In_Dir Sources.utils.utl TriggerCBs
bbe-internet--NetUtils:
BBE_Export_File_In_Dir Sources.arp ARP
BBE_Export_File_In_Dir Sources.ifconfig IfConfig
BBE_Export_File_In_Dir Sources.ifrconfig IfRConfig
BBE_Export_File_In_Dir Sources.ipvars IPVars
BBE_Export_File_In_Dir Sources.inetstat InetStat
BBE_Export_File_In_Dir Sources.map-mbone Map-MBone
BBE_Export_File_In_Dir Sources.mrinfo MRInfo
BBE_Export_File_In_Dir Sources.mtrace MTrace
BBE_Export_File_In_Dir Sources.ping Ping
BBE_Export_File_In_Dir Sources.pong Pong
BBE_Export_File_In_Dir Sources.utils.utl RMFind
BBE_Export_File_In_Dir Sources.route Route
BBE_Export_File_In_Dir Sources.sysctl SysCtl
BBE_Export_File_In_Dir Sources.showstat ShowStat
BBE_Export_File_In_Dir Sources.traceroute TraceRoute
BBE_Export_File_In_Dir awk Version
BBE_Export_Dir Resources.files
BBE_Export_File_In_Dir Resources !Boot
BBE_Export_File_In_Dir Resources !Run
BBE_Export_File_In_Dir Resources !Sprites
BBE_Export_File_In_Dir Resources !Sprites22
bbe-internet--EmergencyUtils:
BBE_Export_File_In_Dir Sources.arp ARP
BBE_Export_File_In_Dir Sources.ifconfig IfConfig
BBE_Export_File_In_Dir Sources.ping Ping
BBE_Export_File_In_Dir Sources.pong Pong
BBE_Export_File_In_Dir Sources.utils.utl CheckMem
BBE_Export_File_In_Dir Sources.newfiler NewFiler
BBE_Export_File_In_Dir Sources.sysctl SysCtl
BBE_Export_File_In_Dir awk Version
BBE_Export_Dir Resources.files
BBE_Export_File_In_Dir Resources !Boot
BBE_Export_File_In_Dir Resources !Run
bbe-internet--BareMinUtils:
BBE_Export_File_In_Dir Sources.ifconfig IfConfig
BBE_Export_File_In_Dir Sources.ping Ping
BBE_Export_Dir Resources.files
BBE_Export_File_In_Dir awk Version
BBE_Export_File_In_Dir Resources !Boot
#---------------------------------------------------------------------------
# Dynamic dependencies:
......@@ -51,3 +51,13 @@ message:
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
The MD5 application includes software derived from the RSA Data Security, Inc.
MD5 Message-Digest Algorithm and comes with the following message:
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.
......@@ -24,7 +24,7 @@
| end
|
If "%*0" = "" Then Error Do not run me with no parameters
If "%1" = "" Then Obey !MkMods %0 arp gethost ifconfig ifrconfig inetstat ipvars map-mbone mrinfo mtrace newfiler ping pong route showstat sysctl traceroute utils
If "%1" = "" Then Obey !MkMods %0 arp gethost ifconfig ifrconfig inetstat ipvars map-mbone md5 mrinfo mtrace newfiler ping pong route showstat sysctl traceroute utils
If "%1" = "" Then Obey
dir %1
......
|
| Copyright (c) 2014, RISC OS Open Ltd
| All rights reserved.
|
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
| * Redistributions of source code must retain the above copyright
| notice, this list of conditions and the following disclaimer.
| * Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
| * Neither the name of RISC OS Open Ltd nor the names of its contributors
| may be used to endorse or promote products derived from this software
| without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
| POSSIBILITY OF SUCH DAMAGE.
|
Dir <Obey$Dir>
amu_machine all
|
| Copyright (c) 2014, RISC OS Open Ltd
| All rights reserved.
|
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
| * Redistributions of source code must retain the above copyright
| notice, this list of conditions and the following disclaimer.
| * Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
| * Neither the name of RISC OS Open Ltd nor the names of its contributors
| may be used to endorse or promote products derived from this software
| without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
| POSSIBILITY OF SUCH DAMAGE.
|
Dir <Obey$Dir>
amu_machine clean
stripdepnd
\ No newline at end of file
#
# Copyright (c) 2014, RISC OS Open Ltd
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of RISC OS Open Ltd nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Makefile for MD5
#
COMPONENT = MD5
INSTTYPE = app
OBJS = md5 md5c mdXhl
LIBS = ${UNIXLIB} ${SOCK5LIB}
CINCLUDES = -ITCPIPLibs:,C:
CDEFINES = -DRISCOS_TWEAK
include CApp
C_WARNINGS = -wp
# Dynamic dependencies:
/*
* Derived from:
*
* 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.
*/
#include <sys/cdefs.h>
#ifndef RISCOS_TWEAK
__FBSDID("$FreeBSD$");
#endif
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <err.h>
#include <md5.h>
#ifndef RISCOS_TWEAK
#include <ripemd.h>
#include <sha.h>
#include <sha256.h>
#include <sha512.h>
#else
#include "unixlib.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
/*
* Length of test block, number of test blocks.
*/
#define TEST_BLOCK_LEN 10000
#define TEST_BLOCK_COUNT 100000
#define MDTESTCOUNT 8
int qflag;
int rflag;
int sflag;
#ifdef RISCOS_TWEAK
const char *__progname = "md5";
const char *MD5TestOutput[MDTESTCOUNT];
#define MDFilter(a,t) usage(a) /* Not supporting stdin -> stdout filter */
char* checkAgainst;
#else
unsigned char* checkAgainst;
#endif
int checksFailed;
typedef void (DIGEST_Init)(void *);
typedef void (DIGEST_Update)(void *, const unsigned char *, size_t);
typedef char *(DIGEST_End)(void *, char *);
extern const char *MD5TestOutput[MDTESTCOUNT];
extern const char *SHA1_TestOutput[MDTESTCOUNT];
extern const char *SHA256_TestOutput[MDTESTCOUNT];
extern const char *SHA512_TestOutput[MDTESTCOUNT];
extern const char *RIPEMD160_TestOutput[MDTESTCOUNT];
typedef struct Algorithm_t {
const char *progname;
const char *name;
const char *(*TestOutput)[MDTESTCOUNT];
DIGEST_Init *Init;
DIGEST_Update *Update;
DIGEST_End *End;
char *(*Data)(const void *, unsigned int, char *);
char *(*File)(const char *, char *);
} Algorithm_t;
static void MD5_Update(MD5_CTX *, const unsigned char *, size_t);
static void MDString(Algorithm_t *, const char *);
static void MDTimeTrial(Algorithm_t *);
static void MDTestSuite(Algorithm_t *);
static void MDFilter(Algorithm_t *, int);
static void usage(Algorithm_t *);
typedef union {
MD5_CTX md5;
#ifndef RISCOS_TWEAK
SHA1_CTX sha1;
SHA256_CTX sha256;
SHA512_CTX sha512;
RIPEMD160_CTX ripemd160;
#endif
} DIGEST_CTX;
/* max(MD5_DIGEST_LENGTH, SHA_DIGEST_LENGTH,
SHA256_DIGEST_LENGTH, SHA512_DIGEST_LENGTH,
RIPEMD160_DIGEST_LENGTH)*2+1 */
#define HEX_DIGEST_LENGTH 129
/* algorithm function table */
struct Algorithm_t Algorithm[] = {
{ "md5", "MD5", &MD5TestOutput, (DIGEST_Init*)&MD5Init,
(DIGEST_Update*)&MD5_Update, (DIGEST_End*)&MD5End,
&MD5Data, &MD5File },
#ifndef RISCOS_TWEAK
{ "sha1", "SHA1", &SHA1_TestOutput, (DIGEST_Init*)&SHA1_Init,
(DIGEST_Update*)&SHA1_Update, (DIGEST_End*)&SHA1_End,
&SHA1_Data, &SHA1_File },
{ "sha256", "SHA256", &SHA256_TestOutput, (DIGEST_Init*)&SHA256_Init,
(DIGEST_Update*)&SHA256_Update, (DIGEST_End*)&SHA256_End,
&SHA256_Data, &SHA256_File },
{ "sha512", "SHA512", &SHA512_TestOutput, (DIGEST_Init*)&SHA512_Init,
(DIGEST_Update*)&SHA512_Update, (DIGEST_End*)&SHA512_End,
&SHA512_Data, &SHA512_File },
{ "rmd160", "RMD160", &RIPEMD160_TestOutput,
(DIGEST_Init*)&RIPEMD160_Init, (DIGEST_Update*)&RIPEMD160_Update,
(DIGEST_End*)&RIPEMD160_End, &RIPEMD160_Data, &RIPEMD160_File }
#endif
};
static void
MD5_Update(MD5_CTX *c, const unsigned char *data, size_t len)
{
MD5Update(c, data, len);
}
/* Main driver.
Arguments (may be any combination):
-sstring - digests string
-t - runs time trial
-x - runs test script
filename - digests file
(none) - digests standard input
*/
int
main(int argc, char *argv[])
{
int ch;
char *p;
char buf[HEX_DIGEST_LENGTH];
int failed;
unsigned digest;
const char* progname;
if ((progname = strrchr(argv[0], '/')) == NULL)
progname = argv[0];
else
progname++;
for (digest = 0; digest < sizeof(Algorithm)/sizeof(*Algorithm); digest++)
if (strcasecmp(Algorithm[digest].progname, progname) == 0)
break;
if (digest == sizeof(Algorithm)/sizeof(*Algorithm))
digest = 0;
failed = 0;
checkAgainst = NULL;
checksFailed = 0;
#ifdef RISCOS_TWEAK
while ((ch = getopt(argc, argv, "c:qrs:txh")) != -1)
#else
while ((ch = getopt(argc, argv, "c:pqrs:tx")) != -1)
#endif
switch (ch) {
case 'c':
checkAgainst = optarg;
break;
case 'p':
MDFilter(&Algorithm[digest], 1);
break;
case 'q':
qflag = 1;
break;
case 'r':
rflag = 1;
break;
case 's':
sflag = 1;
MDString(&Algorithm[digest], optarg);
break;
#ifndef RISCOS_TWEAK
case 't':
MDTimeTrial(&Algorithm[digest]);
break;
case 'x':
MDTestSuite(&Algorithm[digest]);
break;
#else
case 'h':
#endif
default:
usage(&Algorithm[digest]);
}
argc -= optind;
argv += optind;
if (*argv) {
do {
p = Algorithm[digest].File(*argv, buf);
if (!p) {
#ifdef RISCOS_TWEAK
fprintf(stderr, "%s: can't digest '%s'\n", __progname, *argv);
#else
warn("%s", *argv);
#endif
failed++;
} else {
if (qflag)
printf("%s", p);
else if (rflag)
printf("%s %s", p, *argv);
else
printf("%s (%s) = %s",
Algorithm[digest].name, *argv, p);
if (checkAgainst && strcmp(checkAgainst,p))
{
checksFailed++;
if (!qflag)
printf(" [ Failed ]");
}
printf("\n");
}
} while (*++argv);
} else if (!sflag && (optind == 1 || qflag || rflag))
MDFilter(&Algorithm[digest], 0);
if (failed != 0)
return (1);
if (checksFailed != 0)
return (2);
return (0);
}
/*
* Digests a string and prints the result.
*/
static void
MDString(Algorithm_t *alg, const char *string)
{
size_t len = strlen(string);
char buf[HEX_DIGEST_LENGTH];
alg->Data(string,len,buf);
if (qflag)
printf("%s", buf);
else if (rflag)
printf("%s \"%s\"", buf, string);
else
printf("%s (\"%s\") = %s", alg->name, string, buf);
if (checkAgainst && strcmp(buf,checkAgainst))
{
checksFailed++;
if (!qflag)
printf(" [ failed ]");
}
printf("\n");
}
#ifndef RISCOS_TWEAK
/*
* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
*/
static void
MDTimeTrial(Algorithm_t *alg)
{
DIGEST_CTX context;
struct rusage before, after;
struct timeval total;
float seconds;
unsigned char block[TEST_BLOCK_LEN];
unsigned int i;
char *p, buf[HEX_DIGEST_LENGTH];
printf("%s time trial. Digesting %d %d-byte blocks ...",
alg->name, TEST_BLOCK_COUNT, TEST_BLOCK_LEN);
fflush(stdout);
/* Initialize block */
for (i = 0; i < TEST_BLOCK_LEN; i++)
block[i] = (unsigned char) (i & 0xff);
/* Start timer */
getrusage(RUSAGE_SELF, &before);
/* Digest blocks */
alg->Init(&context);
for (i = 0; i < TEST_BLOCK_COUNT; i++)
alg->Update(&context, block, TEST_BLOCK_LEN);
p = alg->End(&context, buf);
/* Stop timer */
getrusage(RUSAGE_SELF, &after);
timersub(&after.ru_utime, &before.ru_utime, &total);
seconds = total.tv_sec + (float) total.tv_usec / 1000000;
printf(" done\n");
printf("Digest = %s", p);
printf("\nTime = %f seconds\n", seconds);
printf("Speed = %f bytes/second\n",
(float) TEST_BLOCK_LEN * (float) TEST_BLOCK_COUNT / seconds);
}
/*
* Digests a reference suite of strings and prints the results.
*/
const char *MDTestInput[MDTESTCOUNT] = {
"",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
"MD5 has not yet (2001-09-03) been broken, but sufficient attacks have been made \
that its security is in some doubt"
};
const char *MD5TestOutput[MDTESTCOUNT] = {
"d41d8cd98f00b204e9800998ecf8427e",
"0cc175b9c0f1b6a831c399e269772661",
"900150983cd24fb0d6963f7d28e17f72",
"f96b697d7cb7938d525a2f31aaf161d0",
"c3fcd3d76192e4007dfb496cca67e13b",
"d174ab98d277d9f5a5611c2c9f419d9f",
"57edf4a22be3c955ac49da2e2107b67a",
"b50663f41d44d92171cb9976bc118538"
};
const char *SHA1_TestOutput[MDTESTCOUNT] = {
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"86f7e437faa5a7fce15d1ddcb9eaeaea377667b8",