]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/sha2_internal.cc
merged from lp:~donkult/apt/experimental
[apt.git] / apt-pkg / contrib / sha2_internal.cc
index 565db2f91d2faefbb4693c0186b7e8d39c200650..6d27e8f2b834e972a3d46a62845b9df6ddb228b0 100644 (file)
@@ -31,6 +31,7 @@
  *
  * $Id: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
  */
+#include <config.h>
 
 #include <string.h>    /* memcpy()/memset() or bcopy()/bzero() */
 #include <assert.h>    /* assert() */
@@ -604,7 +605,12 @@ void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
                        *context->buffer = 0x80;
                }
                /* Set the bit count: */
-               *(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
+               union {
+                       sha2_byte* c;
+                       sha2_word64* l;
+               } bitcount;
+               bitcount.c = &context->buffer[SHA256_SHORT_BLOCK_LENGTH];
+               *(bitcount.l) = context->bitcount;
 
                /* Final transform: */
                SHA256_Transform(context, (sha2_word32*)context->buffer);
@@ -921,8 +927,13 @@ static void SHA512_Last(SHA512_CTX* context) {
                *context->buffer = 0x80;
        }
        /* Store the length of input data (in bits): */
-       *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
-       *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
+       union {
+               sha2_byte* c;
+               sha2_word64* l;
+       } bitcount;
+       bitcount.c = &context->buffer[SHA512_SHORT_BLOCK_LENGTH];
+       bitcount.l[0] = context->bitcount[1];
+       bitcount.l[1] = context->bitcount[0];
 
        /* Final transform: */
        SHA512_Transform(context, (sha2_word64*)context->buffer);