summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2024-08-31 16:17:13 +0000
committerjsing <>2024-08-31 16:17:13 +0000
commit70eebda78549a323c4608f8edfe9bd332ad13111 (patch)
tree9814ebed1a79b15188f1dc92c3d42699303c4c9d
parentef3851a6adc6098adccc7dac9c2e90961097b49b (diff)
downloadopenbsd-70eebda78549a323c4608f8edfe9bd332ad13111.tar.gz
openbsd-70eebda78549a323c4608f8edfe9bd332ad13111.tar.bz2
openbsd-70eebda78549a323c4608f8edfe9bd332ad13111.zip
Unifdef DES_PTR, DES_RISC1 and DES_RISC2.
These are all go fast knobs that convolute the code and can be dangerous. Lets presume that we have a modern and somewhat capable C compiler instead. ok tb@
-rw-r--r--src/lib/libcrypto/des/des_enc.c8
-rw-r--r--src/lib/libcrypto/des/des_fcrypt.c5
-rw-r--r--src/lib/libcrypto/des/des_local.h152
3 files changed, 3 insertions, 162 deletions
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
index a2f07ba71c..deec50bffb 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.19 2024/08/31 16:04:22 jsing Exp $ */ 1/* $OpenBSD: des_enc.c,v 1.20 2024/08/31 16:17:13 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,9 +210,6 @@ void
210DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) 210DES_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#ifdef DES_PTR
214 const unsigned char *des_SP = (const unsigned char *)DES_SPtrans;
215#endif
216#ifndef DES_UNROLL 213#ifndef DES_UNROLL
217 int i; 214 int i;
218#endif 215#endif
@@ -301,9 +298,6 @@ void
301DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc) 298DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
302{ 299{
303 DES_LONG l, r, t, u; 300 DES_LONG l, r, t, u;
304#ifdef DES_PTR
305 const unsigned char *des_SP = (const unsigned char *)DES_SPtrans;
306#endif
307#ifndef DES_UNROLL 301#ifndef DES_UNROLL
308 int i; 302 int i;
309#endif 303#endif
diff --git a/src/lib/libcrypto/des/des_fcrypt.c b/src/lib/libcrypto/des/des_fcrypt.c
index 4d06a79794..049040b184 100644
--- a/src/lib/libcrypto/des/des_fcrypt.c
+++ b/src/lib/libcrypto/des/des_fcrypt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: des_fcrypt.c,v 1.2 2024/08/31 16:04:22 jsing Exp $ */ 1/* $OpenBSD: des_fcrypt.c,v 1.3 2024/08/31 16:17:13 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 *
@@ -89,9 +89,6 @@ fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
89 DES_LONG Eswap1) 89 DES_LONG Eswap1)
90{ 90{
91 DES_LONG l, r, t, u; 91 DES_LONG l, r, t, u;
92#ifdef DES_PTR
93 const unsigned char *des_SP = (const unsigned char *)DES_SPtrans;
94#endif
95 DES_LONG *s; 92 DES_LONG *s;
96 int j; 93 int j;
97 DES_LONG E0, E1; 94 DES_LONG E0, E1;
diff --git a/src/lib/libcrypto/des/des_local.h b/src/lib/libcrypto/des/des_local.h
index c37128473b..9a0d366028 100644
--- a/src/lib/libcrypto/des/des_local.h
+++ b/src/lib/libcrypto/des/des_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: des_local.h,v 1.3 2024/05/24 19:21:58 tb Exp $ */ 1/* $OpenBSD: des_local.h,v 1.4 2024/08/31 16:17:13 jsing Exp $ */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -141,154 +141,6 @@ ROTATE(uint32_t a, uint32_t n)
141 t=R^s[S+1] 141 t=R^s[S+1]
142#endif 142#endif
143 143
144/* The changes to this macro may help or hinder, depending on the
145 * compiler and the architecture. gcc2 always seems to do well :-).
146 * Inspired by Dana How <how@isl.stanford.edu>
147 * DO NOT use the alternative version on machines with 8 byte longs.
148 * It does not seem to work on the Alpha, even when DES_LONG is 4
149 * bytes, probably an issue of accessing non-word aligned objects :-( */
150#ifdef DES_PTR
151
152/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
153 * is no reason to not xor all the sub items together. This potentially
154 * saves a register since things can be xored directly into L */
155
156#if defined(DES_RISC1) || defined(DES_RISC2)
157#ifdef DES_RISC1
158#define D_ENCRYPT(LL,R,S) { \
159 unsigned int u1,u2,u3; \
160 LOAD_DATA(R,S,u,t,E0,E1,u1); \
161 u2=(int)u>>8L; \
162 u1=(int)u&0xfc; \
163 u2&=0xfc; \
164 t=ROTATE(t,4); \
165 u>>=16L; \
166 LL^= *(const DES_LONG *)(des_SP +u1); \
167 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
168 u3=(int)(u>>8L); \
169 u1=(int)u&0xfc; \
170 u3&=0xfc; \
171 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
172 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
173 u2=(int)t>>8L; \
174 u1=(int)t&0xfc; \
175 u2&=0xfc; \
176 t>>=16L; \
177 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
178 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
179 u3=(int)t>>8L; \
180 u1=(int)t&0xfc; \
181 u3&=0xfc; \
182 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
183 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
184#endif
185#ifdef DES_RISC2
186#define D_ENCRYPT(LL,R,S) { \
187 unsigned int u1,u2,s1,s2; \
188 LOAD_DATA(R,S,u,t,E0,E1,u1); \
189 u2=(int)u>>8L; \
190 u1=(int)u&0xfc; \
191 u2&=0xfc; \
192 t=ROTATE(t,4); \
193 LL^= *(const DES_LONG *)(des_SP +u1); \
194 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
195 s1=(int)(u>>16L); \
196 s2=(int)(u>>24L); \
197 s1&=0xfc; \
198 s2&=0xfc; \
199 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
200 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
201 u2=(int)t>>8L; \
202 u1=(int)t&0xfc; \
203 u2&=0xfc; \
204 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
205 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
206 s1=(int)(t>>16L); \
207 s2=(int)(t>>24L); \
208 s1&=0xfc; \
209 s2&=0xfc; \
210 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
211 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
212#endif
213#else
214#define D_ENCRYPT(LL,R,S) { \
215 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
216 t=ROTATE(t,4); \
217 LL^= \
218 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
219 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
220 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
221 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
222 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
223 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
224 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
225 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
226#endif
227
228#else /* original version */
229
230#if defined(DES_RISC1) || defined(DES_RISC2)
231#ifdef DES_RISC1
232#define D_ENCRYPT(LL,R,S) { \
233 unsigned int u1,u2,u3; \
234 LOAD_DATA(R,S,u,t,E0,E1,u1); \
235 u>>=2L; \
236 t=ROTATE(t,6); \
237 u2=(int)u>>8L; \
238 u1=(int)u&0x3f; \
239 u2&=0x3f; \
240 u>>=16L; \
241 LL^=DES_SPtrans[0][u1]; \
242 LL^=DES_SPtrans[2][u2]; \
243 u3=(int)u>>8L; \
244 u1=(int)u&0x3f; \
245 u3&=0x3f; \
246 LL^=DES_SPtrans[4][u1]; \
247 LL^=DES_SPtrans[6][u3]; \
248 u2=(int)t>>8L; \
249 u1=(int)t&0x3f; \
250 u2&=0x3f; \
251 t>>=16L; \
252 LL^=DES_SPtrans[1][u1]; \
253 LL^=DES_SPtrans[3][u2]; \
254 u3=(int)t>>8L; \
255 u1=(int)t&0x3f; \
256 u3&=0x3f; \
257 LL^=DES_SPtrans[5][u1]; \
258 LL^=DES_SPtrans[7][u3]; }
259#endif
260#ifdef DES_RISC2
261#define D_ENCRYPT(LL,R,S) { \
262 unsigned int u1,u2,s1,s2; \
263 LOAD_DATA(R,S,u,t,E0,E1,u1); \
264 u>>=2L; \
265 t=ROTATE(t,6); \
266 u2=(int)u>>8L; \
267 u1=(int)u&0x3f; \
268 u2&=0x3f; \
269 LL^=DES_SPtrans[0][u1]; \
270 LL^=DES_SPtrans[2][u2]; \
271 s1=(int)u>>16L; \
272 s2=(int)u>>24L; \
273 s1&=0x3f; \
274 s2&=0x3f; \
275 LL^=DES_SPtrans[4][s1]; \
276 LL^=DES_SPtrans[6][s2]; \
277 u2=(int)t>>8L; \
278 u1=(int)t&0x3f; \
279 u2&=0x3f; \
280 LL^=DES_SPtrans[1][u1]; \
281 LL^=DES_SPtrans[3][u2]; \
282 s1=(int)t>>16; \
283 s2=(int)t>>24L; \
284 s1&=0x3f; \
285 s2&=0x3f; \
286 LL^=DES_SPtrans[5][s1]; \
287 LL^=DES_SPtrans[7][s2]; }
288#endif
289
290#else
291
292#define D_ENCRYPT(LL,R,S) { \ 144#define D_ENCRYPT(LL,R,S) { \
293 LOAD_DATA_tmp(R,S,u,t,E0,E1); \ 145 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
294 t=ROTATE(t,4); \ 146 t=ROTATE(t,4); \
@@ -301,8 +153,6 @@ ROTATE(uint32_t a, uint32_t n)
301 DES_SPtrans[3][(t>>10L)&0x3f]^ \ 153 DES_SPtrans[3][(t>>10L)&0x3f]^ \
302 DES_SPtrans[5][(t>>18L)&0x3f]^ \ 154 DES_SPtrans[5][(t>>18L)&0x3f]^ \
303 DES_SPtrans[7][(t>>26L)&0x3f]; } 155 DES_SPtrans[7][(t>>26L)&0x3f]; }
304#endif
305#endif
306 156
307 /* IP and FP 157 /* IP and FP
308 * The problem is more of a geometric problem that random bit fiddling. 158 * The problem is more of a geometric problem that random bit fiddling.