Subject: Re: pkg/12417: digest problem with sha1 on alpha, unaligned access
To: Andrew Brown <atatat@atatdot.net>
From: Simon Burge <simonb@wasabisystems.com>
List: netbsd-bugs
Date: 03/16/2001 15:37:26
Andrew Brown wrote:
> >Number: 12417
> >Category: pkg
> >Synopsis: digest problem with sha1 on alpha, unaligned access
>
> >Description:
>
> when using digest to computer sha1 hashes, i get tons of spewage on my
> terminal that looks like this:
>
> pid 1745 (digest): unaligned access: va=0x12012287f pc=0x120006170 ra=0x466f6f0b4e op=l
dl
> pid 1745 (digest): unaligned access: va=0x12012287f pc=0x120006208 ra=0x120122867 op=st
l
The problem is that the workspace array in libc's sha1.c isn't int
aligned. My first patch was
Index: sha1.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/hash/sha1.c,v
retrieving revision 1.6
diff -d -p -u -r1.6 sha1.c
--- sha1.c 2000/09/17 19:55:28 1.6
+++ sha1.c 2001/03/16 04:16:10
@@ -139,7 +139,7 @@ void SHA1Transform(state, buffer)
CHAR64LONG16 *block;
#ifdef SHA1HANDSOFF
- static u_char workspace[64];
+ static u_long workspace[64 / sizeof(u_long)];
#endif
_DIAGASSERT(buffer != 0);
but probably even more correct is
Index: sha1.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/hash/sha1.c,v
retrieving revision 1.6
diff -d -p -u -r1.6 sha1.c
--- sha1.c 2000/09/17 19:55:28 1.6
+++ sha1.c 2001/03/16 04:35:31
@@ -72,7 +72,7 @@ __weak_alias(SHA1Final,_SHA1Final)
typedef union {
u_char c[64];
- u_int l[16];
+ u_int32_t l[16];
} CHAR64LONG16;
#ifdef __sparc_v9__
@@ -139,14 +139,14 @@ void SHA1Transform(state, buffer)
CHAR64LONG16 *block;
#ifdef SHA1HANDSOFF
- static u_char workspace[64];
+ CHAR64LONG16 workspace;
#endif
_DIAGASSERT(buffer != 0);
_DIAGASSERT(state != 0);
#ifdef SHA1HANDSOFF
- block = (CHAR64LONG16 *)(void *)workspace;
+ block = &workspace;
(void)memcpy(block, buffer, 64);
#else
block = (CHAR64LONG16 *)(void *)buffer;
Can anyone see anything wrong with this before I commit it?
Simon.
--
Simon Burge <simonb@wasabisystems.com>
NetBSD CDs, Support and Service: http://www.wasabisystems.com/