]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
1988. [bug] Remove a bus error from the SHA256/SHA512 support.
authorMark Andrews <marka@isc.org>
Fri, 24 Feb 2006 00:03:15 +0000 (00:03 +0000)
committerMark Andrews <marka@isc.org>
Fri, 24 Feb 2006 00:03:15 +0000 (00:03 +0000)
                        [RT #15878]

CHANGES
lib/isc/include/isc/sha2.h
lib/isc/sha2.c

diff --git a/CHANGES b/CHANGES
index bc5e58647dfa7c1c2de3bfcb8bc1b70c70956605..50b5c5e5eedbe7aad7cdf5751f96a5af90be364b 100644 (file)
--- 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]
index d84d7a060d2d1c3c513acfc2e2f5ff0348f34588..511d75ce01dec33051b4382267caa3e273e78664 100644 (file)
@@ -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];
index b0046836ca2ba198fdfeb2c1148956bf443df30c..c05844f4ac45ab302966f64b5b37fa2e9ab1be76 100644 (file)
@@ -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);