Subject: Re: pkg/12417: digest problem with sha1 on alpha, unaligned access
To: Alistair Crooks <agc@pkgsrc.org>
From: Simon Burge <simonb@wasabisystems.com>
List: netbsd-bugs
Date: 03/22/2001 13:25:46
Alistair Crooks wrote:

> On Fri, Mar 16, 2001 at 03:46:08PM +1100, Simon Burge wrote:
> > Simon Burge wrote:
> > 
> > > Andrew Brown wrote:
> > > 
> > > > >Number:         12417
> > > > >Category:       pkg
> > > > >Synopsis:       digest problem with sha1 on alpha, unaligned access
> > 
> > Ok, ick.  My patch is to libc, which means that this wont fix older
> > version of NetBSD that include sha1 in libc (eg, a clean 1.5 install).
> > 
> > Perhaps we should always use (a fixed version of) files/sha1.c for all
> > versions of NetBSD prior to 1.6 (or 1.5S or whatever we're up to)?
> > Al - what's your thoughts on this?
> 
> I'll pull in a fixed version (from the rest of the PR, it seems that
> Andrew still gets warnings) when it's fixed in libc.

Here's a patch for the pkgsrc version:

Index: sha1.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/digest/files/sha1.c,v
retrieving revision 1.1.1.1
diff -d -p -u -r1.1.1.1 sha1.c
--- sha1.c	2001/03/06 11:21:05	1.1.1.1
+++ sha1.c	2001/03/22 02:13:27
@@ -143,14 +143,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;

I haven't committed this as I don't know if you want to bump
the version number or not.

> As far as digest goes, it has its own versioning system, loosely based
> on the date, but with some room for fun.  There is a DIGEST_REQD
> version in pkgsrc which can be bumped when necessary to pull in the
> fixed version, which ensures that people will be using the latest
> version.

Cool.  As far as my earlier comment:

> > Perhaps we should always use (a fixed version of) files/sha1.c for all
> > versions of NetBSD prior to 1.6 (or 1.5S or whatever we're up to)?
> > Al - what's your thoughts on this?

We need either 1.5.1 (the pullup is in) or 1.5T to have a safe sha1 in
libc.  Can we get digest to somehow use it's local version of sha1.c if
the current NetBSD version is older than this?

> I've also included a small regression test in the digest package, and
> would be grateful if people could beef that up a bit, so that we don't
> get bitten in future.

This particular one is hard to regression test, as the code works as
expected but the kernel itself spits out the unaligned access messages.
Except for running slowly, I don't think the process itself has any idea
that it's causing them.  For the alpha, there's a few sysctls you can
set to determine the behaviour of unaligned accesses and the like, but I
would say that they are not suitable for using in a regression test.

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD CDs, Support and Service:    http://www.wasabisystems.com/