Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/lib/libskey Pull up revision 1.19 (requested by mjl):



details:   https://anonhg.NetBSD.org/src/rev/c9f8989b8c5a
branches:  netbsd-1-5
changeset: 490861:c9f8989b8c5a
user:      he <he%NetBSD.org@localhost>
date:      Tue Mar 13 21:13:37 2001 +0000

description:
Pull up revision 1.19 (requested by mjl):
  Fix SHA1 calculation on big-endian machines.  Fixes PR#12045.

diffstat:

 lib/libskey/skeysubr.c |  55 ++++++++++++++++++++++---------------------------
 1 files changed, 25 insertions(+), 30 deletions(-)

diffs (96 lines):

diff -r 8d435d2b12bc -r c9f8989b8c5a lib/libskey/skeysubr.c
--- a/lib/libskey/skeysubr.c    Tue Mar 13 21:08:23 2001 +0000
+++ b/lib/libskey/skeysubr.c    Tue Mar 13 21:13:37 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: skeysubr.c,v 1.15.4.1 2000/07/17 19:55:53 mjl Exp $    */
+/*     $NetBSD: skeysubr.c,v 1.15.4.2 2001/03/13 21:13:37 he Exp $     */
 
 /* S/KEY v1.1b (skeysubr.c)
  *
@@ -158,7 +158,6 @@
 {
        char *buf;
        SHA1_CTX sha;
-       u_int32_t results[5];
        size_t buflen;
        int i, j;
 
@@ -168,28 +167,26 @@
        /* Crunch the key through SHA1 */
        SHA1Init(&sha);
        SHA1Update(&sha, (unsigned char *)buf, buflen);
-       SHA1Final((unsigned char *) (void *)results, &sha);
+       SHA1Final(NULL, &sha);
        free(buf);
 
        /* Fold 160 to 64 bits */
-       results[0] ^= results[2];
-       results[1] ^= results[3];
-       results[0] ^= results[4];
+       sha.state[0] ^= sha.state[2];
+       sha.state[1] ^= sha.state[3];
+       sha.state[0] ^= sha.state[4];
 
        /*
-        * Even though my readings of rfc2289 indicate that this is
-        * wrong (it converts stuff to big endian), it is needed to
-        * make the output match up the regression tests in said rfc.
-        * Something is wrong here? --mjl
+        * SHA1 is a big endian algorithm but RFC2289 mandates that
+        * the result be in little endian form, so we copy to the
+        * result buffer manually.
         */
-               
-       for(i=j=0; j<8; i++, j+=4)
-               {
-               result[j+3] = (unsigned char)(results[i] & 0xff);
-               result[j+2] = (unsigned char)((results[i] >> 8) & 0xff);
-               result[j+1] = (unsigned char)((results[i] >> 16) & 0xff);
-               result[j+0] = (unsigned char)((results[i] >> 24) & 0xff);
-               }
+
+       for(i=j=0; j<8; i++, j+=4) {
+               result[j]   = (unsigned char)(sha.state[i] & 0xff);
+               result[j+1] = (unsigned char)((sha.state[i] >> 8) & 0xff);
+               result[j+2] = (unsigned char)((sha.state[i] >> 16) & 0xff);
+               result[j+3] = (unsigned char)((sha.state[i] >> 24) & 0xff);
+       }
 
        return(0);
 }
@@ -265,25 +262,23 @@
 static void f_sha1(char *x)
 {
        SHA1_CTX sha;
-       u_int32_t results[5];
        int i, j;
        
        SHA1Init(&sha);
        SHA1Update(&sha, (unsigned char *)x, SKEY_BINKEY_SIZE);
-       SHA1Final((unsigned char *) (void *)results, &sha);
+       SHA1Final(NULL, &sha);
 
        /* Fold 160 to 64 bits */
-       results[0] ^= results[2];
-       results[1] ^= results[3];
-       results[0] ^= results[4];
+       sha.state[0] ^= sha.state[2];
+       sha.state[1] ^= sha.state[3];
+       sha.state[0] ^= sha.state[4];
 
-       for(i=j=0; j<8; i++, j+=4)
-               {
-               x[j+3] = (unsigned char)(results[i] & 0xff);
-               x[j+2] = (unsigned char)((results[i] >> 8) & 0xff);
-               x[j+1] = (unsigned char)((results[i] >> 16) & 0xff);
-               x[j+0] = (unsigned char)((results[i] >> 24) & 0xff);
-               }
+       for(i=j=0; j<8; i++, j+=4) {
+               x[j]   = (unsigned char)(sha.state[i] & 0xff);
+               x[j+1] = (unsigned char)((sha.state[i] >> 8) & 0xff);
+               x[j+2] = (unsigned char)((sha.state[i] >> 16) & 0xff);
+               x[j+3] = (unsigned char)((sha.state[i] >> 24) & 0xff);
+       }
 }
 
 #if 0



Home | Main Index | Thread Index | Old Index