diff options
Diffstat (limited to 'src/lib/libcrypto/des/des_enc.c')
-rw-r--r-- | src/lib/libcrypto/des/des_enc.c | 121 |
1 files changed, 24 insertions, 97 deletions
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c index deec50bffb..cb89784fb0 100644 --- a/src/lib/libcrypto/des/des_enc.c +++ b/src/lib/libcrypto/des/des_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: des_enc.c,v 1.20 2024/08/31 16:17:13 jsing Exp $ */ | 1 | /* $OpenBSD: des_enc.c,v 1.21 2025/07/27 13:26:24 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -210,10 +210,8 @@ void | |||
210 | DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) | 210 | DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) |
211 | { | 211 | { |
212 | DES_LONG l, r, t, u; | 212 | DES_LONG l, r, t, u; |
213 | #ifndef DES_UNROLL | ||
214 | int i; | ||
215 | #endif | ||
216 | DES_LONG *s; | 213 | DES_LONG *s; |
214 | int i; | ||
217 | 215 | ||
218 | r = data[0]; | 216 | r = data[0]; |
219 | l = data[1]; | 217 | l = data[1]; |
@@ -231,56 +229,21 @@ DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) | |||
231 | l = ROTATE(l, 29) & 0xffffffffL; | 229 | l = ROTATE(l, 29) & 0xffffffffL; |
232 | 230 | ||
233 | s = ks->ks->deslong; | 231 | s = ks->ks->deslong; |
234 | /* I don't know if it is worth the effort of loop unrolling the | 232 | |
235 | * inner loop */ | ||
236 | if (enc) { | 233 | if (enc) { |
237 | #ifdef DES_UNROLL | 234 | for (i = 0; i < 32; i += 8) { |
238 | D_ENCRYPT(l, r, 0); /* 1 */ | 235 | D_ENCRYPT(l, r, i + 0); |
239 | D_ENCRYPT(r, l, 2); /* 2 */ | 236 | D_ENCRYPT(r, l, i + 2); |
240 | D_ENCRYPT(l, r, 4); /* 3 */ | 237 | D_ENCRYPT(l, r, i + 4); |
241 | D_ENCRYPT(r, l, 6); /* 4 */ | 238 | D_ENCRYPT(r, l, i + 6); |
242 | D_ENCRYPT(l, r, 8); /* 5 */ | ||
243 | D_ENCRYPT(r, l, 10); /* 6 */ | ||
244 | D_ENCRYPT(l, r, 12); /* 7 */ | ||
245 | D_ENCRYPT(r, l, 14); /* 8 */ | ||
246 | D_ENCRYPT(l, r, 16); /* 9 */ | ||
247 | D_ENCRYPT(r, l, 18); /* 10 */ | ||
248 | D_ENCRYPT(l, r, 20); /* 11 */ | ||
249 | D_ENCRYPT(r, l, 22); /* 12 */ | ||
250 | D_ENCRYPT(l, r, 24); /* 13 */ | ||
251 | D_ENCRYPT(r, l, 26); /* 14 */ | ||
252 | D_ENCRYPT(l, r, 28); /* 15 */ | ||
253 | D_ENCRYPT(r, l, 30); /* 16 */ | ||
254 | #else | ||
255 | for (i = 0; i < 32; i += 4) { | ||
256 | D_ENCRYPT(l, r, i + 0); /* 1 */ | ||
257 | D_ENCRYPT(r, l, i + 2); /* 2 */ | ||
258 | } | 239 | } |
259 | #endif | ||
260 | } else { | 240 | } else { |
261 | #ifdef DES_UNROLL | 241 | for (i = 32; i > 0; i -= 8) { |
262 | D_ENCRYPT(l, r, 30); /* 16 */ | 242 | D_ENCRYPT(l, r, i - 2); |
263 | D_ENCRYPT(r, l, 28); /* 15 */ | 243 | D_ENCRYPT(r, l, i - 4); |
264 | D_ENCRYPT(l, r, 26); /* 14 */ | 244 | D_ENCRYPT(l, r, i - 6); |
265 | D_ENCRYPT(r, l, 24); /* 13 */ | 245 | D_ENCRYPT(r, l, i - 8); |
266 | D_ENCRYPT(l, r, 22); /* 12 */ | ||
267 | D_ENCRYPT(r, l, 20); /* 11 */ | ||
268 | D_ENCRYPT(l, r, 18); /* 10 */ | ||
269 | D_ENCRYPT(r, l, 16); /* 9 */ | ||
270 | D_ENCRYPT(l, r, 14); /* 8 */ | ||
271 | D_ENCRYPT(r, l, 12); /* 7 */ | ||
272 | D_ENCRYPT(l, r, 10); /* 6 */ | ||
273 | D_ENCRYPT(r, l, 8); /* 5 */ | ||
274 | D_ENCRYPT(l, r, 6); /* 4 */ | ||
275 | D_ENCRYPT(r, l, 4); /* 3 */ | ||
276 | D_ENCRYPT(l, r, 2); /* 2 */ | ||
277 | D_ENCRYPT(r, l, 0); /* 1 */ | ||
278 | #else | ||
279 | for (i = 30; i > 0; i -= 4) { | ||
280 | D_ENCRYPT(l, r, i - 0); /* 16 */ | ||
281 | D_ENCRYPT(r, l, i - 2); /* 15 */ | ||
282 | } | 246 | } |
283 | #endif | ||
284 | } | 247 | } |
285 | 248 | ||
286 | /* rotate and clear the top bits on machines with 8byte longs */ | 249 | /* rotate and clear the top bits on machines with 8byte longs */ |
@@ -298,10 +261,8 @@ void | |||
298 | DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc) | 261 | DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc) |
299 | { | 262 | { |
300 | DES_LONG l, r, t, u; | 263 | DES_LONG l, r, t, u; |
301 | #ifndef DES_UNROLL | ||
302 | int i; | ||
303 | #endif | ||
304 | DES_LONG *s; | 264 | DES_LONG *s; |
265 | int i; | ||
305 | 266 | ||
306 | r = data[0]; | 267 | r = data[0]; |
307 | l = data[1]; | 268 | l = data[1]; |
@@ -320,53 +281,19 @@ DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc) | |||
320 | /* I don't know if it is worth the effort of loop unrolling the | 281 | /* I don't know if it is worth the effort of loop unrolling the |
321 | * inner loop */ | 282 | * inner loop */ |
322 | if (enc) { | 283 | if (enc) { |
323 | #ifdef DES_UNROLL | 284 | for (i = 0; i < 32; i += 8) { |
324 | D_ENCRYPT(l, r, 0); /* 1 */ | 285 | D_ENCRYPT(l, r, i + 0); |
325 | D_ENCRYPT(r, l, 2); /* 2 */ | 286 | D_ENCRYPT(r, l, i + 2); |
326 | D_ENCRYPT(l, r, 4); /* 3 */ | 287 | D_ENCRYPT(l, r, i + 4); |
327 | D_ENCRYPT(r, l, 6); /* 4 */ | 288 | D_ENCRYPT(r, l, i + 6); |
328 | D_ENCRYPT(l, r, 8); /* 5 */ | ||
329 | D_ENCRYPT(r, l, 10); /* 6 */ | ||
330 | D_ENCRYPT(l, r, 12); /* 7 */ | ||
331 | D_ENCRYPT(r, l, 14); /* 8 */ | ||
332 | D_ENCRYPT(l, r, 16); /* 9 */ | ||
333 | D_ENCRYPT(r, l, 18); /* 10 */ | ||
334 | D_ENCRYPT(l, r, 20); /* 11 */ | ||
335 | D_ENCRYPT(r, l, 22); /* 12 */ | ||
336 | D_ENCRYPT(l, r, 24); /* 13 */ | ||
337 | D_ENCRYPT(r, l, 26); /* 14 */ | ||
338 | D_ENCRYPT(l, r, 28); /* 15 */ | ||
339 | D_ENCRYPT(r, l, 30); /* 16 */ | ||
340 | #else | ||
341 | for (i = 0; i < 32; i += 4) { | ||
342 | D_ENCRYPT(l, r, i + 0); /* 1 */ | ||
343 | D_ENCRYPT(r, l, i + 2); /* 2 */ | ||
344 | } | 289 | } |
345 | #endif | ||
346 | } else { | 290 | } else { |
347 | #ifdef DES_UNROLL | 291 | for (i = 32; i > 0; i -= 8) { |
348 | D_ENCRYPT(l, r, 30); /* 16 */ | 292 | D_ENCRYPT(l, r, i - 2); |
349 | D_ENCRYPT(r, l, 28); /* 15 */ | 293 | D_ENCRYPT(r, l, i - 4); |
350 | D_ENCRYPT(l, r, 26); /* 14 */ | 294 | D_ENCRYPT(l, r, i - 6); |
351 | D_ENCRYPT(r, l, 24); /* 13 */ | 295 | D_ENCRYPT(r, l, i - 8); |
352 | D_ENCRYPT(l, r, 22); /* 12 */ | ||
353 | D_ENCRYPT(r, l, 20); /* 11 */ | ||
354 | D_ENCRYPT(l, r, 18); /* 10 */ | ||
355 | D_ENCRYPT(r, l, 16); /* 9 */ | ||
356 | D_ENCRYPT(l, r, 14); /* 8 */ | ||
357 | D_ENCRYPT(r, l, 12); /* 7 */ | ||
358 | D_ENCRYPT(l, r, 10); /* 6 */ | ||
359 | D_ENCRYPT(r, l, 8); /* 5 */ | ||
360 | D_ENCRYPT(l, r, 6); /* 4 */ | ||
361 | D_ENCRYPT(r, l, 4); /* 3 */ | ||
362 | D_ENCRYPT(l, r, 2); /* 2 */ | ||
363 | D_ENCRYPT(r, l, 0); /* 1 */ | ||
364 | #else | ||
365 | for (i = 30; i > 0; i -= 4) { | ||
366 | D_ENCRYPT(l, r, i - 0); /* 16 */ | ||
367 | D_ENCRYPT(r, l, i - 2); /* 15 */ | ||
368 | } | 296 | } |
369 | #endif | ||
370 | } | 297 | } |
371 | /* rotate and clear the top bits on machines with 8byte longs */ | 298 | /* rotate and clear the top bits on machines with 8byte longs */ |
372 | data[0] = ROTATE(l, 3) & 0xffffffffL; | 299 | data[0] = ROTATE(l, 3) & 0xffffffffL; |