diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libssl/src/crypto/des/fcrypt.c | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libssl/src/crypto/des/fcrypt.c')
-rw-r--r-- | src/lib/libssl/src/crypto/des/fcrypt.c | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/src/lib/libssl/src/crypto/des/fcrypt.c b/src/lib/libssl/src/crypto/des/fcrypt.c index 9b21f81cc2..d3d27de9f7 100644 --- a/src/lib/libssl/src/crypto/des/fcrypt.c +++ b/src/lib/libssl/src/crypto/des/fcrypt.c | |||
@@ -50,48 +50,55 @@ static unsigned const char cov_2char[64]={ | |||
50 | 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A | 50 | 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A |
51 | }; | 51 | }; |
52 | 52 | ||
53 | #ifndef NOPROTO | 53 | void fcrypt_body(DES_LONG *out,DES_key_schedule *ks, |
54 | void fcrypt_body(DES_LONG *out,des_key_schedule ks, | 54 | DES_LONG Eswap0, DES_LONG Eswap1); |
55 | DES_LONG Eswap0, DES_LONG Eswap1); | ||
56 | 55 | ||
57 | #if defined(PERL5) || defined(FreeBSD) || defined(__OpenBSD__) | 56 | char *DES_crypt(const char *buf, const char *salt) |
58 | char *des_crypt(const char *buf,const char *salt); | ||
59 | #else | ||
60 | char *crypt(const char *buf,const char *salt); | ||
61 | #endif | ||
62 | #else | ||
63 | void fcrypt_body(); | ||
64 | #ifdef PERL5 | ||
65 | char *des_crypt(); | ||
66 | #else | ||
67 | char *crypt(); | ||
68 | #endif | ||
69 | #endif | ||
70 | |||
71 | #if defined(PERL5) || defined(FreeBSD) || defined(__OpenBSD__) | ||
72 | char *des_crypt(buf,salt) | ||
73 | #else | ||
74 | char *crypt(buf,salt) | ||
75 | #endif | ||
76 | const char *buf; | ||
77 | const char *salt; | ||
78 | { | 57 | { |
79 | static char buff[14]; | 58 | static char buff[14]; |
80 | 59 | ||
81 | return(des_fcrypt(buf,salt,buff)); | 60 | #ifndef CHARSET_EBCDIC |
61 | return(DES_fcrypt(buf,salt,buff)); | ||
62 | #else | ||
63 | char e_salt[2+1]; | ||
64 | char e_buf[32+1]; /* replace 32 by 8 ? */ | ||
65 | char *ret; | ||
66 | |||
67 | /* Copy at most 2 chars of salt */ | ||
68 | if ((e_salt[0] = salt[0]) != '\0') | ||
69 | e_salt[1] = salt[1]; | ||
70 | |||
71 | /* Copy at most 32 chars of password */ | ||
72 | strncpy (e_buf, buf, sizeof(e_buf)); | ||
73 | |||
74 | /* Make sure we have a delimiter */ | ||
75 | e_salt[sizeof(e_salt)-1] = e_buf[sizeof(e_buf)-1] = '\0'; | ||
76 | |||
77 | /* Convert the e_salt to ASCII, as that's what DES_fcrypt works on */ | ||
78 | ebcdic2ascii(e_salt, e_salt, sizeof e_salt); | ||
79 | |||
80 | /* Convert the cleartext password to ASCII */ | ||
81 | ebcdic2ascii(e_buf, e_buf, sizeof e_buf); | ||
82 | |||
83 | /* Encrypt it (from/to ASCII) */ | ||
84 | ret = DES_fcrypt(e_buf,e_salt,buff); | ||
85 | |||
86 | /* Convert the result back to EBCDIC */ | ||
87 | ascii2ebcdic(ret, ret, strlen(ret)); | ||
88 | |||
89 | return ret; | ||
90 | #endif | ||
82 | } | 91 | } |
83 | 92 | ||
84 | 93 | ||
85 | char *des_fcrypt(buf,salt,ret) | 94 | |
86 | const char *buf; | 95 | char *DES_fcrypt(const char *buf, const char *salt, char *ret) |
87 | const char *salt; | ||
88 | char *ret; | ||
89 | { | 96 | { |
90 | unsigned int i,j,x,y; | 97 | unsigned int i,j,x,y; |
91 | DES_LONG Eswap0,Eswap1; | 98 | DES_LONG Eswap0,Eswap1; |
92 | DES_LONG out[2],ll; | 99 | DES_LONG out[2],ll; |
93 | des_cblock key; | 100 | DES_cblock key; |
94 | des_key_schedule ks; | 101 | DES_key_schedule ks; |
95 | unsigned char bb[9]; | 102 | unsigned char bb[9]; |
96 | unsigned char *b=bb; | 103 | unsigned char *b=bb; |
97 | unsigned char c,u; | 104 | unsigned char c,u; |
@@ -104,10 +111,17 @@ char *ret; | |||
104 | * crypt to "*". This was found when replacing the crypt in | 111 | * crypt to "*". This was found when replacing the crypt in |
105 | * our shared libraries. People found that the disabled | 112 | * our shared libraries. People found that the disabled |
106 | * accounts effectively had no passwd :-(. */ | 113 | * accounts effectively had no passwd :-(. */ |
114 | #ifndef CHARSET_EBCDIC | ||
107 | x=ret[0]=((salt[0] == '\0')?'A':salt[0]); | 115 | x=ret[0]=((salt[0] == '\0')?'A':salt[0]); |
108 | Eswap0=con_salt[x]<<2; | 116 | Eswap0=con_salt[x]<<2; |
109 | x=ret[1]=((salt[1] == '\0')?'A':salt[1]); | 117 | x=ret[1]=((salt[1] == '\0')?'A':salt[1]); |
110 | Eswap1=con_salt[x]<<6; | 118 | Eswap1=con_salt[x]<<6; |
119 | #else | ||
120 | x=ret[0]=((salt[0] == '\0')?os_toascii['A']:salt[0]); | ||
121 | Eswap0=con_salt[x]<<2; | ||
122 | x=ret[1]=((salt[1] == '\0')?os_toascii['A']:salt[1]); | ||
123 | Eswap1=con_salt[x]<<6; | ||
124 | #endif | ||
111 | 125 | ||
112 | /* EAY | 126 | /* EAY |
113 | r=strlen(buf); | 127 | r=strlen(buf); |
@@ -122,8 +136,8 @@ r=(r+7)/8; | |||
122 | for (; i<8; i++) | 136 | for (; i<8; i++) |
123 | key[i]=0; | 137 | key[i]=0; |
124 | 138 | ||
125 | des_set_key_unchecked(&key,ks); | 139 | DES_set_key_unchecked(&key,&ks); |
126 | fcrypt_body(&(out[0]),ks,Eswap0,Eswap1); | 140 | fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1); |
127 | 141 | ||
128 | ll=out[0]; l2c(ll,b); | 142 | ll=out[0]; l2c(ll,b); |
129 | ll=out[1]; l2c(ll,b); | 143 | ll=out[1]; l2c(ll,b); |
@@ -149,4 +163,3 @@ r=(r+7)/8; | |||
149 | ret[13]='\0'; | 163 | ret[13]='\0'; |
150 | return(ret); | 164 | return(ret); |
151 | } | 165 | } |
152 | |||