Module Name: src
Committed By: snj
Date: Sat Jan 30 19:34:44 UTC 2010
Modified Files:
src/common/lib/libc/hash/sha2 [netbsd-5]: sha2.c
Log Message:
Pull up following revision(s) (requested by 1276):
common/lib/libc/hash/sha2/sha2.c: revision 1.21
Fix unaligned access in *_Final for SHA224/SHA256/SHA384.
Remaining part of PR 42273. Tested by snj.
To generate a diff of this commit:
cvs rdiff -u -r1.7.10.2 -r1.7.10.3 src/common/lib/libc/hash/sha2/sha2.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/common/lib/libc/hash/sha2/sha2.c
diff -u src/common/lib/libc/hash/sha2/sha2.c:1.7.10.2 src/common/lib/libc/hash/sha2/sha2.c:1.7.10.3
--- src/common/lib/libc/hash/sha2/sha2.c:1.7.10.2 Sat Jan 30 19:32:29 2010
+++ src/common/lib/libc/hash/sha2/sha2.c Sat Jan 30 19:34:43 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sha2.c,v 1.7.10.2 2010/01/30 19:32:29 snj Exp $ */
+/* $NetBSD: sha2.c,v 1.7.10.3 2010/01/30 19:34:43 snj Exp $ */
/* $KAME: sha2.c,v 1.9 2003/07/20 00:28:38 itojun Exp $ */
/*
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(_KERNEL) || defined(_STANDALONE)
-__KERNEL_RCSID(0, "$NetBSD: sha2.c,v 1.7.10.2 2010/01/30 19:32:29 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sha2.c,v 1.7.10.3 2010/01/30 19:34:43 snj Exp $");
#include <sys/param.h> /* XXX: to pull <machine/macros.h> for vax memset(9) */
#include <lib/libkern/libkern.h>
@@ -51,7 +51,7 @@
#else
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: sha2.c,v 1.7.10.2 2010/01/30 19:32:29 snj Exp $");
+__RCSID("$NetBSD: sha2.c,v 1.7.10.3 2010/01/30 19:34:43 snj Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -553,7 +553,6 @@
static int
SHA224_256_Final(uint8_t digest[], SHA256_CTX *context, size_t len)
{
- uint32_t *d = (void *)digest;
unsigned int usedspace;
size_t i;
@@ -601,7 +600,7 @@
SHA256_Transform(context, (uint32_t *)(void *)context->buffer);
for (i = 0; i < len / 4; i++)
- d[i] = htobe32(context->state[i]);
+ be32enc(digest + 4 * i, context->state[i]);
}
/* Clean up state data: */
@@ -988,7 +987,6 @@
int
SHA384_Final(uint8_t digest[], SHA384_CTX *context)
{
- uint64_t *d = (void *)digest;
size_t i;
/* If no digest buffer is passed, we don't bother doing this: */
@@ -997,7 +995,7 @@
/* Save the hash data for output: */
for (i = 0; i < 6; ++i)
- d[i] = be64toh(context->state[i]);
+ be64enc(digest + 8 * i, context->state[i]);
}
/* Zero out state data */