diff options
author | janjaap <janjaap@cvs.openbsd.org> | 1998-09-09 22:30:01 +0000 |
---|---|---|
committer | janjaap <janjaap@cvs.openbsd.org> | 1998-09-09 22:30:01 +0000 |
commit | 82f933ecb5290017b8bce37e47af4763c0381425 (patch) | |
tree | ff8d0bb088c8d272ee38ec4bc8c9e728b7308166 /lib/libc/hash | |
parent | df21b3e749b2a06f4d5324623cfdaa99b7d4254b (diff) |
Make RMD160Update a little less overzealous when fed small crumbs.
Diffstat (limited to 'lib/libc/hash')
-rw-r--r-- | lib/libc/hash/rmd160.c | 53 |
1 files changed, 29 insertions, 24 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); + } } /********************************************************************/ |