char *DES_fcrypt(const char *buf, const char *salt, char *ret) { unsigned int i, j, x, y; DES_LONG Eswap0, Eswap1; DES_LONG out[2], ll; DES_cblock key; DES_key_schedule ks; unsigned char bb[9]; unsigned char *b = bb; unsigned char c, u; x = ret[0] = salt[0]; if (x == 0 || x >= sizeof(con_salt)) return NULL; Eswap0 = con_salt[x] << 2; x = ret[1] = salt[1]; if (x == 0 || x >= sizeof(con_salt)) return NULL; Eswap1 = con_salt[x] << 6; /* * EAY r=strlen(buf); r=(r+7)/8; */ for (i = 0; i < 8; i++) { c = *(buf++); if (!c) break; key[i] = (c << 1); } for (; i < 8; i++) key[i] = 0; DES_set_key_unchecked(&key, &ks); fcrypt_body(&(out[0]), &ks, Eswap0, Eswap1); ll = out[0]; l2c(ll, b); ll = out[1]; l2c(ll, b); y = 0; u = 0x80; bb[8] = 0; for (i = 2; i < 13; i++) { c = 0; for (j = 0; j < 6; j++) { c <<= 1; if (bb[y] & u) c |= 1; u >>= 1; if (!u) { y++; u = 0x80; } } ret[i] = cov_2char[c]; } ret[13] = '\0'; return ret; }
EXPORT_C char *DES_fcrypt(const char *buf, const char *salt, char *ret) { unsigned int i,j,x,y; DES_LONG Eswap0,Eswap1; DES_LONG out[2],ll; DES_cblock key; DES_key_schedule ks; unsigned char bb[9]; unsigned char *b=bb; unsigned char c,u; /* eay 25/08/92 * If you call crypt("pwd","*") as often happens when you * have * as the pwd field in /etc/passwd, the function * returns *\0XXXXXXXXX * The \0 makes the string look like * so the pwd "*" would * crypt to "*". This was found when replacing the crypt in * our shared libraries. People found that the disabled * accounts effectively had no passwd :-(. */ #ifndef CHARSET_EBCDIC x=ret[0]=((salt[0] == '\0')?'A':salt[0]); Eswap0=con_salt[x]<<2; x=ret[1]=((salt[1] == '\0')?'A':salt[1]); Eswap1=con_salt[x]<<6; #else x=ret[0]=((salt[0] == '\0')?os_toascii['A']:salt[0]); Eswap0=con_salt[x]<<2; x=ret[1]=((salt[1] == '\0')?os_toascii['A']:salt[1]); Eswap1=con_salt[x]<<6; #endif /* EAY r=strlen(buf); r=(r+7)/8; */ for (i=0; i<8; i++) { c= *(buf++); if (!c) break; key[i]=(c<<1); } for (; i<8; i++) key[i]=0; DES_set_key_unchecked(&key,&ks); fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1); ll=out[0]; l2c(ll,b); ll=out[1]; l2c(ll,b); y=0; u=0x80; bb[8]=0; for (i=2; i<13; i++) { c=0; for (j=0; j<6; j++) { c<<=1; if (bb[y] & u) c|=1; u>>=1; if (!u) { y++; u=0x80; } } ret[i]=cov_2char[c]; } ret[13]='\0'; return(ret); }