tags 343524 +patch
thanks

The reason otp does not work on amd64 (and presumably other 64-bit
architectures) is that it assumes a long is 32 bits.  The attached patch
replaces all uses of (unsigned) long with (u)int32 and typedefs (u)int32 to
be (unsigned) int on 32 bit architectures, (unsigned) long otherwise.

This should perhaps be done by using a configure script or some other means
which does not require the list of 64-bit architectures to be hardcoded -
I'm not even 100% confident I've got it right as I don't know a lot about
these things.

-- 
Martin Orr

diff -Naru2 otp-970425.orig/md5.h otp-970425/md5.h
--- otp-970425.orig/md5.h       1996-02-08 18:46:21.000000000 +0000
+++ otp-970425/md5.h    2005-12-16 16:24:56.000000000 +0000
@@ -2,8 +2,10 @@
 #define MD5_H
 
-#ifdef __alpha
+#if defined(__alpha) || defined(__amd64) || defined(__ia64) || defined(__hppa) 
|| defined(__powerpc64__)
 typedef unsigned int uint32;
+typedef int int32;
 #else
 typedef unsigned long uint32;
+typedef long int32;
 #endif
 
diff -Naru2 otp-970425.orig/otp.c otp-970425/otp.c
--- otp-970425.orig/otp.c       1997-05-25 13:34:38.000000000 +0100
+++ otp-970425/otp.c    2005-12-16 16:24:30.000000000 +0000
@@ -153,8 +153,8 @@
                 produce a random value based on a 16 byte seed.  */
 
-static long mrandom()
+static int32 mrandom()
 {
     int i;
-    long r = 0;
+    int32 r = 0;
 
     for (i = 0; i < 4; i++) {
@@ -176,8 +176,8 @@
        pw_length = PW_LENGTH, pw_item, linelen = 79,
        npline, lineno, nch;
-    long rseed;
+    int32 rseed;
     char *password, *pwp, *v, *seed = NULL;
     FILE *ofile = stdout, *sigfile = NULL;
-    unsigned long trash[100];
+    uint32 trash[100];
     struct MD5Context md5c;
     unsigned char digest[16];
@@ -308,8 +308,8 @@
        ri.h.dl = 0;            /* Default drive */
        if (_intdos(&ri, &ro) != 0xFFFF) {
-           trash[1] = (((long) ro.x.ax) << 16) | ro.x.bx;
-           trash[2] = (((long) ro.x.cx) << 16) | ro.x.dx; 
+           trash[1] = (((int32) ro.x.ax) << 16) | ro.x.bx;
+           trash[2] = (((int32) ro.x.cx) << 16) | ro.x.dx; 
        }
-       trash[4] = (long) (char __far *) trash; 
+       trash[4] = (int32) (char __far *) trash; 
 #define OS_KNOWN 1
 #endif
@@ -336,7 +336,7 @@
     MD5Final(digest, &md5c);
     for (j = 0; j < 4; j++) {
-       rseed = (((long) digest[0 + (4 * j)]) << 24) |
-                (((long) digest[1 + (4 * j)]) << 16) |
-                (((long) digest[2 + (4 * j)]) << 8) | digest[3 + (4 * j)];
+       rseed = (((int32) digest[0 + (4 * j)]) << 24) |
+                (((int32) digest[1 + (4 * j)]) << 16) |
+                (((int32) digest[2 + (4 * j)]) << 8) | digest[3 + (4 * j)];
        initstate(rseed, rvec[j], RandVecL);
 #ifdef DEBUG
diff -Naru2 otp-970425.orig/random.c otp-970425/random.c
--- otp-970425.orig/random.c    1996-04-01 18:02:48.000000000 +0100
+++ otp-970425/random.c 2005-12-16 16:25:10.000000000 +0000
@@ -48,8 +48,8 @@
  * 32 bytes, a simple linear congruential R.N.G. is used.
  *
- * Internally, the state information is treated as an array of longs; the
+ * Internally, the state information is treated as an array of int32s; the
  * zeroeth element of the array is the type of R.N.G. being used (small
  * integer); the remainder of the array is the state information for the
- * R.N.G.  Thus, 32 bytes of state information will give 7 longs worth of
+ * R.N.G.  Thus, 32 bytes of state information will give 7 int32s worth of
  * state information, which will allow a degree seven polynomial.  (Note:
  * the zeroeth word of state information also has some other information
@@ -62,5 +62,5 @@
  * have period 2^deg - 1 (where deg is the degree of the polynomial being
  * used, assuming that the polynomial is irreducible and primitive).  The
- * higher order bits will have longer periods, since their values are also
+ * higher order bits will have int32er periods, since their values are also
  * influenced by pseudo-random carries out of the lower bits.  The total
  * period of the generator is approximately deg*(2**deg - 1); thus doubling
@@ -68,5 +68,5 @@
  * generator.  Note: the deg*(2**deg - 1) is an approximation only good for
  * large deg, when the period of the shift register is the dominant factor.
- * With deg equal to seven, the period is actually much longer than the
+ * With deg equal to seven, the period is actually much int32er than the
  * 7*(2**7 - 1) predicted by this formula.
  */
@@ -113,4 +113,13 @@
 static int seps [MAX_TYPES] =  { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
 
+/* Define int32 and uint32 to signed and unsigned 32 bit types */
+#if defined(__alpha) || defined(__amd64) || defined(__ia64) || defined(__hppa) 
|| defined(__powerpc64__)
+typedef unsigned int uint32;
+typedef int int32;
+#else
+typedef unsigned long uint32;
+typedef long int32;
+#endif
+
 /*
  * Initially, everything is set up as if from:
@@ -127,5 +136,5 @@
  */
 
-static long randtbl[DEG_3 + 1] = {
+static int32 randtbl[DEG_3 + 1] = {
        TYPE_3,
        0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5,
@@ -151,6 +160,6 @@
  * to point to randtbl[1] (as explained below).
  */
-static long *fptr = &randtbl[SEP_3 + 1];
-static long *rptr = &randtbl[1];
+static int32 *fptr = &randtbl[SEP_3 + 1];
+static int32 *rptr = &randtbl[1];
 
 /*
@@ -164,9 +173,9 @@
  * the last element to see if the front and rear pointers have wrapped.
  */
-static long *state = &randtbl[1];
+static int32 *state = &randtbl[1];
 static int rand_type = TYPE_3;
 static int rand_deg = DEG_3;
 static int rand_sep = SEP_3;
-static long *end_ptr = &randtbl[DEG_3 + 1];
+static int32 *end_ptr = &randtbl[DEG_3 + 1];
 
 /*
@@ -183,7 +192,7 @@
  */
  
-#define u_int  unsigned long
+#define u_int  uint32
 
-extern long random(); 
+extern int32 random(); 
  
 void
@@ -191,5 +200,5 @@
   u_int x;
 {
-       register long i, j;
+       register int32 i, j;
 
 #ifdef NEEDED
@@ -270,5 +279,5 @@
                rand_sep = SEP_4;
        }
-       state = &(((long *)arg_state)[1]);      /* first location */
+       state = &(((int32 *)arg_state)[1]);     /* first location */
        end_ptr = &state[rand_deg];     /* must set end_ptr before srandom */
        srandom(seed);
@@ -299,5 +308,5 @@
        char *arg_state;
 {
-       register long *new_state = (long *)arg_state;
+       register int32 *new_state = (int32 *)arg_state;
        register int type = new_state[0] % MAX_TYPES;
        register int rear = new_state[0] / MAX_TYPES;
@@ -352,8 +361,8 @@
  * Returns a 31-bit random number.
  */
-long
+int32
 random()
 {
-       long i;
+       int32 i;
 
 #ifdef NEEDED

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to