diff --git a/CHANGES b/CHANGES index bc5e58647d..50b5c5e5ee 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1988. [bug] Remove a bus error from the SHA256/SHA512 support. + [RT #15878] + 1987. [func] DS/DLV SHA256 digest algorithm support. [RT #15608] 1986. [func] Report when a zone is removed. [RT #15849] diff --git a/lib/isc/include/isc/sha2.h b/lib/isc/include/isc/sha2.h index d84d7a060d..511d75ce01 100644 --- a/lib/isc/include/isc/sha2.h +++ b/lib/isc/include/isc/sha2.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: sha2.h,v 1.5 2006/01/31 23:01:23 marka Exp $ */ +/* $Id: sha2.h,v 1.6 2006/02/24 00:03:15 marka Exp $ */ /* $FreeBSD: src/sys/crypto/sha2/sha2.h,v 1.1.2.1 2001/07/03 11:01:36 ume Exp $ */ /* $KAME: sha2.h,v 1.3 2001/03/12 08:27:48 itojun Exp $ */ @@ -79,12 +79,18 @@ ISC_LANG_BEGINDECLS /*** SHA-256/384/512 Context Structures *******************************/ +/* + * Keep buffer immediately after bitcount to preserve alignment. + */ typedef struct { isc_uint32_t state[8]; isc_uint64_t bitcount; isc_uint8_t buffer[ISC_SHA256_BLOCK_LENGTH]; } isc_sha256_t; +/* + * Keep buffer immediately after bitcount to preserve alignment. + */ typedef struct { isc_uint64_t state[8]; isc_uint64_t bitcount[2]; diff --git a/lib/isc/sha2.c b/lib/isc/sha2.c index b0046836ca..c05844f4ac 100644 --- a/lib/isc/sha2.c +++ b/lib/isc/sha2.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: sha2.c,v 1.7 2006/01/31 23:01:23 marka Exp $ */ +/* $Id: sha2.c,v 1.8 2006/02/24 00:03:15 marka Exp $ */ /* $FreeBSD: src/sys/crypto/sha2/sha2.c,v 1.2.2.2 2002/03/05 08:36:47 ume Exp $ */ /* $KAME: sha2.c,v 1.8 2001/11/08 01:07:52 itojun Exp $ */ @@ -592,7 +592,8 @@ isc_sha256_update(isc_sha256_t *context, const isc_uint8_t *data, size_t len) { context->bitcount += freespace << 3; len -= freespace; data += freespace; - isc_sha256_transform(context, (isc_uint32_t*)context->buffer); + isc_sha256_transform(context, + (isc_uint32_t*)context->buffer); } else { /* The buffer is not yet full */ memcpy(&context->buffer[usedspace], data, len); @@ -604,7 +605,8 @@ isc_sha256_update(isc_sha256_t *context, const isc_uint8_t *data, size_t len) { } while (len >= ISC_SHA256_BLOCK_LENGTH) { /* Process as many complete blocks as we can */ - isc_sha256_transform(context, (const isc_uint32_t*)data); + memcpy(context->buffer, data, ISC_SHA256_BLOCK_LENGTH); + isc_sha256_transform(context, (isc_uint32_t*)context->buffer); context->bitcount += ISC_SHA256_BLOCK_LENGTH << 3; len -= ISC_SHA256_BLOCK_LENGTH; data += ISC_SHA256_BLOCK_LENGTH; @@ -648,7 +650,8 @@ isc_sha256_final(isc_uint8_t digest[], isc_sha256_t *context) { usedspace); } /* Do second-to-last transform: */ - isc_sha256_transform(context, (isc_uint32_t*)context->buffer); + isc_sha256_transform(context, + (isc_uint32_t*)context->buffer); /* And set-up for the last transform: */ memset(context->buffer, 0, @@ -926,7 +929,8 @@ void isc_sha512_update(isc_sha512_t *context, const isc_uint8_t *data, size_t le ADDINC128(context->bitcount, freespace << 3); len -= freespace; data += freespace; - isc_sha512_transform(context, (isc_uint64_t*)context->buffer); + isc_sha512_transform(context, + (isc_uint64_t*)context->buffer); } else { /* The buffer is not yet full */ memcpy(&context->buffer[usedspace], data, len); @@ -938,7 +942,8 @@ void isc_sha512_update(isc_sha512_t *context, const isc_uint8_t *data, size_t le } while (len >= ISC_SHA512_BLOCK_LENGTH) { /* Process as many complete blocks as we can */ - isc_sha512_transform(context, (const isc_uint64_t*)data); + memcpy(context->buffer, data, ISC_SHA512_BLOCK_LENGTH); + isc_sha512_transform(context, (isc_uint64_t*)context->buffer); ADDINC128(context->bitcount, ISC_SHA512_BLOCK_LENGTH << 3); len -= ISC_SHA512_BLOCK_LENGTH; data += ISC_SHA512_BLOCK_LENGTH; @@ -975,7 +980,8 @@ void isc_sha512_last(isc_sha512_t *context) { ISC_SHA512_BLOCK_LENGTH - usedspace); } /* Do second-to-last transform: */ - isc_sha512_transform(context, (isc_uint64_t*)context->buffer); + isc_sha512_transform(context, + (isc_uint64_t*)context->buffer); /* And set-up for the last transform: */ memset(context->buffer, 0, ISC_SHA512_BLOCK_LENGTH - 2);