[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Support for sha-256 and friends
Hello.
Are there any plans to add support for sha-256, sha-384 and sha-512
hashes? Any known patent problems?
Reference: http://csrc.nist.gov/encryption/shs/dfips-180-2.pdf
If it's of any interest to anyone - I have sha-256 (the easy one)
working in libc so far (I based it on sha1.c written by Steve Reid).
Need some feedback at this point.
Tested on i386 and sparc64, test vectors match with FIPS 180-2 (except
for the problem described below). I also verified a few digests for
files of various sizes with somebody else's implementation of sha-256.
Problem:
When running 'sha256 -x', the test vectors for "abc" and
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" are
correct, but digest for 1,000,000 "a"s is wrong for some reason.
Different on sparc64 and i386 too. If manually piping 1,000,000 "a"
through sha256, then the digest mathes FIPS 180-2 test vector.
Problem with md5.c ? Need help here...
Todo:
0. Resolve the above problem.
1. The rest of the man pages ( sha256(3) and API )
2. If needed (?) - sha256 in sys/crypto and sbin/isakmpd
3. Sync comments, identation and spacing in lib/libc/hash/sha1.c,
sys/crypto/sha1.c and sbin/isakmpd/sysdep/common/libsysdep/sha1.c
to make diffing easier.
4. Why is it so slow on sparc64, but not on i386?
5. Add sha-384 and sha-512 hashes
6. Mention number of bits of security for different sha's in the
manpages (80, 128, 192, and 256 bits)
7. Look into possibility of optimizing algorithms (without assembly)
8. Is it OK to force 'gcc -O0' for sha256 on sparc64 ?
Files changed:
include/Makefile
lib/libc/hash/Makefile.inc
bin/md5/Makefile
bin/md5/md5.c
New files:
include/sha256.h
lib/libc/hash/sha256.c
lib/libc/hash/sha256hl.c
bin/md5/sha256.1
Complete diff:
Index: include/Makefile
===================================================================
RCS file: /nfs/build/cvs/src/include/Makefile,v
retrieving revision 1.113
diff -u -r1.113 Makefile
--- include/Makefile 3 Sep 2002 18:59:55 -0000 1.113
+++ include/Makefile 3 Nov 2002 09:36:59 -0000
@@ -15,10 +15,10 @@
locale.h login_cap.h malloc.h math.h md4.h md5.h memory.h mpool.h \
ndbm.h netdb.h netgroup.h nlist.h nl_types.h ohash.h olf_abi.h \
paths.h poll.h pwd.h ranlib.h re_comp.h readpassphrase.h regex.h \
- resolv.h rmd160.h search.h setjmp.h sgtty.h sha1.h skipjack.h \
- signal.h stab.h stdbool.h stddef.h stdio.h stdlib.h string.h \
- strings.h struct.h sysexits.h tar.h time.h ttyent.h tzfile.h \
- unistd.h utime.h utmp.h vis.h
+ resolv.h rmd160.h search.h setjmp.h sgtty.h sha1.h sha256.h \
+ skipjack.h signal.h stab.h stdbool.h stddef.h stdio.h stdlib.h \
+ string.h strings.h struct.h sysexits.h tar.h time.h ttyent.h \
+ tzfile.h unistd.h utime.h utmp.h vis.h
FILES+= link.h link_aout.h link_elf.h
Index: include/sha256.h
===================================================================
RCS file: include/sha256.h
diff -N include/sha256.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ include/sha256.h 3 Nov 2002 08:48:42 -0000
@@ -0,0 +1,50 @@
+/* $OpenBSD$ */
+
+/*
+ * SHA-256 in C
+ * Based on SHA-1 implementation by Steve Reid <steve@edmweb.com>
+ * 100% Public Domain
+ */
+
+#ifndef _SHA256_H
+#define _SHA256_H
+
+typedef struct {
+ u_int32_t state[8];
+ u_int32_t count[2];
+ u_char buffer[64];
+} SHA256_CTX;
+
+void SHA256Transform(u_int32_t state[8], const u_char buffer[64]);
+void SHA256Init(SHA256_CTX *context);
+void SHA256Update(SHA256_CTX *context, const u_char *data, u_int len);
+void SHA256Final(u_char digest[32], SHA256_CTX *context);
+char *SHA256End(SHA256_CTX *, char *);
+char *SHA256File(char *, char *);
+char *SHA256Data(const u_char *, size_t, char *);
+
+#define SHA256_DIGESTSIZE 32
+#define SHA256_BLOCKSIZE 64
+
+/* XXX I don't know what these are for...
+#define HTONDIGEST(x) { \
+ x[0] = htonl(x[0]); \
+ x[1] = htonl(x[1]); \
+ x[2] = htonl(x[2]); \
+ x[3] = htonl(x[3]); \
+ x[4] = htonl(x[4]); \
+ x[5] = htonl(x[5]); \
+ x[6] = htonl(x[6]); \
+ x[7] = htonl(x[7]); }
+
+#define NTOHDIGEST(x) { \
+ x[0] = ntohl(x[0]); \
+ x[1] = ntohl(x[1]); \
+ x[2] = ntohl(x[2]); \
+ x[3] = ntohl(x[3]); \
+ x[4] = ntohl(x[4]); \
+ x[5] = ntohl(x[5]); \
+ x[6] = ntohl(x[6]); \
+ x[7] = ntohl(x[7]); }
+*/
+#endif /* _SHA256_H */
Index: lib/libc/hash/Makefile.inc
===================================================================
RCS file: /nfs/build/cvs/src/lib/libc/hash/Makefile.inc,v
retrieving revision 1.12
diff -u -r1.12 Makefile.inc
--- lib/libc/hash/Makefile.inc 16 Jan 2002 19:29:13 -0000 1.12
+++ lib/libc/hash/Makefile.inc 3 Nov 2002 10:32:37 -0000
@@ -3,7 +3,7 @@
# hash functions
.PATH: ${LIBCSRCDIR}/hash
-SRCS+= sha1.c sha1hl.c rmd160.c rmd160hl.c
+SRCS+= sha1.c sha1hl.c sha256.c sha256hl.c rmd160.c rmd160hl.c
MAN+= sha1.3 rmd160.3
MLINKS+=sha1.3 SHA1Init.3 sha1.3 SHA1Update.3 sha1.3 SHA1Final.3
MLINKS+=sha1.3 SHA1End.3 sha1.3 SHA1File.3 sha1.3 SHA1Data.3
@@ -23,4 +23,13 @@
sha1.go:
${CC} ${CFLAGS} ${CPPFLAGS} -O0 -g -c ${.IMPSRC} -o $@
+sha256.o:
+ ${CC} ${CFLAGS} ${CPPFLAGS} -O0 -c ${.IMPSRC}
+
+sha256.po:
+ ${CC} ${CFLAGS} ${CPPFLAGS} -O0 -c ${.IMPSRC} -o $@
+sha256.so:
+ ${CC} ${CFLAGS} ${CPPFLAGS} -O0 ${PICFLAG} -DPIC -c ${.IMPSRC} -o $@
+sha256.go:
+ ${CC} ${CFLAGS} ${CPPFLAGS} -O0 -g -c ${.IMPSRC} -o $@
.endif
Index: lib/libc/hash/sha256.c
===================================================================
RCS file: lib/libc/hash/sha256.c
diff -N lib/libc/hash/sha256.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/libc/hash/sha256.c 3 Nov 2002 12:02:30 -0000
@@ -0,0 +1,243 @@
+/* $OpenBSD$ */
+
+/*
+ * Implementation of SHA-256 secure hashing algorithm, see FIPS 180-2
+ * http://csrc.nist.gov/encryption/shs/dfips-180-2.pdf
+ *
+ * SHA-256 may be used to hash a message, M, having a length of l bits,
+ * where 0 <= l < 2^64.
+ *
+ * The algorithm uses
+ * 1) a message schedule of sixty-four 32-bit words,
+ * 2) eight working variables of 32 bits each, and
+ * 3) a hash value of eight 32-bit words.
+ * The final result of SHA-256 is a 256-bit message digest.
+ *
+ * This implementation is written by Andrey Smagin <andrey@smagin.com>
+ * (heavily based on SHA-1 implementation by Steve Reid <steve@edmweb.com>)
+ * 101% Public Domain
+ *
+ * Test Vectors (from FIPS 180-2)
+ * "abc"
+ * ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad
+ *
+ * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ * 248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1
+ *
+ * 1,000,000 (1 million) repetitions of character "a"
+ * cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0
+ */
+
+#define SHA256HANDSOFF /* Copies data before messing with it. */
+
+#include <sys/param.h>
+
+#include <sha256.h>
+#include <string.h>
+
+/* ROTR32 - used in sha-256 */
+#define ROTR32(x,n) (((x) >> (n)) | ((x) << (32 - (n))))
+
+/* Ch and Maj are the same for sha-256, sha-384 and sha-512 */
+#define Ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
+#define Maj(x,y,z) (((x) & ((y) | (z))) | ((y) & (z)))
+
+/* Sigma functions for sha-256 */
+#define SIGMA0_256(x) (ROTR32((x), 2) ^ ROTR32((x), 13) ^ ROTR32((x), 22))
+#define SIGMA1_256(x) (ROTR32((x), 6) ^ ROTR32((x), 11) ^ ROTR32((x), 25))
+#define sigma0_256(x) (ROTR32((x), 7) ^ ROTR32((x), 18) ^ ((x) >> 3))
+#define sigma1_256(x) (ROTR32((x), 17) ^ ROTR32((x), 19) ^ ((x) >> 10))
+
+/* BLK0() and BLK() perform the initial expand (message schedule). */
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define BLK0(i) (block->l[i] = (ROTR32(block->l[i], 8)&0xFF00FF00) | \
+ (ROTR32(block->l[i],24)&0x00FF00FF) )
+#else
+#define BLK0(i) (block->l[i])
+#endif
+
+#define BLK(i) (block->l[i&15] = sigma1_256(block->l[(i+14)&15]) + \
+ block->l[(i+9)&15] + \
+ sigma0_256( block->l[(i+1)&15] ) + \
+ block->l[i&15])
+
+/* Main hashing function for iterations 0-15 */
+#define R0_15(a,b,c,d,e,f,g,h,i) { \
+ T1 = h + SIGMA1_256(e) + Ch(e,f,g) + K[i] + BLK0(i); \
+ T2 = SIGMA0_256(a) + Maj(a,b,c); \
+ h=g; g=f; f=e; e=d+T1; d=c; c=b; b=a; a=T1+T2;}
+
+/* Main hashing function for iterations 16-63 */
+#define R16_63(a,b,c,d,e,f,g,h,i) { \
+ T1 = h + SIGMA1_256(e) + Ch(e,f,g) + K[i] + BLK(i); \
+ T2 = SIGMA0_256(a) + Maj(a,b,c); \
+ h=g; g=f; f=e; e=d+T1; d=c; c=b; b=a; a=T1+T2;}
+
+/* sha-256 constants - sixty-four 32-bit words in hex */
+static const u_int32_t K[64] = {
+ 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
+ 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
+ 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
+ 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
+ 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
+ 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
+ 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
+ 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
+ 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
+ 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
+ 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
+ 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
+ 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
+ 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
+ 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
+ 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
+};
+
+
+/*
+ * SHA256Init - Initialize new context.
+ */
+void
+SHA256Init(SHA256_CTX * context)
+{
+ /* SHA-256 initial hash values */
+ context->state[0] = 0x6a09e667UL;
+ context->state[1] = 0xbb67ae85UL;
+ context->state[2] = 0x3c6ef372UL;
+ context->state[3] = 0xa54ff53aUL;
+ context->state[4] = 0x510e527fUL;
+ context->state[5] = 0x9b05688cUL;
+ context->state[6] = 0x1f83d9abUL;
+ context->state[7] = 0x5be0cd19UL;
+ context->count[0] = context->count[1] = 0;
+}
+
+
+/*
+ * Hash a single 512-bit block. This is the core of the algorithm.
+ */
+void
+SHA256Transform(u_int32_t state[8], const u_char buffer[64])
+{
+ u_int32_t a, b, c, d, e, f, g, h, T1, T2;
+ typedef union {
+ u_int8_t c[64];
+ u_int32_t l[16];
+ } CHAR64LONG16;
+ CHAR64LONG16 *block;
+
+#ifdef SHA1HANDSOFF
+ static u_int8_t workspace[64];
+ block = (CHAR64LONG16 *)workspace;
+ (void)memcpy(block, buffer, 64);
+#else
+ block = (CHAR64LONG16 *)buffer;
+#endif
+
+ /* Copy context->state[] to working vars */
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+ f = state[5];
+ g = state[6];
+ h = state[7];
+
+ /* 64 rounds. Loop unrolled. */
+ R0_15(a,b,c,d,e,f,g,h, 0); R0_15(a,b,c,d,e,f,g,h, 1);
+ R0_15(a,b,c,d,e,f,g,h, 2); R0_15(a,b,c,d,e,f,g,h, 3);
+ R0_15(a,b,c,d,e,f,g,h, 4); R0_15(a,b,c,d,e,f,g,h, 5);
+ R0_15(a,b,c,d,e,f,g,h, 6); R0_15(a,b,c,d,e,f,g,h, 7);
+ R0_15(a,b,c,d,e,f,g,h, 8); R0_15(a,b,c,d,e,f,g,h, 9);
+ R0_15(a,b,c,d,e,f,g,h,10); R0_15(a,b,c,d,e,f,g,h,11);
+ R0_15(a,b,c,d,e,f,g,h,12); R0_15(a,b,c,d,e,f,g,h,13);
+ R0_15(a,b,c,d,e,f,g,h,14); R0_15(a,b,c,d,e,f,g,h,15);
+ R16_63(a,b,c,d,e,f,g,h,16); R16_63(a,b,c,d,e,f,g,h,17);
+ R16_63(a,b,c,d,e,f,g,h,18); R16_63(a,b,c,d,e,f,g,h,19);
+ R16_63(a,b,c,d,e,f,g,h,20); R16_63(a,b,c,d,e,f,g,h,21);
+ R16_63(a,b,c,d,e,f,g,h,22); R16_63(a,b,c,d,e,f,g,h,23);
+ R16_63(a,b,c,d,e,f,g,h,24); R16_63(a,b,c,d,e,f,g,h,25);
+ R16_63(a,b,c,d,e,f,g,h,26); R16_63(a,b,c,d,e,f,g,h,27);
+ R16_63(a,b,c,d,e,f,g,h,28); R16_63(a,b,c,d,e,f,g,h,29);
+ R16_63(a,b,c,d,e,f,g,h,30); R16_63(a,b,c,d,e,f,g,h,31);
+ R16_63(a,b,c,d,e,f,g,h,32); R16_63(a,b,c,d,e,f,g,h,33);
+ R16_63(a,b,c,d,e,f,g,h,34); R16_63(a,b,c,d,e,f,g,h,35);
+ R16_63(a,b,c,d,e,f,g,h,36); R16_63(a,b,c,d,e,f,g,h,37);
+ R16_63(a,b,c,d,e,f,g,h,38); R16_63(a,b,c,d,e,f,g,h,39);
+ R16_63(a,b,c,d,e,f,g,h,40); R16_63(a,b,c,d,e,f,g,h,41);
+ R16_63(a,b,c,d,e,f,g,h,42); R16_63(a,b,c,d,e,f,g,h,43);
+ R16_63(a,b,c,d,e,f,g,h,44); R16_63(a,b,c,d,e,f,g,h,45);
+ R16_63(a,b,c,d,e,f,g,h,46); R16_63(a,b,c,d,e,f,g,h,47);
+ R16_63(a,b,c,d,e,f,g,h,48); R16_63(a,b,c,d,e,f,g,h,49);
+ R16_63(a,b,c,d,e,f,g,h,50); R16_63(a,b,c,d,e,f,g,h,51);
+ R16_63(a,b,c,d,e,f,g,h,52); R16_63(a,b,c,d,e,f,g,h,53);
+ R16_63(a,b,c,d,e,f,g,h,54); R16_63(a,b,c,d,e,f,g,h,55);
+ R16_63(a,b,c,d,e,f,g,h,56); R16_63(a,b,c,d,e,f,g,h,57);
+ R16_63(a,b,c,d,e,f,g,h,58); R16_63(a,b,c,d,e,f,g,h,59);
+ R16_63(a,b,c,d,e,f,g,h,60); R16_63(a,b,c,d,e,f,g,h,61);
+ R16_63(a,b,c,d,e,f,g,h,62); R16_63(a,b,c,d,e,f,g,h,63);
+
+ /* Add the working vars back into context.state[] */
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
+ state[5] += f;
+ state[6] += g;
+ state[7] += h;
+ /* Wipe variables */
+ a = b = c = d = e = f = g = h = 0;
+}
+
+
+/*
+ * Run your data through this.
+ */
+void
+SHA256Update(SHA256_CTX * context, const u_char * data, u_int len)
+{
+ u_int i, j;
+
+ j = context->count[0];
+ if ((context->count[0] += len << 3) < j)
+ context->count[1] += (len >> 29) + 1;
+ j = (j >> 3) & 63;
+ if ((j + len) > 63) {
+ (void)memcpy(&context->buffer[j], data, (i = 64 - j));
+ SHA256Transform(context->state, context->buffer);
+ for ( ; i + 63 < len; i += 64)
+ SHA256Transform(context->state, &data[i]);
+ j = 0;
+ } else {
+ i = 0;
+ }
+ (void)memcpy(&context->buffer[j], &data[i], len - i);
+}
+
+
+/*
+ * Add padding and return the message digest.
+ */
+void
+SHA256Final(u_char digest[32], SHA256_CTX * context)
+{
+ u_int i;
+ u_char finalcount[8];
+
+ for (i = 0; i < 8; i++) {
+ finalcount[i] = (u_char)((context->count[(i >= 4 ? 0 : 1)]
+ >> ((3 - (i & 3)) * 8) ) & 255); /* Endian independent */
+ }
+ SHA256Update(context, (u_char *)"\200", 1);
+ while ((context->count[0] & 504) != 448)
+ SHA256Update(context, (u_char *)"\0", 1);
+ SHA256Update(context, finalcount, 8); /* Should cause a SHA256Transform() */
+
+ if (digest) {
+ for (i = 0; i < 32; i++)
+ digest[i] = (u_char) ((context->state[i>>2]
+ >> ((3 - (i & 3)) * 8) ) & 255);
+ }
+}
Index: lib/libc/hash/sha256hl.c
===================================================================
RCS file: lib/libc/hash/sha256hl.c
diff -N lib/libc/hash/sha256hl.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/libc/hash/sha256hl.c 3 Nov 2002 09:03:26 -0000
@@ -0,0 +1,82 @@
+/* sha256hl.c
+ * Based on sha1hl.c written by Poul-Henning Kamp
+ *
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$OpenBSD$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <sha256.h>
+
+/* ARGSUSED */
+char *
+SHA256End(ctx, buf)
+ SHA256_CTX *ctx;
+ char *buf;
+{
+ int i;
+ char *p = buf;
+ u_char digest[32];
+ static const char hex[]="0123456789abcdef";
+
+ if (p == NULL && (p = malloc(65)) == NULL)
+ return 0;
+
+ SHA256Final(digest,ctx);
+ for (i = 0; i < 32; i++) {
+ p[i + i] = hex[digest[i] >> 4];
+ p[i + i + 1] = hex[digest[i] & 0x0f];
+ }
+ p[i + i] = '\0';
+ return(p);
+}
+
+char *
+SHA256File (filename, buf)
+ char *filename;
+ char *buf;
+{
+ u_char buffer[BUFSIZ];
+ SHA256_CTX ctx;
+ int fd, num, oerrno;
+
+ SHA256Init(&ctx);
+
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ return(0);
+
+ while ((num = read(fd, buffer, sizeof(buffer))) > 0)
+ SHA256Update(&ctx, buffer, num);
+
+ oerrno = errno;
+ close(fd);
+ errno = oerrno;
+ return(num < 0 ? 0 : SHA256End(&ctx, buf));
+}
+
+char *
+SHA256Data (data, len, buf)
+ const u_char *data;
+ size_t len;
+ char *buf;
+{
+ SHA256_CTX ctx;
+
+ SHA256Init(&ctx);
+ SHA256Update(&ctx, data, len);
+ return(SHA256End(&ctx, buf));
+}
Index: bin/md5/Makefile
===================================================================
RCS file: /nfs/build/cvs/src/bin/md5/Makefile,v
retrieving revision 1.6
diff -u -r1.6 Makefile
--- bin/md5/Makefile 3 Jun 2001 17:51:29 -0000 1.6
+++ bin/md5/Makefile 3 Nov 2002 09:09:26 -0000
@@ -1,8 +1,9 @@
# $OpenBSD: Makefile,v 1.6 2001/06/03 17:51:29 millert Exp $
PROG= md5
-MAN= md5.1 sha1.1 rmd160.1
+MAN= md5.1 sha1.1 sha256.1 rmd160.1
LINKS= ${BINDIR}/md5 ${BINDIR}/sha1 \
+ ${BINDIR}/md5 ${BINDIR}/sha256 \
${BINDIR}/md5 ${BINDIR}/rmd160
COPTS+= -ansi -Wall -Wconversion -Wmissing-prototypes -Werror
Index: bin/md5/md5.1
===================================================================
RCS file: /nfs/build/cvs/src/bin/md5/md5.1,v
retrieving revision 1.11
diff -u -r1.11 md5.1
--- bin/md5/md5.1 3 Jun 2001 17:51:29 -0000 1.11
+++ bin/md5/md5.1 3 Nov 2002 08:37:55 -0000
@@ -48,6 +48,7 @@
.Sh SEE ALSO
.Xr cksum 1 ,
.Xr rmd160 1 ,
-.Xr sha1 1
+.Xr sha1 1 ,
+.Xr sha256 1
.Pp
RFC 1321 describes in detail the MD2, MD4, and MD5 message-digest algorithms.
Index: bin/md5/md5.c
===================================================================
RCS file: /nfs/build/cvs/src/bin/md5/md5.c,v
retrieving revision 1.15
diff -u -r1.15 md5.c
--- bin/md5/md5.c 20 Jan 2002 13:32:04 -0000 1.15
+++ bin/md5/md5.c 3 Nov 2002 09:10:23 -0000
@@ -28,6 +28,7 @@
*/
#include <sys/param.h>
+
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
@@ -38,16 +39,19 @@
#include <md5.h>
#include <sha1.h>
+#include <sha256.h>
#include <rmd160.h>
#define DIGEST_MD5 0
#define DIGEST_SHA1 1
#define DIGEST_RMD160 2
+#define DIGEST_SHA256 3
union ANY_CTX {
MD5_CTX md5;
SHA1_CTX sha1;
RMD160_CTX rmd160;
+ SHA256_CTX sha256;
};
struct hash_functions {
@@ -68,6 +72,9 @@
}, {
"RMD160",
RMD160Init, RMD160Update, RMD160End, RMD160File, RMD160Data
+ }, {
+ "SHA256",
+ SHA256Init, SHA256Update, SHA256End, SHA256File, SHA256Data
},
};
@@ -90,6 +97,8 @@
digest_type = DIGEST_RMD160;
else if (strcmp(__progname, "sha1") == 0)
digest_type = DIGEST_SHA1;
+ else if (strcmp(__progname, "sha256") == 0)
+ digest_type = DIGEST_SHA256;
else
digest_type = DIGEST_MD5;
Index: bin/md5/rmd160.1
===================================================================
RCS file: /nfs/build/cvs/src/bin/md5/rmd160.1,v
retrieving revision 1.9
diff -u -r1.9 rmd160.1
--- bin/md5/rmd160.1 6 Sep 2001 14:46:47 -0000 1.9
+++ bin/md5/rmd160.1 3 Nov 2002 08:38:13 -0000
@@ -48,7 +48,8 @@
.Sh SEE ALSO
.Xr cksum 1 ,
.Xr md5 1 ,
-.Xr sha1 1
+.Xr sha1 1 ,
+.Xr sha256 1
.Pp
RMD-160 is part of the ISO draft standard
.Qq ISO/IEC DIS 10118-3
Index: bin/md5/sha1.1
===================================================================
RCS file: /nfs/build/cvs/src/bin/md5/sha1.1,v
retrieving revision 1.10
diff -u -r1.10 sha1.1
--- bin/md5/sha1.1 29 Oct 2001 18:08:29 -0000 1.10
+++ bin/md5/sha1.1 3 Nov 2002 08:38:36 -0000
@@ -49,7 +49,8 @@
.Sh SEE ALSO
.Xr cksum 1 ,
.Xr md5 1 ,
-.Xr rmd160 1
+.Xr rmd160 1 ,
+.Xr sha256 1
.Rs
.%A J. Burrows
.%T The Secure Hash Standard
Index: bin/md5/sha256.1
===================================================================
RCS file: bin/md5/sha256.1
diff -N bin/md5/sha256.1
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ bin/md5/sha256.1 3 Nov 2002 08:36:59 -0000
@@ -0,0 +1,58 @@
+.\" $OpenBSD: sha1.1,v 1.10 2001/10/29 18:08:29 millert Exp $
+.\"
+.Dd November 3, 2002
+.Dt SHA256 1
+.Os
+.Sh NAME
+.Nm sha256
+.Nd calculate a message-digest fingerprint (checksum) for a file
+.Sh SYNOPSIS
+.Nm sha256
+.Oo
+.Fl p | Fl t | Fl x |
+.Fl s Ar string | Ar file ...
+.Oc
+.Sh DESCRIPTION
+.Nm
+takes as input a message of arbitrary length and produces
+as output a 256-bit "fingerprint" or "message digest" of the input.
+It is conjectured that it is computationally infeasible to produce
+two messages having the same message digest, or to produce any
+message having a given prespecified target message digest.
+.Pp
+The
+.Em SHA-256
+algorithm is intended for digital signature applications, where a
+large file must be "compressed" in a secure manner before being
+encrypted with a private (secret) key under a public-key cryptosystem
+such as
+.Em RSA .
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl s Ar string
+Prints a checksum of the given
+.Ar string .
+.It Fl p
+Echos stdin to stdout and appends the
+.Em SHA-256
+sum to stdout.
+.It Fl t
+Runs a built-in time trial.
+.It Fl x
+Runs a built-in test script.
+.El
+.Pp
+The SHA-256
+sum of each file listed on the command line is printed after the options
+are processed.
+.Sh SEE ALSO
+.Xr cksum 1 ,
+.Xr md5 1 ,
+.Xr rmd160 1 ,
+.Xr sha1 1
+.Rs
+.%A Federal Information Processing Standards
+.%T Secure Hash Standard
+.%O FIPS PUB 180-2
+.Re