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:
John "Elwin" Edwards 2014-05-03 10:31:30 -07:00
parent b9cc9cf3a7
commit 120beada5a
6 changed files with 104 additions and 66 deletions

View file

@ -1,32 +1,32 @@
/*
* FreeSec: libcrypt
* FreeSec: libcrypt
*
* Copyright (C) 1994 David Burren
* All rights reserved.
* Copyright (C) 1994 David Burren
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name(s) of the author(s) nor the names of other contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name(s) of the author(s) nor the names of other contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*
* This is an original implementation of the DES and the crypt(3) interfaces
@ -50,12 +50,34 @@
*/
#include <sys/types.h>
#include <sys/param.h>
#include <string.h>
#ifdef DEBUG
# include <stdio.h>
#endif
static unsigned int md_endian = 0x01020304;
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 '_'
static unsigned char IP[64] = {
@ -182,8 +204,7 @@ static unsigned char ascii64[] =
/* 0123456789012345678901234567890123456789012345678901234567890123 */
static __inline int
ascii_to_bin(ch)
char ch;
ascii_to_bin(int ch)
{
if (ch > 'z')
return(0);
@ -201,7 +222,7 @@ ascii_to_bin(ch)
}
static void
des_init()
des_init(void)
{
int i, j, b, k, inbit, obit;
unsigned int *p, *il, *ir, *fl, *fr;
@ -236,7 +257,7 @@ des_init()
* initialise the inverted key permutation.
*/
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;
}
@ -245,7 +266,7 @@ des_init()
* compression permutation.
*/
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;
}
@ -253,7 +274,7 @@ des_init()
* Invert the key compression permutation.
*/
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.
*/
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 (i = 0; i < 256; i++) {
@ -330,8 +351,7 @@ des_init()
}
static void
setup_salt(salt)
int salt;
setup_salt(int salt)
{
unsigned int obit, saltbit;
int i;
@ -352,8 +372,7 @@ setup_salt(salt)
}
static int
des_setkey(key)
const char *key;
des_setkey(const char *key)
{
unsigned int k0, k1, rawkey0, rawkey1;
int shifts, round;
@ -361,8 +380,8 @@ des_setkey(key)
if (!des_initialised)
des_init();
rawkey0 = ntohl(*(unsigned int *) key);
rawkey1 = ntohl(*(unsigned int *) (key + 4));
rawkey0 = xntohl(*(unsigned int *) key);
rawkey1 = xntohl(*(unsigned int *) (key + 4));
if ((rawkey0 | rawkey1)
&& rawkey0 == old_rawkey0
@ -433,15 +452,14 @@ des_setkey(key)
}
static int
do_des(l_in, r_in, l_out, r_out, count)
unsigned int l_in, r_in, *l_out, *r_out;
int count;
do_des(unsigned int l_in, unsigned int r_in, unsigned int *l_out,
unsigned int *r_out, int count)
{
/*
* 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 f, r48l, r48r;
unsigned int f = 0, r48l, r48r;
int round;
if (count == 0) {
@ -551,11 +569,7 @@ do_des(l_in, r_in, l_out, r_out, count)
}
static int
des_cipher(in, out, salt, count)
const char *in;
char *out;
int salt;
int count;
des_cipher(const char *in, char *out, int salt, int count)
{
unsigned int l_out, r_out, rawl, rawr;
unsigned int x[2];
@ -567,20 +581,18 @@ des_cipher(in, out, salt, count)
setup_salt(salt);
memcpy(x, in, sizeof x);
rawl = ntohl(x[0]);
rawr = ntohl(x[1]);
rawl = xntohl(x[0]);
rawr = xntohl(x[1]);
retval = do_des(rawl, rawr, &l_out, &r_out, count);
x[0] = htonl(l_out);
x[1] = htonl(r_out);
x[0] = xhtonl(l_out);
x[1] = xhtonl(r_out);
memcpy(out, x, sizeof x);
return(retval);
}
char *
xcrypt(key, setting)
const char *key;
const char *setting;
xcrypt(const char *key, const char *setting)
{
int i;
unsigned int count, salt, l, r0, r1, keybuf[2];
@ -599,7 +611,7 @@ xcrypt(key, setting)
if ((*q++ = *key << 1))
key++;
}
if (des_setkey((unsigned char *) keybuf))
if (des_setkey((const char *) keybuf))
return(NULL);
if (*setting == _PASSWORD_EFMT1) {
@ -618,7 +630,7 @@ xcrypt(key, setting)
/*
* 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);
/*
* And XOR with the next 8 characters of the key.
@ -628,7 +640,7 @@ xcrypt(key, setting)
*key)
*q++ ^= *key++ << 1;
if (des_setkey((unsigned char *) keybuf))
if (des_setkey((const char *) keybuf))
return(NULL);
}
strncpy((char *)output, setting, 9);