summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2024-08-31 14:25:04 +0000
committerjsing <>2024-08-31 14:25:04 +0000
commit944223ad13f1cd54e8c12b05523d90eb3197fa51 (patch)
tree40009e93e9a7c8faebc7901bc4b41a42e1bab2d9
parent357d0eb629b6a1fdf3f95c86b815313d192ceb93 (diff)
downloadopenbsd-944223ad13f1cd54e8c12b05523d90eb3197fa51.tar.gz
openbsd-944223ad13f1cd54e8c12b05523d90eb3197fa51.tar.bz2
openbsd-944223ad13f1cd54e8c12b05523d90eb3197fa51.zip
Expand DES_cbc_encrypt() in cbc_enc.c.
Copy ncbc_enc.c where it was previously #included, then clean up with `unifdef -m -DCBC_ENC_C__DONT_UPDATE_IV`. Discussed with tb@
-rw-r--r--src/lib/libcrypto/des/cbc_enc.c76
1 files changed, 73 insertions, 3 deletions
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c
index 6c1ec7117d..1f11cc3600 100644
--- a/src/lib/libcrypto/des/cbc_enc.c
+++ b/src/lib/libcrypto/des/cbc_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cbc_enc.c,v 1.4 2023/07/08 07:11:07 beck Exp $ */ 1/* $OpenBSD: cbc_enc.c,v 1.5 2024/08/31 14:25:04 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 *
@@ -56,6 +56,76 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#define CBC_ENC_C__DONT_UPDATE_IV 59#include "des_local.h"
60 60
61#include "ncbc_enc.c" /* des_cbc_encrypt */ 61void
62DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
63 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
64{
65 DES_LONG tin0, tin1;
66 DES_LONG tout0, tout1, xor0, xor1;
67 long l = length;
68 DES_LONG tin[2];
69 unsigned char *iv;
70
71 iv = &(*ivec)[0];
72
73 if (enc) {
74 c2l(iv, tout0);
75 c2l(iv, tout1);
76 for (l -= 8; l >= 0; l -= 8) {
77 c2l(in, tin0);
78 c2l(in, tin1);
79 tin0 ^= tout0;
80 tin[0] = tin0;
81 tin1 ^= tout1;
82 tin[1] = tin1;
83 DES_encrypt1((DES_LONG *)tin, _schedule, DES_ENCRYPT);
84 tout0 = tin[0];
85 l2c(tout0, out);
86 tout1 = tin[1];
87 l2c(tout1, out);
88 }
89 if (l != -8) {
90 c2ln(in, tin0, tin1, l + 8);
91 tin0 ^= tout0;
92 tin[0] = tin0;
93 tin1 ^= tout1;
94 tin[1] = tin1;
95 DES_encrypt1((DES_LONG *)tin, _schedule, DES_ENCRYPT);
96 tout0 = tin[0];
97 l2c(tout0, out);
98 tout1 = tin[1];
99 l2c(tout1, out);
100 }
101 } else {
102 c2l(iv, xor0);
103 c2l(iv, xor1);
104 for (l -= 8; l >= 0; l -= 8) {
105 c2l(in, tin0);
106 tin[0] = tin0;
107 c2l(in, tin1);
108 tin[1] = tin1;
109 DES_encrypt1((DES_LONG *)tin, _schedule, DES_DECRYPT);
110 tout0 = tin[0] ^ xor0;
111 tout1 = tin[1] ^ xor1;
112 l2c(tout0, out);
113 l2c(tout1, out);
114 xor0 = tin0;
115 xor1 = tin1;
116 }
117 if (l != -8) {
118 c2l(in, tin0);
119 tin[0] = tin0;
120 c2l(in, tin1);
121 tin[1] = tin1;
122 DES_encrypt1((DES_LONG *)tin, _schedule, DES_DECRYPT);
123 tout0 = tin[0] ^ xor0;
124 tout1 = tin[1] ^ xor1;
125 l2cn(tout0, tout1, out, l + 8);
126 }
127 }
128 tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
129 tin[0] = tin[1] = 0;
130}
131LCRYPTO_ALIAS(DES_cbc_encrypt);