Subject: openssl build on 64bit arch
To: None <tech-security@netbsd.org>
From: None <itojun@iijlab.net>
List: tech-security
Date: 09/02/2000 15:06:44
  by mail.netbsd.org with SMTP; 2 Sep 2000 06:06:46 -0000
	by coconut.itojun.org (8.9.3+3.2W/3.7W) with ESMTP id PAA05078;
	Sat, 2 Sep 2000 15:06:44 +0900 (JST)
To: tech-security@netbsd.org
cc: thorpej@netbsd.org
Subject: openssl build on 64bit arch
From: itojun@iijlab.net
Date: Sat, 02 Sep 2000 15:06:44 +0900
Message-ID: <5076.967874804@coconut.itojun.org>

	it looks to me that the in-tree openssl build (lib/libcrypto and
	lib/libssl) is very unstable on non-32bit architectures.

	this is because of two issues:
	- in normal openssl build, the build framework generates
	  crypto/opensslconf.h on the fly, which will include architecture-
	  dependent #defines.  see the following, for example.
	  netbsd src/crypto/dist/openssl contains a tree that is configured on
	  32bit arch, and will behave badly on 64bit arch.
>#undef SIXTY_FOUR_BIT_LONG
>#undef SIXTY_FOUR_BIT
>#define THIRTY_TWO_BIT
>#undef SIXTEEN_BIT
>#undef EIGHT_BIT
>#endif
	- openssl headers (/usr/include/openssl) are very prone to error.
	  it has so many #ifdef in it, and it is so easy for third-party
	  software to redefine things.  problem happens when third-party
	  software changes definition and variable/struct definition becomes
	  different from compiled library.
	- in some places, openssl code effectively assumes "unsigned long" to
	  be 32bit quantity.  still, openssl code is inconsistent about this
	  assumption.

	i have filed PR 10920 and 10921, and trying to solve the issue.
	attached patch will solve issues in big number library, blowfish,
	and some other crypto functions.  as it will change ABI, we need to
	do a shlib major bump to incorporate it.
	the patch is not complete, however - if I run test suite available in
	openssl distribution, RSA-related tests will fail badly.

	the fix is not very trivial, and if I were to provide long-term
	solution to it, I would need to talk with openssl maintainer to change
	their build framework completely, so that:
	- remove all #ifdef in header files
	- always use u_int32_t and others for types

	now we are close to release 1.5.  what should we do about this problem?
	as it is a problem in openssl build framework, we could solve it in
	the following ways:
	- use pkgsrc.  pkgsrc build allows on-the-fly creation of
	  opensslconf.h.   this does not solve problem 3, however.
	- use something similar to Makefile.bsd-wrapper (openbsd), which
	  effectively allows us to obey openssl build framework, and allow
	  us to generate opensslconf.h on-the-fly.
	  this does not solve problem 3.
	- maintain openssl by ourselves, to solve all the problems?

itojun


Index: crypto/opensslconf.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/opensslconf.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 opensslconf.h
--- crypto/opensslconf.h	2000/07/16 05:04:37	1.1.1.2
+++ crypto/opensslconf.h	2000/09/02 05:52:16
@@ -56,6 +56,7 @@
 #endif
 #endif
 
+#if 0
 #if defined(HEADER_DES_H) && !defined(DES_LONG)
 /* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
  * %20 speed up (longs are 8 bytes, int's are 4). */
@@ -63,6 +64,7 @@
 #define DES_LONG unsigned long
 #endif
 #endif
+#endif
 
 #if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
 #define CONFIG_HEADER_BN_H
@@ -88,10 +90,12 @@
 #undef RC4_INDEX
 #endif
 
+#if 0
 #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
 #define CONFIG_HEADER_BF_LOCL_H
 #undef BF_PTR
 #endif /* HEADER_BF_LOCL_H */
+#endif
 
 #if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
 #define CONFIG_HEADER_DES_LOCL_H
Index: crypto/bf/bf_locl.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/bf/bf_locl.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 bf_locl.h
--- crypto/bf/bf_locl.h	2000/07/16 05:05:11	1.1.1.2
+++ crypto/bf/bf_locl.h	2000/09/02 05:52:16
@@ -61,10 +61,10 @@
 #include <openssl/opensslconf.h> /* BF_PTR, BF_PTR2 */
 
 #undef c2l
-#define c2l(c,l)	(l =((unsigned long)(*((c)++)))    , \
-			 l|=((unsigned long)(*((c)++)))<< 8L, \
-			 l|=((unsigned long)(*((c)++)))<<16L, \
-			 l|=((unsigned long)(*((c)++)))<<24L)
+#define c2l(c,l)	(l =((BF_LONG)(*((c)++)))    , \
+			 l|=((BF_LONG)(*((c)++)))<< 8L, \
+			 l|=((BF_LONG)(*((c)++)))<<16L, \
+			 l|=((BF_LONG)(*((c)++)))<<24L)
 
 /* NOTE - c is not incremented as per c2l */
 #undef c2ln
@@ -72,14 +72,14 @@
 			c+=n; \
 			l1=l2=0; \
 			switch (n) { \
-			case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
-			case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
-			case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
-			case 5: l2|=((unsigned long)(*(--(c))));     \
-			case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
-			case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
-			case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
-			case 1: l1|=((unsigned long)(*(--(c))));     \
+			case 8: l2 =((BF_LONG)(*(--(c))))<<24L; \
+			case 7: l2|=((BF_LONG)(*(--(c))))<<16L; \
+			case 6: l2|=((BF_LONG)(*(--(c))))<< 8L; \
+			case 5: l2|=((BF_LONG)(*(--(c))));     \
+			case 4: l1 =((BF_LONG)(*(--(c))))<<24L; \
+			case 3: l1|=((BF_LONG)(*(--(c))))<<16L; \
+			case 2: l1|=((BF_LONG)(*(--(c))))<< 8L; \
+			case 1: l1|=((BF_LONG)(*(--(c))));     \
 				} \
 			}
 
@@ -110,14 +110,14 @@
 			c+=n; \
 			l1=l2=0; \
 			switch (n) { \
-			case 8: l2 =((unsigned long)(*(--(c))))    ; \
-			case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
-			case 6: l2|=((unsigned long)(*(--(c))))<<16; \
-			case 5: l2|=((unsigned long)(*(--(c))))<<24; \
-			case 4: l1 =((unsigned long)(*(--(c))))    ; \
-			case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
-			case 2: l1|=((unsigned long)(*(--(c))))<<16; \
-			case 1: l1|=((unsigned long)(*(--(c))))<<24; \
+			case 8: l2 =((BF_LONG)(*(--(c))))    ; \
+			case 7: l2|=((BF_LONG)(*(--(c))))<< 8; \
+			case 6: l2|=((BF_LONG)(*(--(c))))<<16; \
+			case 5: l2|=((BF_LONG)(*(--(c))))<<24; \
+			case 4: l1 =((BF_LONG)(*(--(c))))    ; \
+			case 3: l1|=((BF_LONG)(*(--(c))))<< 8; \
+			case 2: l1|=((BF_LONG)(*(--(c))))<<16; \
+			case 1: l1|=((BF_LONG)(*(--(c))))<<24; \
 				} \
 			}
 
@@ -137,10 +137,10 @@
 			}
 
 #undef n2l
-#define n2l(c,l)        (l =((unsigned long)(*((c)++)))<<24L, \
-                         l|=((unsigned long)(*((c)++)))<<16L, \
-                         l|=((unsigned long)(*((c)++)))<< 8L, \
-                         l|=((unsigned long)(*((c)++))))
+#define n2l(c,l)        (l =((BF_LONG)(*((c)++)))<<24L, \
+                         l|=((BF_LONG)(*((c)++)))<<16L, \
+                         l|=((BF_LONG)(*((c)++)))<< 8L, \
+                         l|=((BF_LONG)(*((c)++))))
 
 #undef l2n
 #define l2n(l,c)        (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
@@ -151,7 +151,7 @@
 /* This is actually a big endian algorithm, the most significant byte
  * is used to lookup array 0 */
 
-#if defined(BF_PTR2)
+#if 0 /*defined(BF_PTR2)*/
 
 /*
  * This is basically a special Intel version. Point is that Intel
@@ -170,11 +170,8 @@
 	LL^=t \
 	)
 
-#elif defined(BF_PTR)
+#elif 0 /*defined(BF_PTR)*/
 
-#ifndef BF_LONG_LOG2
-#define BF_LONG_LOG2  2       /* default to BF_LONG being 32 bits */
-#endif
 #define BF_M  (0xFF<<BF_LONG_LOG2)
 #define BF_0  (24-BF_LONG_LOG2)
 #define BF_1  (16-BF_LONG_LOG2)
Index: crypto/bf/blowfish.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/bf/blowfish.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 blowfish.h
--- crypto/bf/blowfish.h	2000/07/16 05:05:14	1.1.1.2
+++ crypto/bf/blowfish.h	2000/09/02 05:52:17
@@ -77,21 +77,9 @@
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */
 
-#if defined(WIN16) || defined(__LP32__)
-#define BF_LONG unsigned long
-#elif defined(_CRAY) || defined(__ILP64__)
-#define BF_LONG unsigned long
-#define BF_LONG_LOG2 3
-/*
- * _CRAY note. I could declare short, but I have no idea what impact
- * does it have on performance on none-T3E machines. I could declare
- * int, but at least on C90 sizeof(int) can be chosen at compile time.
- * So I've chosen long...
- *					<appro@fy.chalmers.se>
- */
-#else
-#define BF_LONG unsigned int
-#endif
+#include <sys/types.h>
+#define	BF_LONG	u_int32_t
+#define	BF_LONG_LOG2	2
 
 #define BF_ROUNDS	16
 #define BF_BLOCK	8
Index: crypto/bn/bn.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/bn/bn.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 bn.h
--- crypto/bn/bn.h	2000/07/16 05:05:22	1.1.1.2
+++ crypto/bn/bn.h	2000/09/02 05:52:19
@@ -93,13 +93,15 @@
 #define BN_DIV2W
 #endif
 
+#include <sys/types.h>
+
 /* assuming long is 64bit - this is the DEC Alpha
  * unsigned long long is only 64 bits :-(, don't define
  * BN_LLONG for the DEC Alpha */
 #ifdef SIXTY_FOUR_BIT_LONG
-#define BN_ULLONG	unsigned long long
-#define BN_ULONG	unsigned long
-#define BN_LONG		long
+#define BN_ULLONG	u_int128_t
+#define BN_ULONG	u_int64_t
+#define BN_LONG		int64_t
 #define BN_BITS		128
 #define BN_BYTES	8
 #define BN_BITS2	64
@@ -111,8 +113,10 @@
 #define BN_MASK2h1	(0xffffffff80000000L)
 #define BN_TBIT		(0x8000000000000000L)
 #define BN_DEC_CONV	(10000000000000000000UL)
-#define BN_DEC_FMT1	"%lu"
-#define BN_DEC_FMT2	"%019lu"
+#define BN_DEC_FMT1	"%llu"
+#define BN_DEC_FMT2	"%019llu"
+#define BN_DEC_CAST1	(unsigned long long)
+#define BN_DEC_CAST2	(unsigned long long)
 #define BN_DEC_NUM	19
 #endif
 
@@ -124,8 +128,8 @@
 #ifdef SIXTY_FOUR_BIT
 #undef BN_LLONG
 #undef BN_ULLONG
-#define BN_ULONG	unsigned long long
-#define BN_LONG		long long
+#define BN_ULONG	u_int64_t
+#define BN_LONG		int64_t
 #define BN_BITS		128
 #define BN_BYTES	8
 #define BN_BITS2	64
@@ -138,39 +142,34 @@
 #define BN_DEC_CONV	(10000000000000000000LL)
 #define BN_DEC_FMT1	"%llu"
 #define BN_DEC_FMT2	"%019llu"
+#define BN_DEC_CAST1	(unsigned long long)
+#define BN_DEC_CAST2	(unsigned long long)
 #define BN_DEC_NUM	19
 #endif
 
 #ifdef THIRTY_TWO_BIT
-#if defined(WIN32) && !defined(__GNUC__)
-#define BN_ULLONG	unsigned _int64
-#else
-#define BN_ULLONG	unsigned long long
-#endif
-#define BN_ULONG	unsigned long
-#define BN_LONG		long
+#define BN_ULLONG	u_int64_t
+#define BN_ULONG	u_int32_t
+#define BN_LONG		int32_t
 #define BN_BITS		64
 #define BN_BYTES	4
 #define BN_BITS2	32
 #define BN_BITS4	16
-#ifdef WIN32
-/* VC++ doesn't like the LL suffix */
-#define BN_MASK		(0xffffffffffffffffL)
-#else
 #define BN_MASK		(0xffffffffffffffffLL)
-#endif
 #define BN_MASK2	(0xffffffffL)
 #define BN_MASK2l	(0xffff)
 #define BN_MASK2h1	(0xffff8000L)
 #define BN_MASK2h	(0xffff0000L)
 #define BN_TBIT		(0x80000000L)
 #define BN_DEC_CONV	(1000000000L)
-#define BN_DEC_FMT1	"%lu"
-#define BN_DEC_FMT2	"%09lu"
+#define BN_DEC_FMT1	"%llu"
+#define BN_DEC_FMT2	"%09llu"
+#define BN_DEC_CAST1	(unsigned long long)
+#define BN_DEC_CAST2	(unsigned long long)
 #define BN_DEC_NUM	9
 #endif
 
-#ifdef SIXTEEN_BIT
+#if 0 /*def SIXTEEN_BIT*/
 #ifndef BN_DIV2W
 #define BN_DIV2W
 #endif
@@ -193,7 +192,7 @@
 #define BN_DEC_NUM	5
 #endif
 
-#ifdef EIGHT_BIT
+#if 0 /*def EIGHT_BIT*/
 #ifndef BN_DIV2W
 #define BN_DIV2W
 #endif
Index: crypto/bn/bn_print.c
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/bn/bn_print.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 bn_print.c
--- crypto/bn/bn_print.c	2000/07/16 05:05:33	1.1.1.2
+++ crypto/bn/bn_print.c	2000/09/02 05:52:19
@@ -139,12 +139,12 @@
 		/* We now have a series of blocks, BN_DEC_NUM chars
 		 * in length, where the last one needs truncation.
 		 * The blocks need to be reversed in order. */
-		sprintf(p,BN_DEC_FMT1,*lp);
+		sprintf(p,BN_DEC_FMT1,BN_DEC_CAST1 *lp);
 		while (*p) p++;
 		while (lp != bn_data)
 			{
 			lp--;
-			sprintf(p,BN_DEC_FMT2,*lp);
+			sprintf(p,BN_DEC_FMT2,BN_DEC_CAST2 *lp);
 			while (*p) p++;
 			}
 		}
Index: crypto/des/des.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/des/des.h,v
retrieving revision 1.5
diff -u -r1.5 des.h
--- crypto/des/des.h	2000/07/16 09:50:33	1.5
+++ crypto/des/des.h	2000/09/02 05:52:21
@@ -71,8 +71,11 @@
 #error <openssl/des.h> replaces <kerberos/des.h>.
 #endif
 
+#include <sys/types.h>
+#define	DES_LONG	u_int32_t
+
 #include <stdio.h>
-#include <openssl/opensslconf.h> /* DES_LONG */
+#include <openssl/opensslconf.h> /* DES_LONG - overridden in above*/
 #include <openssl/e_os2.h>	/* OPENSSL_EXTERN */
 
 typedef unsigned char des_cblock[8];
Index: crypto/des/destest.c
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/des/destest.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 destest.c
--- crypto/des/destest.c	2000/07/16 05:06:09	1.1.1.2
+++ crypto/des/destest.c	2000/09/02 05:52:23
@@ -698,7 +698,7 @@
 	if (cs != cbc_cksum_ret)
 		{
 		printf("bad return value (%08lX), should be %08lX\n",
-			(unsigned long)cs,(unsigned long)cbc_cksum_ret);
+			(DES_LONG)cs,(DES_LONG)cbc_cksum_ret);
 		err=1;
 		}
 	if (memcmp(cret,cbc_cksum_data,8) != 0)
@@ -713,57 +713,57 @@
 	if (cs != 0x70d7a63aL)
 		{
 		printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
-			(unsigned long)cs);
+			(DES_LONG)cs);
 		err=1;
 		}
 #ifdef _CRAY
 	if (lqret[0].a != 0x327eba8dL)
 		{
 		printf("quad_cksum error, out[0] %08lx is not %08lx\n",
-			(unsigned long)lqret[0].a,0x327eba8dUL);
+			(DES_LONG)lqret[0].a,0x327eba8dUL);
 		err=1;
 		}
 	if (lqret[0].b != 0x201a49ccL)
 		{
 		printf("quad_cksum error, out[1] %08lx is not %08lx\n",
-			(unsigned long)lqret[0].b,0x201a49ccUL);
+			(DES_LONG)lqret[0].b,0x201a49ccUL);
 		err=1;
 		}
 	if (lqret[1].a != 0x70d7a63aL)
 		{
 		printf("quad_cksum error, out[2] %08lx is not %08lx\n",
-			(unsigned long)lqret[1].a,0x70d7a63aUL);
+			(DES_LONG)lqret[1].a,0x70d7a63aUL);
 		err=1;
 		}
 	if (lqret[1].b != 0x501c2c26L)
 		{
 		printf("quad_cksum error, out[3] %08lx is not %08lx\n",
-			(unsigned long)lqret[1].b,0x501c2c26UL);
+			(DES_LONG)lqret[1].b,0x501c2c26UL);
 		err=1;
 		}
 #else
 	if (lqret[0] != 0x327eba8dL)
 		{
 		printf("quad_cksum error, out[0] %08lx is not %08lx\n",
-			(unsigned long)lqret[0],0x327eba8dUL);
+			(DES_LONG)lqret[0],0x327eba8dUL);
 		err=1;
 		}
 	if (lqret[1] != 0x201a49ccL)
 		{
 		printf("quad_cksum error, out[1] %08lx is not %08lx\n",
-			(unsigned long)lqret[1],0x201a49ccUL);
+			(DES_LONG)lqret[1],0x201a49ccUL);
 		err=1;
 		}
 	if (lqret[2] != 0x70d7a63aL)
 		{
 		printf("quad_cksum error, out[2] %08lx is not %08lx\n",
-			(unsigned long)lqret[2],0x70d7a63aUL);
+			(DES_LONG)lqret[2],0x70d7a63aUL);
 		err=1;
 		}
 	if (lqret[3] != 0x501c2c26L)
 		{
 		printf("quad_cksum error, out[3] %08lx is not %08lx\n",
-			(unsigned long)lqret[3],0x501c2c26UL);
+			(DES_LONG)lqret[3],0x501c2c26UL);
 		err=1;
 		}
 #endif
Index: crypto/idea/i_cbc.c
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/idea/i_cbc.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 i_cbc.c
--- crypto/idea/i_cbc.c	2000/06/16 05:28:51	1.1.1.1
+++ crypto/idea/i_cbc.c	2000/09/02 05:52:23
@@ -62,10 +62,10 @@
 void idea_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
 	     IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int encrypt)
 	{
-	register unsigned long tin0,tin1;
-	register unsigned long tout0,tout1,xor0,xor1;
+	register u_int32_t tin0,tin1;
+	register u_int32_t tout0,tout1,xor0,xor1;
 	register long l=length;
-	unsigned long tin[2];
+	u_int32_t tin[2];
 
 	if (encrypt)
 		{
@@ -133,10 +133,10 @@
 	tin[0]=tin[1]=0;
 	}
 
-void idea_encrypt(unsigned long *d, IDEA_KEY_SCHEDULE *key)
+void idea_encrypt(u_int32_t *d, IDEA_KEY_SCHEDULE *key)
 	{
 	register IDEA_INT *p;
-	register unsigned long x1,x2,x3,x4,t0,t1,ul;
+	register u_int32_t x1,x2,x3,x4,t0,t1,ul;
 
 	x2=d[0];
 	x1=(x2>>16);
Index: crypto/idea/i_cfb64.c
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/idea/i_cfb64.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 i_cfb64.c
--- crypto/idea/i_cfb64.c	2000/06/16 05:28:51	1.1.1.1
+++ crypto/idea/i_cfb64.c	2000/09/02 05:52:24
@@ -68,10 +68,10 @@
 	     IDEA_KEY_SCHEDULE *schedule, unsigned char *ivec, int *num,
 	     int encrypt)
 	{
-	register unsigned long v0,v1,t;
+	register u_int32_t v0,v1,t;
 	register int n= *num;
 	register long l=length;
-	unsigned long ti[2];
+	u_int32_t ti[2];
 	unsigned char *iv,c,cc;
 
 	iv=(unsigned char *)ivec;
@@ -83,7 +83,7 @@
 				{
 				n2l(iv,v0); ti[0]=v0;
 				n2l(iv,v1); ti[1]=v1;
-				idea_encrypt((unsigned long *)ti,schedule);
+				idea_encrypt((u_int32_t *)ti,schedule);
 				iv=(unsigned char *)ivec;
 				t=ti[0]; l2n(t,iv);
 				t=ti[1]; l2n(t,iv);
@@ -103,7 +103,7 @@
 				{
 				n2l(iv,v0); ti[0]=v0;
 				n2l(iv,v1); ti[1]=v1;
-				idea_encrypt((unsigned long *)ti,schedule);
+				idea_encrypt((u_int32_t *)ti,schedule);
 				iv=(unsigned char *)ivec;
 				t=ti[0]; l2n(t,iv);
 				t=ti[1]; l2n(t,iv);
Index: crypto/idea/i_ecb.c
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/idea/i_ecb.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 i_ecb.c
--- crypto/idea/i_ecb.c	2000/06/16 05:28:51	1.1.1.1
+++ crypto/idea/i_ecb.c	2000/09/02 05:52:24
@@ -73,7 +73,7 @@
 void idea_ecb_encrypt(unsigned char *in, unsigned char *out,
 	     IDEA_KEY_SCHEDULE *ks)
 	{
-	unsigned long l0,l1,d[2];
+	u_int32_t l0,l1,d[2];
 
 	n2l(in,l0); d[0]=l0;
 	n2l(in,l1); d[1]=l1;
Index: crypto/idea/i_ofb64.c
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/idea/i_ofb64.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 i_ofb64.c
--- crypto/idea/i_ofb64.c	2000/06/16 05:28:51	1.1.1.1
+++ crypto/idea/i_ofb64.c	2000/09/02 05:52:24
@@ -66,12 +66,12 @@
 void idea_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
 	     IDEA_KEY_SCHEDULE *schedule, unsigned char *ivec, int *num)
 	{
-	register unsigned long v0,v1,t;
+	register u_int32_t v0,v1,t;
 	register int n= *num;
 	register long l=length;
 	unsigned char d[8];
 	register char *dp;
-	unsigned long ti[2];
+	u_int32_t ti[2];
 	unsigned char *iv;
 	int save=0;
 
@@ -87,7 +87,7 @@
 		{
 		if (n == 0)
 			{
-			idea_encrypt((unsigned long *)ti,schedule);
+			idea_encrypt((u_int32_t *)ti,schedule);
 			dp=(char *)d;
 			t=ti[0]; l2n(t,dp);
 			t=ti[1]; l2n(t,dp);
Index: crypto/idea/idea.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/idea/idea.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 idea.h
--- crypto/idea/idea.h	2000/06/16 05:28:51	1.1.1.1
+++ crypto/idea/idea.h	2000/09/02 05:52:24
@@ -67,6 +67,8 @@
 #error IDEA is disabled.
 #endif
 
+#include <sys/types.h>
+
 #define IDEA_ENCRYPT	1
 #define IDEA_DECRYPT	0
 
@@ -91,7 +93,7 @@
 	int *num,int enc);
 void idea_ofb64_encrypt(unsigned char *in, unsigned char *out,
 	long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num);
-void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks);
+void idea_encrypt(u_int32_t *in, IDEA_KEY_SCHEDULE *ks);
 #ifdef  __cplusplus
 }
 #endif
Index: crypto/idea/idea_lcl.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/idea/idea_lcl.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 idea_lcl.h
--- crypto/idea/idea_lcl.h	2000/07/16 05:06:49	1.1.1.2
+++ crypto/idea/idea_lcl.h	2000/09/02 05:52:25
@@ -60,7 +60,7 @@
  * Colin Plumb <colin@nyx10.cs.du.edu> */
 /* Removal of the inner if from from Wei Dai 24/4/96 */
 #define idea_mul(r,a,b,ul) \
-ul=(unsigned long)a*b; \
+ul=(u_int32_t)a*b; \
 if (ul != 0) \
 	{ \
 	r=(ul&0xffff)-(ul>>16); \
@@ -74,7 +74,7 @@
 if (a == 0) r=(0x10001-b)&0xffff; \
 else if (b == 0) r=(0x10001-a)&0xffff; \
 else	{ \
-	ul=(unsigned long)a*b; \
+	ul=(u_int32_t)a*b; \
 	sl=(ul&0xffff)-(ul>>16); \
 	if (sl <= 0) sl+=0x10001; \
 	r=sl; \
@@ -96,14 +96,14 @@
 			c+=n; \
 			l1=l2=0; \
 			switch (n) { \
-			case 8: l2 =((unsigned long)(*(--(c))))    ; \
-			case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
-			case 6: l2|=((unsigned long)(*(--(c))))<<16; \
-			case 5: l2|=((unsigned long)(*(--(c))))<<24; \
-			case 4: l1 =((unsigned long)(*(--(c))))    ; \
-			case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
-			case 2: l1|=((unsigned long)(*(--(c))))<<16; \
-			case 1: l1|=((unsigned long)(*(--(c))))<<24; \
+			case 8: l2 =((u_int32_t)(*(--(c))))    ; \
+			case 7: l2|=((u_int32_t)(*(--(c))))<< 8; \
+			case 6: l2|=((u_int32_t)(*(--(c))))<<16; \
+			case 5: l2|=((u_int32_t)(*(--(c))))<<24; \
+			case 4: l1 =((u_int32_t)(*(--(c))))    ; \
+			case 3: l1|=((u_int32_t)(*(--(c))))<< 8; \
+			case 2: l1|=((u_int32_t)(*(--(c))))<<16; \
+			case 1: l1|=((u_int32_t)(*(--(c))))<<24; \
 				} \
 			}
 
@@ -123,10 +123,10 @@
 			}
 
 #undef n2l
-#define n2l(c,l)        (l =((unsigned long)(*((c)++)))<<24L, \
-                         l|=((unsigned long)(*((c)++)))<<16L, \
-                         l|=((unsigned long)(*((c)++)))<< 8L, \
-                         l|=((unsigned long)(*((c)++))))
+#define n2l(c,l)        (l =((u_int32_t)(*((c)++)))<<24L, \
+                         l|=((u_int32_t)(*((c)++)))<<16L, \
+                         l|=((u_int32_t)(*((c)++)))<< 8L, \
+                         l|=((u_int32_t)(*((c)++))))
 
 #undef l2n
 #define l2n(l,c)        (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
@@ -148,14 +148,14 @@
 			c+=n; \
 			l1=l2=0; \
 			switch (n) { \
-			case 8: l2 =((unsigned long)(*(--(c))))<<24; \
-			case 7: l2|=((unsigned long)(*(--(c))))<<16; \
-			case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
-			case 5: l2|=((unsigned long)(*(--(c))));     \
-			case 4: l1 =((unsigned long)(*(--(c))))<<24; \
-			case 3: l1|=((unsigned long)(*(--(c))))<<16; \
-			case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
-			case 1: l1|=((unsigned long)(*(--(c))));     \
+			case 8: l2 =((u_int32_t)(*(--(c))))<<24; \
+			case 7: l2|=((u_int32_t)(*(--(c))))<<16; \
+			case 6: l2|=((u_int32_t)(*(--(c))))<< 8; \
+			case 5: l2|=((u_int32_t)(*(--(c))));     \
+			case 4: l1 =((u_int32_t)(*(--(c))))<<24; \
+			case 3: l1|=((u_int32_t)(*(--(c))))<<16; \
+			case 2: l1|=((u_int32_t)(*(--(c))))<< 8; \
+			case 1: l1|=((u_int32_t)(*(--(c))));     \
 				} \
 			}
 
@@ -175,18 +175,18 @@
 			}
 
 #undef c2s
-#define c2s(c,l)	(l =((unsigned long)(*((c)++)))    , \
-			 l|=((unsigned long)(*((c)++)))<< 8L)
+#define c2s(c,l)	(l =((u_int32_t)(*((c)++)))    , \
+			 l|=((u_int32_t)(*((c)++)))<< 8L)
 
 #undef s2c
 #define s2c(l,c)	(*((c)++)=(unsigned char)(((l)     )&0xff), \
 			 *((c)++)=(unsigned char)(((l)>> 8L)&0xff))
 
 #undef c2l
-#define c2l(c,l)	(l =((unsigned long)(*((c)++)))     , \
-			 l|=((unsigned long)(*((c)++)))<< 8L, \
-			 l|=((unsigned long)(*((c)++)))<<16L, \
-			 l|=((unsigned long)(*((c)++)))<<24L)
+#define c2l(c,l)	(l =((u_int32_t)(*((c)++)))     , \
+			 l|=((u_int32_t)(*((c)++)))<< 8L, \
+			 l|=((u_int32_t)(*((c)++)))<<16L, \
+			 l|=((u_int32_t)(*((c)++)))<<24L)
 
 #undef l2c
 #define l2c(l,c)	(*((c)++)=(unsigned char)(((l)     )&0xff), \
Index: crypto/idea/idea_spd.c
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/idea/idea_spd.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 idea_spd.c
--- crypto/idea/idea_spd.c	2000/07/16 05:06:49	1.1.1.2
+++ crypto/idea/idea_spd.c	2000/09/02 05:52:25
@@ -256,7 +256,7 @@
 	Time_F(START);
 	for (count=0,run=1; COND(cb); count+=4)
 		{
-		unsigned long data[2];
+		u_int32_t data[2];
 
 		idea_encrypt(data,&sch);
 		idea_encrypt(data,&sch);
Index: crypto/md5/md5.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/md5/md5.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 md5.h
--- crypto/md5/md5.h	2000/07/16 05:06:55	1.1.1.2
+++ crypto/md5/md5.h	2000/09/02 05:52:25
@@ -74,21 +74,9 @@
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */
 
-#if defined(WIN16) || defined(__LP32__)
-#define MD5_LONG unsigned long
-#elif defined(_CRAY) || defined(__ILP64__)
-#define MD5_LONG unsigned long
-#define MD5_LONG_LOG2 3
-/*
- * _CRAY note. I could declare short, but I have no idea what impact
- * does it have on performance on none-T3E machines. I could declare
- * int, but at least on C90 sizeof(int) can be chosen at compile time.
- * So I've chosen long...
- *					<appro@fy.chalmers.se>
- */
-#else
-#define MD5_LONG unsigned int
-#endif
+#include <sys/types.h>
+#define	MD5_LONG	u_int32_t
+#define	MD5_LONG_LOG2	2
 
 #define MD5_CBLOCK	64
 #define MD5_LBLOCK	(MD5_CBLOCK/4)
Index: crypto/md5/md5_locl.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/md5/md5_locl.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 md5_locl.h
--- crypto/md5/md5_locl.h	2000/07/16 05:06:56	1.1.1.2
+++ crypto/md5/md5_locl.h	2000/09/02 05:52:26
@@ -61,10 +61,6 @@
 #include <openssl/opensslconf.h>
 #include <openssl/md5.h>
 
-#ifndef MD5_LONG_LOG2
-#define MD5_LONG_LOG2 2 /* default to 32 bits */
-#endif
-
 #ifdef MD5_ASM
 # if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
 #  define md5_block_host_order md5_block_asm_host_order
Index: crypto/sha/sha.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/sha/sha.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 sha.h
--- crypto/sha/sha.h	2000/07/16 05:08:06	1.1.1.2
+++ crypto/sha/sha.h	2000/09/02 05:52:26
@@ -74,14 +74,9 @@
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */
 
-#if defined(WIN16) || defined(__LP32__)
-#define SHA_LONG unsigned long
-#elif defined(_CRAY) || defined(__ILP64__)
-#define SHA_LONG unsigned long
-#define SHA_LONG_LOG2 3
-#else
-#define SHA_LONG unsigned int
-#endif
+#include <sys/types.h>
+#define SHA_LONG	u_int32_t
+#define	SHA_LONG_LOG2	2
 
 #define SHA_LBLOCK	16
 #define SHA_CBLOCK	(SHA_LBLOCK*4)	/* SHA treats input data as a
Index: crypto/sha/sha_locl.h
===================================================================
RCS file: /cvsroot/basesrc/crypto/dist/openssl/crypto/sha/sha_locl.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 sha_locl.h
--- crypto/sha/sha_locl.h	2000/07/16 05:08:10	1.1.1.2
+++ crypto/sha/sha_locl.h	2000/09/02 05:52:27
@@ -74,7 +74,7 @@
 #define HASH_CBLOCK             SHA_CBLOCK
 #define HASH_LBLOCK             SHA_LBLOCK
 #define HASH_MAKE_STRING(c,s)   do {	\
-	unsigned long ll;		\
+	SHA_LONG ll;		\
 	ll=(c)->h0; HOST_l2c(ll,(s));	\
 	ll=(c)->h1; HOST_l2c(ll,(s));	\
 	ll=(c)->h2; HOST_l2c(ll,(s));	\
@@ -223,9 +223,9 @@
 void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num)
 	{
 	const SHA_LONG *W=d;
-	register unsigned long A,B,C,D,E,T;
+	register SHA_LONG A,B,C,D,E,T;
 #ifndef MD32_XARRAY
-	unsigned long	XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
+	SHA_LONG	XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
 			XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
 #else
 	SHA_LONG	XX[16];
@@ -348,9 +348,9 @@
 void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num)
 	{
 	const unsigned char *data=p;
-	register unsigned long A,B,C,D,E,T,l;
+	register SHA_LONG A,B,C,D,E,T,l;
 #ifndef MD32_XARRAY
-	unsigned long	XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
+	SHA_LONG	XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
 			XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
 #else
 	SHA_LONG	XX[16];