summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des/des_fcrypt.c
diff options
context:
space:
mode:
authorjsing <>2025-07-27 13:26:24 +0000
committerjsing <>2025-07-27 13:26:24 +0000
commit305717a23aaf1a0716fdfeb5149ac4a9b8e3393a (patch)
treeb7ee90b2d082264c7abf0b2f61589f17d8cce991 /src/lib/libcrypto/des/des_fcrypt.c
parentc8c2f886f887bd8387f9dee0bdf4c876658d2833 (diff)
downloadopenbsd-305717a23aaf1a0716fdfeb5149ac4a9b8e3393a.tar.gz
openbsd-305717a23aaf1a0716fdfeb5149ac4a9b8e3393a.tar.bz2
openbsd-305717a23aaf1a0716fdfeb5149ac4a9b8e3393a.zip
Rework DES encryption/decryption loops.
Use a slightly unrolled loop, which gets us half way between DES_UNROLL and no DES_UNROLL. While we're not terribly concerned by DES performance, this gets us a small gain on aarch64 and a small loss on arm. But above all, we end up with simpler code. ok tb@
Diffstat (limited to 'src/lib/libcrypto/des/des_fcrypt.c')
-rw-r--r--src/lib/libcrypto/des/des_fcrypt.c34
1 files changed, 7 insertions, 27 deletions
diff --git a/src/lib/libcrypto/des/des_fcrypt.c b/src/lib/libcrypto/des/des_fcrypt.c
index b33b1240c2..2dd071f5d0 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.4 2024/08/31 16:22:18 jsing Exp $ */ 1/* $OpenBSD: des_fcrypt.c,v 1.5 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 *
@@ -90,8 +90,8 @@ fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
90{ 90{
91 DES_LONG l, r, t, u; 91 DES_LONG l, r, t, u;
92 DES_LONG *s; 92 DES_LONG *s;
93 int j;
94 DES_LONG E0, E1; 93 DES_LONG E0, E1;
94 int i, j;
95 95
96 l = 0; 96 l = 0;
97 r = 0; 97 r = 0;
@@ -101,32 +101,12 @@ fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
101 E1 = Eswap1; 101 E1 = Eswap1;
102 102
103 for (j = 0; j < 25; j++) { 103 for (j = 0; j < 25; j++) {
104#ifndef DES_UNROLL 104 for (i = 0; i < 32; i += 8) {
105 int i; 105 D_ENCRYPT(l, r, i + 0);
106 106 D_ENCRYPT(r, l, i + 2);
107 for (i = 0; i < 32; i += 4) { 107 D_ENCRYPT(l, r, i + 4);
108 D_ENCRYPT(l, r, i + 0); /* 1 */ 108 D_ENCRYPT(r, l, i + 6);
109 D_ENCRYPT(r, l, i + 2); /* 2 */
110 } 109 }
111#else
112 D_ENCRYPT(l, r, 0); /* 1 */
113 D_ENCRYPT(r, l, 2); /* 2 */
114 D_ENCRYPT(l, r, 4); /* 3 */
115 D_ENCRYPT(r, l, 6); /* 4 */
116 D_ENCRYPT(l, r, 8); /* 5 */
117 D_ENCRYPT(r, l, 10); /* 6 */
118 D_ENCRYPT(l, r, 12); /* 7 */
119 D_ENCRYPT(r, l, 14); /* 8 */
120 D_ENCRYPT(l, r, 16); /* 9 */
121 D_ENCRYPT(r, l, 18); /* 10 */
122 D_ENCRYPT(l, r, 20); /* 11 */
123 D_ENCRYPT(r, l, 22); /* 12 */
124 D_ENCRYPT(l, r, 24); /* 13 */
125 D_ENCRYPT(r, l, 26); /* 14 */
126 D_ENCRYPT(l, r, 28); /* 15 */
127 D_ENCRYPT(r, l, 30); /* 16 */
128#endif
129
130 t = l; 110 t = l;
131 l = r; 111 l = r;
132 r = t; 112 r = t;