Fix 32-bit integer math on 64-bit processor. Just use int32_t(!) instead

of incorrect and machine-dependent integer math.  Now we can encrypt a file
on an i386 and decrypt it on an amd64, and vice versa.

Submitted by:	Andrew Heybey < ath at niksun dot com >
This commit is contained in:
Jung-uk Kim 2006-07-25 22:20:05 +00:00
parent ce92ededd9
commit 93e3b716ba
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=160681

View file

@ -1,4 +1,4 @@
/*
/*-
* "enigma.c" is in file cbw.tar from
* anonymous FTP host watmsg.waterloo.edu: pub/crypt/cbw.tar.Z
*
@ -40,7 +40,7 @@ setup(char *pw)
int ic, i, k, temp;
char salt[3];
unsigned rnd;
long seed;
int32_t seed;
strlcpy(salt, pw, sizeof(salt));
memcpy(buf, crypt(pw, salt), sizeof(buf));
@ -53,13 +53,6 @@ setup(char *pw)
}
for(i=0;i<ROTORSZ;i++) {
seed = 5*seed + buf[i%13];
if( sizeof(long) > 4 ) {
/* Force seed to stay in 32-bit signed math */
if( seed & 0x80000000 )
seed = seed | (-1L & ~0xFFFFFFFFL);
else
seed &= 0x7FFFFFFF;
}
rnd = seed % 65521;
k = ROTORSZ-1 - i;
ic = (rnd&MASK)%(k+1);
@ -140,7 +133,7 @@ shuffle(char deckary[])
{
int i, ic, k, temp;
unsigned rnd;
static long seed = 123;
static int32_t seed = 123;
for(i=0;i<ROTORSZ;i++) {
seed = 5*seed + buf[i%13];