diff options
Diffstat (limited to 'secure/lib/libcrypt/crypt-des.c')
-rw-r--r-- | secure/lib/libcrypt/crypt-des.c | 88 |
1 files changed, 43 insertions, 45 deletions
diff --git a/secure/lib/libcrypt/crypt-des.c b/secure/lib/libcrypt/crypt-des.c index 9e8c5ca..634a1ad 100644 --- a/secure/lib/libcrypt/crypt-des.c +++ b/secure/lib/libcrypt/crypt-des.c @@ -5,9 +5,13 @@ * All rights reserved. * * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet - * crypt.c should now *only* export crypt(), in order to make + * this file should now *only* export crypt(), in order to make * binaries of libcrypt exportable from the USA * + * Adapted for FreeBSD-4.0 by Mark R V Murray + * this file should now *only* export crypt_des(), in order to make + * a module that can be optionally included in libcrypt. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +20,7 @@ * 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. - * 4. Neither the name of the author nor the names of other contributors + * 3. Neither the name of the author nor the names of other contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -49,18 +53,15 @@ * posted to the sci.crypt newsgroup by the author and is available for FTP. * * ARCHITECTURE ASSUMPTIONS: - * This code assumes that u_longs are 32 bits. It will probably not - * operate on 64-bit machines without modifications. * It is assumed that the 8-byte arrays passed by reference can be - * addressed as arrays of u_longs (ie. the CPU is not picky about + * addressed as arrays of u_int32_t's (ie. the CPU is not picky about * alignment). */ #include <sys/types.h> #include <sys/param.h> #include <pwd.h> #include <string.h> - -char *crypt_md5(const char *pw, const char *salt); +#include "crypt.h" /* We can't always assume gcc */ #ifdef __GNUC__ @@ -158,7 +159,7 @@ static u_char pbox[32] = { 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 }; -static u_long bits32[32] = +static u_int32_t bits32[32] = { 0x80000000, 0x40000000, 0x20000000, 0x10000000, 0x08000000, 0x04000000, 0x02000000, 0x01000000, @@ -172,20 +173,20 @@ static u_long bits32[32] = static u_char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; -static u_long saltbits; -static long old_salt; -static u_long *bits28, *bits24; -static u_char init_perm[64], final_perm[64]; -static u_long en_keysl[16], en_keysr[16]; -static u_long de_keysl[16], de_keysr[16]; -static int des_initialised = 0; -static u_char m_sbox[4][4096]; -static u_long psbox[4][256]; -static u_long ip_maskl[8][256], ip_maskr[8][256]; -static u_long fp_maskl[8][256], fp_maskr[8][256]; -static u_long key_perm_maskl[8][128], key_perm_maskr[8][128]; -static u_long comp_maskl[8][128], comp_maskr[8][128]; -static u_long old_rawkey0, old_rawkey1; +static u_int32_t saltbits; +static long old_salt; +static u_int32_t *bits28, *bits24; +static u_char init_perm[64], final_perm[64]; +static u_int32_t en_keysl[16], en_keysr[16]; +static u_int32_t de_keysl[16], de_keysr[16]; +static int des_initialised = 0; +static u_char m_sbox[4][4096]; +static u_int32_t psbox[4][256]; +static u_int32_t ip_maskl[8][256], ip_maskr[8][256]; +static u_int32_t fp_maskl[8][256], fp_maskr[8][256]; +static u_int32_t key_perm_maskl[8][128], key_perm_maskr[8][128]; +static u_int32_t comp_maskl[8][128], comp_maskr[8][128]; +static u_int32_t old_rawkey0, old_rawkey1; static u_char ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -214,7 +215,7 @@ static void des_init() { int i, j, b, k, inbit, obit; - u_long *p, *il, *ir, *fl, *fr; + u_int32_t *p, *il, *ir, *fl, *fr; old_rawkey0 = old_rawkey1 = 0L; saltbits = 0L; @@ -343,8 +344,8 @@ des_init() static void setup_salt(long salt) { - u_long obit, saltbit; - int i; + u_int32_t obit, saltbit; + int i; if (salt == old_salt) return; @@ -364,14 +365,14 @@ setup_salt(long salt) static int des_setkey(const char *key) { - u_long k0, k1, rawkey0, rawkey1; - int shifts, round; + u_int32_t k0, k1, rawkey0, rawkey1; + int shifts, round; if (!des_initialised) des_init(); - rawkey0 = ntohl(*(u_long *) key); - rawkey1 = ntohl(*(u_long *) (key + 4)); + rawkey0 = ntohl(*(u_int32_t *) key); + rawkey1 = ntohl(*(u_int32_t *) (key + 4)); if ((rawkey0 | rawkey1) && rawkey0 == old_rawkey0 @@ -411,7 +412,7 @@ des_setkey(const char *key) */ shifts = 0; for (round = 0; round < 16; round++) { - u_long t0, t1; + u_int32_t t0, t1; shifts += key_shifts[round]; @@ -442,14 +443,14 @@ des_setkey(const char *key) } static int -do_des( u_long l_in, u_long r_in, u_long *l_out, u_long *r_out, int count) +do_des( u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, int count) { /* * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. */ - u_long l, r, *kl, *kr, *kl1, *kr1; - u_long f, r48l, r48r; - int round; + u_int32_t l, r, *kl, *kr, *kl1, *kr1; + u_int32_t f, r48l, r48r; + int round; if (count == 0) { return(1); @@ -560,35 +561,32 @@ do_des( u_long l_in, u_long r_in, u_long *l_out, u_long *r_out, int count) static int des_cipher(const char *in, char *out, long salt, int count) { - u_long l_out, r_out, rawl, rawr; - int retval; + u_int32_t l_out, r_out, rawl, rawr; + int retval; if (!des_initialised) des_init(); setup_salt(salt); - rawl = ntohl(*((u_long *) in)++); - rawr = ntohl(*((u_long *) in)); + rawl = ntohl(*((u_int32_t *) in)++); + rawr = ntohl(*((u_int32_t *) in)); retval = do_des(rawl, rawr, &l_out, &r_out, count); - *((u_long *) out)++ = htonl(l_out); - *((u_long *) out) = htonl(r_out); + *((u_int32_t *) out)++ = htonl(l_out); + *((u_int32_t *) out) = htonl(r_out); return(retval); } char * -crypt(char *key, char *setting) +crypt_des(const char *key, const char *setting) { int i; - u_long count, salt, l, r0, r1, keybuf[2]; + u_int32_t count, salt, l, r0, r1, keybuf[2]; u_char *p, *q; static u_char output[21]; - if (!strncmp(setting, "$1$", 3)) - return crypt_md5(key, setting); - if (!des_initialised) des_init(); |