diff options
author | jsing <> | 2024-08-31 14:29:15 +0000 |
---|---|---|
committer | jsing <> | 2024-08-31 14:29:15 +0000 |
commit | 75ec7abc023daea589657436d50ed2db343e308f (patch) | |
tree | 252649a77f9e35405503b52095329b5ec714f4e5 | |
parent | 944223ad13f1cd54e8c12b05523d90eb3197fa51 (diff) | |
download | openbsd-75ec7abc023daea589657436d50ed2db343e308f.tar.gz openbsd-75ec7abc023daea589657436d50ed2db343e308f.tar.bz2 openbsd-75ec7abc023daea589657436d50ed2db343e308f.zip |
Expand DES_ncbc_encrypt() in des_enc.c.
Copy ncbc_enc.c where it was previously #included, then clean up with
`unifdef -m -UCBC_ENC_C__DONT_UPDATE_IV`.
Discussed with tb@
-rw-r--r-- | src/lib/libcrypto/des/des_enc.c | 83 |
1 files changed, 80 insertions, 3 deletions
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c index f332b9a431..86fab01fcb 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.16 2024/03/29 01:47:29 joshua Exp $ */ | 1 | /* $OpenBSD: des_enc.c,v 1.17 2024/08/31 14:29:15 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 | * |
@@ -284,8 +284,85 @@ LCRYPTO_ALIAS(DES_decrypt3); | |||
284 | 284 | ||
285 | #ifndef DES_DEFAULT_OPTIONS | 285 | #ifndef DES_DEFAULT_OPTIONS |
286 | 286 | ||
287 | #undef CBC_ENC_C__DONT_UPDATE_IV | 287 | void |
288 | #include "ncbc_enc.c" /* DES_ncbc_encrypt */ | 288 | DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length, |
289 | DES_key_schedule *_schedule, DES_cblock *ivec, int enc) | ||
290 | { | ||
291 | DES_LONG tin0, tin1; | ||
292 | DES_LONG tout0, tout1, xor0, xor1; | ||
293 | long l = length; | ||
294 | DES_LONG tin[2]; | ||
295 | unsigned char *iv; | ||
296 | |||
297 | iv = &(*ivec)[0]; | ||
298 | |||
299 | if (enc) { | ||
300 | c2l(iv, tout0); | ||
301 | c2l(iv, tout1); | ||
302 | for (l -= 8; l >= 0; l -= 8) { | ||
303 | c2l(in, tin0); | ||
304 | c2l(in, tin1); | ||
305 | tin0 ^= tout0; | ||
306 | tin[0] = tin0; | ||
307 | tin1 ^= tout1; | ||
308 | tin[1] = tin1; | ||
309 | DES_encrypt1((DES_LONG *)tin, _schedule, DES_ENCRYPT); | ||
310 | tout0 = tin[0]; | ||
311 | l2c(tout0, out); | ||
312 | tout1 = tin[1]; | ||
313 | l2c(tout1, out); | ||
314 | } | ||
315 | if (l != -8) { | ||
316 | c2ln(in, tin0, tin1, l + 8); | ||
317 | tin0 ^= tout0; | ||
318 | tin[0] = tin0; | ||
319 | tin1 ^= tout1; | ||
320 | tin[1] = tin1; | ||
321 | DES_encrypt1((DES_LONG *)tin, _schedule, DES_ENCRYPT); | ||
322 | tout0 = tin[0]; | ||
323 | l2c(tout0, out); | ||
324 | tout1 = tin[1]; | ||
325 | l2c(tout1, out); | ||
326 | } | ||
327 | iv = &(*ivec)[0]; | ||
328 | l2c(tout0, iv); | ||
329 | l2c(tout1, iv); | ||
330 | } else { | ||
331 | c2l(iv, xor0); | ||
332 | c2l(iv, xor1); | ||
333 | for (l -= 8; l >= 0; l -= 8) { | ||
334 | c2l(in, tin0); | ||
335 | tin[0] = tin0; | ||
336 | c2l(in, tin1); | ||
337 | tin[1] = tin1; | ||
338 | DES_encrypt1((DES_LONG *)tin, _schedule, DES_DECRYPT); | ||
339 | tout0 = tin[0] ^ xor0; | ||
340 | tout1 = tin[1] ^ xor1; | ||
341 | l2c(tout0, out); | ||
342 | l2c(tout1, out); | ||
343 | xor0 = tin0; | ||
344 | xor1 = tin1; | ||
345 | } | ||
346 | if (l != -8) { | ||
347 | c2l(in, tin0); | ||
348 | tin[0] = tin0; | ||
349 | c2l(in, tin1); | ||
350 | tin[1] = tin1; | ||
351 | DES_encrypt1((DES_LONG *)tin, _schedule, DES_DECRYPT); | ||
352 | tout0 = tin[0] ^ xor0; | ||
353 | tout1 = tin[1] ^ xor1; | ||
354 | l2cn(tout0, tout1, out, l + 8); | ||
355 | xor0 = tin0; | ||
356 | xor1 = tin1; | ||
357 | } | ||
358 | iv = &(*ivec)[0]; | ||
359 | l2c(xor0, iv); | ||
360 | l2c(xor1, iv); | ||
361 | } | ||
362 | tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0; | ||
363 | tin[0] = tin[1] = 0; | ||
364 | } | ||
365 | LCRYPTO_ALIAS(DES_ncbc_encrypt); | ||
289 | 366 | ||
290 | void | 367 | void |
291 | DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, | 368 | DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, |