srogue: more compatibility improvements.
Randomness now uses mdport, and xcrypt.c has been replaced with the rogue5 version. Super-Rogue now builds on MinGW.
This commit is contained in:
parent
b9cc9cf3a7
commit
120beada5a
6 changed files with 104 additions and 66 deletions
|
|
@ -24,7 +24,7 @@ AC_PROG_GCC_TRADITIONAL
|
||||||
AC_TYPE_SIGNAL
|
AC_TYPE_SIGNAL
|
||||||
AC_FUNC_STAT
|
AC_FUNC_STAT
|
||||||
AC_FUNC_VPRINTF
|
AC_FUNC_VPRINTF
|
||||||
AC_CHECK_FUNCS([erasechar killchar alarm getpass memset setenv strchr nlist _spawnl spawnl getpwuid loadav getloadavg strerror setgid setuid getuid getgid])
|
AC_CHECK_FUNCS([erasechar killchar alarm getpass memset setenv strchr nlist _spawnl spawnl getpwuid loadav getloadavg strerror setgid setuid getuid getgid lrand48 random srand48 srandom])
|
||||||
AC_PROG_INSTALL
|
AC_PROG_INSTALL
|
||||||
|
|
||||||
AC_ARG_WITH(program-name, AC_HELP_STRING([--with-program-name=NAME],[alternate executable name]),[progname="$withval" ], [progname="srogue"] )
|
AC_ARG_WITH(program-name, AC_HELP_STRING([--with-program-name=NAME],[alternate executable name]),[progname="$withval" ], [progname="srogue"] )
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ char **envp;
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
seed = dnum;
|
seed = dnum;
|
||||||
srandom(seed); /* init rnd number gen */
|
md_srandom(seed); /* init rnd number gen */
|
||||||
|
|
||||||
md_onsignal_exit(); /* just in case */
|
md_onsignal_exit(); /* just in case */
|
||||||
|
|
||||||
|
|
@ -354,7 +354,7 @@ int range;
|
||||||
if (range == 0)
|
if (range == 0)
|
||||||
wh = 0;
|
wh = 0;
|
||||||
else {
|
else {
|
||||||
wh = random() % range;
|
wh = md_random() % range;
|
||||||
wh &= 0x7FFFFFFF;
|
wh &= 0x7FFFFFFF;
|
||||||
}
|
}
|
||||||
return wh;
|
return wh;
|
||||||
|
|
|
||||||
|
|
@ -1567,3 +1567,27 @@ md_resetpriv(void)
|
||||||
setgid(playgid);
|
setgid(playgid);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
md_random(void)
|
||||||
|
{
|
||||||
|
#if defined (HAVE_LRAND48)
|
||||||
|
return lrand48();
|
||||||
|
#elif defined (HAVE_RANDOM)
|
||||||
|
return random();
|
||||||
|
#else
|
||||||
|
return rand();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
md_srandom(unsigned int seed)
|
||||||
|
{
|
||||||
|
#if defined (HAVE_SRAND48)
|
||||||
|
srand48(seed);
|
||||||
|
#elif defined (HAVE_SRANDOM)
|
||||||
|
srandom(seed);
|
||||||
|
#else
|
||||||
|
srand(seed);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,8 @@ int md_issymlink(char *sp);
|
||||||
long md_memused(void);
|
long md_memused(void);
|
||||||
void md_droppriv(void);
|
void md_droppriv(void);
|
||||||
void md_resetpriv(void);
|
void md_resetpriv(void);
|
||||||
|
int md_random(void);
|
||||||
|
void md_srandom(unsigned int seed);
|
||||||
char *xcrypt(const char *key, const char *setting);
|
char *xcrypt(const char *key, const char *setting);
|
||||||
|
|
||||||
#define reg register /* register abbr. */
|
#define reg register /* register abbr. */
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ char *file, **envp;
|
||||||
#endif
|
#endif
|
||||||
if (!wizard)
|
if (!wizard)
|
||||||
{
|
{
|
||||||
#ifndef __DJGPP__
|
#if defined(HAVE_WORKING_FORK)
|
||||||
endwin();
|
endwin();
|
||||||
if (!use_savedir)
|
if (!use_savedir)
|
||||||
{
|
{
|
||||||
|
|
@ -344,6 +344,6 @@ char *file, **envp;
|
||||||
strcpy(file_name, file);
|
strcpy(file_name, file);
|
||||||
setup();
|
setup();
|
||||||
restscr(cw);
|
restscr(cw);
|
||||||
srandom(getpid());
|
md_srandom(getpid());
|
||||||
playit();
|
playit();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,12 +50,34 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/param.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef DEBUG
|
static unsigned int md_endian = 0x01020304;
|
||||||
# include <stdio.h>
|
|
||||||
#endif
|
unsigned int
|
||||||
|
xntohl(unsigned int x)
|
||||||
|
{
|
||||||
|
if ( *((char *)&md_endian) == 0x01 )
|
||||||
|
return(x);
|
||||||
|
else
|
||||||
|
return( ((x & 0x000000ffU) << 24) |
|
||||||
|
((x & 0x0000ff00U) << 8) |
|
||||||
|
((x & 0x00ff0000U) >> 8) |
|
||||||
|
((x & 0xff000000U) >> 24) );
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
xhtonl(unsigned int x)
|
||||||
|
{
|
||||||
|
if ( *((char *)&md_endian) == 0x01 )
|
||||||
|
return(x);
|
||||||
|
else
|
||||||
|
return( ((x & 0x000000ffU) << 24) |
|
||||||
|
((x & 0x0000ff00U) << 8) |
|
||||||
|
((x & 0x00ff0000U) >> 8) |
|
||||||
|
((x & 0xff000000U) >> 24) );
|
||||||
|
}
|
||||||
|
|
||||||
#define _PASSWORD_EFMT1 '_'
|
#define _PASSWORD_EFMT1 '_'
|
||||||
|
|
||||||
static unsigned char IP[64] = {
|
static unsigned char IP[64] = {
|
||||||
|
|
@ -182,8 +204,7 @@ static unsigned char ascii64[] =
|
||||||
/* 0123456789012345678901234567890123456789012345678901234567890123 */
|
/* 0123456789012345678901234567890123456789012345678901234567890123 */
|
||||||
|
|
||||||
static __inline int
|
static __inline int
|
||||||
ascii_to_bin(ch)
|
ascii_to_bin(int ch)
|
||||||
char ch;
|
|
||||||
{
|
{
|
||||||
if (ch > 'z')
|
if (ch > 'z')
|
||||||
return(0);
|
return(0);
|
||||||
|
|
@ -201,7 +222,7 @@ ascii_to_bin(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
des_init()
|
des_init(void)
|
||||||
{
|
{
|
||||||
int i, j, b, k, inbit, obit;
|
int i, j, b, k, inbit, obit;
|
||||||
unsigned int *p, *il, *ir, *fl, *fr;
|
unsigned int *p, *il, *ir, *fl, *fr;
|
||||||
|
|
@ -236,7 +257,7 @@ des_init()
|
||||||
* initialise the inverted key permutation.
|
* initialise the inverted key permutation.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < 64; i++) {
|
for (i = 0; i < 64; i++) {
|
||||||
init_perm[final_perm[i] = IP[i] - 1] = i;
|
init_perm[final_perm[i] = IP[i] - 1] = (unsigned char) i;
|
||||||
inv_key_perm[i] = 255;
|
inv_key_perm[i] = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,7 +266,7 @@ des_init()
|
||||||
* compression permutation.
|
* compression permutation.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < 56; i++) {
|
for (i = 0; i < 56; i++) {
|
||||||
inv_key_perm[key_perm[i] - 1] = i;
|
inv_key_perm[key_perm[i] - 1] = (unsigned char) i;
|
||||||
inv_comp_perm[i] = 255;
|
inv_comp_perm[i] = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,7 +274,7 @@ des_init()
|
||||||
* Invert the key compression permutation.
|
* Invert the key compression permutation.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < 48; i++) {
|
for (i = 0; i < 48; i++) {
|
||||||
inv_comp_perm[comp_perm[i] - 1] = i;
|
inv_comp_perm[comp_perm[i] - 1] = (unsigned char) i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -315,7 +336,7 @@ des_init()
|
||||||
* handling the output of the S-box arrays setup above.
|
* handling the output of the S-box arrays setup above.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < 32; i++)
|
for (i = 0; i < 32; i++)
|
||||||
un_pbox[pbox[i] - 1] = i;
|
un_pbox[pbox[i] - 1] = (unsigned char) i;
|
||||||
|
|
||||||
for (b = 0; b < 4; b++)
|
for (b = 0; b < 4; b++)
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
|
|
@ -330,8 +351,7 @@ des_init()
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setup_salt(salt)
|
setup_salt(int salt)
|
||||||
int salt;
|
|
||||||
{
|
{
|
||||||
unsigned int obit, saltbit;
|
unsigned int obit, saltbit;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -352,8 +372,7 @@ setup_salt(salt)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
des_setkey(key)
|
des_setkey(const char *key)
|
||||||
const char *key;
|
|
||||||
{
|
{
|
||||||
unsigned int k0, k1, rawkey0, rawkey1;
|
unsigned int k0, k1, rawkey0, rawkey1;
|
||||||
int shifts, round;
|
int shifts, round;
|
||||||
|
|
@ -361,8 +380,8 @@ des_setkey(key)
|
||||||
if (!des_initialised)
|
if (!des_initialised)
|
||||||
des_init();
|
des_init();
|
||||||
|
|
||||||
rawkey0 = ntohl(*(unsigned int *) key);
|
rawkey0 = xntohl(*(unsigned int *) key);
|
||||||
rawkey1 = ntohl(*(unsigned int *) (key + 4));
|
rawkey1 = xntohl(*(unsigned int *) (key + 4));
|
||||||
|
|
||||||
if ((rawkey0 | rawkey1)
|
if ((rawkey0 | rawkey1)
|
||||||
&& rawkey0 == old_rawkey0
|
&& rawkey0 == old_rawkey0
|
||||||
|
|
@ -433,15 +452,14 @@ des_setkey(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
do_des(l_in, r_in, l_out, r_out, count)
|
do_des(unsigned int l_in, unsigned int r_in, unsigned int *l_out,
|
||||||
unsigned int l_in, r_in, *l_out, *r_out;
|
unsigned int *r_out, int count)
|
||||||
int count;
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
|
* l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
|
||||||
*/
|
*/
|
||||||
unsigned int l, r, *kl, *kr, *kl1, *kr1;
|
unsigned int l, r, *kl, *kr, *kl1, *kr1;
|
||||||
unsigned int f, r48l, r48r;
|
unsigned int f = 0, r48l, r48r;
|
||||||
int round;
|
int round;
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
|
@ -551,11 +569,7 @@ do_des(l_in, r_in, l_out, r_out, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
des_cipher(in, out, salt, count)
|
des_cipher(const char *in, char *out, int salt, int count)
|
||||||
const char *in;
|
|
||||||
char *out;
|
|
||||||
int salt;
|
|
||||||
int count;
|
|
||||||
{
|
{
|
||||||
unsigned int l_out, r_out, rawl, rawr;
|
unsigned int l_out, r_out, rawl, rawr;
|
||||||
unsigned int x[2];
|
unsigned int x[2];
|
||||||
|
|
@ -567,20 +581,18 @@ des_cipher(in, out, salt, count)
|
||||||
setup_salt(salt);
|
setup_salt(salt);
|
||||||
|
|
||||||
memcpy(x, in, sizeof x);
|
memcpy(x, in, sizeof x);
|
||||||
rawl = ntohl(x[0]);
|
rawl = xntohl(x[0]);
|
||||||
rawr = ntohl(x[1]);
|
rawr = xntohl(x[1]);
|
||||||
retval = do_des(rawl, rawr, &l_out, &r_out, count);
|
retval = do_des(rawl, rawr, &l_out, &r_out, count);
|
||||||
|
|
||||||
x[0] = htonl(l_out);
|
x[0] = xhtonl(l_out);
|
||||||
x[1] = htonl(r_out);
|
x[1] = xhtonl(r_out);
|
||||||
memcpy(out, x, sizeof x);
|
memcpy(out, x, sizeof x);
|
||||||
return(retval);
|
return(retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
xcrypt(key, setting)
|
xcrypt(const char *key, const char *setting)
|
||||||
const char *key;
|
|
||||||
const char *setting;
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned int count, salt, l, r0, r1, keybuf[2];
|
unsigned int count, salt, l, r0, r1, keybuf[2];
|
||||||
|
|
@ -599,7 +611,7 @@ xcrypt(key, setting)
|
||||||
if ((*q++ = *key << 1))
|
if ((*q++ = *key << 1))
|
||||||
key++;
|
key++;
|
||||||
}
|
}
|
||||||
if (des_setkey((unsigned char *) keybuf))
|
if (des_setkey((const char *) keybuf))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
if (*setting == _PASSWORD_EFMT1) {
|
if (*setting == _PASSWORD_EFMT1) {
|
||||||
|
|
@ -618,7 +630,7 @@ xcrypt(key, setting)
|
||||||
/*
|
/*
|
||||||
* Encrypt the key with itself.
|
* Encrypt the key with itself.
|
||||||
*/
|
*/
|
||||||
if (des_cipher((unsigned char*)keybuf, (unsigned char*)keybuf, 0, 1))
|
if (des_cipher((const char*)keybuf, (char*)keybuf, 0, 1))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
/*
|
/*
|
||||||
* And XOR with the next 8 characters of the key.
|
* And XOR with the next 8 characters of the key.
|
||||||
|
|
@ -628,7 +640,7 @@ xcrypt(key, setting)
|
||||||
*key)
|
*key)
|
||||||
*q++ ^= *key++ << 1;
|
*q++ ^= *key++ << 1;
|
||||||
|
|
||||||
if (des_setkey((unsigned char *) keybuf))
|
if (des_setkey((const char *) keybuf))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
strncpy((char *)output, setting, 9);
|
strncpy((char *)output, setting, 9);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue