diff --git a/regress/lib/libc/md5sha/Makefile b/regress/lib/libc/md5sha/Makefile new file mode 100644 index 000000000000..c37bfa9dc9c6 --- /dev/null +++ b/regress/lib/libc/md5sha/Makefile @@ -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 diff --git a/regress/lib/libc/md5sha/md5test-in b/regress/lib/libc/md5sha/md5test-in new file mode 100644 index 000000000000..763e4f91ccae --- /dev/null +++ b/regress/lib/libc/md5sha/md5test-in @@ -0,0 +1,7 @@ + +a +abc +message digest +abcdefghijklmnopqrstuvwxyz +ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 diff --git a/regress/lib/libc/md5sha/md5test-out b/regress/lib/libc/md5sha/md5test-out new file mode 100644 index 000000000000..bb86bb6556dc --- /dev/null +++ b/regress/lib/libc/md5sha/md5test-out @@ -0,0 +1,7 @@ +d41d8cd98f00b204e9800998ecf8427e +0cc175b9c0f1b6a831c399e269772661 +900150983cd24fb0d6963f7d28e17f72 +f96b697d7cb7938d525a2f31aaf161d0 +c3fcd3d76192e4007dfb496cca67e13b +d174ab98d277d9f5a5611c2c9f419d9f +57edf4a22be3c955ac49da2e2107b67a diff --git a/regress/lib/libc/md5sha/sha1test-in b/regress/lib/libc/md5sha/sha1test-in new file mode 100644 index 000000000000..632d13358459 --- /dev/null +++ b/regress/lib/libc/md5sha/sha1test-in @@ -0,0 +1,2 @@ +abc +abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq diff --git a/regress/lib/libc/md5sha/sha1test-out b/regress/lib/libc/md5sha/sha1test-out new file mode 100644 index 000000000000..c23a05876c27 --- /dev/null +++ b/regress/lib/libc/md5sha/sha1test-out @@ -0,0 +1,2 @@ +a9993e364706816aba3e25717850c26c9cd0d89d +84983e441c3bd26ebaae4aa1f95129e5e54670f1 diff --git a/regress/lib/libc/md5sha/sha1test2-out b/regress/lib/libc/md5sha/sha1test2-out new file mode 100644 index 000000000000..a483a0e3c378 --- /dev/null +++ b/regress/lib/libc/md5sha/sha1test2-out @@ -0,0 +1 @@ +34aa973cd4c4daa4f61eeb2bdbad27316534016f diff --git a/regress/lib/libc/md5sha/test.c b/regress/lib/libc/md5sha/test.c new file mode 100644 index 000000000000..fb62768ccae0 --- /dev/null +++ b/regress/lib/libc/md5sha/test.c @@ -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 +#include +#include +#include +#include + +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 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); + +}