summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des/xcbc_enc.c
diff options
context:
space:
mode:
authorbeck <>2023-07-08 07:11:07 +0000
committerbeck <>2023-07-08 07:11:07 +0000
commit243979914a45e120f0afd37f88c5afbe1c1b5493 (patch)
tree893e40f2d049c1ae16b1df1305f2bb885508c93f /src/lib/libcrypto/des/xcbc_enc.c
parent9fd37e06e49f349066b61c8890e3b9ba79944481 (diff)
downloadopenbsd-243979914a45e120f0afd37f88c5afbe1c1b5493.tar.gz
openbsd-243979914a45e120f0afd37f88c5afbe1c1b5493.tar.bz2
openbsd-243979914a45e120f0afd37f88c5afbe1c1b5493.zip
Hit the des directory with the loving mallet of knfmt
ok tb@
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c163
1 files changed, 85 insertions, 78 deletions
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
index 0152f3eff5..754d989fbf 100644
--- a/src/lib/libcrypto/des/xcbc_enc.c
+++ b/src/lib/libcrypto/des/xcbc_enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: xcbc_enc.c,v 1.10 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: xcbc_enc.c,v 1.11 2023/07/08 07:11:07 beck 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 *
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 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 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 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 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. 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 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. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 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: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 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 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 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 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -60,89 +60,96 @@
60 60
61/* RSA's DESX */ 61/* RSA's DESX */
62 62
63void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out, 63void
64 long length, DES_key_schedule *schedule, 64DES_xcbc_encrypt(const unsigned char *in, unsigned char *out,
65 DES_cblock *ivec, const_DES_cblock *inw, 65 long length, DES_key_schedule *schedule,
66 const_DES_cblock *outw, int enc) 66 DES_cblock *ivec, const_DES_cblock *inw,
67 { 67 const_DES_cblock *outw, int enc)
68 DES_LONG tin0,tin1; 68{
69 DES_LONG tout0,tout1,xor0,xor1; 69 DES_LONG tin0, tin1;
70 DES_LONG inW0,inW1,outW0,outW1; 70 DES_LONG tout0, tout1, xor0, xor1;
71 DES_LONG inW0, inW1, outW0, outW1;
71 const unsigned char *in2; 72 const unsigned char *in2;
72 long l=length; 73 long l = length;
73 DES_LONG tin[2]; 74 DES_LONG tin[2];
74 unsigned char *iv; 75 unsigned char *iv;
75 76
76 in2 = &(*inw)[0]; 77 in2 = &(*inw)[0];
77 c2l(in2,inW0); 78 c2l(in2, inW0);
78 c2l(in2,inW1); 79 c2l(in2, inW1);
79 in2 = &(*outw)[0]; 80 in2 = &(*outw)[0];
80 c2l(in2,outW0); 81 c2l(in2, outW0);
81 c2l(in2,outW1); 82 c2l(in2, outW1);
82 83
83 iv = &(*ivec)[0]; 84 iv = &(*ivec)[0];
84 85
85 if (enc) 86 if (enc) {
87 c2l(iv, tout0);
88 c2l(iv, tout1);
89 for (l -= 8; l >= 0; l -= 8)
86 { 90 {
87 c2l(iv,tout0); 91 c2l(in, tin0);
88 c2l(iv,tout1); 92 c2l(in, tin1);
89 for (l-=8; l>=0; l-=8) 93 tin0 ^= tout0 ^ inW0;
90 { 94 tin[0] = tin0;
91 c2l(in,tin0); 95 tin1 ^= tout1 ^ inW1;
92 c2l(in,tin1); 96 tin[1] = tin1;
93 tin0^=tout0^inW0; tin[0]=tin0; 97 DES_encrypt1(tin, schedule, DES_ENCRYPT);
94 tin1^=tout1^inW1; tin[1]=tin1; 98 tout0 = tin[0] ^ outW0;
95 DES_encrypt1(tin,schedule,DES_ENCRYPT); 99 l2c(tout0, out);
96 tout0=tin[0]^outW0; l2c(tout0,out); 100 tout1 = tin[1] ^ outW1;
97 tout1=tin[1]^outW1; l2c(tout1,out); 101 l2c(tout1, out);
98 }
99 if (l != -8)
100 {
101 c2ln(in,tin0,tin1,l+8);
102 tin0^=tout0^inW0; tin[0]=tin0;
103 tin1^=tout1^inW1; tin[1]=tin1;
104 DES_encrypt1(tin,schedule,DES_ENCRYPT);
105 tout0=tin[0]^outW0; l2c(tout0,out);
106 tout1=tin[1]^outW1; l2c(tout1,out);
107 }
108 iv = &(*ivec)[0];
109 l2c(tout0,iv);
110 l2c(tout1,iv);
111 } 102 }
112 else 103 if (l != -8) {
104 c2ln(in, tin0, tin1, l + 8);
105 tin0 ^= tout0 ^ inW0;
106 tin[0] = tin0;
107 tin1 ^= tout1 ^ inW1;
108 tin[1] = tin1;
109 DES_encrypt1(tin, schedule, DES_ENCRYPT);
110 tout0 = tin[0] ^ outW0;
111 l2c(tout0, out);
112 tout1 = tin[1] ^ outW1;
113 l2c(tout1, out);
114 }
115 iv = &(*ivec)[0];
116 l2c(tout0, iv);
117 l2c(tout1, iv);
118 } else {
119 c2l(iv, xor0);
120 c2l(iv, xor1);
121 for (l -= 8; l > 0; l -= 8)
113 { 122 {
114 c2l(iv,xor0); 123 c2l(in, tin0);
115 c2l(iv,xor1); 124 tin[0] = tin0 ^ outW0;
116 for (l-=8; l>0; l-=8) 125 c2l(in, tin1);
117 { 126 tin[1] = tin1 ^ outW1;
118 c2l(in,tin0); tin[0]=tin0^outW0; 127 DES_encrypt1(tin, schedule, DES_DECRYPT);
119 c2l(in,tin1); tin[1]=tin1^outW1; 128 tout0 = tin[0] ^ xor0 ^ inW0;
120 DES_encrypt1(tin,schedule,DES_DECRYPT); 129 tout1 = tin[1] ^ xor1 ^ inW1;
121 tout0=tin[0]^xor0^inW0; 130 l2c(tout0, out);
122 tout1=tin[1]^xor1^inW1; 131 l2c(tout1, out);
123 l2c(tout0,out); 132 xor0 = tin0;
124 l2c(tout1,out); 133 xor1 = tin1;
125 xor0=tin0; 134 }
126 xor1=tin1; 135 if (l != -8) {
127 } 136 c2l(in, tin0);
128 if (l != -8) 137 tin[0] = tin0 ^ outW0;
129 { 138 c2l(in, tin1);
130 c2l(in,tin0); tin[0]=tin0^outW0; 139 tin[1] = tin1 ^ outW1;
131 c2l(in,tin1); tin[1]=tin1^outW1; 140 DES_encrypt1(tin, schedule, DES_DECRYPT);
132 DES_encrypt1(tin,schedule,DES_DECRYPT); 141 tout0 = tin[0] ^ xor0 ^ inW0;
133 tout0=tin[0]^xor0^inW0; 142 tout1 = tin[1] ^ xor1 ^ inW1;
134 tout1=tin[1]^xor1^inW1; 143 l2cn(tout0, tout1, out, l + 8);
135 l2cn(tout0,tout1,out,l+8); 144 xor0 = tin0;
136 xor0=tin0; 145 xor1 = tin1;
137 xor1=tin1; 146 }
138 }
139 147
140 iv = &(*ivec)[0]; 148 iv = &(*ivec)[0];
141 l2c(xor0,iv); 149 l2c(xor0, iv);
142 l2c(xor1,iv); 150 l2c(xor1, iv);
143 }
144 tin0=tin1=tout0=tout1=xor0=xor1=0;
145 inW0=inW1=outW0=outW1=0;
146 tin[0]=tin[1]=0;
147 } 151 }
148 152 tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
153 inW0 = inW1 = outW0 = outW1 = 0;
154 tin[0] = tin[1] = 0;
155}