]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/sha1.c
Fix ldaps / TLS processing...
[openldap] / libraries / liblutil / sha1.c
index 3c356afc00d639f776637617cf8b51d4b8b3d159..032c6de3cebb1e09457ab82bb6e66565f505e3a1 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*     Acquired from:
  *     $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $       */
 
@@ -15,6 +20,9 @@
  *   34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
  */
 
+/*
+ * This code assumes uint32 is 32 bits and char is 8 bits
+ */
 
 #include "portable.h"
 #include <ac/string.h>
 /* include socket.h to get sys/types.h and/or winsock2.h */
 #include <ac/socket.h>
 
-#if defined(HAVE_SYS_PARAM_H)
-#include <sys/param.h>
-#endif
+#include <ac/param.h>
 
 #include "lutil_sha1.h"
 
+/* undefining this will cause pointer alignment errors */
 #define SHA1HANDSOFF           /* Copies data before messing with it. */
 #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
 
  * I got the idea of expanding during the round function from SSLeay
  */
 #if BYTE_ORDER == LITTLE_ENDIAN
-# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
-    |(rol(block->l[i],8)&0x00FF00FF))
+# define blk0(i) (block[i] = (rol(block[i],24)&0xFF00FF00) \
+    |(rol(block[i],8)&0x00FF00FF))
 #else
-# define blk0(i) block->l[i]
+# define blk0(i) block[i]
 #endif
-#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
-    ^block->l[(i+2)&15]^block->l[i&15],1))
+#define blk(i) (block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15] \
+    ^block[(i+2)&15]^block[i&15],1))
 
 /*
  * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
@@ -61,16 +68,12 @@ void
 lutil_SHA1Transform( uint32 *state, const unsigned char *buffer )
 {
     uint32 a, b, c, d, e;
-    typedef union char64long16_u {
-       unsigned char c[64];
-       u_int l[16];
-    } CHAR64LONG16;
 
 #ifdef SHA1HANDSOFF
-    CHAR64LONG16 block[1];
+    uint32 block[16];
     (void)memcpy(block, buffer, 64);
 #else
-    CHAR64LONG16 *block = (CHAR64LONG16 *)buffer;
+    uint32 *block = (u_int32 *) buffer;
 #endif
 
     /* Copy context->state[] to working vars */