summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libc/hash/rmd160.c53
-rw-r--r--sys/netinet/ip_rmd160.c51
2 files changed, 57 insertions, 47 deletions
diff --git a/lib/libc/hash/rmd160.c b/lib/libc/hash/rmd160.c
index eb484bb02c4..72a7ad869d7 100644
--- a/lib/libc/hash/rmd160.c
+++ b/lib/libc/hash/rmd160.c
@@ -333,37 +333,42 @@ void RMD160Update(context, data, nbytes)
(void)memset(X, 0, sizeof(X));
- if (context->buflen > 0) {
- ofs = 64 - context->buflen;
- if ( ofs > nbytes )
- ofs = nbytes;
- (void)memcpy(context->bbuffer + context->buflen, data, ofs);
+ if ( context->buflen + nbytes < 64 )
+ {
+ (void)memcpy(context->bbuffer + context->buflen, data, nbytes);
+ context->buflen += nbytes;
+ }
+ else
+ {
+ /* process first block */
+ ofs = 64 - context->buflen;
+ (void)memcpy(context->bbuffer + context->buflen, data, ofs);
#if BYTE_ORDER == LITTLE_ENDIAN
- (void)memcpy(X, context->bbuffer, sizeof(X));
+ (void)memcpy(X, context->bbuffer, sizeof(X));
#else
- for (j=0; j < 16; j++)
- X[j] = BYTES_TO_DWORD(context->bbuffer + (4 * j));
+ for (j=0; j < 16; j++)
+ X[j] = BYTES_TO_DWORD(context->bbuffer + (4 * j));
#endif
- RMD160Transform(context->state, X);
- nbytes -= ofs;
- }
+ RMD160Transform(context->state, X);
+ nbytes -= ofs;
- /* process all complete blocks */
- for (i = 0; i < (nbytes >> 6); i++) {
+ /* process remaining complete blocks */
+ for (i = 0; i < (nbytes >> 6); i++) {
#if BYTE_ORDER == LITTLE_ENDIAN
- (void)memcpy(X, data + (64 * i) + ofs, sizeof(X));
+ (void)memcpy(X, data + (64 * i) + ofs, sizeof(X));
#else
- for (j=0; j < 16; j++)
- X[j] = BYTES_TO_DWORD(data + (64 * i) + (4 * j) + ofs);
+ for (j=0; j < 16; j++)
+ X[j] = BYTES_TO_DWORD(data + (64 * i) + (4 * j) + ofs);
#endif
- RMD160Transform(context->state, X);
- }
-
- /*
- * Put bytes from data into context's buffer
- */
- context->buflen = nbytes & 63;
- memcpy(context->bbuffer, data + (64 * i) + ofs, context->buflen);
+ RMD160Transform(context->state, X);
+ }
+
+ /*
+ * Put last bytes from data into context's buffer
+ */
+ context->buflen = nbytes & 63;
+ memcpy(context->bbuffer, data + (64 * i) + ofs, context->buflen);
+ }
}
/********************************************************************/
diff --git a/sys/netinet/ip_rmd160.c b/sys/netinet/ip_rmd160.c
index f50d1cd44d3..7133fede608 100644
--- a/sys/netinet/ip_rmd160.c
+++ b/sys/netinet/ip_rmd160.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_rmd160.c,v 1.4 1998/06/02 16:12:40 janjaap Exp $ */
+/* $OpenBSD: ip_rmd160.c,v 1.5 1998/09/09 22:34:28 janjaap Exp $ */
/********************************************************************\
*
* FILE: rmd160.c
@@ -334,37 +334,42 @@ void RMD160Update(context, data, nbytes)
bzero(X, sizeof(X));
- if (context->buflen > 0) {
- ofs = 64 - context->buflen;
- if ( ofs > nbytes )
- ofs = nbytes;
+ if ( context->buflen + nbytes < 64 )
+ {
+ bcopy(data, context->bbuffer + context->buflen, nbytes);
+ context->buflen += nbytes;
+ }
+ else
+ {
+ /* process first block */
+ 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));
+ for (j=0; j < 16; j++)
+ X[j] = BYTES_TO_DWORD(context->bbuffer + (4 * j));
#endif
- RMD160Transform(context->state, X);
- nbytes -= ofs;
- }
+ RMD160Transform(context->state, X);
+ nbytes -= ofs;
- /* process all complete blocks */
- for (i = 0; i < (nbytes >> 6); i++) {
+ /* process remaining complete blocks */
+ for (i = 0; i < (nbytes >> 6); i++) {
#if BYTE_ORDER == LITTLE_ENDIAN
- bcopy(data + (64 * i) + ofs, 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) + ofs);
+ for (j=0; j < 16; j++)
+ X[j] = BYTES_TO_DWORD(data + (64 * i) + (4 * j) + ofs);
#endif
- RMD160Transform(context->state, X);
- }
-
- /*
- * Put bytes from data into context's buffer
- */
- context->buflen = nbytes & 63;
- bcopy(data + (64 * i) + ofs, context->bbuffer, context->buflen);
+ RMD160Transform(context->state, X);
+ }
+
+ /*
+ * Put last bytes from data into context's buffer
+ */
+ context->buflen = nbytes & 63;
+ bcopy(data + (64 * i) + ofs, context->bbuffer, context->buflen);
+ }
}
/********************************************************************/