Browse Source

The data pointer passed to the transform function may not be properly

aligned so copy it in a way that a) is endian indepenent and b) does
not rely on alignment.  Problem found and solution tested by hshoexer@
OPENBSD_3_6
millert 20 years ago
parent
commit
c71980a843
1 changed files with 7 additions and 9 deletions
  1. +7
    -9
      src/lib/libc/hash/sha2.c

+ 7
- 9
src/lib/libc/hash/sha2.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: sha2.c,v 1.3 2004/04/28 22:06:02 millert Exp $ */
/* $OpenBSD: sha2.c,v 1.4 2004/04/29 14:13:17 millert Exp $ */
/* /*
* FILE: sha2.c * FILE: sha2.c
@ -35,7 +35,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$OpenBSD: sha2.c,v 1.3 2004/04/28 22:06:02 millert Exp $";
static const char rcsid[] = "$OpenBSD: sha2.c,v 1.4 2004/04/29 14:13:17 millert Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/types.h> #include <sys/types.h>
@ -688,15 +688,13 @@ SHA512_Transform(SHA512_CTX *context, const u_int64_t *data) {
j = 0; j = 0;
do { do {
#if BYTE_ORDER == LITTLE_ENDIAN
/* Convert TO host byte order */
REVERSE64(*data++, W512[j]);
W512[j] = (u_int64_t)data[7] | ((u_int64_t)data[6] << 8) |
((u_int64_t)data[5] << 16) | ((u_int64_t)data[4] << 24) |
((u_int64_t)data[3] << 32) | ((u_int64_t)data[2] << 40) |
((u_int64_t)data[1] << 48) | ((u_int64_t)data[0] << 56);
data++;
/* Apply the SHA-512 compression function to update a..h */ /* Apply the SHA-512 compression function to update a..h */
T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j]; T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j];
#else /* BYTE_ORDER == LITTLE_ENDIAN */
/* Apply the SHA-512 compression function to update a..h with copy */
T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j] = *data++);
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
T2 = Sigma0_512(a) + Maj(a, b, c); T2 = Sigma0_512(a) + Maj(a, b, c);
h = g; h = g;
g = f; g = f;


Loading…
Cancel
Save