diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-04-27 15:54:57 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-04-27 15:54:57 +0000 |
commit | e298b0d5fb907dccdfb221b2ee383749e48808cc (patch) | |
tree | cbe71ca358c1d95b86bf8cb58543b6312ad4fd78 | |
parent | 9317ac921d2496374211fbee07b48153a979975c (diff) |
Make the bit count u_int64_t instead of two u_int32_t. Adapted from
changes Niklas made to the md5 code long ago. OK hshoexer@
-rw-r--r-- | include/sha1.h | 6 | ||||
-rw-r--r-- | lib/libc/hash/sha1.c | 18 |
2 files changed, 11 insertions, 13 deletions
diff --git a/include/sha1.h b/include/sha1.h index 2c2b0d2541e..7fbeeb4fbea 100644 --- a/include/sha1.h +++ b/include/sha1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sha1.h,v 1.17 2004/04/26 19:38:12 millert Exp $ */ +/* $OpenBSD: sha1.h,v 1.18 2004/04/27 15:54:56 millert Exp $ */ /* * SHA-1 in C @@ -15,17 +15,17 @@ typedef struct { u_int32_t state[5]; - u_int32_t count[2]; + u_int64_t count; u_int8_t buffer[SHA1_BLOCK_LENGTH]; } SHA1_CTX; #include <sys/cdefs.h> __BEGIN_DECLS +void SHA1Init(SHA1_CTX *); void SHA1Transform(u_int32_t [5], const u_int8_t [SHA1_BLOCK_LENGTH]) __attribute__((__bounded__(__minbytes__,1,5))) __attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH))); -void SHA1Init(SHA1_CTX *); void SHA1Update(SHA1_CTX *, const u_int8_t *, unsigned int) __attribute__((__bounded__(__string__,2,3))); void SHA1Final(u_int8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *) diff --git a/lib/libc/hash/sha1.c b/lib/libc/hash/sha1.c index cda161a05d5..847c5e8fd32 100644 --- a/lib/libc/hash/sha1.c +++ b/lib/libc/hash/sha1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sha1.c,v 1.14 2004/04/26 19:38:12 millert Exp $ */ +/* $OpenBSD: sha1.c,v 1.15 2004/04/27 15:54:56 millert Exp $ */ /* * SHA-1 in C @@ -15,7 +15,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: sha1.c,v 1.14 2004/04/26 19:38:12 millert Exp $"; +static char rcsid[] = "$OpenBSD: sha1.c,v 1.15 2004/04/27 15:54:56 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #define SHA1HANDSOFF /* Copies data before messing with it. */ @@ -118,12 +118,12 @@ SHA1Init(SHA1_CTX *context) { /* SHA1 initialization constants */ + context->count = 0; context->state[0] = 0x67452301; context->state[1] = 0xEFCDAB89; context->state[2] = 0x98BADCFE; context->state[3] = 0x10325476; context->state[4] = 0xC3D2E1F0; - context->count[0] = context->count[1] = 0; } @@ -135,10 +135,8 @@ SHA1Update(SHA1_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; + j = (u_int32_t)((context->count >> 3) & 63); + context->count += (len << 3); if ((j + len) > 63) { (void)memcpy(&context->buffer[j], data, (i = 64-j)); SHA1Transform(context->state, context->buffer); @@ -162,11 +160,11 @@ SHA1Final(u_char digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context) 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 */ + finalcount[i] = (u_char)((context->count >> + ((7 - (i & 7)) * 8)) & 255); /* Endian independent */ } SHA1Update(context, (u_char *)"\200", 1); - while ((context->count[0] & 504) != 448) + while ((context->count & 504) != 448) SHA1Update(context, (u_char *)"\0", 1); SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ |