X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fsha.c;h=a75b8cf8977e6ce60f9cad21feed2fd17b0d68f7;hb=c50728dcc26ea56e6e20937a97a26a70b0484703;hp=f6969a6081e298ad8f06bbeec71c1d11e318c938;hpb=6d03f507ba5b0d8a99ef0875c5a12cef134fe344;p=gnulib.git diff --git a/lib/sha.c b/lib/sha.c index f6969a608..a75b8cf89 100644 --- a/lib/sha.c +++ b/lib/sha.c @@ -1,7 +1,7 @@ /* sha.c - Functions to compute the SHA1 hash (message-digest) of files or blocks of memory. Complies to the NIST specification FIPS-180-1. - Copyright (C) 2000 Scott G. Miller + Copyright (C) 2000, 2001 Scott G. Miller Credits: Robert Klep -- Expansion function fix @@ -24,6 +24,7 @@ #include "md5.h" #include "sha.h" +#include "unlocked-io.h" /* Not-swap is a macro that does an endian swap on architectures that are @@ -241,7 +242,8 @@ sha_process_bytes (const void *buffer, size_t len, struct sha_ctx *ctx) #define F4(B,C,D) (B ^ C ^ D) /* Process LEN bytes of BUFFER, accumulating context into CTX. - It is assumed that LEN % 64 == 0. */ + It is assumed that LEN % 64 == 0. + Most of this code comes from GnuPG's cipher/sha1.c. */ void sha_process_block (const void *buffer, size_t len, struct sha_ctx *ctx) @@ -249,7 +251,7 @@ sha_process_block (const void *buffer, size_t len, struct sha_ctx *ctx) const md5_uint32 *words = buffer; size_t nwords = len / sizeof (md5_uint32); const md5_uint32 *endp = words + nwords; - md5_uint32 x[80]; + md5_uint32 x[16]; md5_uint32 a = ctx->A; md5_uint32 b = ctx->B; md5_uint32 c = ctx->C; @@ -265,7 +267,7 @@ sha_process_block (const void *buffer, size_t len, struct sha_ctx *ctx) #define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \ ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \ - , (x[I&0x0f] = (tm << 1) | (tm >> 31)) ) + , (x[I&0x0f] = rol(tm, 1)) ) #define R(A,B,C,D,E,F,K,M) do { E += rol( A, 5 ) \ + F( B, C, D ) \ @@ -278,6 +280,7 @@ sha_process_block (const void *buffer, size_t len, struct sha_ctx *ctx) { md5_uint32 tm; int t; + /* FIXME: see sha1.c for a better implementation. */ for (t = 0; t < 16; t++) { x[t] = NOTSWAP (*words);