Fix unaligned access in *_Final for SHA224/SHA256/SHA384.
Remaining part of PR 42273. Tested by snj.
This commit is contained in:
parent
cc376dc80f
commit
85b087f151
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: sha2.c,v 1.20 2009/11/06 20:31:18 joerg Exp $ */
|
||||
/* $NetBSD: sha2.c,v 1.21 2010/01/24 21:11:18 joerg 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.20 2009/11/06 20:31:18 joerg Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: sha2.c,v 1.21 2010/01/24 21:11:18 joerg Exp $");
|
||||
|
||||
#include <sys/param.h> /* XXX: to pull <machine/macros.h> for vax memset(9) */
|
||||
#include <lib/libkern/libkern.h>
|
||||
|
@ -51,7 +51,7 @@ __KERNEL_RCSID(0, "$NetBSD: sha2.c,v 1.20 2009/11/06 20:31:18 joerg Exp $");
|
|||
#else
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: sha2.c,v 1.20 2009/11/06 20:31:18 joerg Exp $");
|
||||
__RCSID("$NetBSD: sha2.c,v 1.21 2010/01/24 21:11:18 joerg Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
@ -555,7 +555,6 @@ SHA256_Update(SHA256_CTX *context, const uint8_t *data, size_t len)
|
|||
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;
|
||||
|
||||
|
@ -603,7 +602,7 @@ SHA224_256_Final(uint8_t digest[], SHA256_CTX *context, size_t len)
|
|||
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: */
|
||||
|
@ -990,7 +989,6 @@ SHA384_Transform(SHA512_CTX *context, const uint64_t *data)
|
|||
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: */
|
||||
|
@ -999,7 +997,7 @@ SHA384_Final(uint8_t digest[], SHA384_CTX *context)
|
|||
|
||||
/* 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 */
|
||||
|
|
Loading…
Reference in New Issue