diff options
author | jsing <> | 2024-08-31 15:56:09 +0000 |
---|---|---|
committer | jsing <> | 2024-08-31 15:56:09 +0000 |
commit | f9b9e21742d3301ba7b9599b7dce4b24758771df (patch) | |
tree | 5be74158601e3b85e402eb7beaf58bd8a48fccb6 /src/lib/libcrypto/des/fcrypt.c | |
parent | 3c39830fa152936fa313a77ccae2d45e94a01253 (diff) | |
download | openbsd-f9b9e21742d3301ba7b9599b7dce4b24758771df.tar.gz openbsd-f9b9e21742d3301ba7b9599b7dce4b24758771df.tar.bz2 openbsd-f9b9e21742d3301ba7b9599b7dce4b24758771df.zip |
Combine DES code into a smaller set of files.
Discussed with tb@
Diffstat (limited to 'src/lib/libcrypto/des/fcrypt.c')
-rw-r--r-- | src/lib/libcrypto/des/fcrypt.c | 261 |
1 files changed, 0 insertions, 261 deletions
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c deleted file mode 100644 index c970ef4c55..0000000000 --- a/src/lib/libcrypto/des/fcrypt.c +++ /dev/null | |||
@@ -1,261 +0,0 @@ | |||
1 | /* $OpenBSD: fcrypt.c,v 1.17 2024/08/31 15:39:33 jsing Exp $ */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | |||
61 | /* This version of crypt has been developed from my MIT compatible | ||
62 | * DES library. | ||
63 | * Eric Young (eay@cryptsoft.com) | ||
64 | */ | ||
65 | |||
66 | /* Modification by Jens Kupferschmidt (Cu) | ||
67 | * I have included directive PARA for shared memory computers. | ||
68 | * I have included a directive LONGCRYPT to using this routine to cipher | ||
69 | * passwords with more than 8 bytes like HP-UX 10.x it used. The MAXPLEN | ||
70 | * definition is the maximum of length of password and can changed. I have | ||
71 | * defined 24. | ||
72 | */ | ||
73 | |||
74 | #define DES_FCRYPT | ||
75 | #include "des_local.h" | ||
76 | #undef DES_FCRYPT | ||
77 | |||
78 | #ifndef OPENBSD_DES_ASM | ||
79 | |||
80 | #undef PERM_OP | ||
81 | #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)), \ | ||
82 | (b)^=(t), \ | ||
83 | (a)^=((t)<<(n))) | ||
84 | |||
85 | #undef HPERM_OP | ||
86 | #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)), \ | ||
87 | (a)=(a)^(t)^(t>>(16-(n)))) \ | ||
88 | |||
89 | void | ||
90 | fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0, | ||
91 | DES_LONG Eswap1) | ||
92 | { | ||
93 | DES_LONG l, r, t, u; | ||
94 | #ifdef DES_PTR | ||
95 | const unsigned char *des_SP = (const unsigned char *)DES_SPtrans; | ||
96 | #endif | ||
97 | DES_LONG *s; | ||
98 | int j; | ||
99 | DES_LONG E0, E1; | ||
100 | |||
101 | l = 0; | ||
102 | r = 0; | ||
103 | |||
104 | s = (DES_LONG *)ks; | ||
105 | E0 = Eswap0; | ||
106 | E1 = Eswap1; | ||
107 | |||
108 | for (j = 0; j < 25; j++) { | ||
109 | #ifndef DES_UNROLL | ||
110 | int i; | ||
111 | |||
112 | for (i = 0; i < 32; i += 4) { | ||
113 | D_ENCRYPT(l, r, i + 0); /* 1 */ | ||
114 | D_ENCRYPT(r, l, i + 2); /* 2 */ | ||
115 | } | ||
116 | #else | ||
117 | D_ENCRYPT(l, r, 0); /* 1 */ | ||
118 | D_ENCRYPT(r, l, 2); /* 2 */ | ||
119 | D_ENCRYPT(l, r, 4); /* 3 */ | ||
120 | D_ENCRYPT(r, l, 6); /* 4 */ | ||
121 | D_ENCRYPT(l, r, 8); /* 5 */ | ||
122 | D_ENCRYPT(r, l, 10); /* 6 */ | ||
123 | D_ENCRYPT(l, r, 12); /* 7 */ | ||
124 | D_ENCRYPT(r, l, 14); /* 8 */ | ||
125 | D_ENCRYPT(l, r, 16); /* 9 */ | ||
126 | D_ENCRYPT(r, l, 18); /* 10 */ | ||
127 | D_ENCRYPT(l, r, 20); /* 11 */ | ||
128 | D_ENCRYPT(r, l, 22); /* 12 */ | ||
129 | D_ENCRYPT(l, r, 24); /* 13 */ | ||
130 | D_ENCRYPT(r, l, 26); /* 14 */ | ||
131 | D_ENCRYPT(l, r, 28); /* 15 */ | ||
132 | D_ENCRYPT(r, l, 30); /* 16 */ | ||
133 | #endif | ||
134 | |||
135 | t = l; | ||
136 | l = r; | ||
137 | r = t; | ||
138 | } | ||
139 | l = ROTATE(l, 3) & 0xffffffffL; | ||
140 | r = ROTATE(r, 3) & 0xffffffffL; | ||
141 | |||
142 | PERM_OP(l, r, t, 1, 0x55555555L); | ||
143 | PERM_OP(r, l, t, 8, 0x00ff00ffL); | ||
144 | PERM_OP(l, r, t, 2, 0x33333333L); | ||
145 | PERM_OP(r, l, t, 16, 0x0000ffffL); | ||
146 | PERM_OP(l, r, t, 4, 0x0f0f0f0fL); | ||
147 | |||
148 | out[0] = r; | ||
149 | out[1] = l; | ||
150 | } | ||
151 | |||
152 | #endif /* OPENBSD_DES_ASM */ | ||
153 | |||
154 | /* Added more values to handle illegal salt values the way normal | ||
155 | * crypt() implementations do. The patch was sent by | ||
156 | * Bjorn Gronvall <bg@sics.se> | ||
157 | */ | ||
158 | static unsigned const char con_salt[128] = { | ||
159 | 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, | ||
160 | 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1, | ||
161 | 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, | ||
162 | 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, | ||
163 | 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, | ||
164 | 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x00, 0x01, | ||
165 | 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, | ||
166 | 0x0A, 0x0B, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, | ||
167 | 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, | ||
168 | 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, | ||
169 | 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, | ||
170 | 0x23, 0x24, 0x25, 0x20, 0x21, 0x22, 0x23, 0x24, | ||
171 | 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, | ||
172 | 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, | ||
173 | 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, | ||
174 | 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, | ||
175 | }; | ||
176 | |||
177 | static unsigned const char cov_2char[64] = { | ||
178 | 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, | ||
179 | 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, | ||
180 | 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, | ||
181 | 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, | ||
182 | 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, | ||
183 | 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, | ||
184 | 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, | ||
185 | 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A | ||
186 | }; | ||
187 | |||
188 | char * | ||
189 | DES_crypt(const char *buf, const char *salt) | ||
190 | { | ||
191 | static char buff[14]; | ||
192 | |||
193 | return (DES_fcrypt(buf, salt, buff)); | ||
194 | } | ||
195 | LCRYPTO_ALIAS(DES_crypt); | ||
196 | |||
197 | char * | ||
198 | DES_fcrypt(const char *buf, const char *salt, char *ret) | ||
199 | { | ||
200 | unsigned int i, j, x, y; | ||
201 | DES_LONG Eswap0, Eswap1; | ||
202 | DES_LONG out[2], ll; | ||
203 | DES_cblock key; | ||
204 | DES_key_schedule ks; | ||
205 | unsigned char bb[9]; | ||
206 | unsigned char *b = bb; | ||
207 | unsigned char c, u; | ||
208 | |||
209 | /* eay 25/08/92 | ||
210 | * If you call crypt("pwd","*") as often happens when you | ||
211 | * have * as the pwd field in /etc/passwd, the function | ||
212 | * returns *\0xxxxxxxxx | ||
213 | * The \0 makes the string look like * so the pwd "*" would | ||
214 | * crypt to "*". This was found when replacing the crypt in | ||
215 | * our shared libraries. People found that the disabled | ||
216 | * accounts effectively had no passwd :-(. */ | ||
217 | x = ret[0] = ((salt[0] == '\0') ? 'A' : salt[0]); | ||
218 | Eswap0 = con_salt[x] << 2; | ||
219 | x = ret[1] = ((salt[1] == '\0') ? 'A' : salt[1]); | ||
220 | Eswap1 = con_salt[x] << 6; | ||
221 | /* EAY | ||
222 | r=strlen(buf); | ||
223 | r=(r+7)/8; | ||
224 | */ | ||
225 | for (i = 0; i < 8; i++) { | ||
226 | c = *(buf++); | ||
227 | if (!c) | ||
228 | break; | ||
229 | key[i] = (c << 1); | ||
230 | } | ||
231 | for (; i < 8; i++) | ||
232 | key[i] = 0; | ||
233 | |||
234 | DES_set_key_unchecked(&key, &ks); | ||
235 | fcrypt_body(&(out[0]), &ks, Eswap0, Eswap1); | ||
236 | |||
237 | ll = out[0]; | ||
238 | l2c(ll, b); | ||
239 | ll = out[1]; | ||
240 | l2c(ll, b); | ||
241 | y = 0; | ||
242 | u = 0x80; | ||
243 | bb[8] = 0; | ||
244 | for (i = 2; i < 13; i++) { | ||
245 | c = 0; | ||
246 | for (j = 0; j < 6; j++) { | ||
247 | c <<= 1; | ||
248 | if (bb[y] & u) | ||
249 | c |= 1; | ||
250 | u >>= 1; | ||
251 | if (!u) { | ||
252 | y++; | ||
253 | u = 0x80; | ||
254 | } | ||
255 | } | ||
256 | ret[i] = cov_2char[c]; | ||
257 | } | ||
258 | ret[13] = '\0'; | ||
259 | return (ret); | ||
260 | } | ||
261 | LCRYPTO_ALIAS(DES_fcrypt); | ||