Quick & dirty sha1/md5 regression test.
This commit is contained in:
parent
8875442492
commit
639160ce5f
17
regress/lib/libc/md5sha/Makefile
Normal file
17
regress/lib/libc/md5sha/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
# $NetBSD: Makefile,v 1.1 2000/08/19 17:51:19 sommerfeld Exp $
|
||||
|
||||
PROG= test
|
||||
SRCS= test.c
|
||||
MKMAN= no
|
||||
WARNS= 1
|
||||
LDSTATIC= -static
|
||||
|
||||
# MD5 tests from RFC1321
|
||||
# SHA1 tests from FIPS-180-1
|
||||
|
||||
regress:
|
||||
./test -r < ${.CURDIR}/md5test-in | diff - ${.CURDIR}/md5test-out
|
||||
./test -rs < ${.CURDIR}/sha1test-in | diff - ${.CURDIR}/sha1test-out
|
||||
jot -s "" -b "a" -n 1000000 | ./test -rs | diff - ${.CURDIR}/sha1test2-out
|
||||
|
||||
.include <bsd.prog.mk>
|
7
regress/lib/libc/md5sha/md5test-in
Normal file
7
regress/lib/libc/md5sha/md5test-in
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
a
|
||||
abc
|
||||
message digest
|
||||
abcdefghijklmnopqrstuvwxyz
|
||||
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
|
||||
12345678901234567890123456789012345678901234567890123456789012345678901234567890
|
7
regress/lib/libc/md5sha/md5test-out
Normal file
7
regress/lib/libc/md5sha/md5test-out
Normal file
@ -0,0 +1,7 @@
|
||||
d41d8cd98f00b204e9800998ecf8427e
|
||||
0cc175b9c0f1b6a831c399e269772661
|
||||
900150983cd24fb0d6963f7d28e17f72
|
||||
f96b697d7cb7938d525a2f31aaf161d0
|
||||
c3fcd3d76192e4007dfb496cca67e13b
|
||||
d174ab98d277d9f5a5611c2c9f419d9f
|
||||
57edf4a22be3c955ac49da2e2107b67a
|
2
regress/lib/libc/md5sha/sha1test-in
Normal file
2
regress/lib/libc/md5sha/sha1test-in
Normal file
@ -0,0 +1,2 @@
|
||||
abc
|
||||
abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
|
2
regress/lib/libc/md5sha/sha1test-out
Normal file
2
regress/lib/libc/md5sha/sha1test-out
Normal file
@ -0,0 +1,2 @@
|
||||
a9993e364706816aba3e25717850c26c9cd0d89d
|
||||
84983e441c3bd26ebaae4aa1f95129e5e54670f1
|
1
regress/lib/libc/md5sha/sha1test2-out
Normal file
1
regress/lib/libc/md5sha/sha1test2-out
Normal file
@ -0,0 +1 @@
|
||||
34aa973cd4c4daa4f61eeb2bdbad27316534016f
|
140
regress/lib/libc/md5sha/test.c
Normal file
140
regress/lib/libc/md5sha/test.c
Normal file
@ -0,0 +1,140 @@
|
||||
/* $NetBSD: test.c,v 1.1 2000/08/19 17:51:21 sommerfeld Exp $ */
|
||||
|
||||
/*
|
||||
* Combined MD5/SHA1 time and regression test.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <md5.h>
|
||||
#include <sha1.h>
|
||||
|
||||
int mflag, rflag, sflag, tflag;
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
extern char *__progname;
|
||||
(void)fprintf(stderr,
|
||||
"Usage:\t%s -r[ms] < test-file\n"
|
||||
"\t%s -t[ms]\n",
|
||||
__progname, __progname);
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static void
|
||||
hexdump (unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<len; i++) {
|
||||
printf("%02x", buf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
timetest(void)
|
||||
{
|
||||
printf("sorry, not yet\n");
|
||||
}
|
||||
|
||||
#define CHOMP(buf, len, last) \
|
||||
if ((len > 0) && \
|
||||
(buf[len-1] == '\n')) { \
|
||||
buf[len-1] = '\0'; \
|
||||
len--; \
|
||||
last = 1; \
|
||||
}
|
||||
|
||||
static void
|
||||
regress(void)
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
unsigned char out[20];
|
||||
int len, outlen, last;
|
||||
|
||||
while (fgets((char *)buf, sizeof(buf), stdin) != NULL) {
|
||||
last = 0;
|
||||
|
||||
len = strlen(buf);
|
||||
CHOMP(buf, len, last);
|
||||
if (mflag) {
|
||||
MD5_CTX ctx;
|
||||
|
||||
MD5Init(&ctx);
|
||||
MD5Update(&ctx, buf, len);
|
||||
while (!last &&
|
||||
fgets((char *)buf, sizeof(buf), stdin) != NULL) {
|
||||
len = strlen(buf);
|
||||
CHOMP(buf, len, last);
|
||||
MD5Update(&ctx, buf, len);
|
||||
}
|
||||
MD5Final(out, &ctx);
|
||||
outlen = 16;
|
||||
} else {
|
||||
SHA1_CTX ctx;
|
||||
|
||||
SHA1Init(&ctx);
|
||||
SHA1Update(&ctx, buf, len);
|
||||
while (!last &&
|
||||
fgets((char *)buf, sizeof(buf), stdin) != NULL) {
|
||||
len = strlen(buf);
|
||||
CHOMP(buf, len, last);
|
||||
SHA1Update(&ctx, buf, len);
|
||||
}
|
||||
SHA1Final(out, &ctx);
|
||||
outlen = 20;
|
||||
}
|
||||
hexdump(out, outlen);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "mrst")) != -1)
|
||||
switch (ch) {
|
||||
case 'm':
|
||||
mflag = 1;
|
||||
break;
|
||||
case 'r':
|
||||
rflag = 1;
|
||||
break;
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
case 't':
|
||||
tflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc > 0)
|
||||
usage();
|
||||
|
||||
if (!(mflag || sflag))
|
||||
mflag = 1;
|
||||
|
||||
if ((mflag ^ sflag) != 1)
|
||||
usage();
|
||||
|
||||
if ((tflag ^ rflag) != 1)
|
||||
usage();
|
||||
|
||||
if (tflag)
|
||||
timetest();
|
||||
|
||||
if (rflag)
|
||||
regress();
|
||||
|
||||
exit(0);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user