Add a '-p' option to md5. This will save some time in generation of the

ctm deltas.
This commit is contained in:
Poul-Henning Kamp 1995-02-26 01:55:31 +00:00
parent 671e2cee97
commit 23b406e176
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=6725
2 changed files with 15 additions and 7 deletions

View File

@ -3,7 +3,7 @@
md5 \- calculate a message-digest fingerprint (checksum) for a file md5 \- calculate a message-digest fingerprint (checksum) for a file
.SH SYNOPSIS .SH SYNOPSIS
.B md5 .B md5
[ -t | -x | -sstring | filename(s) ] [ -p | -t | -x | -sstring | filename(s) ]
.SH DESCRIPTION .SH DESCRIPTION
.B md5 .B md5
takes as input a message of arbitrary length and produces takes as input a message of arbitrary length and produces
@ -26,6 +26,9 @@ must be the last objects on the command line.
.B -sstring .B -sstring
prints a checksum of the given "string". prints a checksum of the given "string".
.PP .PP
.B -p
echos stdin to stdout and appends the MD5 sum to stdout.
.PP
.B -t .B -t
runs a built-in time trial. runs a built-in time trial.
.PP .PP

View File

@ -1,5 +1,5 @@
/* /*
* $Id$ * $Id: md5.c,v 1.2 1995/02/20 00:48:50 phk Exp $
* *
* Derived from: * Derived from:
*/ */
@ -36,7 +36,7 @@
static void MDString PROTO_LIST((char *)); static void MDString PROTO_LIST((char *));
static void MDTimeTrial PROTO_LIST((void)); static void MDTimeTrial PROTO_LIST((void));
static void MDTestSuite PROTO_LIST((void)); static void MDTestSuite PROTO_LIST((void));
static void MDFilter PROTO_LIST((void)); static void MDFilter PROTO_LIST((int));
/* Main driver. /* Main driver.
@ -61,6 +61,8 @@ main(argc, argv)
MDString(argv[i] + 2); MDString(argv[i] + 2);
else if (strcmp(argv[i], "-t") == 0) else if (strcmp(argv[i], "-t") == 0)
MDTimeTrial(); MDTimeTrial();
else if (strcmp(argv[i], "-p") == 0)
MDFilter(1);
else if (strcmp(argv[i], "-x") == 0) else if (strcmp(argv[i], "-x") == 0)
MDTestSuite(); MDTestSuite();
else { else {
@ -71,7 +73,7 @@ main(argc, argv)
printf("MD5 (%s) = %s\n", argv[i], p); printf("MD5 (%s) = %s\n", argv[i], p);
} }
else else
MDFilter(); MDFilter(0);
return (0); return (0);
} }
@ -94,7 +96,7 @@ MDTimeTrial()
{ {
MD5_CTX context; MD5_CTX context;
time_t endTime, startTime; time_t endTime, startTime;
unsigned char block[TEST_BLOCK_LEN], digest[16]; unsigned char block[TEST_BLOCK_LEN];
unsigned int i; unsigned int i;
char *p; char *p;
@ -151,14 +153,17 @@ MDTestSuite()
* Digests the standard input and prints the result. * Digests the standard input and prints the result.
*/ */
static void static void
MDFilter() MDFilter(int pipe)
{ {
MD5_CTX context; MD5_CTX context;
int len; int len;
unsigned char buffer[BUFSIZ], digest[16]; unsigned char buffer[BUFSIZ], digest[16];
MD5Init(&context); MD5Init(&context);
while (len = fread(buffer, 1, BUFSIZ, stdin)) while (len = fread(buffer, 1, BUFSIZ, stdin)) {
if(pipe && (len != fwrite(buffer, 1, len, stdout)))
perror(stdout);
MD5Update(&context, buffer, len); MD5Update(&context, buffer, len);
}
printf("%s\n", MD5End(&context)); printf("%s\n", MD5End(&context));
} }