X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/b57f37fb6a4d30ac9aaba3bbca06f5a3307c804a..36fb4e9a7743326d1a2ca7601bc9bf1c5b9a0bcb:/libratbox/src/crypt.c diff --git a/libratbox/src/crypt.c b/libratbox/src/crypt.c index 5088bfe..c6d7135 100644 --- a/libratbox/src/crypt.c +++ b/libratbox/src/crypt.c @@ -36,19 +36,19 @@ extern char *crypt(const char *key, const char *salt); char * rb_crypt(const char *key, const char *salt) { - return(crypt(key, salt)); + return (crypt(key, salt)); } #else -static char * __md5_crypt( const char *pw, const char *salt); -static char * __des_crypt( const char *pw, const char *salt); +static char *__md5_crypt(const char *pw, const char *salt); +static char *__des_crypt(const char *pw, const char *salt); -char * +char * rb_crypt(const char *key, const char *salt) { /* First, check if we are supposed to be using the MD5 replacement * instead of DES... */ - if (salt[0]=='$' && salt[1]=='1' && salt[2]=='$') + if(salt[0] == '$' && salt[1] == '1' && salt[2] == '$') return __md5_crypt(key, salt); else return __des_crypt(key, salt); @@ -110,62 +110,62 @@ rb_crypt(const char *key, const char *salt) * * ARCHITECTURE ASSUMPTIONS: * It is assumed that the 8-byte arrays passed by reference can be - * addressed as arrays of rb_uint32_t's (ie. the CPU is not picky about + * addressed as arrays of uint32_t's (ie. the CPU is not picky about * alignment). */ /* Re-entrantify me -- all this junk needs to be in * struct crypt_data to make this really reentrant... */ -static u_char inv_key_perm[64]; -static u_char inv_comp_perm[56]; -static u_char u_sbox[8][64]; -static u_char un_pbox[32]; -static rb_uint32_t en_keysl[16], en_keysr[16]; -static rb_uint32_t de_keysl[16], de_keysr[16]; -static rb_uint32_t ip_maskl[8][256], ip_maskr[8][256]; -static rb_uint32_t fp_maskl[8][256], fp_maskr[8][256]; -static rb_uint32_t key_perm_maskl[8][128], key_perm_maskr[8][128]; -static rb_uint32_t comp_maskl[8][128], comp_maskr[8][128]; -static rb_uint32_t saltbits; -static rb_uint32_t old_salt; -static rb_uint32_t old_rawkey0, old_rawkey1; +static uint8_t inv_key_perm[64]; +static uint8_t inv_comp_perm[56]; +static uint8_t u_sbox[8][64]; +static uint8_t un_pbox[32]; +static uint32_t en_keysl[16], en_keysr[16]; +static uint32_t de_keysl[16], de_keysr[16]; +static uint32_t ip_maskl[8][256], ip_maskr[8][256]; +static uint32_t fp_maskl[8][256], fp_maskr[8][256]; +static uint32_t key_perm_maskl[8][128], key_perm_maskr[8][128]; +static uint32_t comp_maskl[8][128], comp_maskr[8][128]; +static uint32_t saltbits; +static uint32_t old_salt; +static uint32_t old_rawkey0, old_rawkey1; /* Static stuff that stays resident and doesn't change after * being initialized, and therefore doesn't need to be made * reentrant. */ -static u_char init_perm[64], final_perm[64]; -static u_char m_sbox[4][4096]; -static rb_uint32_t psbox[4][256]; +static uint8_t init_perm[64], final_perm[64]; +static uint8_t m_sbox[4][4096]; +static uint32_t psbox[4][256]; /* A pile of data */ -static const u_char ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +static const uint8_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -static const u_char IP[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 +static const uint8_t IP[64] = { + 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 }; -static const u_char key_perm[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 +static const uint8_t key_perm[56] = { + 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, + 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 }; -static const u_char key_shifts[16] = { +static const uint8_t key_shifts[16] = { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 }; -static const u_char comp_perm[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, +static const uint8_t comp_perm[48] = { + 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 }; @@ -174,64 +174,55 @@ static const u_char comp_perm[48] = { * No E box is used, as it's replaced by some ANDs, shifts, and ORs. */ -static const u_char sbox[8][64] = { +static const uint8_t sbox[8][64] = { { - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 - }, + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}, { - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 - }, + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}, { - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 - }, + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}, { - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 - }, + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}, { - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 - }, + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}, { - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 - }, + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}, { - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 - }, + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}, { - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 - } + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11} }; -static const u_char pbox[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 +static const uint8_t pbox[32] = { + 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, + 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 }; -static const rb_uint32_t bits32[32] = -{ +static const uint32_t bits32[32] = { 0x80000000, 0x40000000, 0x20000000, 0x10000000, 0x08000000, 0x04000000, 0x02000000, 0x01000000, 0x00800000, 0x00400000, 0x00200000, 0x00100000, @@ -242,37 +233,38 @@ static const rb_uint32_t bits32[32] = 0x00000008, 0x00000004, 0x00000002, 0x00000001 }; -static const u_char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; -static const rb_uint32_t *bits28, *bits24; +static const uint8_t bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; + +static const uint32_t *bits28, *bits24; -static int +static int ascii_to_bin(char ch) { - if (ch > 'z') - return(0); - if (ch >= 'a') - return(ch - 'a' + 38); - if (ch > 'Z') - return(0); - if (ch >= 'A') - return(ch - 'A' + 12); - if (ch > '9') - return(0); - if (ch >= '.') - return(ch - '.'); - return(0); + if(ch > 'z') + return (0); + if(ch >= 'a') + return (ch - 'a' + 38); + if(ch > 'Z') + return (0); + if(ch >= 'A') + return (ch - 'A' + 12); + if(ch > '9') + return (0); + if(ch >= '.') + return (ch - '.'); + return (0); } static void des_init(void) { - int i, j, b, k, inbit, obit; - rb_uint32_t *p, *il, *ir, *fl, *fr; + int i, j, b, k, inbit, obit; + uint32_t *p, *il, *ir, *fl, *fr; static int des_initialised = 0; - if (des_initialised==1) - return; + if(des_initialised == 1) + return; old_rawkey0 = old_rawkey1 = 0L; saltbits = 0L; @@ -282,8 +274,9 @@ des_init(void) /* * Invert the S-boxes, reordering the input bits. */ - for (i = 0; i < 8; i++) - for (j = 0; j < 64; j++) { + for(i = 0; i < 8; i++) + for(j = 0; j < 64; j++) + { b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); u_sbox[i][j] = sbox[i][b]; } @@ -292,19 +285,20 @@ des_init(void) * Convert the inverted S-boxes into 4 arrays of 8 bits. * Each will handle 12 bits of the S-box input. */ - for (b = 0; b < 4; b++) - for (i = 0; i < 64; i++) - for (j = 0; j < 64; j++) + for(b = 0; b < 4; b++) + for(i = 0; i < 64; i++) + for(j = 0; j < 64; j++) m_sbox[b][(i << 6) | j] = - (u_char)((u_sbox[(b << 1)][i] << 4) | - u_sbox[(b << 1) + 1][j]); + (uint8_t)((u_sbox[(b << 1)][i] << 4) | + u_sbox[(b << 1) + 1][j]); /* * Set up the initial & final permutations into a useful form, and * initialise the inverted key permutation. */ - for (i = 0; i < 64; i++) { - init_perm[final_perm[i] = IP[i] - 1] = (u_char)i; + for(i = 0; i < 64; i++) + { + init_perm[final_perm[i] = IP[i] - 1] = (uint8_t)i; inv_key_perm[i] = 255; } @@ -312,51 +306,60 @@ des_init(void) * Invert the key permutation and initialise the inverted key * compression permutation. */ - for (i = 0; i < 56; i++) { - inv_key_perm[key_perm[i] - 1] = (u_char)i; + for(i = 0; i < 56; i++) + { + inv_key_perm[key_perm[i] - 1] = (uint8_t)i; inv_comp_perm[i] = 255; } /* * Invert the key compression permutation. */ - for (i = 0; i < 48; i++) { - inv_comp_perm[comp_perm[i] - 1] = (u_char)i; + for(i = 0; i < 48; i++) + { + inv_comp_perm[comp_perm[i] - 1] = (uint8_t)i; } /* * Set up the OR-mask arrays for the initial and final permutations, * and for the key initial and compression permutations. */ - for (k = 0; k < 8; k++) { - for (i = 0; i < 256; i++) { + for(k = 0; k < 8; k++) + { + for(i = 0; i < 256; i++) + { *(il = &ip_maskl[k][i]) = 0L; *(ir = &ip_maskr[k][i]) = 0L; *(fl = &fp_maskl[k][i]) = 0L; *(fr = &fp_maskr[k][i]) = 0L; - for (j = 0; j < 8; j++) { + for(j = 0; j < 8; j++) + { inbit = 8 * k + j; - if (i & bits8[j]) { - if ((obit = init_perm[inbit]) < 32) + if(i & bits8[j]) + { + if((obit = init_perm[inbit]) < 32) *il |= bits32[obit]; else - *ir |= bits32[obit-32]; - if ((obit = final_perm[inbit]) < 32) + *ir |= bits32[obit - 32]; + if((obit = final_perm[inbit]) < 32) *fl |= bits32[obit]; else *fr |= bits32[obit - 32]; } } } - for (i = 0; i < 128; i++) { + for(i = 0; i < 128; i++) + { *(il = &key_perm_maskl[k][i]) = 0L; *(ir = &key_perm_maskr[k][i]) = 0L; - for (j = 0; j < 7; j++) { + for(j = 0; j < 7; j++) + { inbit = 8 * k + j; - if (i & bits8[j + 1]) { - if ((obit = inv_key_perm[inbit]) == 255) + if(i & bits8[j + 1]) + { + if((obit = inv_key_perm[inbit]) == 255) continue; - if (obit < 28) + if(obit < 28) *il |= bits28[obit]; else *ir |= bits28[obit - 28]; @@ -364,12 +367,14 @@ des_init(void) } *(il = &comp_maskl[k][i]) = 0L; *(ir = &comp_maskr[k][i]) = 0L; - for (j = 0; j < 7; j++) { + for(j = 0; j < 7; j++) + { inbit = 7 * k + j; - if (i & bits8[j + 1]) { - if ((obit=inv_comp_perm[inbit]) == 255) + if(i & bits8[j + 1]) + { + if((obit = inv_comp_perm[inbit]) == 255) continue; - if (obit < 24) + if(obit < 24) *il |= bits24[obit]; else *ir |= bits24[obit - 24]; @@ -382,14 +387,16 @@ des_init(void) * Invert the P-box permutation, and convert into OR-masks for * handling the output of the S-box arrays setup above. */ - for (i = 0; i < 32; i++) - un_pbox[pbox[i] - 1] = (u_char)i; + for(i = 0; i < 32; i++) + un_pbox[pbox[i] - 1] = (uint8_t)i; - for (b = 0; b < 4; b++) - for (i = 0; i < 256; i++) { + for(b = 0; b < 4; b++) + for(i = 0; i < 256; i++) + { *(p = &psbox[b][i]) = 0L; - for (j = 0; j < 8; j++) { - if (i & bits8[j]) + for(j = 0; j < 8; j++) + { + if(i & bits8[j]) *p |= bits32[un_pbox[8 * b + j]]; } } @@ -401,18 +408,19 @@ des_init(void) static void setup_salt(long salt) { - rb_uint32_t obit, saltbit; - int i; + uint32_t obit, saltbit; + int i; - if (salt == (long)old_salt) + if(salt == (long)old_salt) return; old_salt = salt; saltbits = 0L; saltbit = 1; obit = 0x800000; - for (i = 0; i < 24; i++) { - if (salt & saltbit) + for(i = 0; i < 24; i++) + { + if(salt & saltbit) saltbits |= obit; saltbit <<= 1; obit >>= 1; @@ -423,53 +431,53 @@ setup_salt(long salt) static int des_setkey(const char *key) { - rb_uint32_t k0, k1, rawkey0, rawkey1; - int shifts, round; + uint32_t k0, k1, rawkey0, rawkey1; + int shifts, round; des_init(); - rawkey0 = ntohl(*(const rb_uint32_t *) key); - rawkey1 = ntohl(*(const rb_uint32_t *) (key + 4)); + rawkey0 = ntohl(*(const uint32_t *)key); + rawkey1 = ntohl(*(const uint32_t *)(key + 4)); - if ((rawkey0 | rawkey1) - && rawkey0 == old_rawkey0 - && rawkey1 == old_rawkey1) { + if((rawkey0 | rawkey1) && rawkey0 == old_rawkey0 && rawkey1 == old_rawkey1) + { /* * Already setup for this key. * This optimisation fails on a zero key (which is weak and * has bad parity anyway) in order to simplify the starting * conditions. */ - return(0); + return (0); } old_rawkey0 = rawkey0; old_rawkey1 = rawkey1; /* - * Do key permutation and split into two 28-bit subkeys. + * Do key permutation and split into two 28-bit subkeys. */ k0 = key_perm_maskl[0][rawkey0 >> 25] - | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskl[4][rawkey1 >> 25] - | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; + | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskl[4][rawkey1 >> 25] + | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; k1 = key_perm_maskr[0][rawkey0 >> 25] - | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskr[4][rawkey1 >> 25] - | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; + | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskr[4][rawkey1 >> 25] + | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; /* - * Rotate subkeys and do compression permutation. + * Rotate subkeys and do compression permutation. */ shifts = 0; - for (round = 0; round < 16; round++) { - rb_uint32_t t0, t1; + for(round = 0; round < 16; round++) + { + uint32_t t0, t1; shifts += key_shifts[round]; @@ -477,48 +485,51 @@ des_setkey(const char *key) t1 = (k1 << shifts) | (k1 >> (28 - shifts)); de_keysl[15 - round] = - en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] - | comp_maskl[1][(t0 >> 14) & 0x7f] - | comp_maskl[2][(t0 >> 7) & 0x7f] - | comp_maskl[3][t0 & 0x7f] - | comp_maskl[4][(t1 >> 21) & 0x7f] - | comp_maskl[5][(t1 >> 14) & 0x7f] - | comp_maskl[6][(t1 >> 7) & 0x7f] - | comp_maskl[7][t1 & 0x7f]; + en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] + | comp_maskl[1][(t0 >> 14) & 0x7f] + | comp_maskl[2][(t0 >> 7) & 0x7f] + | comp_maskl[3][t0 & 0x7f] + | comp_maskl[4][(t1 >> 21) & 0x7f] + | comp_maskl[5][(t1 >> 14) & 0x7f] + | comp_maskl[6][(t1 >> 7) & 0x7f] | comp_maskl[7][t1 & 0x7f]; de_keysr[15 - round] = - en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] - | comp_maskr[1][(t0 >> 14) & 0x7f] - | comp_maskr[2][(t0 >> 7) & 0x7f] - | comp_maskr[3][t0 & 0x7f] - | comp_maskr[4][(t1 >> 21) & 0x7f] - | comp_maskr[5][(t1 >> 14) & 0x7f] - | comp_maskr[6][(t1 >> 7) & 0x7f] - | comp_maskr[7][t1 & 0x7f]; + en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] + | comp_maskr[1][(t0 >> 14) & 0x7f] + | comp_maskr[2][(t0 >> 7) & 0x7f] + | comp_maskr[3][t0 & 0x7f] + | comp_maskr[4][(t1 >> 21) & 0x7f] + | comp_maskr[5][(t1 >> 14) & 0x7f] + | comp_maskr[6][(t1 >> 7) & 0x7f] | comp_maskr[7][t1 & 0x7f]; } - return(0); + return (0); } static int -do_des( rb_uint32_t l_in, rb_uint32_t r_in, rb_uint32_t *l_out, rb_uint32_t *r_out, int count) +do_des(uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out, 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. */ - rb_uint32_t l, r, *kl, *kr, *kl1, *kr1; - rb_uint32_t f, r48l, r48r; - int round; + uint32_t l, r, *kl, *kr, *kl1, *kr1; + uint32_t f, r48l, r48r; + int round; - if (count == 0) { - return(1); - } else if (count > 0) { + if(count == 0) + { + return (1); + } + else if(count > 0) + { /* * Encrypting */ kl1 = en_keysl; kr1 = en_keysr; - } else { + } + else + { /* * Decrypting */ @@ -528,47 +539,45 @@ do_des( rb_uint32_t l_in, rb_uint32_t r_in, rb_uint32_t *l_out, rb_uint32_t *r_o } /* - * Do initial permutation (IP). + * Do initial permutation (IP). */ l = ip_maskl[0][l_in >> 24] - | ip_maskl[1][(l_in >> 16) & 0xff] - | ip_maskl[2][(l_in >> 8) & 0xff] - | ip_maskl[3][l_in & 0xff] - | ip_maskl[4][r_in >> 24] - | ip_maskl[5][(r_in >> 16) & 0xff] - | ip_maskl[6][(r_in >> 8) & 0xff] - | ip_maskl[7][r_in & 0xff]; + | ip_maskl[1][(l_in >> 16) & 0xff] + | ip_maskl[2][(l_in >> 8) & 0xff] + | ip_maskl[3][l_in & 0xff] + | ip_maskl[4][r_in >> 24] + | ip_maskl[5][(r_in >> 16) & 0xff] + | ip_maskl[6][(r_in >> 8) & 0xff] | ip_maskl[7][r_in & 0xff]; r = ip_maskr[0][l_in >> 24] - | ip_maskr[1][(l_in >> 16) & 0xff] - | ip_maskr[2][(l_in >> 8) & 0xff] - | ip_maskr[3][l_in & 0xff] - | ip_maskr[4][r_in >> 24] - | ip_maskr[5][(r_in >> 16) & 0xff] - | ip_maskr[6][(r_in >> 8) & 0xff] - | ip_maskr[7][r_in & 0xff]; - - while (count--) { + | ip_maskr[1][(l_in >> 16) & 0xff] + | ip_maskr[2][(l_in >> 8) & 0xff] + | ip_maskr[3][l_in & 0xff] + | ip_maskr[4][r_in >> 24] + | ip_maskr[5][(r_in >> 16) & 0xff] + | ip_maskr[6][(r_in >> 8) & 0xff] | ip_maskr[7][r_in & 0xff]; + + while(count--) + { /* * Do each round. */ kl = kl1; kr = kr1; round = 16; - while (round--) { + while(round--) + { /* * Expand R to 48 bits (simulate the E-box). */ - r48l = ((r & 0x00000001) << 23) + r48l = ((r & 0x00000001) << 23) | ((r & 0xf8000000) >> 9) | ((r & 0x1f800000) >> 11) - | ((r & 0x01f80000) >> 13) - | ((r & 0x001f8000) >> 15); + | ((r & 0x01f80000) >> 13) | ((r & 0x001f8000) >> 15); - r48r = ((r & 0x0001f800) << 7) + r48r = ((r & 0x0001f800) << 7) | ((r & 0x00001f80) << 5) | ((r & 0x000001f8) << 3) - | ((r & 0x0000001f) << 1) - | ((r & 0x80000000) >> 31); + | ((r & 0x0000001f) << 1) | ((r & 0x80000000) >> 31); /* * Do salting for crypt() and friends, and * XOR with the permuted key. @@ -581,9 +590,9 @@ do_des( rb_uint32_t l_in, rb_uint32_t r_in, rb_uint32_t *l_out, rb_uint32_t *r_o * and do the pbox permutation at the same time. */ f = psbox[0][m_sbox[0][r48l >> 12]] - | psbox[1][m_sbox[1][r48l & 0xfff]] - | psbox[2][m_sbox[2][r48r >> 12]] - | psbox[3][m_sbox[3][r48r & 0xfff]]; + | psbox[1][m_sbox[1][r48l & 0xfff]] + | psbox[2][m_sbox[2][r48r >> 12]] + | psbox[3][m_sbox[3][r48r & 0xfff]]; /* * Now that we've permuted things, complete f(). */ @@ -597,35 +606,34 @@ do_des( rb_uint32_t l_in, rb_uint32_t r_in, rb_uint32_t *l_out, rb_uint32_t *r_o /* * Do final permutation (inverse of IP). */ - *l_out = fp_maskl[0][l >> 24] + *l_out = fp_maskl[0][l >> 24] | fp_maskl[1][(l >> 16) & 0xff] | fp_maskl[2][(l >> 8) & 0xff] | fp_maskl[3][l & 0xff] | fp_maskl[4][r >> 24] | fp_maskl[5][(r >> 16) & 0xff] - | fp_maskl[6][(r >> 8) & 0xff] - | fp_maskl[7][r & 0xff]; - *r_out = fp_maskr[0][l >> 24] + | fp_maskl[6][(r >> 8) & 0xff] | fp_maskl[7][r & 0xff]; + *r_out = fp_maskr[0][l >> 24] | fp_maskr[1][(l >> 16) & 0xff] | fp_maskr[2][(l >> 8) & 0xff] | fp_maskr[3][l & 0xff] | fp_maskr[4][r >> 24] | fp_maskr[5][(r >> 16) & 0xff] - | fp_maskr[6][(r >> 8) & 0xff] - | fp_maskr[7][r & 0xff]; - return(0); + | fp_maskr[6][(r >> 8) & 0xff] | fp_maskr[7][r & 0xff]; + return (0); } #if 0 static int -des_cipher(const char *in, char *out, rb_uint32_t salt, int count) +des_cipher(const char *in, char *out, uint32_t salt, int count) { - rb_uint32_t l_out, r_out, rawl, rawr; - int retval; - union { - rb_uint32_t *ui32; - const char *c; + uint32_t l_out, r_out, rawl, rawr; + int retval; + union + { + uint32_t *ui32; + const char *c; } trans; des_init(); @@ -641,7 +649,7 @@ des_cipher(const char *in, char *out, rb_uint32_t salt, int count) trans.c = out; *trans.ui32++ = htonl(l_out); *trans.ui32 = htonl(r_out); - return(retval); + return (retval); } #endif @@ -649,16 +657,17 @@ des_cipher(const char *in, char *out, rb_uint32_t salt, int count) void setkey(const char *key) { - int i, j; - rb_uint32_t packed_keys[2]; - u_char *p; + int i, j; + uint32_t packed_keys[2]; + uint8_t *p; - p = (u_char *) packed_keys; + p = (uint8_t *)packed_keys; - for (i = 0; i < 8; i++) { + for(i = 0; i < 8; i++) + { p[i] = 0; - for (j = 0; j < 8; j++) - if (*key++ & 1) + for(j = 0; j < 8; j++) + if(*key++ & 1) p[i] |= bits8[j]; } des_setkey((char *)p); @@ -668,23 +677,24 @@ setkey(const char *key) void encrypt(char *block, int flag) { - rb_uint32_t io[2]; - u_char *p; - int i, j; + uint32_t io[2]; + uint8_t *p; + int i, j; des_init(); setup_salt(0L); - p = (u_char*)block; - for (i = 0; i < 2; i++) { + p = (uint8_t *)block; + for(i = 0; i < 2; i++) + { io[i] = 0L; - for (j = 0; j < 32; j++) - if (*p++ & 1) + for(j = 0; j < 32; j++) + if(*p++ & 1) io[i] |= bits32[j]; } do_des(io[0], io[1], io, io + 1, flag ? -1 : 1); - for (i = 0; i < 2; i++) - for (j = 0; j < 32; j++) + for(i = 0; i < 2; i++) + for(j = 0; j < 32; j++) block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0; } #endif @@ -692,9 +702,9 @@ encrypt(char *block, int flag) static char * __des_crypt(const char *key, const char *setting) { - rb_uint32_t count, salt, l, r0, r1, keybuf[2]; - u_char *p, *q; - static char output[21]; + uint32_t count, salt, l, r0, r1, keybuf[2]; + uint8_t *p, *q; + static char output[21]; des_init(); @@ -702,44 +712,47 @@ __des_crypt(const char *key, const char *setting) * Copy the key, shifting each character up by one bit * and padding with zeros. */ - q = (u_char *)keybuf; - while (q - (u_char *)keybuf - 8) { + q = (uint8_t *)keybuf; + while(q - (uint8_t *)keybuf - 8) + { *q++ = *key << 1; - if (*(q - 1)) + if(*(q - 1)) key++; } - if (des_setkey((char *)keybuf)) - return(NULL); + if(des_setkey((char *)keybuf)) + return (NULL); #if 0 - if (*setting == _PASSWORD_EFMT1) { - int i; + if(*setting == _PASSWORD_EFMT1) + { + int i; /* * "new"-style: - * setting - underscore, 4 bytes of count, 4 bytes of salt - * key - unlimited characters + * setting - underscore, 4 bytes of count, 4 bytes of salt + * key - unlimited characters */ - for (i = 1, count = 0L; i < 5; i++) + for(i = 1, count = 0L; i < 5; i++) count |= ascii_to_bin(setting[i]) << ((i - 1) * 6); - for (i = 5, salt = 0L; i < 9; i++) + for(i = 5, salt = 0L; i < 9; i++) salt |= ascii_to_bin(setting[i]) << ((i - 5) * 6); - while (*key) { + while(*key) + { /* * Encrypt the key with itself. */ - if (des_cipher((char *)keybuf, (char *)keybuf, 0L, 1)) - return(NULL); + if(des_cipher((char *)keybuf, (char *)keybuf, 0L, 1)) + return (NULL); /* * And XOR with the next 8 characters of the key. */ - q = (u_char *)keybuf; - while (q - (u_char *)keybuf - 8 && *key) + q = (uint8_t *)keybuf; + while(q - (uint8_t *)keybuf - 8 && *key) *q++ ^= *key++ << 1; - if (des_setkey((char *)keybuf)) - return(NULL); + if(des_setkey((char *)keybuf)) + return (NULL); } strncpy(output, setting, 9); @@ -751,19 +764,19 @@ __des_crypt(const char *key, const char *setting) * NUL in it. */ output[9] = '\0'; - p = (u_char *)output + strlen(output); - } else + p = (uint8_t *)output + strlen(output); + } + else #endif { /* * "old"-style: - * setting - 2 bytes of salt - * key - up to 8 characters + * setting - 2 bytes of salt + * key - up to 8 characters */ count = 25; - salt = (ascii_to_bin(setting[1]) << 6) - | ascii_to_bin(setting[0]); + salt = (ascii_to_bin(setting[1]) << 6) | ascii_to_bin(setting[0]); output[0] = setting[0]; /* @@ -774,14 +787,14 @@ __des_crypt(const char *key, const char *setting) */ output[1] = setting[1] ? setting[1] : output[0]; - p = (u_char *)output + 2; + p = (uint8_t *)output + 2; } setup_salt(salt); /* * Do it. */ - if (do_des(0L, 0L, &r0, &r1, (int)count)) - return(NULL); + if(do_des(0L, 0L, &r0, &r1, (int)count)) + return (NULL); /* * Now encode the result... */ @@ -803,7 +816,7 @@ __des_crypt(const char *key, const char *setting) *p++ = ascii64[l & 0x3f]; *p = 0; - return(output); + return (output); } /* Now md5 crypt */ @@ -884,22 +897,23 @@ __des_crypt(const char *key, const char *setting) /**********************************************************************/ /* MD5 context. */ -struct MD5Context { - rb_uint32_t state[4]; /* state (ABCD) */ - rb_uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ +struct MD5Context +{ + uint32_t state[4]; /* state (ABCD) */ + uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ }; -static void __md5_Init (struct MD5Context *); -static void __md5_Update (struct MD5Context *, const char *, unsigned int); -static void __md5_Pad (struct MD5Context *); -static void __md5_Final (char [16], struct MD5Context *); -static void __md5_Transform (rb_uint32_t [4], const unsigned char [64]); +static void __md5_Init(struct MD5Context *); +static void __md5_Update(struct MD5Context *, const char *, unsigned int); +static void __md5_Pad(struct MD5Context *); +static void __md5_Final(char[16], struct MD5Context *); +static void __md5_Transform(uint32_t[4], const unsigned char[64]); static const char __md5__magic[] = "$1$"; /* This string is magic for this algorithm. Having it this way, we can get better later on */ -static const unsigned char __md5_itoa64[] = /* 0 ... 63 => ascii - 64 */ +static const unsigned char __md5_itoa64[] = /* 0 ... 63 => ascii - 64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -910,36 +924,37 @@ static const unsigned char __md5_itoa64[] = /* 0 ... 63 => ascii - 64 */ #else /* i386 */ /* - * __md5_Encodes input (rb_uint32_t) into output (unsigned char). Assumes len is + * __md5_Encodes input (uint32_t) into output (unsigned char). Assumes len is * a multiple of 4. */ static void -__md5_Encode (unsigned char *output, rb_uint32_t *input, unsigned int len) +__md5_Encode(unsigned char *output, uint32_t *input, unsigned int len) { unsigned int i, j; - for (i = 0, j = 0; j < len; i++, j += 4) { + for(i = 0, j = 0; j < len; i++, j += 4) + { output[j] = (unsigned char)(input[i] & 0xff); - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + output[j + 1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j + 2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j + 3] = (unsigned char)((input[i] >> 24) & 0xff); } } /* - * __md5_Decodes input (unsigned char) into output (rb_uint32_t). Assumes len is + * __md5_Decodes input (unsigned char) into output (uint32_t). Assumes len is * a multiple of 4. */ static void -__md5_Decode (rb_uint32_t *output, const unsigned char *input, unsigned int len) +__md5_Decode(uint32_t *output, const unsigned char *input, unsigned int len) { unsigned int i, j; - for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((rb_uint32_t)input[j]) | (((rb_uint32_t)input[j+1]) << 8) | - (((rb_uint32_t)input[j+2]) << 16) | (((rb_uint32_t)input[j+3]) << 24); + for(i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((uint32_t)input[j]) | (((uint32_t)input[j + 1]) << 8) | + (((uint32_t)input[j + 2]) << 16) | (((uint32_t)input[j + 3]) << 24); } #endif /* i386 */ @@ -957,29 +972,30 @@ __md5_Decode (rb_uint32_t *output, const unsigned char *input, unsigned int len) * Rotation is separate from addition to prevent recomputation. */ #define FF(a, b, c, d, x, s, ac) { \ - (a) += F ((b), (c), (d)) + (x) + (rb_uint32_t)(ac); \ + (a) += F ((b), (c), (d)) + (x) + (uint32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } #define GG(a, b, c, d, x, s, ac) { \ - (a) += G ((b), (c), (d)) + (x) + (rb_uint32_t)(ac); \ + (a) += G ((b), (c), (d)) + (x) + (uint32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } #define HH(a, b, c, d, x, s, ac) { \ - (a) += H ((b), (c), (d)) + (x) + (rb_uint32_t)(ac); \ + (a) += H ((b), (c), (d)) + (x) + (uint32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } #define II(a, b, c, d, x, s, ac) { \ - (a) += I ((b), (c), (d)) + (x) + (rb_uint32_t)(ac); \ + (a) += I ((b), (c), (d)) + (x) + (uint32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } /* MD5 initialization. Begins an MD5 operation, writing a new context. */ -static void __md5_Init (struct MD5Context *context) +static void +__md5_Init(struct MD5Context *context) { context->count[0] = context->count[1] = 0; @@ -996,29 +1012,29 @@ static void __md5_Init (struct MD5Context *context) * context. */ -static void __md5_Update ( struct MD5Context *context, const char *xinput, unsigned int inputLen) +static void +__md5_Update(struct MD5Context *context, const char *xinput, unsigned int inputLen) { unsigned int i, lindex, partLen; - const unsigned char *input = (const unsigned char *)xinput; /* i hate gcc */ + const unsigned char *input = (const unsigned char *)xinput; /* i hate gcc */ /* Compute number of bytes mod 64 */ lindex = (unsigned int)((context->count[0] >> 3) & 0x3F); /* Update number of bits */ - if ((context->count[0] += ((rb_uint32_t)inputLen << 3)) - < ((rb_uint32_t)inputLen << 3)) + if((context->count[0] += ((uint32_t)inputLen << 3)) < ((uint32_t)inputLen << 3)) context->count[1]++; - context->count[1] += ((rb_uint32_t)inputLen >> 29); + context->count[1] += ((uint32_t)inputLen >> 29); partLen = 64 - lindex; /* Transform as many times as possible. */ - if (inputLen >= partLen) { - memcpy(&context->buffer[lindex], input, - partLen); - __md5_Transform (context->state, context->buffer); + if(inputLen >= partLen) + { + memcpy(&context->buffer[lindex], input, partLen); + __md5_Transform(context->state, context->buffer); - for (i = partLen; i + 63 < inputLen; i += 64) - __md5_Transform (context->state, &input[i]); + for(i = partLen; i + 63 < inputLen; i += 64) + __md5_Transform(context->state, &input[i]); lindex = 0; } @@ -1026,15 +1042,15 @@ static void __md5_Update ( struct MD5Context *context, const char *xinput, unsig i = 0; /* Buffer remaining input */ - memcpy (&context->buffer[lindex], &input[i], - inputLen-i); + memcpy(&context->buffer[lindex], &input[i], inputLen - i); } /* * MD5 padding. Adds padding followed by original length. */ -static void __md5_Pad ( struct MD5Context *context) +static void +__md5_Pad(struct MD5Context *context) { char bits[8]; unsigned int lindex, padLen; @@ -1044,15 +1060,15 @@ static void __md5_Pad ( struct MD5Context *context) PADDING[0] = 0x80; /* Save number of bits */ - __md5_Encode (bits, context->count, 8); + __md5_Encode(bits, context->count, 8); /* Pad out to 56 mod 64. */ lindex = (unsigned int)((context->count[0] >> 3) & 0x3f); padLen = (lindex < 56) ? (56 - lindex) : (120 - lindex); - __md5_Update (context, PADDING, padLen); + __md5_Update(context, PADDING, padLen); /* Append length (before padding) */ - __md5_Update (context, bits, 8); + __md5_Update(context, bits, 8); } /* @@ -1060,30 +1076,31 @@ static void __md5_Pad ( struct MD5Context *context) * the message digest and zeroizing the context. */ -static void __md5_Final ( char xdigest[16], struct MD5Context *context) +static void +__md5_Final(char xdigest[16], struct MD5Context *context) { unsigned char *digest = (unsigned char *)xdigest; /* Do padding. */ - __md5_Pad (context); + __md5_Pad(context); /* Store state in digest */ - __md5_Encode (digest, context->state, 16); + __md5_Encode(digest, context->state, 16); /* Zeroize sensitive information. */ - memset (context, 0, sizeof (*context)); + memset(context, 0, sizeof(*context)); } /* MD5 basic transformation. Transforms state based on block. */ static void -__md5_Transform (state, block) - rb_uint32_t state[4]; - const unsigned char block[64]; +__md5_Transform(state, block) + uint32_t state[4]; + const unsigned char block[64]; { - rb_uint32_t a, b, c, d, x[16]; + uint32_t a, b, c, d, x[16]; #if MD5_SIZE_OVER_SPEED > 1 - rb_uint32_t temp; + uint32_t temp; const char *ps; static const char S[] = { @@ -1095,27 +1112,27 @@ __md5_Transform (state, block) #endif /* MD5_SIZE_OVER_SPEED > 1 */ #if MD5_SIZE_OVER_SPEED > 0 - const rb_uint32_t *pc; + const uint32_t *pc; const char *pp; int i; - static const rb_uint32_t C[] = { - /* round 1 */ + static const uint32_t C[] = { + /* round 1 */ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, - /* round 2 */ + /* round 2 */ 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, - 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, + 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, - /* round 3 */ + /* round 3 */ 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, - /* round 4 */ + /* round 4 */ 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, @@ -1123,103 +1140,141 @@ __md5_Transform (state, block) }; static const char P[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */ - 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */ - 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */ - 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */ + 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */ + 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */ + 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */ }; #endif /* MD5_SIZE_OVER_SPEED > 0 */ - __md5_Decode (x, block, 64); + __md5_Decode(x, block, 64); - a = state[0]; b = state[1]; c = state[2]; d = state[3]; + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; #if MD5_SIZE_OVER_SPEED > 2 - pc = C; pp = P; ps = S - 4; + pc = C; + pp = P; + ps = S - 4; - for ( i = 0 ; i < 64 ; i++ ) { - if ((i&0x0f) == 0) ps += 4; + for(i = 0; i < 64; i++) + { + if((i & 0x0f) == 0) + ps += 4; temp = a; - switch (i>>4) { - case 0: - temp += F(b,c,d); - break; - case 1: - temp += G(b,c,d); - break; - case 2: - temp += H(b,c,d); - break; - case 3: - temp += I(b,c,d); - break; + switch (i >> 4) + { + case 0: + temp += F(b, c, d); + break; + case 1: + temp += G(b, c, d); + break; + case 2: + temp += H(b, c, d); + break; + case 3: + temp += I(b, c, d); + break; } temp += x[(int)(*pp++)] + *pc++; - temp = ROTATE_LEFT(temp, ps[i&3]); + temp = ROTATE_LEFT(temp, ps[i & 3]); temp += b; - a = d; d = c; c = b; b = temp; + a = d; + d = c; + c = b; + b = temp; } #elif MD5_SIZE_OVER_SPEED > 1 - pc = C; pp = P; ps = S; + pc = C; + pp = P; + ps = S; /* Round 1 */ - for ( i = 0 ; i < 16 ; i++ ) { - FF (a, b, c, d, x[(int)(*pp++)], ps[i&0x3], *pc++); - temp = d; d = c; c = b; b = a; a = temp; + for(i = 0; i < 16; i++) + { + FF(a, b, c, d, x[(int)(*pp++)], ps[i & 0x3], *pc++); + temp = d; + d = c; + c = b; + b = a; + a = temp; } /* Round 2 */ ps += 4; - for ( ; i < 32 ; i++ ) { - GG (a, b, c, d, x[(int)(*pp++)], ps[i&0x3], *pc++); - temp = d; d = c; c = b; b = a; a = temp; + for(; i < 32; i++) + { + GG(a, b, c, d, x[(int)(*pp++)], ps[i & 0x3], *pc++); + temp = d; + d = c; + c = b; + b = a; + a = temp; } /* Round 3 */ ps += 4; - for ( ; i < 48 ; i++ ) { - HH (a, b, c, d, x[(int)(*pp++)], ps[i&0x3], *pc++); - temp = d; d = c; c = b; b = a; a = temp; + for(; i < 48; i++) + { + HH(a, b, c, d, x[(int)(*pp++)], ps[i & 0x3], *pc++); + temp = d; + d = c; + c = b; + b = a; + a = temp; } /* Round 4 */ ps += 4; - for ( ; i < 64 ; i++ ) { - II (a, b, c, d, x[(int)(*pp++)], ps[i&0x3], *pc++); - temp = d; d = c; c = b; b = a; a = temp; + for(; i < 64; i++) + { + II(a, b, c, d, x[(int)(*pp++)], ps[i & 0x3], *pc++); + temp = d; + d = c; + c = b; + b = a; + a = temp; } #elif MD5_SIZE_OVER_SPEED > 0 - pc = C; pp = P; + pc = C; + pp = P; /* Round 1 */ - for ( i = 0 ; i < 4 ; i++ ) { - FF (a, b, c, d, x[(int)(*pp++)], 7, *pc++); - FF (d, a, b, c, x[(int)(*pp++)], 12, *pc++); - FF (c, d, a, b, x[(int)(*pp++)], 17, *pc++); - FF (b, c, d, a, x[(int)(*pp++)], 22, *pc++); + for(i = 0; i < 4; i++) + { + FF(a, b, c, d, x[(int)(*pp++)], 7, *pc++); + FF(d, a, b, c, x[(int)(*pp++)], 12, *pc++); + FF(c, d, a, b, x[(int)(*pp++)], 17, *pc++); + FF(b, c, d, a, x[(int)(*pp++)], 22, *pc++); } /* Round 2 */ - for ( i = 0 ; i < 4 ; i++ ) { - GG (a, b, c, d, x[(int)(*pp++)], 5, *pc++); - GG (d, a, b, c, x[(int)(*pp++)], 9, *pc++); - GG (c, d, a, b, x[(int)(*pp++)], 14, *pc++); - GG (b, c, d, a, x[(int)(*pp++)], 20, *pc++); + for(i = 0; i < 4; i++) + { + GG(a, b, c, d, x[(int)(*pp++)], 5, *pc++); + GG(d, a, b, c, x[(int)(*pp++)], 9, *pc++); + GG(c, d, a, b, x[(int)(*pp++)], 14, *pc++); + GG(b, c, d, a, x[(int)(*pp++)], 20, *pc++); } /* Round 3 */ - for ( i = 0 ; i < 4 ; i++ ) { - HH (a, b, c, d, x[(int)(*pp++)], 4, *pc++); - HH (d, a, b, c, x[(int)(*pp++)], 11, *pc++); - HH (c, d, a, b, x[(int)(*pp++)], 16, *pc++); - HH (b, c, d, a, x[(int)(*pp++)], 23, *pc++); + for(i = 0; i < 4; i++) + { + HH(a, b, c, d, x[(int)(*pp++)], 4, *pc++); + HH(d, a, b, c, x[(int)(*pp++)], 11, *pc++); + HH(c, d, a, b, x[(int)(*pp++)], 16, *pc++); + HH(b, c, d, a, x[(int)(*pp++)], 23, *pc++); } /* Round 4 */ - for ( i = 0 ; i < 4 ; i++ ) { - II (a, b, c, d, x[(int)(*pp++)], 6, *pc++); - II (d, a, b, c, x[(int)(*pp++)], 10, *pc++); - II (c, d, a, b, x[(int)(*pp++)], 15, *pc++); - II (b, c, d, a, x[(int)(*pp++)], 21, *pc++); + for(i = 0; i < 4; i++) + { + II(a, b, c, d, x[(int)(*pp++)], 6, *pc++); + II(d, a, b, c, x[(int)(*pp++)], 10, *pc++); + II(c, d, a, b, x[(int)(*pp++)], 15, *pc++); + II(b, c, d, a, x[(int)(*pp++)], 21, *pc++); } #else /* Round 1 */ @@ -1227,88 +1282,88 @@ __md5_Transform (state, block) #define S12 12 #define S13 17 #define S14 22 - FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ - FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ - FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ - FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ - FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ - FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ - FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ - FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ - FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ - FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ - FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ - FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ - FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ - FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ - FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ - FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */ + FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */ + FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */ + FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */ + FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */ + FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */ + FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */ + FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */ + FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */ + FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */ + FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ /* Round 2 */ #define S21 5 #define S22 9 #define S23 14 #define S24 20 - GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ - GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ - GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ - GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ - GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ - GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ - GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ - GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ - GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ - GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ - GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ - GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ - GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ - GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ - GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ - GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */ + GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */ + GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */ + GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */ + GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */ + GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */ + GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */ + GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */ + GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */ + GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */ + GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ /* Round 3 */ #define S31 4 #define S32 11 #define S33 16 #define S34 23 - HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ - HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ - HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ - HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ - HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ - HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ - HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ - HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ - HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ - HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ - HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ - HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ - HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ - HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ - HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ - HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ + HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */ + HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */ + HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */ + HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */ + HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */ + HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */ + HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */ + HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */ + HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */ + HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */ /* Round 4 */ #define S41 6 #define S42 10 #define S43 15 #define S44 21 - II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ - II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ - II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ - II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ - II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ - II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ - II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ - II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ - II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ - II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ - II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ - II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ - II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ - II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ - II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ - II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ + II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */ + II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */ + II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */ + II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */ + II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */ + II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */ + II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */ + II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */ + II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */ + II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */ #endif state[0] += a; @@ -1317,14 +1372,16 @@ __md5_Transform (state, block) state[3] += d; /* Zeroize sensitive information. */ - memset (x, 0, sizeof (x)); + memset(x, 0, sizeof(x)); } -static void __md5_to64( char *s, unsigned long v, int n) +static void +__md5_to64(char *s, unsigned long v, int n) { - while (--n >= 0) { - *s++ = __md5_itoa64[v&0x3f]; + while(--n >= 0) + { + *s++ = __md5_itoa64[v & 0x3f]; v >>= 6; } } @@ -1335,15 +1392,16 @@ static void __md5_to64( char *s, unsigned long v, int n) * Use MD5 for what it is best at... */ -static char * __md5_crypt( const char *pw, const char *salt) +static char * +__md5_crypt(const char *pw, const char *salt) { /* Static stuff */ static const char *sp, *ep; static char passwd[120], *p; - char final[17]; /* final[16] exists only to aid in looping */ - int sl,pl,i,__md5__magic_len,pw_len; - struct MD5Context ctx,ctx1; + char final[17]; /* final[16] exists only to aid in looping */ + int sl, pl, i, __md5__magic_len, pw_len; + struct MD5Context ctx, ctx1; unsigned long l; /* Refine the Salt first */ @@ -1351,11 +1409,11 @@ static char * __md5_crypt( const char *pw, const char *salt) /* If it starts with the magic string, then skip that */ __md5__magic_len = strlen(__md5__magic); - if(!strncmp(sp,__md5__magic,__md5__magic_len)) + if(!strncmp(sp, __md5__magic, __md5__magic_len)) sp += __md5__magic_len; /* It stops at the first '$', max 8 chars */ - for(ep=sp;*ep && *ep != '$' && ep < (sp+8);ep++) + for(ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++) continue; /* get the length of the true salt */ @@ -1365,79 +1423,83 @@ static char * __md5_crypt( const char *pw, const char *salt) /* The password first, since that is what is most unknown */ pw_len = strlen(pw); - __md5_Update(&ctx,pw,pw_len); + __md5_Update(&ctx, pw, pw_len); /* Then our magic string */ - __md5_Update(&ctx,__md5__magic,__md5__magic_len); + __md5_Update(&ctx, __md5__magic, __md5__magic_len); /* Then the raw salt */ - __md5_Update(&ctx,sp,sl); + __md5_Update(&ctx, sp, sl); /* Then just as many characters of the MD5(pw,salt,pw) */ __md5_Init(&ctx1); - __md5_Update(&ctx1,pw,pw_len); - __md5_Update(&ctx1,sp,sl); - __md5_Update(&ctx1,pw,pw_len); - __md5_Final(final,&ctx1); + __md5_Update(&ctx1, pw, pw_len); + __md5_Update(&ctx1, sp, sl); + __md5_Update(&ctx1, pw, pw_len); + __md5_Final(final, &ctx1); for(pl = pw_len; pl > 0; pl -= 16) - __md5_Update(&ctx,final,pl>16 ? 16 : pl); + __md5_Update(&ctx, final, pl > 16 ? 16 : pl); /* Don't leave anything around in vm they could use. */ - memset(final,0,sizeof final); + memset(final, 0, sizeof final); /* Then something really weird... */ - for (i = pw_len; i ; i >>= 1) { - __md5_Update(&ctx, ((i&1) ? final : pw), 1); + for(i = pw_len; i; i >>= 1) + { + __md5_Update(&ctx, ((i & 1) ? final : pw), 1); } /* Now make the output string */ - strcpy(passwd,__md5__magic); - strncat(passwd,sp,sl); - strcat(passwd,"$"); + strcpy(passwd, __md5__magic); + strncat(passwd, sp, sl); + strcat(passwd, "$"); - __md5_Final(final,&ctx); + __md5_Final(final, &ctx); /* * and now, just to make sure things don't run too fast * On a 60 Mhz Pentium this takes 34 msec, so you would * need 30 seconds to build a 1000 entry dictionary... */ - for(i=0;i<1000;i++) { + for(i = 0; i < 1000; i++) + { __md5_Init(&ctx1); if(i & 1) - __md5_Update(&ctx1,pw,pw_len); + __md5_Update(&ctx1, pw, pw_len); else - __md5_Update(&ctx1,final,16); + __md5_Update(&ctx1, final, 16); if(i % 3) - __md5_Update(&ctx1,sp,sl); + __md5_Update(&ctx1, sp, sl); if(i % 7) - __md5_Update(&ctx1,pw,pw_len); + __md5_Update(&ctx1, pw, pw_len); if(i & 1) - __md5_Update(&ctx1,final,16); + __md5_Update(&ctx1, final, 16); else - __md5_Update(&ctx1,pw,pw_len); - __md5_Final(final,&ctx1); + __md5_Update(&ctx1, pw, pw_len); + __md5_Final(final, &ctx1); } p = passwd + strlen(passwd); final[16] = final[5]; - for ( i=0 ; i < 5 ; i++ ) { - l = (final[i]<<16) | (final[i+6]<<8) | final[i+12]; - __md5_to64(p,l,4); p += 4; + for(i = 0; i < 5; i++) + { + l = (final[i] << 16) | (final[i + 6] << 8) | final[i + 12]; + __md5_to64(p, l, 4); + p += 4; } l = final[11]; - __md5_to64(p,l,2); p += 2; + __md5_to64(p, l, 2); + p += 2; *p = '\0'; /* Don't leave anything around in vm they could use. */ - memset(final,0,sizeof final); + memset(final, 0, sizeof final); return passwd; } #endif /* NEED_CRYPT */ -