#include <string.h>
#include "ufc-crypt.h"
#include "crypt.h"
#include "crypt-private.h"
Include dependency graph for crypt-entry.cpp:
Go to the source code of this file.
Defines | |
#define | STATIC static |
Functions | |
void | _ufc_setup_salt_r (const char *s, struct crypt_data *__data) |
void | _ufc_mk_keytab_r (char *key, struct crypt_data *__data) |
void | _ufc_dofinalperm_r (ufc_long *res, struct crypt_data *__data) |
void | _ufc_output_conversion_r (ufc_long v1, ufc_long v2, const char *salt, struct crypt_data *__data) |
char * | __md5_crypt_r (const char *key, const char *salt, char *buffer, int buflen) |
char * | __md5_crypt (const char *key, const char *salt) |
char * | crypt_r (const char *key, const char *salt, struct crypt_data *data) |
char * | crypt (const char *key, const char *salt) |
char * | __fcrypt (const char *key, const char *salt) |
Variables | |
static const char | md5_salt_prefix [] = "$1$" |
crypt_data | _ufc_foobar |
#define STATIC static |
Definition at line 33 of file crypt-entry.cpp.
char* __fcrypt | ( | const char * | key, | |
const char * | salt | |||
) |
Definition at line 138 of file crypt-entry.cpp.
References crypt().
00139 { 00140 return crypt (key, salt); 00141 }
char* __md5_crypt | ( | const char * | key, | |
const char * | salt | |||
) |
Referenced by crypt().
char* __md5_crypt_r | ( | const char * | key, | |
const char * | salt, | |||
char * | buffer, | |||
int | buflen | |||
) |
Referenced by crypt_r().
void _ufc_dofinalperm_r | ( | ufc_long * | res, | |
struct crypt_data * | __data | |||
) |
Definition at line 659 of file crypt_util.cpp.
Referenced by __encrypt_r(), and crypt_r().
00660 { 00661 ufc_long v1, v2, x; 00662 ufc_long l1,l2,r1,r2; 00663 00664 l1 = res[0]; l2 = res[1]; 00665 r1 = res[2]; r2 = res[3]; 00666 00667 x = (l1 ^ l2) & __data->current_saltbits; l1 ^= x; l2 ^= x; 00668 x = (r1 ^ r2) & __data->current_saltbits; r1 ^= x; r2 ^= x; 00669 00670 v1=v2=0; l1 >>= 3; l2 >>= 3; r1 >>= 3; r2 >>= 3; 00671 00672 v1 |= efp[15][ r2 & 0x3f][0]; v2 |= efp[15][ r2 & 0x3f][1]; 00673 v1 |= efp[14][(r2 >>= 6) & 0x3f][0]; v2 |= efp[14][ r2 & 0x3f][1]; 00674 v1 |= efp[13][(r2 >>= 10) & 0x3f][0]; v2 |= efp[13][ r2 & 0x3f][1]; 00675 v1 |= efp[12][(r2 >>= 6) & 0x3f][0]; v2 |= efp[12][ r2 & 0x3f][1]; 00676 00677 v1 |= efp[11][ r1 & 0x3f][0]; v2 |= efp[11][ r1 & 0x3f][1]; 00678 v1 |= efp[10][(r1 >>= 6) & 0x3f][0]; v2 |= efp[10][ r1 & 0x3f][1]; 00679 v1 |= efp[ 9][(r1 >>= 10) & 0x3f][0]; v2 |= efp[ 9][ r1 & 0x3f][1]; 00680 v1 |= efp[ 8][(r1 >>= 6) & 0x3f][0]; v2 |= efp[ 8][ r1 & 0x3f][1]; 00681 00682 v1 |= efp[ 7][ l2 & 0x3f][0]; v2 |= efp[ 7][ l2 & 0x3f][1]; 00683 v1 |= efp[ 6][(l2 >>= 6) & 0x3f][0]; v2 |= efp[ 6][ l2 & 0x3f][1]; 00684 v1 |= efp[ 5][(l2 >>= 10) & 0x3f][0]; v2 |= efp[ 5][ l2 & 0x3f][1]; 00685 v1 |= efp[ 4][(l2 >>= 6) & 0x3f][0]; v2 |= efp[ 4][ l2 & 0x3f][1]; 00686 00687 v1 |= efp[ 3][ l1 & 0x3f][0]; v2 |= efp[ 3][ l1 & 0x3f][1]; 00688 v1 |= efp[ 2][(l1 >>= 6) & 0x3f][0]; v2 |= efp[ 2][ l1 & 0x3f][1]; 00689 v1 |= efp[ 1][(l1 >>= 10) & 0x3f][0]; v2 |= efp[ 1][ l1 & 0x3f][1]; 00690 v1 |= efp[ 0][(l1 >>= 6) & 0x3f][0]; v2 |= efp[ 0][ l1 & 0x3f][1]; 00691 00692 res[0] = v1; res[1] = v2; 00693 }
void _ufc_mk_keytab_r | ( | char * | key, | |
struct crypt_data * | __data | |||
) |
Definition at line 601 of file crypt_util.cpp.
Referenced by __setkey_r(), and crypt_r().
00602 { 00603 ufc_long v1, v2, *k1; 00604 int i; 00605 #ifdef _UFC_32_ 00606 long32 v, *k2; 00607 k2 = (long32*)__data->keysched; 00608 #endif 00609 #ifdef _UFC_64_ 00610 long64 v, *k2; 00611 k2 = (long64*)__data->keysched; 00612 #endif 00613 00614 v1 = v2 = 0; k1 = &do_pc1[0][0][0]; 00615 for(i = 8; i--;) { 00616 v1 |= k1[*key & 0x7f]; k1 += 128; 00617 v2 |= k1[*key++ & 0x7f]; k1 += 128; 00618 } 00619 00620 for(i = 0; i < 16; i++) { 00621 k1 = &do_pc2[0][0]; 00622 00623 v1 = (v1 << rots[i]) | (v1 >> (28 - rots[i])); 00624 v = k1[(v1 >> 21) & 0x7f]; k1 += 128; 00625 v |= k1[(v1 >> 14) & 0x7f]; k1 += 128; 00626 v |= k1[(v1 >> 7) & 0x7f]; k1 += 128; 00627 v |= k1[(v1 ) & 0x7f]; k1 += 128; 00628 00629 #ifdef _UFC_32_ 00630 *k2++ = (v | 0x00008000); 00631 v = 0; 00632 #endif 00633 #ifdef _UFC_64_ 00634 v = (v << 32); 00635 #endif 00636 00637 v2 = (v2 << rots[i]) | (v2 >> (28 - rots[i])); 00638 v |= k1[(v2 >> 21) & 0x7f]; k1 += 128; 00639 v |= k1[(v2 >> 14) & 0x7f]; k1 += 128; 00640 v |= k1[(v2 >> 7) & 0x7f]; k1 += 128; 00641 v |= k1[(v2 ) & 0x7f]; 00642 00643 #ifdef _UFC_32_ 00644 *k2++ = (v | 0x00008000); 00645 #endif 00646 #ifdef _UFC_64_ 00647 *k2++ = v | 0x0000800000008000l; 00648 #endif 00649 } 00650 00651 __data->direction = 0; 00652 }
void _ufc_output_conversion_r | ( | ufc_long | v1, | |
ufc_long | v2, | |||
const char * | salt, | |||
struct crypt_data * | __data | |||
) |
Definition at line 701 of file crypt_util.cpp.
Referenced by crypt_r().
00702 { 00703 int i, s, shf; 00704 00705 __data->crypt_3_buf[0] = salt[0]; 00706 __data->crypt_3_buf[1] = salt[1] ? salt[1] : salt[0]; 00707 00708 for(i = 0; i < 5; i++) { 00709 shf = (26 - 6 * i); /* to cope with MSC compiler bug */ 00710 __data->crypt_3_buf[i + 2] = bin_to_ascii((v1 >> shf) & 0x3f); 00711 } 00712 00713 s = (v2 & 0xf) << 2; 00714 v2 = (v2 >> 2) | ((v1 & 0x3) << 30); 00715 00716 for(i = 5; i < 10; i++) { 00717 shf = (56 - 6 * i); 00718 __data->crypt_3_buf[i + 2] = bin_to_ascii((v2 >> shf) & 0x3f); 00719 } 00720 00721 __data->crypt_3_buf[12] = bin_to_ascii(s); 00722 __data->crypt_3_buf[13] = 0; 00723 }
void _ufc_setup_salt_r | ( | const char * | s, | |
struct crypt_data * | __data | |||
) |
Definition at line 555 of file crypt_util.cpp.
Referenced by __encrypt_r(), __setkey_r(), and crypt_r().
00556 { 00557 ufc_long i, j, saltbits; 00558 00559 if(__data->initialized == 0) 00560 __init_des_r(__data); 00561 00562 if(s[0] == __data->current_salt[0] && s[1] == __data->current_salt[1]) 00563 return; 00564 __data->current_salt[0] = s[0]; __data->current_salt[1] = s[1]; 00565 00566 /* 00567 * This is the only crypt change to DES: 00568 * entries are swapped in the expansion table 00569 * according to the bits set in the salt. 00570 */ 00571 saltbits = 0; 00572 for(i = 0; i < 2; i++) { 00573 long c=ascii_to_bin(s[i]); 00574 for(j = 0; j < 6; j++) { 00575 if((c >> j) & 0x1) 00576 saltbits |= BITMASK[6 * i + j]; 00577 } 00578 } 00579 00580 /* 00581 * Permute the sb table values 00582 * to reflect the changed e 00583 * selection table 00584 */ 00585 #ifdef _UFC_32_ 00586 #define LONGG long32* 00587 #endif 00588 #ifdef _UFC_64_ 00589 #define LONGG long64* 00590 #endif 00591 00592 shuffle_sb((LONGG)__data->sb0, __data->current_saltbits ^ saltbits); 00593 shuffle_sb((LONGG)__data->sb1, __data->current_saltbits ^ saltbits); 00594 shuffle_sb((LONGG)__data->sb2, __data->current_saltbits ^ saltbits); 00595 shuffle_sb((LONGG)__data->sb3, __data->current_saltbits ^ saltbits); 00596 00597 __data->current_saltbits = saltbits; 00598 }
char* crypt | ( | const char * | key, | |
const char * | salt | |||
) |
Definition at line 118 of file crypt-entry.cpp.
Referenced by __fcrypt(), and mux_crypt().
00119 { 00120 #ifdef _LIBC 00121 /* Try to find out whether we have to use MD5 encryption replacement. */ 00122 if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0) 00123 return __md5_crypt (key, salt); 00124 #endif 00125 00126 return crypt_r (key, salt, &_ufc_foobar); 00127 }
char* crypt_r | ( | const char * | key, | |
const char * | salt, | |||
struct crypt_data * | data | |||
) |
Definition at line 74 of file crypt-entry.cpp.
References __md5_crypt_r(), _ufc_dofinalperm_r(), _ufc_doit_r(), _ufc_mk_keytab_r(), _ufc_output_conversion_r(), _ufc_setup_salt_r(), and md5_salt_prefix.
Referenced by crypt().
00075 { 00076 ufc_long res[4]; 00077 char ktab[9]; 00078 ufc_long xx = 25; /* to cope with GCC long long compiler bugs */ 00079 00080 #ifdef _LIBC 00081 /* Try to find out whether we have to use MD5 encryption replacement. */ 00082 if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0) 00083 return __md5_crypt_r (key, salt, (char *) data, 00084 sizeof (struct crypt_data)); 00085 #endif 00086 00087 /* 00088 * Hack DES tables according to salt 00089 */ 00090 _ufc_setup_salt_r (salt, data); 00091 00092 /* 00093 * Setup key schedule 00094 */ 00095 memset(ktab, 0, sizeof(ktab)); 00096 strncpy (ktab, key, 8); 00097 _ufc_mk_keytab_r (ktab, data); 00098 00099 /* 00100 * Go for the 25 DES encryptions 00101 */ 00102 memset(res, 0, sizeof (res)); 00103 _ufc_doit_r (xx, data, &res[0]); 00104 00105 /* 00106 * Do final permutations 00107 */ 00108 _ufc_dofinalperm_r (res, data); 00109 00110 /* 00111 * And convert back to 6 bit ASCII 00112 */ 00113 _ufc_output_conversion_r (res[0], res[1], salt, data); 00114 return data->crypt_3_buf; 00115 }
struct crypt_data _ufc_foobar |
Definition at line 259 of file crypt_util.cpp.
Referenced by __init_des(), crypt(), encrypt(), and setkey().
const char md5_salt_prefix[] = "$1$" [static] |