diff options
author | janjaap <janjaap@cvs.openbsd.org> | 1998-03-23 15:17:49 +0000 |
---|---|---|
committer | janjaap <janjaap@cvs.openbsd.org> | 1998-03-23 15:17:49 +0000 |
commit | 88834bd4136475ba09163937d8438bfd60858f2b (patch) | |
tree | 3bddf665ba4e30ef93e19ff875ac078b0af7cadc /sys | |
parent | db8d5de735f8838a61a5b9b288e23049858a08af (diff) |
Also digest the leftovers.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/ip_rmd160.c | 68 | ||||
-rw-r--r-- | sys/netinet/ip_rmd160.h | 5 |
2 files changed, 48 insertions, 25 deletions
diff --git a/sys/netinet/ip_rmd160.c b/sys/netinet/ip_rmd160.c index a4086e8f4c4..457642f06a5 100644 --- a/sys/netinet/ip_rmd160.c +++ b/sys/netinet/ip_rmd160.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_rmd160.c,v 1.2 1998/02/17 01:39:07 dgregor Exp $ */ +/* $OpenBSD: ip_rmd160.c,v 1.3 1998/03/23 15:17:47 janjaap Exp $ */ /********************************************************************\ * * FILE: rmd160.c @@ -110,6 +110,7 @@ void RMD160Init(context) context->state[3] = 0x10325476U; context->state[4] = 0xc3d2e1f0U; context->length[0] = context->length[1] = 0; + context->buflen = 0; } /********************************************************************/ @@ -320,38 +321,48 @@ void RMD160Update(context, data, nbytes) u_int32_t nbytes; { u_int32_t X[16]; + u_int32_t ofs = 0; u_int32_t i; #if BYTE_ORDER != LITTLE_ENDIAN u_int32_t j; #endif + + /* update length[] */ + if (context->length[0] + nbytes < context->length[0]) + context->length[1]++; /* overflow to msb of length */ + context->length[0] += nbytes; + bzero(X, sizeof(X)); + if (context->buflen > 0) { + ofs = 64 - context->buflen; + bcopy(data, context->bbuffer + context->buflen, ofs); +#if BYTE_ORDER == LITTLE_ENDIAN + bcopy(context->bbuffer, X, sizeof(X)); +#else + for (j=0; j < 16; j++) + X[j] = BYTES_TO_DWORD(context->bbuffer + (4 * j)); +#endif + RMD160Transform(context->state, X); + nbytes -= ofs; + } + /* process all complete blocks */ for (i = 0; i < (nbytes >> 6); i++) { #if BYTE_ORDER == LITTLE_ENDIAN - bcopy(data, X, sizeof(X)); + bcopy(data + (64 * i) + ofs, X, sizeof(X)); #else for (j=0; j < 16; j++) - X[j] = BYTES_TO_DWORD(data + (64 * i) + (4 * j)); + X[j] = BYTES_TO_DWORD(data + (64 * i) + (4 * j) + ofs); #endif RMD160Transform(context->state, X); } - /* update length[] */ - if (context->length[0] + nbytes < context->length[0]) - context->length[1]++; /* overflow to msb of length */ - context->length[0] += nbytes; - /* * Put bytes from data into context's buffer */ - bzero(context->buffer, 16 * sizeof(u_int32_t)); - /* extract bytes 6 to 10 inclusive */ - data += (context->length[0] & 0x3C0); - for (i = 0; i < (context->length[0] & 63); i++) { - /* byte i goes into word buffer[i div 4] at pos. 8*(i mod 4) */ - context->buffer[i>>2] ^= (u_int32_t) *data++ << (8 * (i & 3)); - } + context->buflen = nbytes & 63; + bcopy(data + (64 * i) + ofs, context->bbuffer, context->buflen); } /********************************************************************/ @@ -361,22 +372,33 @@ void RMD160Final(digest, context) RMD160_CTX *context; { u_int32_t i; + u_int32_t X[16]; +#if BYTE_ORDER != LITTLE_ENDIAN + u_int32_t j; +#endif /* append the bit m_n == 1 */ - context->buffer[(context->length[0] >> 2) & 15] ^= - 1U << (8 * (context->length[0] & 3) + 7); + context->bbuffer[context->buflen] = '\200'; - if ((context->length[0] & 63) > 55) { + + bzero(context->bbuffer + context->buflen + 1, 63 - context->buflen); +#if BYTE_ORDER == LITTLE_ENDIAN + bcopy(context->bbuffer, X, sizeof(X)); +#else + for (j=0; j < 16; j++) + X[j] = BYTES_TO_DWORD(context->bbuffer + (4 * j)); +#endif + if ((context->buflen) > 55) { /* length goes to next block */ - RMD160Transform(context->state, context->buffer); - bzero(context->buffer, 16 * sizeof(u_int32_t)); + RMD160Transform(context->state, X); + bzero(X, sizeof(X)); } /* append length in bits */ - context->buffer[14] = context->length[0] << 3; - context->buffer[15] = (context->length[0] >> 29) | + X[14] = context->length[0] << 3; + X[15] = (context->length[0] >> 29) | (context->length[1] << 3); - RMD160Transform(context->state, context->buffer); + RMD160Transform(context->state, X); if (digest != NULL) { for (i = 0; i < 20; i += 4) { diff --git a/sys/netinet/ip_rmd160.h b/sys/netinet/ip_rmd160.h index 270976300b8..bae7366317f 100644 --- a/sys/netinet/ip_rmd160.h +++ b/sys/netinet/ip_rmd160.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_rmd160.h,v 1.1 1997/11/24 19:14:16 provos Exp $ */ +/* $OpenBSD: ip_rmd160.h,v 1.2 1998/03/23 15:17:48 janjaap Exp $ */ /********************************************************************\ * @@ -27,7 +27,8 @@ typedef struct { u_int32_t state[5]; /* state (ABCDE) */ u_int32_t length[2]; /* number of bits */ - u_int32_t buffer[16]; /* input buffer */ + u_char bbuffer[64]; /* overflow buffer */ + u_int32_t buflen; /* number of chars in bbuffer */ } RMD160_CTX; /********************************************************************/ |