-----BEGIN PGP SIGNED MESSAGE-----
These are some patches which I put together to make PGP 2.6 work on Alpha's
running OSF/1 v2.0. I do not use PGP much, so I doubt I've found
all the bugs. Furthermore, some of the defects corrected are definitely
NOT the best way. I do NOT recommend using these patches in place
of the latest and greatest version from MIT unless that version
turns out not to work.
My patches assume you use the RSAREF routines, as they were
the easiest to adapt to 64 bit work.
You'll want to do is place a link to lmul.h in the
rsaref directory.
Some patches affect the RSAREF routines themselves. . .
-Castor Fu
[email protected]
Note: As these patches are pretty clearly useless without MIT PGP I
don't consider them to be cryptographic in nature. These patches
have been sent to
[email protected] in accordance with the PGP license agreement.
diff -c -r ./pgp26/src/keyadd.c ../pgp26/pgp26/src/keyadd.c
*** ./pgp26/src/keyadd.c Sat May 21 09:49:21 1994
- --- ../pgp26/pgp26/src/keyadd.c Thu Aug 11 15:02:14 1994
***************
*** 95,101 ****
int copying;
word32 rstamp, kstamp, xstamp;
byte keyID[KEYFRAGSIZE];
! char userid[256];
/* First, copy the userid packet itself, plus any comments or ctrls */
ringuseridpos = ringpos = *pringpos;
- --- 95,101 ----
int copying;
word32 rstamp, kstamp, xstamp;
byte keyID[KEYFRAGSIZE];
! byte userid[256];
/* First, copy the userid packet itself, plus any comments or ctrls */
ringuseridpos = ringpos = *pringpos;
***************
*** 175,181 ****
} else {
long save_keypos;
long save_ringpos;
! long KeyIDpos, KeyIDlen;
byte sigClass;
fprintf(pgpout, LANG("Verifying signature from %s\n"), LOCAL_CHARSET(signator));
fprintf(pgpout, LANG("on userid \"%s\"\n"), LOCAL_CHARSET(userid));
- --- 175,182 ----
} else {
long save_keypos;
long save_ringpos;
! long KeyIDpos;
! int KeyIDlen;
byte sigClass;
fprintf(pgpout, LANG("Verifying signature from %s\n"), LOCAL_CHARSET(signator));
fprintf(pgpout, LANG("on userid \"%s\"\n"), LOCAL_CHARSET(userid));
diff -c -r ./pgp26/src/lmul.h ../pgp26/pgp26/src/lmul.h
*** ./pgp26/src/lmul.h Sat May 07 12:14:58 1994
- --- ../pgp26/pgp26/src/lmul.h Thu Aug 11 15:53:12 1994
***************
*** 13,39 ****
*
* lmul(i1,i2,ol,oh) takes the product of i1, i2 and yields ol, oh
* the lower and upper halves of the result.
*/
#ifdef PATCH_ASM
#define lmul(i1,i2,ol, oh) (ol=(i1)*(i2), oh=(i1)^(i2))
! #else
! #if defined(__GNUC__) && defined(mips) && defined(MUNIT32)
#define lmul(a,b,xl,xh) \
{ \
asm("multu %2, %3\n\tmflo %0\n\tmfhi %1" : \
"=d" (xl) , "=d" (xh) : "d" (a), "d" (b)); \
}
! #else
! #if defined(__GNUC__) && defined(mc68020) && defined(MUNIT32)
#define lmul(a,b,xl,xh) \
{\
xl = a; \
asm("mulul %3, %1:%0" : "=d" (xl) , "=d" (xh) : "0" (xl) , "d" (b)); \
}
! #else
! #if defined(__GNUC__) && defined(i386) && defined(MUNIT32)
#define lmul(a,b,xl,xh) asm("mull %3":"=a" (xl),"=d" (xh):"0" (a),"g" (b))
#else
- --- 13,71 ----
*
* lmul(i1,i2,ol,oh) takes the product of i1, i2 and yields ol, oh
* the lower and upper halves of the result.
+ *
*/
#ifdef PATCH_ASM
#define lmul(i1,i2,ol, oh) (ol=(i1)*(i2), oh=(i1)^(i2))
! #elif defined(__alpha) && !defined(__GNUC__)
! /*
! *
! * DEC asm mechanism. No external docs apparently exist. (#pragma inline
! * is documented in cc(1).
! *
! * However, the format seems pretty clear. . .
! *
! * asm(char *asmstr, ...) allows one to implement an assembly language
! * procedure as asmstr, and arguments may be passed in the usual way.
! * The compiler proceeds with the usual register conventions, i.e.:
! * $0 return value
! * $1-$8, $22-$25 scratch these registers are freely available.
! * $9-$13 saved registers must be saved before being manipulated.
! * $15 FP
! * $16-$21 arguments
! * $26 RA $27 PV
! * $28 volatile scratch $29 GP
! * $30 SP $31 0/sink reg.
! *
! * Note that the optimizer probably is stupid about asm, so be careful.
! */
!
!
! extern unsigned long asm(char *,...);
! #pragma intrinsic(asm)
! #define umulh(i1,i2) asm("umulh $16, $17, $0", i1, i2)
!
! #define lmul(a,b,xl,xh) \
! {\
! xl = a*b;\
! xh = umulh(a,b);\
! }
!
! #elif defined(__GNUC__) && defined(mips) && defined(MUNIT32)
#define lmul(a,b,xl,xh) \
{ \
asm("multu %2, %3\n\tmflo %0\n\tmfhi %1" : \
"=d" (xl) , "=d" (xh) : "d" (a), "d" (b)); \
}
! #elif defined(__GNUC__) && defined(mc68020) && defined(MUNIT32)
#define lmul(a,b,xl,xh) \
{\
xl = a; \
asm("mulul %3, %1:%0" : "=d" (xl) , "=d" (xh) : "0" (xl) , "d" (b)); \
}
! #elif defined(__GNUC__) && defined(i386) && defined(MUNIT32)
#define lmul(a,b,xl,xh) asm("mull %3":"=a" (xl),"=d" (xh):"0" (a),"g" (b))
#else
***************
*** 66,73 ****
xl = Xx6; \
xh = Xx4; \
}
! #endif
! #endif
! #endif
! #endif
#endif /* PATCH_ASM */
- --- 98,102 ----
xl = Xx6; \
xh = Xx4; \
}
! #endif /* MUNIT16 */
#endif /* PATCH_ASM */
diff -c -r ./pgp26/src/makefile ../pgp26/pgp26/src/makefile
*** ./pgp26/src/makefile Tue May 24 09:00:25 1994
- --- ../pgp26/pgp26/src/makefile Thu Aug 11 15:41:30 1994
***************
*** 93,99 ****
all: $(PROJ)
# If you want to use MPILIB, uncomment this line:
! USEMPILIB = -DUSEMPILIB
# For an RSAREF version, uncomment the following lines
RSADIR = ../../rsaref
- --- 93,99 ----
all: $(PROJ)
# If you want to use MPILIB, uncomment this line:
! #USEMPILIB = -DUSEMPILIB
# For an RSAREF version, uncomment the following lines
RSADIR = ../../rsaref
***************
*** 388,395 ****
# The Open Software Foundation's OSF/1
osf:
! $(MAKE) all \
! CFLAGS="$(RSAINCDIR) -O -I. -D_BSD -DUNIX -DNOTERMIO -DPORTABLE $(BYTEORDER)"
# A/UX 3.0 using unproto (mine is invoked as a cpp using the CFLAGS shown
# I placed the cpp in a subdirectory of /src/pgp called unproto
- --- 388,395 ----
# The Open Software Foundation's OSF/1
osf:
! $(MAKE) all CC="c89" LD="3rd c89"\
! CFLAGS="$(RSAINCDIR) -g -I. -D_BSD -DUNIX -DNOTERMIO -DPORTABLE $(BYTEORDER)"
# A/UX 3.0 using unproto (mine is invoked as a cpp using the CFLAGS shown
# I placed the cpp in a subdirectory of /src/pgp called unproto
diff -c -r ./pgp26/src/md5.h ../pgp26/pgp26/src/md5.h
*** ./pgp26/src/md5.h Sat May 07 12:14:58 1994
- --- ../pgp26/pgp26/src/md5.h Thu Aug 11 15:35:02 1994
***************
*** 1,7 ****
- --- 1,14 ----
#ifndef MD5_H
#define MD5_H
+ #include <limits.h>
+
+ #if (ULONG_MAX <= (1UL << 31))
typedef unsigned long uint32;
+ #else
+ typedef unsigned int uint32;
+ #endif
+
struct MD5Context {
uint32 buf[4];
diff -c -r ./pgp26/src/system.c ../pgp26/pgp26/src/system.c
*** ./pgp26/src/system.c Mon May 09 08:17:11 1994
- --- ../pgp26/pgp26/src/system.c Tue Jun 21 19:29:07 1994
***************
*** 330,336 ****
}
#endif /* _BSD */
! #if (defined(MACH) || defined(SVR2) || defined(_BSD)) && !defined(NEXT) && !defined(AUX) || (defined(sun) && defined(i386))
int remove(name)
char *name;
{
- --- 330,337 ----
}
#endif /* _BSD */
! /* This is an ANSI C defined function! */
! #if !defined(__STDC__) && ((defined(MACH) || defined(SVR2) || defined(_BSD)) && !defined(NEXT) && !defined(AUX) || (defined(sun) && defined(i386)))
int remove(name)
char *name;
{
diff -c -r ./pgp26/src/usuals.h ../pgp26/pgp26/src/usuals.h
*** ./pgp26/src/usuals.h Sat May 07 12:15:00 1994
- --- ../pgp26/pgp26/src/usuals.h Thu Aug 11 14:49:33 1994
***************
*** 1,5 ****
- --- 1,7 ----
/* usuals.h - The usual typedefs, etc.
*/
+
+ #include <limits.h> /* for ULONG_MAX */
#ifndef USUALS /* Assures no redefinitions of usual types...*/
#define USUALS
***************
*** 8,14 ****
typedef byte *byteptr; /* pointer to byte */
typedef char *string; /* pointer to ASCII character string */
typedef unsigned short word16; /* values are 0-65535 */
! #ifdef __alpha
typedef unsigned int word32; /* values are 0-4294967295 */
#else
typedef unsigned long word32; /* values are 0-4294967295 */
- --- 10,17 ----
typedef byte *byteptr; /* pointer to byte */
typedef char *string; /* pointer to ASCII character string */
typedef unsigned short word16; /* values are 0-65535 */
!
! #if (ULONG_MAX > (1UL << 31) )
typedef unsigned int word32; /* values are 0-4294967295 */
#else
typedef unsigned long word32; /* values are 0-4294967295 */
diff -c -r ./rsaref/install/unix/global.h ../pgp26/rsaref/install/unix/global.h
*** ./rsaref/install/unix/global.h Sat Feb 29 09:13:47 1992
- --- ../pgp26/rsaref/install/unix/global.h Tue Jun 21 18:45:06 1994
***************
*** 21,27 ****
typedef unsigned short int UINT2;
/* UINT4 defines a four byte word */
! typedef unsigned long int UINT4;
/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
- --- 21,31 ----
typedef unsigned short int UINT2;
/* UINT4 defines a four byte word */
! typedef unsigned int UINT4;
!
! #ifdef __alpha
! typedef unsigned long int UINT8;
! #endif
/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
diff -c -r ./rsaref/install/unix/makefile ../pgp26/rsaref/install/unix/makefile
*** ./rsaref/install/unix/makefile Mon May 23 12:32:04 1994
- --- ../pgp26/rsaref/install/unix/makefile Wed Aug 10 10:50:52 1994
***************
*** 17,23 ****
O = o
# commands
! CC = gcc
RANLIB = ranlib
LIB = ar
ASM = masm
- --- 17,23 ----
O = o
# commands
! CC = c89
RANLIB = ranlib
LIB = ar
ASM = masm
***************
*** 35,41 ****
PROG = rdemo
# Normal GCC flags.
! CFLAGS = $(INCL) -O -c -DPROTOTYPES=1 -DUSEMPILIB
MFLAGS = -I. -I$(SRCDIR)
# The location of the common source directory.
- --- 35,41 ----
PROG = rdemo
# Normal GCC flags.
! CFLAGS = $(INCL) -O -c -DPROTOTYPES=1 # -DUSEMPILIB
MFLAGS = -I. -I$(SRCDIR)
# The location of the common source directory.
diff -c -r ./rsaref/source/nn.c ../pgp26/rsaref/source/nn.c
*** ./rsaref/source/nn.c Sun May 22 14:01:23 1994
- --- ../pgp26/rsaref/source/nn.c Wed Aug 10 10:30:50 1994
***************
*** 23,28 ****
- --- 23,30 ----
#include "nn.h"
#include "digit.h"
+ #include "lmul.h"
+
static NN_DIGIT NN_LShift PROTO_LIST
((NN_DIGIT *, NN_DIGIT *, unsigned int, unsigned int));
static NN_DIGIT NN_RShift PROTO_LIST
***************
*** 593,599 ****
NN_DIGIT *a, *b, c, *d;
unsigned int digits;
{
! NN_DIGIT carry, t[2];
unsigned int i;
if (c == 0)
- --- 595,606 ----
NN_DIGIT *a, *b, c, *d;
unsigned int digits;
{
! NN_DIGIT carry;
! #ifdef lmul
! NN_DIGIT t0, t1;
! #else
! NN_DIGIT t[2];
! #endif
unsigned int i;
if (c == 0)
***************
*** 601,606 ****
- --- 608,614 ----
carry = 0;
for (i = 0; i < digits; i++) {
+ #ifndef lmul
NN_DigitMult (t, c, d[i]);
if ((a[i] = b[i] + carry) < carry)
carry = 1;
***************
*** 609,614 ****
- --- 617,633 ----
if ((a[i] += t[0]) < t[0])
carry++;
carry += t[1];
+
+ #else
+ lmul(c, d[i], t0, t1);
+ if ((a[i] = b[i] + carry) < carry)
+ carry = 1;
+ else
+ carry = 0;
+ if ((a[i] += t0) < t0)
+ carry++;
+ carry += t1;
+ #endif
}
return (carry);
***************
*** 622,628 ****
NN_DIGIT *a, *b, c, *d;
unsigned int digits;
{
! NN_DIGIT borrow, t[2];
unsigned int i;
if (c == 0)
- --- 641,652 ----
NN_DIGIT *a, *b, c, *d;
unsigned int digits;
{
! NN_DIGIT borrow,
! #ifndef lmul
! t[2];
! #else
! t0, t1;
! #endif
unsigned int i;
if (c == 0)
***************
*** 630,635 ****
- --- 654,660 ----
borrow = 0;
for (i = 0; i < digits; i++) {
+ #ifndef lmul
NN_DigitMult (t, c, d[i]);
if ((a[i] = b[i] - borrow) > (MAX_NN_DIGIT - borrow))
borrow = 1;
***************
*** 638,643 ****
- --- 663,678 ----
if ((a[i] -= t[0]) > (MAX_NN_DIGIT - t[0]))
borrow++;
borrow += t[1];
+ #else
+ lmul(c, d[i], t0, t1);
+ if ((a[i] = b[i] - borrow) > (MAX_NN_DIGIT - borrow))
+ borrow = 1;
+ else
+ borrow = 0;
+ if ((a[i] -= t0) > (MAX_NN_DIGIT - t0))
+ borrow++;
+ borrow += t1;
+ #endif
}
return (borrow);
diff -c -r ./rsaref/source/nn.h ../pgp26/rsaref/source/nn.h
*** ./rsaref/source/nn.h Sat Feb 29 09:13:09 1992
- --- ../pgp26/rsaref/source/nn.h Wed Aug 10 10:12:06 1994
***************
*** 7,15 ****
- --- 7,29 ----
/* Type definitions.
*/
+ #if !defined( __alpha)
+
typedef UINT4 NN_DIGIT;
typedef UINT2 NN_HALF_DIGIT;
+ /* Length of digit in bits */
+ #define NN_DIGIT_BITS 32
+ #else
+
+ typedef UINT8 NN_DIGIT;
+ typedef UINT4 NN_HALF_DIGIT;
+ #define NN_DIGIT_BITS 64
+
+ #endif
+
+ #define NN_HALF_DIGIT_BITS (NN_DIGIT_BITS/2)
+
/* Constants.
Note: MAX_NN_DIGITS is long enough to hold any RSA modulus, plus
***************
*** 18,34 ****
MAX_NN_DIGITS digits, except for double-length intermediate values
in NN_Mult (t), NN_ModMult (t), NN_ModInv (w), and NN_Div (c).
*/
- - /* Length of digit in bits */
- - #define NN_DIGIT_BITS 32
- - #define NN_HALF_DIGIT_BITS 16
/* Length of digit in bytes */
#define NN_DIGIT_LEN (NN_DIGIT_BITS / 8)
/* Maximum length in digits */
#define MAX_NN_DIGITS \
((MAX_RSA_MODULUS_LEN + NN_DIGIT_LEN - 1) / NN_DIGIT_LEN + 1)
/* Maximum digits */
! #define MAX_NN_DIGIT 0xffffffff
! #define MAX_NN_HALF_DIGIT 0xffff
/* Macros.
*/
- --- 32,46 ----
MAX_NN_DIGITS digits, except for double-length intermediate values
in NN_Mult (t), NN_ModMult (t), NN_ModInv (w), and NN_Div (c).
*/
/* Length of digit in bytes */
#define NN_DIGIT_LEN (NN_DIGIT_BITS / 8)
/* Maximum length in digits */
#define MAX_NN_DIGITS \
((MAX_RSA_MODULUS_LEN + NN_DIGIT_LEN - 1) / NN_DIGIT_LEN + 1)
+
/* Maximum digits */
! #define MAX_NN_HALF_DIGIT ((1L << NN_HALF_DIGIT_BITS)-1)
! #define MAX_NN_DIGIT ((NN_DIGIT) MAX_NN_HALF_DIGIT << NN_HALF_DIGIT_BITS | MAX_NN_HALF_DIGIT)
/* Macros.
*/
diff -c -r ./rsaref/test/global.h ../pgp26/rsaref/test/global.h
*** ./rsaref/test/global.h Sat Feb 29 09:13:47 1992
- --- ../pgp26/rsaref/test/global.h Tue Jun 21 18:45:06 1994
***************
*** 21,27 ****
typedef unsigned short int UINT2;
/* UINT4 defines a four byte word */
! typedef unsigned long int UINT4;
/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
- --- 21,31 ----
typedef unsigned short int UINT2;
/* UINT4 defines a four byte word */
! typedef unsigned int UINT4;
!
! #ifdef __alpha
! typedef unsigned long int UINT8;
! #endif
/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
-----BEGIN PGP SIGNATURE-----
Version: 2.6
iQCVAgUBLlo5ykhOZTWYCX+PAQE2IQQApCx5tjryLLAoc5+Tb9xqzk1De8NiVMKc
jZ2FAnn/kowDD5AsRRCofLsEkG1pTm2Q8eKTlNT5vHEqVXikLjl34UxflevdfbUb
lT/pFbYemq7GotAJT1JWjO7AlNvrLJQsHLsHSEkBSGhA4PuzjvkgSMMixznzHZOO
J4cE+0QAvMs=
=Bhce
-----END PGP SIGNATURE-----