diff options
author | markus <> | 2002-09-05 12:51:52 +0000 |
---|---|---|
committer | markus <> | 2002-09-05 12:51:52 +0000 |
commit | 5514995a9d5ed91db089875adb509c7781357c0e (patch) | |
tree | 2484410a46ba6c05ef94c253da36fbceef990b64 /src/lib/libssl/src/crypto/des/fcrypt.c | |
parent | fd9566423b542798f5c8b06e68101a9ea5bb9885 (diff) | |
download | openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.gz openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.bz2 openbsd-5514995a9d5ed91db089875adb509c7781357c0e.zip |
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libssl/src/crypto/des/fcrypt.c')
-rw-r--r-- | src/lib/libssl/src/crypto/des/fcrypt.c | 96 |
1 files changed, 58 insertions, 38 deletions
diff --git a/src/lib/libssl/src/crypto/des/fcrypt.c b/src/lib/libssl/src/crypto/des/fcrypt.c index 129beb27da..2758c32656 100644 --- a/src/lib/libssl/src/crypto/des/fcrypt.c +++ b/src/lib/libssl/src/crypto/des/fcrypt.c | |||
@@ -1,9 +1,16 @@ | |||
1 | /* NOCW */ | 1 | /* NOCW */ |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #ifdef _OSD_POSIX | ||
4 | #ifndef CHARSET_EBCDIC | ||
5 | #define CHARSET_EBCDIC 1 | ||
6 | #endif | ||
7 | #endif | ||
8 | #ifdef CHARSET_EBCDIC | ||
9 | #include <openssl/ebcdic.h> | ||
10 | #endif | ||
3 | 11 | ||
4 | /* This version of crypt has been developed from my MIT compatable | 12 | /* This version of crypt has been developed from my MIT compatible |
5 | * DES library. | 13 | * DES library. |
6 | * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au | ||
7 | * Eric Young (eay@cryptsoft.com) | 14 | * Eric Young (eay@cryptsoft.com) |
8 | */ | 15 | */ |
9 | 16 | ||
@@ -11,7 +18,7 @@ | |||
11 | * I have included directive PARA for shared memory computers. | 18 | * I have included directive PARA for shared memory computers. |
12 | * I have included a directive LONGCRYPT to using this routine to cipher | 19 | * I have included a directive LONGCRYPT to using this routine to cipher |
13 | * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN | 20 | * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN |
14 | * definition is the maximum of lenght of password and can changed. I have | 21 | * definition is the maximum of length of password and can changed. I have |
15 | * defined 24. | 22 | * defined 24. |
16 | */ | 23 | */ |
17 | 24 | ||
@@ -51,48 +58,54 @@ static unsigned const char cov_2char[64]={ | |||
51 | 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A | 58 | 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A |
52 | }; | 59 | }; |
53 | 60 | ||
54 | #ifndef NOPROTO | 61 | void fcrypt_body(DES_LONG *out,DES_key_schedule *ks, |
55 | void fcrypt_body(DES_LONG *out,des_key_schedule ks, | 62 | DES_LONG Eswap0, DES_LONG Eswap1); |
56 | DES_LONG Eswap0, DES_LONG Eswap1); | ||
57 | 63 | ||
58 | #if defined(PERL5) || defined(FreeBSD) | 64 | char *DES_crypt(const char *buf, const char *salt) |
59 | char *des_crypt(const char *buf,const char *salt); | ||
60 | #else | ||
61 | char *crypt(const char *buf,const char *salt); | ||
62 | #endif | ||
63 | #else | ||
64 | void fcrypt_body(); | ||
65 | #ifdef PERL5 | ||
66 | char *des_crypt(); | ||
67 | #else | ||
68 | char *crypt(); | ||
69 | #endif | ||
70 | #endif | ||
71 | |||
72 | #if defined(PERL5) || defined(FreeBSD) | ||
73 | char *des_crypt(buf,salt) | ||
74 | #else | ||
75 | char *crypt(buf,salt) | ||
76 | #endif | ||
77 | const char *buf; | ||
78 | const char *salt; | ||
79 | { | 65 | { |
80 | static char buff[14]; | 66 | static char buff[14]; |
81 | 67 | ||
82 | return(des_fcrypt(buf,salt,buff)); | 68 | #ifndef CHARSET_EBCDIC |
69 | return(DES_fcrypt(buf,salt,buff)); | ||
70 | #else | ||
71 | char e_salt[2+1]; | ||
72 | char e_buf[32+1]; /* replace 32 by 8 ? */ | ||
73 | char *ret; | ||
74 | |||
75 | /* Copy at most 2 chars of salt */ | ||
76 | if ((e_salt[0] = salt[0]) != '\0') | ||
77 | e_salt[1] = salt[1]; | ||
78 | |||
79 | /* Copy at most 32 chars of password */ | ||
80 | strncpy (e_buf, buf, sizeof(e_buf)); | ||
81 | |||
82 | /* Make sure we have a delimiter */ | ||
83 | e_salt[sizeof(e_salt)-1] = e_buf[sizeof(e_buf)-1] = '\0'; | ||
84 | |||
85 | /* Convert the e_salt to ASCII, as that's what DES_fcrypt works on */ | ||
86 | ebcdic2ascii(e_salt, e_salt, sizeof e_salt); | ||
87 | |||
88 | /* Convert the cleartext password to ASCII */ | ||
89 | ebcdic2ascii(e_buf, e_buf, sizeof e_buf); | ||
90 | |||
91 | /* Encrypt it (from/to ASCII) */ | ||
92 | ret = DES_fcrypt(e_buf,e_salt,buff); | ||
93 | |||
94 | /* Convert the result back to EBCDIC */ | ||
95 | ascii2ebcdic(ret, ret, strlen(ret)); | ||
96 | |||
97 | return ret; | ||
98 | #endif | ||
83 | } | 99 | } |
84 | 100 | ||
85 | 101 | ||
86 | char *des_fcrypt(buf,salt,ret) | 102 | char *DES_fcrypt(const char *buf, const char *salt, char *ret) |
87 | const char *buf; | ||
88 | const char *salt; | ||
89 | char *ret; | ||
90 | { | 103 | { |
91 | unsigned int i,j,x,y; | 104 | unsigned int i,j,x,y; |
92 | DES_LONG Eswap0,Eswap1; | 105 | DES_LONG Eswap0,Eswap1; |
93 | DES_LONG out[2],ll; | 106 | DES_LONG out[2],ll; |
94 | des_cblock key; | 107 | DES_cblock key; |
95 | des_key_schedule ks; | 108 | DES_key_schedule ks; |
96 | unsigned char bb[9]; | 109 | unsigned char bb[9]; |
97 | unsigned char *b=bb; | 110 | unsigned char *b=bb; |
98 | unsigned char c,u; | 111 | unsigned char c,u; |
@@ -103,12 +116,19 @@ char *ret; | |||
103 | * returns *\0XXXXXXXXX | 116 | * returns *\0XXXXXXXXX |
104 | * The \0 makes the string look like * so the pwd "*" would | 117 | * The \0 makes the string look like * so the pwd "*" would |
105 | * crypt to "*". This was found when replacing the crypt in | 118 | * crypt to "*". This was found when replacing the crypt in |
106 | * our shared libraries. People found that the disbled | 119 | * our shared libraries. People found that the disabled |
107 | * accounts effectivly had no passwd :-(. */ | 120 | * accounts effectively had no passwd :-(. */ |
121 | #ifndef CHARSET_EBCDIC | ||
108 | x=ret[0]=((salt[0] == '\0')?'A':salt[0]); | 122 | x=ret[0]=((salt[0] == '\0')?'A':salt[0]); |
109 | Eswap0=con_salt[x]<<2; | 123 | Eswap0=con_salt[x]<<2; |
110 | x=ret[1]=((salt[1] == '\0')?'A':salt[1]); | 124 | x=ret[1]=((salt[1] == '\0')?'A':salt[1]); |
111 | Eswap1=con_salt[x]<<6; | 125 | Eswap1=con_salt[x]<<6; |
126 | #else | ||
127 | x=ret[0]=((salt[0] == '\0')?os_toascii['A']:salt[0]); | ||
128 | Eswap0=con_salt[x]<<2; | ||
129 | x=ret[1]=((salt[1] == '\0')?os_toascii['A']:salt[1]); | ||
130 | Eswap1=con_salt[x]<<6; | ||
131 | #endif | ||
112 | 132 | ||
113 | /* EAY | 133 | /* EAY |
114 | r=strlen(buf); | 134 | r=strlen(buf); |
@@ -123,8 +143,8 @@ r=(r+7)/8; | |||
123 | for (; i<8; i++) | 143 | for (; i<8; i++) |
124 | key[i]=0; | 144 | key[i]=0; |
125 | 145 | ||
126 | des_set_key((des_cblock *)(key),ks); | 146 | DES_set_key_unchecked(&key,&ks); |
127 | fcrypt_body(&(out[0]),ks,Eswap0,Eswap1); | 147 | fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1); |
128 | 148 | ||
129 | ll=out[0]; l2c(ll,b); | 149 | ll=out[0]; l2c(ll,b); |
130 | ll=out[1]; l2c(ll,b); | 150 | ll=out[1]; l2c(ll,b); |