summaryrefslogtreecommitdiff
path: root/src
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
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 'src')
-rw-r--r--src/lib/libcrypto/des/cbc_cksm.c86
-rw-r--r--src/lib/libcrypto/des/cbc_enc.c14
-rw-r--r--src/lib/libcrypto/des/cfb64ede.c292
-rw-r--r--src/lib/libcrypto/des/cfb64enc.c103
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c192
-rw-r--r--src/lib/libcrypto/des/des.h165
-rw-r--r--src/lib/libcrypto/des/des_enc.c538
-rw-r--r--src/lib/libcrypto/des/des_local.h393
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c49
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c80
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c228
-rw-r--r--src/lib/libcrypto/des/enc_read.c193
-rw-r--r--src/lib/libcrypto/des/enc_writ.c122
-rw-r--r--src/lib/libcrypto/des/fcrypt.c151
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c119
-rw-r--r--src/lib/libcrypto/des/ncbc_enc.c151
-rw-r--r--src/lib/libcrypto/des/ofb64ede.c86
-rw-r--r--src/lib/libcrypto/des/ofb64enc.c85
-rw-r--r--src/lib/libcrypto/des/ofb_enc.c126
-rw-r--r--src/lib/libcrypto/des/pcbc_enc.c115
-rw-r--r--src/lib/libcrypto/des/qud_cksm.c81
-rw-r--r--src/lib/libcrypto/des/rand_key.c4
-rw-r--r--src/lib/libcrypto/des/set_key.c464
-rw-r--r--src/lib/libcrypto/des/spr.h290
-rw-r--r--src/lib/libcrypto/des/str2key.c160
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c163
26 files changed, 2219 insertions, 2231 deletions
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c
index 2c1c4aa839..640c124966 100644
--- a/src/lib/libcrypto/des/cbc_cksm.c
+++ b/src/lib/libcrypto/des/cbc_cksm.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: cbc_cksm.c,v 1.8 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: cbc_cksm.c,v 1.9 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
@@ -58,49 +58,49 @@
58 58
59#include "des_local.h" 59#include "des_local.h"
60 60
61DES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output, 61DES_LONG
62 long length, DES_key_schedule *schedule, 62DES_cbc_cksum(const unsigned char *in, DES_cblock *output,
63 const_DES_cblock *ivec) 63 long length, DES_key_schedule *schedule,
64 { 64 const_DES_cblock *ivec)
65 DES_LONG tout0,tout1,tin0,tin1; 65{
66 long l=length; 66 DES_LONG tout0, tout1, tin0, tin1;
67 long l = length;
67 DES_LONG tin[2]; 68 DES_LONG tin[2];
68 unsigned char *out = &(*output)[0]; 69 unsigned char *out = &(*output)[0];
69 const unsigned char *iv = &(*ivec)[0]; 70 const unsigned char *iv = &(*ivec)[0];
70 71
71 c2l(iv,tout0); 72 c2l(iv, tout0);
72 c2l(iv,tout1); 73 c2l(iv, tout1);
73 for (; l>0; l-=8) 74 for (; l > 0; l -= 8)
74 { 75 {
75 if (l >= 8) 76 if (l >= 8) {
76 { 77 c2l(in, tin0);
77 c2l(in,tin0); 78 c2l(in, tin1);
78 c2l(in,tin1); 79 } else
79 } 80 c2ln(in, tin0, tin1, l);
80 else 81
81 c2ln(in,tin0,tin1,l); 82 tin0 ^= tout0;
82 83 tin[0] = tin0;
83 tin0^=tout0; tin[0]=tin0; 84 tin1 ^= tout1;
84 tin1^=tout1; tin[1]=tin1; 85 tin[1] = tin1;
85 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT); 86 DES_encrypt1((DES_LONG *)tin, schedule, DES_ENCRYPT);
86 /* fix 15/10/91 eay - thanks to keithr@sco.COM */ 87 /* fix 15/10/91 eay - thanks to keithr@sco.COM */
87 tout0=tin[0]; 88 tout0 = tin[0];
88 tout1=tin[1]; 89 tout1 = tin[1];
89 } 90 }
90 if (out != NULL) 91 if (out != NULL) {
91 { 92 l2c(tout0, out);
92 l2c(tout0,out); 93 l2c(tout1, out);
93 l2c(tout1,out); 94 }
94 } 95 tout0 = tin0 = tin1 = tin[0] = tin[1] = 0;
95 tout0=tin0=tin1=tin[0]=tin[1]=0;
96 /* 96 /*
97 Transform the data in tout1 so that it will 97 Transform the data in tout1 so that it will
98 match the return value that the MIT Kerberos 98 match the return value that the MIT Kerberos
99 mit_des_cbc_cksum API returns. 99 mit_des_cbc_cksum API returns.
100 */ 100 */
101 tout1 = ((tout1 >> 24L) & 0x000000FF) 101 tout1 = ((tout1 >> 24L) & 0x000000FF) |
102 | ((tout1 >> 8L) & 0x0000FF00) 102 ((tout1 >> 8L) & 0x0000FF00) |
103 | ((tout1 << 8L) & 0x00FF0000) 103 ((tout1 << 8L) & 0x00FF0000) |
104 | ((tout1 << 24L) & 0xFF000000); 104 ((tout1 << 24L) & 0xFF000000);
105 return(tout1); 105 return (tout1);
106 } 106}
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c
index 5db52809c0..6c1ec7117d 100644
--- a/src/lib/libcrypto/des/cbc_enc.c
+++ b/src/lib/libcrypto/des/cbc_enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: cbc_enc.c,v 1.3 2014/06/12 15:49:28 deraadt Exp $ */ 1/* $OpenBSD: cbc_enc.c,v 1.4 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
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c
index f2b2fe2db5..700a36620f 100644
--- a/src/lib/libcrypto/des/cfb64ede.c
+++ b/src/lib/libcrypto/des/cfb64ede.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: cfb64ede.c,v 1.10 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: cfb64ede.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
@@ -63,182 +63,178 @@
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65 65
66void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, 66void
67 long length, DES_key_schedule *ks1, 67DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68 DES_key_schedule *ks2, DES_key_schedule *ks3, 68 long length, DES_key_schedule *ks1,
69 DES_cblock *ivec, int *num, int enc) 69 DES_key_schedule *ks2, DES_key_schedule *ks3,
70 { 70 DES_cblock *ivec, int *num, int enc)
71 DES_LONG v0,v1; 71{
72 long l=length; 72 DES_LONG v0, v1;
73 int n= *num; 73 long l = length;
74 int n = *num;
74 DES_LONG ti[2]; 75 DES_LONG ti[2];
75 unsigned char *iv,c,cc; 76 unsigned char *iv, c, cc;
76 77
77 iv=&(*ivec)[0]; 78 iv = &(*ivec)[0];
78 if (enc) 79 if (enc) {
79 { 80 while (l--) {
80 while (l--) 81 if (n == 0) {
81 { 82 c2l(iv, v0);
82 if (n == 0) 83 c2l(iv, v1);
83 {
84 c2l(iv,v0);
85 c2l(iv,v1);
86 84
87 ti[0]=v0; 85 ti[0] = v0;
88 ti[1]=v1; 86 ti[1] = v1;
89 DES_encrypt3(ti,ks1,ks2,ks3); 87 DES_encrypt3(ti, ks1, ks2, ks3);
90 v0=ti[0]; 88 v0 = ti[0];
91 v1=ti[1]; 89 v1 = ti[1];
92 90
93 iv = &(*ivec)[0]; 91 iv = &(*ivec)[0];
94 l2c(v0,iv); 92 l2c(v0, iv);
95 l2c(v1,iv); 93 l2c(v1, iv);
96 iv = &(*ivec)[0]; 94 iv = &(*ivec)[0];
97 }
98 c= *(in++)^iv[n];
99 *(out++)=c;
100 iv[n]=c;
101 n=(n+1)&0x07;
102 } 95 }
96 c = *(in++) ^ iv[n];
97 *(out++) = c;
98 iv[n] = c;
99 n = (n + 1) & 0x07;
103 } 100 }
104 else 101 } else {
105 { 102 while (l--) {
106 while (l--) 103 if (n == 0) {
107 { 104 c2l(iv, v0);
108 if (n == 0) 105 c2l(iv, v1);
109 {
110 c2l(iv,v0);
111 c2l(iv,v1);
112 106
113 ti[0]=v0; 107 ti[0] = v0;
114 ti[1]=v1; 108 ti[1] = v1;
115 DES_encrypt3(ti,ks1,ks2,ks3); 109 DES_encrypt3(ti, ks1, ks2, ks3);
116 v0=ti[0]; 110 v0 = ti[0];
117 v1=ti[1]; 111 v1 = ti[1];
118 112
119 iv = &(*ivec)[0]; 113 iv = &(*ivec)[0];
120 l2c(v0,iv); 114 l2c(v0, iv);
121 l2c(v1,iv); 115 l2c(v1, iv);
122 iv = &(*ivec)[0]; 116 iv = &(*ivec)[0];
123 }
124 cc= *(in++);
125 c=iv[n];
126 iv[n]=cc;
127 *(out++)=c^cc;
128 n=(n+1)&0x07;
129 } 117 }
118 cc = *(in++);
119 c = iv[n];
120 iv[n] = cc;
121 *(out++) = c ^ cc;
122 n = (n + 1) & 0x07;
130 } 123 }
131 v0=v1=ti[0]=ti[1]=c=cc=0;
132 *num=n;
133 } 124 }
125 v0 = v1 = ti[0] = ti[1] = c = cc = 0;
126 *num = n;
127}
134 128
135/* This is compatible with the single key CFB-r for DES, even thought that's 129/* This is compatible with the single key CFB-r for DES, even thought that's
136 * not what EVP needs. 130 * not what EVP needs.
137 */ 131 */
138 132
139void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out, 133void
140 int numbits,long length,DES_key_schedule *ks1, 134DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out,
141 DES_key_schedule *ks2,DES_key_schedule *ks3, 135 int numbits, long length, DES_key_schedule *ks1,
142 DES_cblock *ivec,int enc) 136 DES_key_schedule *ks2, DES_key_schedule *ks3,
143 { 137 DES_cblock *ivec, int enc)
144 DES_LONG d0,d1,v0,v1; 138{
145 unsigned long l=length,n=((unsigned int)numbits+7)/8; 139 DES_LONG d0, d1, v0, v1;
146 int num=numbits,i; 140 unsigned long l = length, n = ((unsigned int)numbits + 7)/8;
141 int num = numbits, i;
147 DES_LONG ti[2]; 142 DES_LONG ti[2];
148 unsigned char *iv; 143 unsigned char *iv;
149 unsigned char ovec[16]; 144 unsigned char ovec[16];
150 145
151 if (num > 64) return; 146 if (num > 64)
147 return;
152 iv = &(*ivec)[0]; 148 iv = &(*ivec)[0];
153 c2l(iv,v0); 149 c2l(iv, v0);
154 c2l(iv,v1); 150 c2l(iv, v1);
155 if (enc) 151 if (enc) {
156 { 152 while (l >= n) {
157 while (l >= n) 153 l -= n;
158 { 154 ti[0] = v0;
159 l-=n; 155 ti[1] = v1;
160 ti[0]=v0; 156 DES_encrypt3(ti, ks1, ks2, ks3);
161 ti[1]=v1; 157 c2ln(in, d0, d1, n);
162 DES_encrypt3(ti,ks1,ks2,ks3); 158 in += n;
163 c2ln(in,d0,d1,n); 159 d0 ^= ti[0];
164 in+=n; 160 d1 ^= ti[1];
165 d0^=ti[0]; 161 l2cn(d0, d1, out, n);
166 d1^=ti[1]; 162 out += n;
167 l2cn(d0,d1,out,n);
168 out+=n;
169 /* 30-08-94 - eay - changed because l>>32 and 163 /* 30-08-94 - eay - changed because l>>32 and
170 * l<<32 are bad under gcc :-( */ 164 * l<<32 are bad under gcc :-( */
171 if (num == 32) 165 if (num == 32) {
172 { v0=v1; v1=d0; } 166 v0 = v1;
173 else if (num == 64) 167 v1 = d0;
174 { v0=d0; v1=d1; } 168 } else if (num == 64) {
175 else 169 v0 = d0;
176 { 170 v1 = d1;
177 iv=&ovec[0]; 171 } else {
178 l2c(v0,iv); 172 iv = &ovec[0];
179 l2c(v1,iv); 173 l2c(v0, iv);
180 l2c(d0,iv); 174 l2c(v1, iv);
181 l2c(d1,iv); 175 l2c(d0, iv);
176 l2c(d1, iv);
182 /* shift ovec left most of the bits... */ 177 /* shift ovec left most of the bits... */
183 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0)); 178 memmove(ovec, ovec + num/8,
179 8 + (num % 8 ? 1 : 0));
184 /* now the remaining bits */ 180 /* now the remaining bits */
185 if(num%8 != 0) 181 if (num % 8 != 0)
186 for(i=0 ; i < 8 ; ++i) 182 for (i = 0; i < 8; ++i)
187 { 183 {
188 ovec[i]<<=num%8; 184 ovec[i] <<= num % 8;
189 ovec[i]|=ovec[i+1]>>(8-num%8); 185 ovec[i] |= ovec[i + 1] >>
190 } 186 (8 - num % 8);
191 iv=&ovec[0]; 187 }
192 c2l(iv,v0); 188 iv = &ovec[0];
193 c2l(iv,v1); 189 c2l(iv, v0);
194 } 190 c2l(iv, v1);
195 } 191 }
196 } 192 }
197 else 193 } else {
198 { 194 while (l >= n) {
199 while (l >= n) 195 l -= n;
200 { 196 ti[0] = v0;
201 l-=n; 197 ti[1] = v1;
202 ti[0]=v0; 198 DES_encrypt3(ti, ks1, ks2, ks3);
203 ti[1]=v1; 199 c2ln(in, d0, d1, n);
204 DES_encrypt3(ti,ks1,ks2,ks3); 200 in += n;
205 c2ln(in,d0,d1,n);
206 in+=n;
207 /* 30-08-94 - eay - changed because l>>32 and 201 /* 30-08-94 - eay - changed because l>>32 and
208 * l<<32 are bad under gcc :-( */ 202 * l<<32 are bad under gcc :-( */
209 if (num == 32) 203 if (num == 32) {
210 { v0=v1; v1=d0; } 204 v0 = v1;
211 else if (num == 64) 205 v1 = d0;
212 { v0=d0; v1=d1; } 206 } else if (num == 64) {
213 else 207 v0 = d0;
214 { 208 v1 = d1;
215 iv=&ovec[0]; 209 } else {
216 l2c(v0,iv); 210 iv = &ovec[0];
217 l2c(v1,iv); 211 l2c(v0, iv);
218 l2c(d0,iv); 212 l2c(v1, iv);
219 l2c(d1,iv); 213 l2c(d0, iv);
214 l2c(d1, iv);
220 /* shift ovec left most of the bits... */ 215 /* shift ovec left most of the bits... */
221 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0)); 216 memmove(ovec, ovec + num/8,
217 8 + (num % 8 ? 1 : 0));
222 /* now the remaining bits */ 218 /* now the remaining bits */
223 if(num%8 != 0) 219 if (num % 8 != 0)
224 for(i=0 ; i < 8 ; ++i) 220 for (i = 0; i < 8; ++i)
225 { 221 {
226 ovec[i]<<=num%8; 222 ovec[i] <<= num % 8;
227 ovec[i]|=ovec[i+1]>>(8-num%8); 223 ovec[i] |= ovec[i + 1] >>
228 } 224 (8 - num % 8);
229 iv=&ovec[0]; 225 }
230 c2l(iv,v0); 226 iv = &ovec[0];
231 c2l(iv,v1); 227 c2l(iv, v0);
232 } 228 c2l(iv, v1);
233 d0^=ti[0];
234 d1^=ti[1];
235 l2cn(d0,d1,out,n);
236 out+=n;
237 } 229 }
230 d0 ^= ti[0];
231 d1 ^= ti[1];
232 l2cn(d0, d1, out, n);
233 out += n;
238 } 234 }
239 iv = &(*ivec)[0];
240 l2c(v0,iv);
241 l2c(v1,iv);
242 v0=v1=d0=d1=ti[0]=ti[1]=0;
243 } 235 }
244 236 iv = &(*ivec)[0];
237 l2c(v0, iv);
238 l2c(v1, iv);
239 v0 = v1 = d0 = d1 = ti[0] = ti[1] = 0;
240}
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c
index 4e9284599d..d7434b9db9 100644
--- a/src/lib/libcrypto/des/cfb64enc.c
+++ b/src/lib/libcrypto/des/cfb64enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: cfb64enc.c,v 1.7 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: cfb64enc.c,v 1.8 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
@@ -63,59 +63,60 @@
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65 65
66void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, 66void
67 long length, DES_key_schedule *schedule, 67DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68 DES_cblock *ivec, int *num, int enc) 68 long length, DES_key_schedule *schedule,
69 { 69 DES_cblock *ivec, int *num, int enc)
70 DES_LONG v0,v1; 70{
71 long l=length; 71 DES_LONG v0, v1;
72 int n= *num; 72 long l = length;
73 int n = *num;
73 DES_LONG ti[2]; 74 DES_LONG ti[2];
74 unsigned char *iv,c,cc; 75 unsigned char *iv, c, cc;
75 76
76 iv = &(*ivec)[0]; 77 iv = &(*ivec)[0];
77 if (enc) 78 if (enc) {
78 { 79 while (l--) {
79 while (l--) 80 if (n == 0) {
80 { 81 c2l(iv, v0);
81 if (n == 0) 82 ti[0] = v0;
82 { 83 c2l(iv, v1);
83 c2l(iv,v0); ti[0]=v0; 84 ti[1] = v1;
84 c2l(iv,v1); ti[1]=v1; 85 DES_encrypt1(ti, schedule, DES_ENCRYPT);
85 DES_encrypt1(ti,schedule,DES_ENCRYPT);
86 iv = &(*ivec)[0]; 86 iv = &(*ivec)[0];
87 v0=ti[0]; l2c(v0,iv); 87 v0 = ti[0];
88 v0=ti[1]; l2c(v0,iv); 88 l2c(v0, iv);
89 v0 = ti[1];
90 l2c(v0, iv);
89 iv = &(*ivec)[0]; 91 iv = &(*ivec)[0];
90 }
91 c= *(in++)^iv[n];
92 *(out++)=c;
93 iv[n]=c;
94 n=(n+1)&0x07;
95 } 92 }
93 c = *(in++) ^ iv[n];
94 *(out++) = c;
95 iv[n] = c;
96 n = (n + 1) & 0x07;
96 } 97 }
97 else 98 } else {
98 { 99 while (l--) {
99 while (l--) 100 if (n == 0) {
100 { 101 c2l(iv, v0);
101 if (n == 0) 102 ti[0] = v0;
102 { 103 c2l(iv, v1);
103 c2l(iv,v0); ti[0]=v0; 104 ti[1] = v1;
104 c2l(iv,v1); ti[1]=v1; 105 DES_encrypt1(ti, schedule, DES_ENCRYPT);
105 DES_encrypt1(ti,schedule,DES_ENCRYPT);
106 iv = &(*ivec)[0]; 106 iv = &(*ivec)[0];
107 v0=ti[0]; l2c(v0,iv); 107 v0 = ti[0];
108 v0=ti[1]; l2c(v0,iv); 108 l2c(v0, iv);
109 v0 = ti[1];
110 l2c(v0, iv);
109 iv = &(*ivec)[0]; 111 iv = &(*ivec)[0];
110 }
111 cc= *(in++);
112 c=iv[n];
113 iv[n]=cc;
114 *(out++)=c^cc;
115 n=(n+1)&0x07;
116 } 112 }
113 cc = *(in++);
114 c = iv[n];
115 iv[n] = cc;
116 *(out++) = c ^ cc;
117 n = (n + 1) & 0x07;
117 } 118 }
118 v0=v1=ti[0]=ti[1]=c=cc=0;
119 *num=n;
120 } 119 }
121 120 v0 = v1 = ti[0] = ti[1] = c = cc = 0;
121 *num = n;
122}
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c
index 9ba31f4e11..dac86751d3 100644
--- a/src/lib/libcrypto/des/cfb_enc.c
+++ b/src/lib/libcrypto/des/cfb_enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: cfb_enc.c,v 1.15 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: cfb_enc.c,v 1.16 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
@@ -67,123 +67,123 @@
67 */ 67 */
68/* Until Aug 1 2003 this function did not correctly implement CFB-r, so it 68/* Until Aug 1 2003 this function did not correctly implement CFB-r, so it
69 * will not be compatible with any encryption prior to that date. Ben. */ 69 * will not be compatible with any encryption prior to that date. Ben. */
70void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, 70void
71 long length, DES_key_schedule *schedule, DES_cblock *ivec, 71DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
72 int enc) 72 long length, DES_key_schedule *schedule, DES_cblock *ivec,
73 { 73 int enc)
74 DES_LONG d0,d1,v0,v1; 74{
75 unsigned long l=length; 75 DES_LONG d0, d1, v0, v1;
76 int num=numbits/8,n=(numbits+7)/8,i,rem=numbits%8; 76 unsigned long l = length;
77 int num = numbits/8, n = (numbits + 7)/8, i, rem = numbits % 8;
77 DES_LONG ti[2]; 78 DES_LONG ti[2];
78 unsigned char *iv; 79 unsigned char *iv;
79#if BYTE_ORDER != LITTLE_ENDIAN 80#if BYTE_ORDER != LITTLE_ENDIAN
80 unsigned char ovec[16]; 81 unsigned char ovec[16];
81#else 82#else
82 unsigned int sh[4]; 83 unsigned int sh[4];
83 unsigned char *ovec=(unsigned char *)sh; 84 unsigned char *ovec = (unsigned char *)sh;
84#endif 85#endif
85 86
86 if (numbits<=0 || numbits > 64) return; 87 if (numbits <= 0 || numbits > 64)
88 return;
87 iv = &(*ivec)[0]; 89 iv = &(*ivec)[0];
88 c2l(iv,v0); 90 c2l(iv, v0);
89 c2l(iv,v1); 91 c2l(iv, v1);
90 if (enc) 92 if (enc) {
91 { 93 while (l >= (unsigned long)n) {
92 while (l >= (unsigned long)n) 94 l -= n;
93 { 95 ti[0] = v0;
94 l-=n; 96 ti[1] = v1;
95 ti[0]=v0; 97 DES_encrypt1((DES_LONG *)ti, schedule, DES_ENCRYPT);
96 ti[1]=v1; 98 c2ln(in, d0, d1, n);
97 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT); 99 in += n;
98 c2ln(in,d0,d1,n); 100 d0 ^= ti[0];
99 in+=n; 101 d1 ^= ti[1];
100 d0^=ti[0]; 102 l2cn(d0, d1, out, n);
101 d1^=ti[1]; 103 out += n;
102 l2cn(d0,d1,out,n);
103 out+=n;
104 /* 30-08-94 - eay - changed because l>>32 and 104 /* 30-08-94 - eay - changed because l>>32 and
105 * l<<32 are bad under gcc :-( */ 105 * l<<32 are bad under gcc :-( */
106 if (numbits == 32) 106 if (numbits == 32) {
107 { v0=v1; v1=d0; } 107 v0 = v1;
108 else if (numbits == 64) 108 v1 = d0;
109 { v0=d0; v1=d1; } 109 } else if (numbits == 64) {
110 else 110 v0 = d0;
111 { 111 v1 = d1;
112 } else {
112#if BYTE_ORDER != LITTLE_ENDIAN 113#if BYTE_ORDER != LITTLE_ENDIAN
113 iv=&ovec[0]; 114 iv = &ovec[0];
114 l2c(v0,iv); 115 l2c(v0, iv);
115 l2c(v1,iv); 116 l2c(v1, iv);
116 l2c(d0,iv); 117 l2c(d0, iv);
117 l2c(d1,iv); 118 l2c(d1, iv);
118#else 119#else
119 sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; 120 sh[0] = v0, sh[1] = v1, sh[2] = d0, sh[3] = d1;
120#endif 121#endif
121 if (rem==0) 122 if (rem == 0)
122 memmove(ovec,ovec+num,8); 123 memmove(ovec, ovec + num, 8);
123 else 124 else
124 for(i=0 ; i < 8 ; ++i) 125 for (i = 0; i < 8; ++i)
125 ovec[i]=ovec[i+num]<<rem | 126 ovec[i] = ovec[i + num] << rem |
126 ovec[i+num+1]>>(8-rem); 127 ovec[i + num + 1] >> (8 -
128 rem);
127#if BYTE_ORDER == LITTLE_ENDIAN 129#if BYTE_ORDER == LITTLE_ENDIAN
128 v0=sh[0], v1=sh[1]; 130 v0 = sh[0], v1 = sh[1];
129#else 131#else
130 iv=&ovec[0]; 132 iv = &ovec[0];
131 c2l(iv,v0); 133 c2l(iv, v0);
132 c2l(iv,v1); 134 c2l(iv, v1);
133#endif 135#endif
134 }
135 } 136 }
136 } 137 }
137 else 138 } else {
138 { 139 while (l >= (unsigned long)n) {
139 while (l >= (unsigned long)n) 140 l -= n;
140 { 141 ti[0] = v0;
141 l-=n; 142 ti[1] = v1;
142 ti[0]=v0; 143 DES_encrypt1((DES_LONG *)ti, schedule, DES_ENCRYPT);
143 ti[1]=v1; 144 c2ln(in, d0, d1, n);
144 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT); 145 in += n;
145 c2ln(in,d0,d1,n);
146 in+=n;
147 /* 30-08-94 - eay - changed because l>>32 and 146 /* 30-08-94 - eay - changed because l>>32 and
148 * l<<32 are bad under gcc :-( */ 147 * l<<32 are bad under gcc :-( */
149 if (numbits == 32) 148 if (numbits == 32) {
150 { v0=v1; v1=d0; } 149 v0 = v1;
151 else if (numbits == 64) 150 v1 = d0;
152 { v0=d0; v1=d1; } 151 } else if (numbits == 64) {
153 else 152 v0 = d0;
154 { 153 v1 = d1;
154 } else {
155#if BYTE_ORDER != LITTLE_ENDIAN 155#if BYTE_ORDER != LITTLE_ENDIAN
156 iv=&ovec[0]; 156 iv = &ovec[0];
157 l2c(v0,iv); 157 l2c(v0, iv);
158 l2c(v1,iv); 158 l2c(v1, iv);
159 l2c(d0,iv); 159 l2c(d0, iv);
160 l2c(d1,iv); 160 l2c(d1, iv);
161#else 161#else
162 sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; 162 sh[0] = v0, sh[1] = v1, sh[2] = d0, sh[3] = d1;
163#endif 163#endif
164 if (rem==0) 164 if (rem == 0)
165 memmove(ovec,ovec+num,8); 165 memmove(ovec, ovec + num, 8);
166 else 166 else
167 for(i=0 ; i < 8 ; ++i) 167 for (i = 0; i < 8; ++i)
168 ovec[i]=ovec[i+num]<<rem | 168 ovec[i] = ovec[i + num] << rem |
169 ovec[i+num+1]>>(8-rem); 169 ovec[i + num + 1] >> (8 -
170 rem);
170#if BYTE_ORDER == LITTLE_ENDIAN 171#if BYTE_ORDER == LITTLE_ENDIAN
171 v0=sh[0], v1=sh[1]; 172 v0 = sh[0], v1 = sh[1];
172#else 173#else
173 iv=&ovec[0]; 174 iv = &ovec[0];
174 c2l(iv,v0); 175 c2l(iv, v0);
175 c2l(iv,v1); 176 c2l(iv, v1);
176#endif 177#endif
177 }
178 d0^=ti[0];
179 d1^=ti[1];
180 l2cn(d0,d1,out,n);
181 out+=n;
182 } 178 }
179 d0 ^= ti[0];
180 d1 ^= ti[1];
181 l2cn(d0, d1, out, n);
182 out += n;
183 } 183 }
184 iv = &(*ivec)[0];
185 l2c(v0,iv);
186 l2c(v1,iv);
187 v0=v1=d0=d1=ti[0]=ti[1]=0;
188 } 184 }
189 185 iv = &(*ivec)[0];
186 l2c(v0, iv);
187 l2c(v1, iv);
188 v0 = v1 = d0 = d1 = ti[0] = ti[1] = 0;
189}
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
index e1331d3fa2..ef2ecb4d03 100644
--- a/src/lib/libcrypto/des/des.h
+++ b/src/lib/libcrypto/des/des.h
@@ -1,25 +1,25 @@
1/* $OpenBSD: des.h,v 1.19 2015/02/07 13:19:15 doug Exp $ */ 1/* $OpenBSD: des.h,v 1.20 2023/07/08 07:11:07 beck 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 *
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
@@ -65,7 +65,6 @@
65#error DES is disabled. 65#error DES is disabled.
66#endif 66#endif
67 67
68
69#ifdef __cplusplus 68#ifdef __cplusplus
70extern "C" { 69extern "C" {
71#endif 70#endif
@@ -75,16 +74,14 @@ typedef /* const */ unsigned char const_DES_cblock[8];
75/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * 74/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *
76 * and const_DES_cblock * are incompatible pointer types. */ 75 * and const_DES_cblock * are incompatible pointer types. */
77 76
78typedef struct DES_ks 77typedef struct DES_ks {
79 { 78 union {
80 union 79 DES_cblock cblock;
81 {
82 DES_cblock cblock;
83 /* make sure things are correct size on machines with 80 /* make sure things are correct size on machines with
84 * 8 byte longs */ 81 * 8 byte longs */
85 DES_LONG deslong[2]; 82 DES_LONG deslong[2];
86 } ks[16]; 83 } ks[16];
87 } DES_key_schedule; 84} DES_key_schedule;
88 85
89#define DES_KEY_SZ (sizeof(DES_cblock)) 86#define DES_KEY_SZ (sizeof(DES_cblock))
90#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) 87#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
@@ -112,26 +109,26 @@ extern int DES_rw_mode; /* defaults to DES_PCBC_MODE */
112 109
113const char *DES_options(void); 110const char *DES_options(void);
114void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, 111void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
115 DES_key_schedule *ks1,DES_key_schedule *ks2, 112 DES_key_schedule *ks1, DES_key_schedule *ks2,
116 DES_key_schedule *ks3, int enc); 113 DES_key_schedule *ks3, int enc);
117DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output, 114DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
118 long length,DES_key_schedule *schedule, 115 long length, DES_key_schedule *schedule,
119 const_DES_cblock *ivec); 116 const_DES_cblock *ivec);
120/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ 117/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
121void DES_cbc_encrypt(const unsigned char *input,unsigned char *output, 118void DES_cbc_encrypt(const unsigned char *input, unsigned char *output,
122 long length,DES_key_schedule *schedule,DES_cblock *ivec, 119 long length, DES_key_schedule *schedule, DES_cblock *ivec,
123 int enc); 120 int enc);
124void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output, 121void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
125 long length,DES_key_schedule *schedule,DES_cblock *ivec, 122 long length, DES_key_schedule *schedule, DES_cblock *ivec,
126 int enc); 123 int enc);
127void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output, 124void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
128 long length,DES_key_schedule *schedule,DES_cblock *ivec, 125 long length, DES_key_schedule *schedule, DES_cblock *ivec,
129 const_DES_cblock *inw,const_DES_cblock *outw,int enc); 126 const_DES_cblock *inw, const_DES_cblock *outw, int enc);
130void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits, 127void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
131 long length,DES_key_schedule *schedule,DES_cblock *ivec, 128 long length, DES_key_schedule *schedule, DES_cblock *ivec,
132 int enc); 129 int enc);
133void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output, 130void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
134 DES_key_schedule *ks,int enc); 131 DES_key_schedule *ks, int enc);
135 132
136/* This is the DES encryption function that gets called by just about 133/* This is the DES encryption function that gets called by just about
137 every other DES routine in the library. You should not use this 134 every other DES routine in the library. You should not use this
@@ -142,7 +139,7 @@ void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,
142 Data is a pointer to 2 unsigned long's and ks is the 139 Data is a pointer to 2 unsigned long's and ks is the
143 DES_key_schedule to use. enc, is non zero specifies encryption, 140 DES_key_schedule to use. enc, is non zero specifies encryption,
144 zero if decryption. */ 141 zero if decryption. */
145void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc); 142void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc);
146 143
147/* This functions is the same as DES_encrypt1() except that the DES 144/* This functions is the same as DES_encrypt1() except that the DES
148 initial permutation (IP) and final permutation (FP) have been left 145 initial permutation (IP) and final permutation (FP) have been left
@@ -150,47 +147,47 @@ void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
150 It is used by the routines in the library that implement triple DES. 147 It is used by the routines in the library that implement triple DES.
151 IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same 148 IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same
152 as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */ 149 as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */
153void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc); 150void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc);
154 151
155void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, 152void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
156 DES_key_schedule *ks2, DES_key_schedule *ks3); 153 DES_key_schedule *ks2, DES_key_schedule *ks3);
157void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, 154void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
158 DES_key_schedule *ks2, DES_key_schedule *ks3); 155 DES_key_schedule *ks2, DES_key_schedule *ks3);
159void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output, 156void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
160 long length, 157 long length,
161 DES_key_schedule *ks1,DES_key_schedule *ks2, 158 DES_key_schedule *ks1, DES_key_schedule *ks2,
162 DES_key_schedule *ks3,DES_cblock *ivec,int enc); 159 DES_key_schedule *ks3, DES_cblock *ivec, int enc);
163void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out, 160void DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
164 long length, 161 long length,
165 DES_key_schedule *ks1,DES_key_schedule *ks2, 162 DES_key_schedule *ks1, DES_key_schedule *ks2,
166 DES_key_schedule *ks3, 163 DES_key_schedule *ks3,
167 DES_cblock *ivec1,DES_cblock *ivec2, 164 DES_cblock *ivec1, DES_cblock *ivec2,
168 int enc); 165 int enc);
169void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out, 166void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
170 long length,DES_key_schedule *ks1, 167 long length, DES_key_schedule *ks1,
171 DES_key_schedule *ks2,DES_key_schedule *ks3, 168 DES_key_schedule *ks2, DES_key_schedule *ks3,
172 DES_cblock *ivec,int *num,int enc); 169 DES_cblock *ivec, int *num, int enc);
173void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out, 170void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out,
174 int numbits,long length,DES_key_schedule *ks1, 171 int numbits, long length, DES_key_schedule *ks1,
175 DES_key_schedule *ks2,DES_key_schedule *ks3, 172 DES_key_schedule *ks2, DES_key_schedule *ks3,
176 DES_cblock *ivec,int enc); 173 DES_cblock *ivec, int enc);
177void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out, 174void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
178 long length,DES_key_schedule *ks1, 175 long length, DES_key_schedule *ks1,
179 DES_key_schedule *ks2,DES_key_schedule *ks3, 176 DES_key_schedule *ks2, DES_key_schedule *ks3,
180 DES_cblock *ivec,int *num); 177 DES_cblock *ivec, int *num);
181int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched, 178int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
182 DES_cblock *iv); 179 DES_cblock *iv);
183int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched, 180int DES_enc_write(int fd, const void *buf, int len, DES_key_schedule *sched,
184 DES_cblock *iv); 181 DES_cblock *iv);
185char *DES_fcrypt(const char *buf,const char *salt, char *ret); 182char *DES_fcrypt(const char *buf, const char *salt, char *ret);
186char *DES_crypt(const char *buf,const char *salt); 183char *DES_crypt(const char *buf, const char *salt);
187void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits, 184void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
188 long length,DES_key_schedule *schedule,DES_cblock *ivec); 185 long length, DES_key_schedule *schedule, DES_cblock *ivec);
189void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output, 186void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
190 long length,DES_key_schedule *schedule,DES_cblock *ivec, 187 long length, DES_key_schedule *schedule, DES_cblock *ivec,
191 int enc); 188 int enc);
192DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[], 189DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
193 long length,int out_count,DES_cblock *seed); 190 long length, int out_count, DES_cblock *seed);
194int DES_random_key(DES_cblock *ret); 191int DES_random_key(DES_cblock *ret);
195void DES_set_odd_parity(DES_cblock *key); 192void DES_set_odd_parity(DES_cblock *key);
196int DES_check_key_parity(const_DES_cblock *key); 193int DES_check_key_parity(const_DES_cblock *key);
@@ -198,17 +195,17 @@ int DES_is_weak_key(const_DES_cblock *key);
198/* DES_set_key (= set_key = DES_key_sched = key_sched) calls 195/* DES_set_key (= set_key = DES_key_sched = key_sched) calls
199 * DES_set_key_checked if global variable DES_check_key is set, 196 * DES_set_key_checked if global variable DES_check_key is set,
200 * DES_set_key_unchecked otherwise. */ 197 * DES_set_key_unchecked otherwise. */
201int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule); 198int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
202int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule); 199int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
203int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule); 200int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
204void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule); 201void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
205void DES_string_to_key(const char *str,DES_cblock *key); 202void DES_string_to_key(const char *str, DES_cblock *key);
206void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2); 203void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
207void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length, 204void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,
208 DES_key_schedule *schedule,DES_cblock *ivec,int *num, 205 DES_key_schedule *schedule, DES_cblock *ivec, int *num,
209 int enc); 206 int enc);
210void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length, 207void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,
211 DES_key_schedule *schedule,DES_cblock *ivec,int *num); 208 DES_key_schedule *schedule, DES_cblock *ivec, int *num);
212 209
213#define DES_fixup_key_parity DES_set_odd_parity 210#define DES_fixup_key_parity DES_set_odd_parity
214 211
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
index 8d6232bbde..a8d8bd7ecb 100644
--- a/src/lib/libcrypto/des/des_enc.c
+++ b/src/lib/libcrypto/des/des_enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: des_enc.c,v 1.13 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: des_enc.c,v 1.14 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
@@ -61,21 +61,22 @@
61 61
62#ifndef OPENBSD_DES_ASM 62#ifndef OPENBSD_DES_ASM
63 63
64void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) 64void
65 { 65DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
66 DES_LONG l,r,t,u; 66{
67 DES_LONG l, r, t, u;
67#ifdef DES_PTR 68#ifdef DES_PTR
68 const unsigned char *des_SP=(const unsigned char *)DES_SPtrans; 69 const unsigned char *des_SP = (const unsigned char *)DES_SPtrans;
69#endif 70#endif
70#ifndef DES_UNROLL 71#ifndef DES_UNROLL
71 int i; 72 int i;
72#endif 73#endif
73 DES_LONG *s; 74 DES_LONG *s;
74 75
75 r=data[0]; 76 r = data[0];
76 l=data[1]; 77 l = data[1];
77 78
78 IP(r,l); 79 IP(r, l);
79 /* Things have been modified so that the initial rotate is 80 /* Things have been modified so that the initial rotate is
80 * done outside the loop. This required the 81 * done outside the loop. This required the
81 * DES_SPtrans values in sp.h to be rotated 1 bit to the right. 82 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
@@ -84,90 +85,88 @@ void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
84 * for pointing this out. */ 85 * for pointing this out. */
85 /* clear the top bits on machines with 8byte longs */ 86 /* clear the top bits on machines with 8byte longs */
86 /* shift left by 2 */ 87 /* shift left by 2 */
87 r=ROTATE(r,29)&0xffffffffL; 88 r = ROTATE(r, 29) & 0xffffffffL;
88 l=ROTATE(l,29)&0xffffffffL; 89 l = ROTATE(l, 29) & 0xffffffffL;
89 90
90 s=ks->ks->deslong; 91 s = ks->ks->deslong;
91 /* I don't know if it is worth the effort of loop unrolling the 92 /* I don't know if it is worth the effort of loop unrolling the
92 * inner loop */ 93 * inner loop */
93 if (enc) 94 if (enc) {
94 {
95#ifdef DES_UNROLL 95#ifdef DES_UNROLL
96 D_ENCRYPT(l,r, 0); /* 1 */ 96 D_ENCRYPT(l, r, 0); /* 1 */
97 D_ENCRYPT(r,l, 2); /* 2 */ 97 D_ENCRYPT(r, l, 2); /* 2 */
98 D_ENCRYPT(l,r, 4); /* 3 */ 98 D_ENCRYPT(l, r, 4); /* 3 */
99 D_ENCRYPT(r,l, 6); /* 4 */ 99 D_ENCRYPT(r, l, 6); /* 4 */
100 D_ENCRYPT(l,r, 8); /* 5 */ 100 D_ENCRYPT(l, r, 8); /* 5 */
101 D_ENCRYPT(r,l,10); /* 6 */ 101 D_ENCRYPT(r, l, 10); /* 6 */
102 D_ENCRYPT(l,r,12); /* 7 */ 102 D_ENCRYPT(l, r, 12); /* 7 */
103 D_ENCRYPT(r,l,14); /* 8 */ 103 D_ENCRYPT(r, l, 14); /* 8 */
104 D_ENCRYPT(l,r,16); /* 9 */ 104 D_ENCRYPT(l, r, 16); /* 9 */
105 D_ENCRYPT(r,l,18); /* 10 */ 105 D_ENCRYPT(r, l, 18); /* 10 */
106 D_ENCRYPT(l,r,20); /* 11 */ 106 D_ENCRYPT(l, r, 20); /* 11 */
107 D_ENCRYPT(r,l,22); /* 12 */ 107 D_ENCRYPT(r, l, 22); /* 12 */
108 D_ENCRYPT(l,r,24); /* 13 */ 108 D_ENCRYPT(l, r, 24); /* 13 */
109 D_ENCRYPT(r,l,26); /* 14 */ 109 D_ENCRYPT(r, l, 26); /* 14 */
110 D_ENCRYPT(l,r,28); /* 15 */ 110 D_ENCRYPT(l, r, 28); /* 15 */
111 D_ENCRYPT(r,l,30); /* 16 */ 111 D_ENCRYPT(r, l, 30); /* 16 */
112#else 112#else
113 for (i=0; i<32; i+=4) 113 for (i = 0; i < 32; i += 4)
114 {
115 D_ENCRYPT(l,r,i+0); /* 1 */
116 D_ENCRYPT(r,l,i+2); /* 2 */
117 }
118#endif
119 }
120 else
121 { 114 {
115 D_ENCRYPT(l, r, i + 0); /* 1 */
116 D_ENCRYPT(r, l, i + 2); /* 2 */
117 }
118#endif
119 } else {
122#ifdef DES_UNROLL 120#ifdef DES_UNROLL
123 D_ENCRYPT(l,r,30); /* 16 */ 121 D_ENCRYPT(l, r, 30); /* 16 */
124 D_ENCRYPT(r,l,28); /* 15 */ 122 D_ENCRYPT(r, l, 28); /* 15 */
125 D_ENCRYPT(l,r,26); /* 14 */ 123 D_ENCRYPT(l, r, 26); /* 14 */
126 D_ENCRYPT(r,l,24); /* 13 */ 124 D_ENCRYPT(r, l, 24); /* 13 */
127 D_ENCRYPT(l,r,22); /* 12 */ 125 D_ENCRYPT(l, r, 22); /* 12 */
128 D_ENCRYPT(r,l,20); /* 11 */ 126 D_ENCRYPT(r, l, 20); /* 11 */
129 D_ENCRYPT(l,r,18); /* 10 */ 127 D_ENCRYPT(l, r, 18); /* 10 */
130 D_ENCRYPT(r,l,16); /* 9 */ 128 D_ENCRYPT(r, l, 16); /* 9 */
131 D_ENCRYPT(l,r,14); /* 8 */ 129 D_ENCRYPT(l, r, 14); /* 8 */
132 D_ENCRYPT(r,l,12); /* 7 */ 130 D_ENCRYPT(r, l, 12); /* 7 */
133 D_ENCRYPT(l,r,10); /* 6 */ 131 D_ENCRYPT(l, r, 10); /* 6 */
134 D_ENCRYPT(r,l, 8); /* 5 */ 132 D_ENCRYPT(r, l, 8); /* 5 */
135 D_ENCRYPT(l,r, 6); /* 4 */ 133 D_ENCRYPT(l, r, 6); /* 4 */
136 D_ENCRYPT(r,l, 4); /* 3 */ 134 D_ENCRYPT(r, l, 4); /* 3 */
137 D_ENCRYPT(l,r, 2); /* 2 */ 135 D_ENCRYPT(l, r, 2); /* 2 */
138 D_ENCRYPT(r,l, 0); /* 1 */ 136 D_ENCRYPT(r, l, 0); /* 1 */
139#else 137#else
140 for (i=30; i>0; i-=4) 138 for (i = 30; i > 0; i -= 4)
141 { 139 {
142 D_ENCRYPT(l,r,i-0); /* 16 */ 140 D_ENCRYPT(l, r, i - 0); /* 16 */
143 D_ENCRYPT(r,l,i-2); /* 15 */ 141 D_ENCRYPT(r, l, i - 2); /* 15 */
144 }
145#endif
146 } 142 }
147 143#endif
148 /* rotate and clear the top bits on machines with 8byte longs */
149 l=ROTATE(l,3)&0xffffffffL;
150 r=ROTATE(r,3)&0xffffffffL;
151
152 FP(r,l);
153 data[0]=l;
154 data[1]=r;
155 l=r=t=u=0;
156 } 144 }
157 145
158void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc) 146 /* rotate and clear the top bits on machines with 8byte longs */
159 { 147 l = ROTATE(l, 3) & 0xffffffffL;
160 DES_LONG l,r,t,u; 148 r = ROTATE(r, 3) & 0xffffffffL;
149
150 FP(r, l);
151 data[0] = l;
152 data[1] = r;
153 l = r = t = u = 0;
154}
155
156void
157DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
158{
159 DES_LONG l, r, t, u;
161#ifdef DES_PTR 160#ifdef DES_PTR
162 const unsigned char *des_SP=(const unsigned char *)DES_SPtrans; 161 const unsigned char *des_SP = (const unsigned char *)DES_SPtrans;
163#endif 162#endif
164#ifndef DES_UNROLL 163#ifndef DES_UNROLL
165 int i; 164 int i;
166#endif 165#endif
167 DES_LONG *s; 166 DES_LONG *s;
168 167
169 r=data[0]; 168 r = data[0];
170 l=data[1]; 169 l = data[1];
171 170
172 /* Things have been modified so that the initial rotate is 171 /* Things have been modified so that the initial rotate is
173 * done outside the loop. This required the 172 * done outside the loop. This required the
@@ -176,229 +175,224 @@ void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
176 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> 175 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
177 * for pointing this out. */ 176 * for pointing this out. */
178 /* clear the top bits on machines with 8byte longs */ 177 /* clear the top bits on machines with 8byte longs */
179 r=ROTATE(r,29)&0xffffffffL; 178 r = ROTATE(r, 29) & 0xffffffffL;
180 l=ROTATE(l,29)&0xffffffffL; 179 l = ROTATE(l, 29) & 0xffffffffL;
181 180
182 s=ks->ks->deslong; 181 s = ks->ks->deslong;
183 /* I don't know if it is worth the effort of loop unrolling the 182 /* I don't know if it is worth the effort of loop unrolling the
184 * inner loop */ 183 * inner loop */
185 if (enc) 184 if (enc) {
186 {
187#ifdef DES_UNROLL 185#ifdef DES_UNROLL
188 D_ENCRYPT(l,r, 0); /* 1 */ 186 D_ENCRYPT(l, r, 0); /* 1 */
189 D_ENCRYPT(r,l, 2); /* 2 */ 187 D_ENCRYPT(r, l, 2); /* 2 */
190 D_ENCRYPT(l,r, 4); /* 3 */ 188 D_ENCRYPT(l, r, 4); /* 3 */
191 D_ENCRYPT(r,l, 6); /* 4 */ 189 D_ENCRYPT(r, l, 6); /* 4 */
192 D_ENCRYPT(l,r, 8); /* 5 */ 190 D_ENCRYPT(l, r, 8); /* 5 */
193 D_ENCRYPT(r,l,10); /* 6 */ 191 D_ENCRYPT(r, l, 10); /* 6 */
194 D_ENCRYPT(l,r,12); /* 7 */ 192 D_ENCRYPT(l, r, 12); /* 7 */
195 D_ENCRYPT(r,l,14); /* 8 */ 193 D_ENCRYPT(r, l, 14); /* 8 */
196 D_ENCRYPT(l,r,16); /* 9 */ 194 D_ENCRYPT(l, r, 16); /* 9 */
197 D_ENCRYPT(r,l,18); /* 10 */ 195 D_ENCRYPT(r, l, 18); /* 10 */
198 D_ENCRYPT(l,r,20); /* 11 */ 196 D_ENCRYPT(l, r, 20); /* 11 */
199 D_ENCRYPT(r,l,22); /* 12 */ 197 D_ENCRYPT(r, l, 22); /* 12 */
200 D_ENCRYPT(l,r,24); /* 13 */ 198 D_ENCRYPT(l, r, 24); /* 13 */
201 D_ENCRYPT(r,l,26); /* 14 */ 199 D_ENCRYPT(r, l, 26); /* 14 */
202 D_ENCRYPT(l,r,28); /* 15 */ 200 D_ENCRYPT(l, r, 28); /* 15 */
203 D_ENCRYPT(r,l,30); /* 16 */ 201 D_ENCRYPT(r, l, 30); /* 16 */
204#else 202#else
205 for (i=0; i<32; i+=4) 203 for (i = 0; i < 32; i += 4)
206 {
207 D_ENCRYPT(l,r,i+0); /* 1 */
208 D_ENCRYPT(r,l,i+2); /* 2 */
209 }
210#endif
211 }
212 else
213 { 204 {
205 D_ENCRYPT(l, r, i + 0); /* 1 */
206 D_ENCRYPT(r, l, i + 2); /* 2 */
207 }
208#endif
209 } else {
214#ifdef DES_UNROLL 210#ifdef DES_UNROLL
215 D_ENCRYPT(l,r,30); /* 16 */ 211 D_ENCRYPT(l, r, 30); /* 16 */
216 D_ENCRYPT(r,l,28); /* 15 */ 212 D_ENCRYPT(r, l, 28); /* 15 */
217 D_ENCRYPT(l,r,26); /* 14 */ 213 D_ENCRYPT(l, r, 26); /* 14 */
218 D_ENCRYPT(r,l,24); /* 13 */ 214 D_ENCRYPT(r, l, 24); /* 13 */
219 D_ENCRYPT(l,r,22); /* 12 */ 215 D_ENCRYPT(l, r, 22); /* 12 */
220 D_ENCRYPT(r,l,20); /* 11 */ 216 D_ENCRYPT(r, l, 20); /* 11 */
221 D_ENCRYPT(l,r,18); /* 10 */ 217 D_ENCRYPT(l, r, 18); /* 10 */
222 D_ENCRYPT(r,l,16); /* 9 */ 218 D_ENCRYPT(r, l, 16); /* 9 */
223 D_ENCRYPT(l,r,14); /* 8 */ 219 D_ENCRYPT(l, r, 14); /* 8 */
224 D_ENCRYPT(r,l,12); /* 7 */ 220 D_ENCRYPT(r, l, 12); /* 7 */
225 D_ENCRYPT(l,r,10); /* 6 */ 221 D_ENCRYPT(l, r, 10); /* 6 */
226 D_ENCRYPT(r,l, 8); /* 5 */ 222 D_ENCRYPT(r, l, 8); /* 5 */
227 D_ENCRYPT(l,r, 6); /* 4 */ 223 D_ENCRYPT(l, r, 6); /* 4 */
228 D_ENCRYPT(r,l, 4); /* 3 */ 224 D_ENCRYPT(r, l, 4); /* 3 */
229 D_ENCRYPT(l,r, 2); /* 2 */ 225 D_ENCRYPT(l, r, 2); /* 2 */
230 D_ENCRYPT(r,l, 0); /* 1 */ 226 D_ENCRYPT(r, l, 0); /* 1 */
231#else 227#else
232 for (i=30; i>0; i-=4) 228 for (i = 30; i > 0; i -= 4)
233 { 229 {
234 D_ENCRYPT(l,r,i-0); /* 16 */ 230 D_ENCRYPT(l, r, i - 0); /* 16 */
235 D_ENCRYPT(r,l,i-2); /* 15 */ 231 D_ENCRYPT(r, l, i - 2); /* 15 */
236 }
237#endif
238 } 232 }
239 /* rotate and clear the top bits on machines with 8byte longs */ 233#endif
240 data[0]=ROTATE(l,3)&0xffffffffL;
241 data[1]=ROTATE(r,3)&0xffffffffL;
242 l=r=t=u=0;
243 } 234 }
235 /* rotate and clear the top bits on machines with 8byte longs */
236 data[0] = ROTATE(l, 3) & 0xffffffffL;
237 data[1] = ROTATE(r, 3) & 0xffffffffL;
238 l = r = t = u = 0;
239}
244 240
245#endif /* OPENBSD_DES_ASM */ 241#endif /* OPENBSD_DES_ASM */
246 242
247void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, 243void
248 DES_key_schedule *ks2, DES_key_schedule *ks3) 244DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
249 { 245 DES_key_schedule *ks2, DES_key_schedule *ks3)
250 DES_LONG l,r; 246{
251 247 DES_LONG l, r;
252 l=data[0]; 248
253 r=data[1]; 249 l = data[0];
254 IP(l,r); 250 r = data[1];
255 data[0]=l; 251 IP(l, r);
256 data[1]=r; 252 data[0] = l;
257 DES_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT); 253 data[1] = r;
258 DES_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT); 254 DES_encrypt2((DES_LONG *)data, ks1, DES_ENCRYPT);
259 DES_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT); 255 DES_encrypt2((DES_LONG *)data, ks2, DES_DECRYPT);
260 l=data[0]; 256 DES_encrypt2((DES_LONG *)data, ks3, DES_ENCRYPT);
261 r=data[1]; 257 l = data[0];
262 FP(r,l); 258 r = data[1];
263 data[0]=l; 259 FP(r, l);
264 data[1]=r; 260 data[0] = l;
265 } 261 data[1] = r;
266 262}
267void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, 263
268 DES_key_schedule *ks2, DES_key_schedule *ks3) 264void
269 { 265DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
270 DES_LONG l,r; 266 DES_key_schedule *ks2, DES_key_schedule *ks3)
271 267{
272 l=data[0]; 268 DES_LONG l, r;
273 r=data[1]; 269
274 IP(l,r); 270 l = data[0];
275 data[0]=l; 271 r = data[1];
276 data[1]=r; 272 IP(l, r);
277 DES_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT); 273 data[0] = l;
278 DES_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT); 274 data[1] = r;
279 DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT); 275 DES_encrypt2((DES_LONG *)data, ks3, DES_DECRYPT);
280 l=data[0]; 276 DES_encrypt2((DES_LONG *)data, ks2, DES_ENCRYPT);
281 r=data[1]; 277 DES_encrypt2((DES_LONG *)data, ks1, DES_DECRYPT);
282 FP(r,l); 278 l = data[0];
283 data[0]=l; 279 r = data[1];
284 data[1]=r; 280 FP(r, l);
285 } 281 data[0] = l;
282 data[1] = r;
283}
286 284
287#ifndef DES_DEFAULT_OPTIONS 285#ifndef DES_DEFAULT_OPTIONS
288 286
289#undef CBC_ENC_C__DONT_UPDATE_IV 287#undef CBC_ENC_C__DONT_UPDATE_IV
290#include "ncbc_enc.c" /* DES_ncbc_encrypt */ 288#include "ncbc_enc.c" /* DES_ncbc_encrypt */
291 289
292void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, 290void
293 long length, DES_key_schedule *ks1, 291DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
294 DES_key_schedule *ks2, DES_key_schedule *ks3, 292 long length, DES_key_schedule *ks1,
295 DES_cblock *ivec, int enc) 293 DES_key_schedule *ks2, DES_key_schedule *ks3,
296 { 294 DES_cblock *ivec, int enc)
297 DES_LONG tin0,tin1; 295{
298 DES_LONG tout0,tout1,xor0,xor1; 296 DES_LONG tin0, tin1;
297 DES_LONG tout0, tout1, xor0, xor1;
299 const unsigned char *in; 298 const unsigned char *in;
300 unsigned char *out; 299 unsigned char *out;
301 long l=length; 300 long l = length;
302 DES_LONG tin[2]; 301 DES_LONG tin[2];
303 unsigned char *iv; 302 unsigned char *iv;
304 303
305 in=input; 304 in = input;
306 out=output; 305 out = output;
307 iv = &(*ivec)[0]; 306 iv = &(*ivec)[0];
308 307
309 if (enc) 308 if (enc) {
309 c2l(iv, tout0);
310 c2l(iv, tout1);
311 for (l -= 8; l >= 0; l -= 8)
310 { 312 {
311 c2l(iv,tout0); 313 c2l(in, tin0);
312 c2l(iv,tout1); 314 c2l(in, tin1);
313 for (l-=8; l>=0; l-=8) 315 tin0 ^= tout0;
314 { 316 tin1 ^= tout1;
315 c2l(in,tin0); 317
316 c2l(in,tin1); 318 tin[0] = tin0;
317 tin0^=tout0; 319 tin[1] = tin1;
318 tin1^=tout1; 320 DES_encrypt3((DES_LONG *)tin, ks1, ks2, ks3);
319 321 tout0 = tin[0];
320 tin[0]=tin0; 322 tout1 = tin[1];
321 tin[1]=tin1; 323
322 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); 324 l2c(tout0, out);
323 tout0=tin[0]; 325 l2c(tout1, out);
324 tout1=tin[1]; 326 }
325 327 if (l != -8) {
326 l2c(tout0,out); 328 c2ln(in, tin0, tin1, l + 8);
327 l2c(tout1,out); 329 tin0 ^= tout0;
328 } 330 tin1 ^= tout1;
329 if (l != -8) 331
330 { 332 tin[0] = tin0;
331 c2ln(in,tin0,tin1,l+8); 333 tin[1] = tin1;
332 tin0^=tout0; 334 DES_encrypt3((DES_LONG *)tin, ks1, ks2, ks3);
333 tin1^=tout1; 335 tout0 = tin[0];
334 336 tout1 = tin[1];
335 tin[0]=tin0; 337
336 tin[1]=tin1; 338 l2c(tout0, out);
337 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); 339 l2c(tout1, out);
338 tout0=tin[0];
339 tout1=tin[1];
340
341 l2c(tout0,out);
342 l2c(tout1,out);
343 }
344 iv = &(*ivec)[0];
345 l2c(tout0,iv);
346 l2c(tout1,iv);
347 } 340 }
348 else 341 iv = &(*ivec)[0];
342 l2c(tout0, iv);
343 l2c(tout1, iv);
344 } else {
345 DES_LONG t0, t1;
346
347 c2l(iv, xor0);
348 c2l(iv, xor1);
349 for (l -= 8; l >= 0; l -= 8)
349 { 350 {
350 DES_LONG t0,t1; 351 c2l(in, tin0);
351 352 c2l(in, tin1);
352 c2l(iv,xor0); 353
353 c2l(iv,xor1); 354 t0 = tin0;
354 for (l-=8; l>=0; l-=8) 355 t1 = tin1;
355 { 356
356 c2l(in,tin0); 357 tin[0] = tin0;
357 c2l(in,tin1); 358 tin[1] = tin1;
358 359 DES_decrypt3((DES_LONG *)tin, ks1, ks2, ks3);
359 t0=tin0; 360 tout0 = tin[0];
360 t1=tin1; 361 tout1 = tin[1];
361 362
362 tin[0]=tin0; 363 tout0 ^= xor0;
363 tin[1]=tin1; 364 tout1 ^= xor1;
364 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); 365 l2c(tout0, out);
365 tout0=tin[0]; 366 l2c(tout1, out);
366 tout1=tin[1]; 367 xor0 = t0;
367 368 xor1 = t1;
368 tout0^=xor0; 369 }
369 tout1^=xor1; 370 if (l != -8) {
370 l2c(tout0,out); 371 c2l(in, tin0);
371 l2c(tout1,out); 372 c2l(in, tin1);
372 xor0=t0; 373
373 xor1=t1; 374 t0 = tin0;
374 } 375 t1 = tin1;
375 if (l != -8) 376
376 { 377 tin[0] = tin0;
377 c2l(in,tin0); 378 tin[1] = tin1;
378 c2l(in,tin1); 379 DES_decrypt3((DES_LONG *)tin, ks1, ks2, ks3);
379 380 tout0 = tin[0];
380 t0=tin0; 381 tout1 = tin[1];
381 t1=tin1; 382
382 383 tout0 ^= xor0;
383 tin[0]=tin0; 384 tout1 ^= xor1;
384 tin[1]=tin1; 385 l2cn(tout0, tout1, out, l + 8);
385 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); 386 xor0 = t0;
386 tout0=tin[0]; 387 xor1 = t1;
387 tout1=tin[1]; 388 }
388
389 tout0^=xor0;
390 tout1^=xor1;
391 l2cn(tout0,tout1,out,l+8);
392 xor0=t0;
393 xor1=t1;
394 }
395 389
396 iv = &(*ivec)[0]; 390 iv = &(*ivec)[0];
397 l2c(xor0,iv); 391 l2c(xor0, iv);
398 l2c(xor1,iv); 392 l2c(xor1, iv);
399 }
400 tin0=tin1=tout0=tout1=xor0=xor1=0;
401 tin[0]=tin[1]=0;
402 } 393 }
394 tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
395 tin[0] = tin[1] = 0;
396}
403 397
404#endif /* DES_DEFAULT_OPTIONS */ 398#endif /* DES_DEFAULT_OPTIONS */
diff --git a/src/lib/libcrypto/des/des_local.h b/src/lib/libcrypto/des/des_local.h
index a058ac2c32..f081adedb2 100644
--- a/src/lib/libcrypto/des/des_local.h
+++ b/src/lib/libcrypto/des/des_local.h
@@ -1,25 +1,25 @@
1/* $OpenBSD: des_local.h,v 1.1 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: des_local.h,v 1.2 2023/07/08 07:11:07 beck 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 *
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
@@ -79,64 +79,65 @@ __BEGIN_HIDDEN_DECLS
79#define MAXWRITE (1024*16) 79#define MAXWRITE (1024*16)
80#define BSIZE (MAXWRITE+4) 80#define BSIZE (MAXWRITE+4)
81 81
82#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ 82#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
83 l|=((DES_LONG)(*((c)++)))<< 8L, \ 83 l|=((DES_LONG)(*((c)++)))<< 8L, \
84 l|=((DES_LONG)(*((c)++)))<<16L, \ 84 l|=((DES_LONG)(*((c)++)))<<16L, \
85 l|=((DES_LONG)(*((c)++)))<<24L) 85 l|=((DES_LONG)(*((c)++)))<<24L)
86 86
87/* NOTE - c is not incremented as per c2l */ 87/* NOTE - c is not incremented as per c2l */
88#define c2ln(c,l1,l2,n) { \ 88#define c2ln(c,l1,l2,n) { \
89 c+=n; \ 89 c+=n; \
90 l1=l2=0; \ 90 l1=l2=0; \
91 switch (n) { \ 91 switch (n) { \
92 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \ 92 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
93 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \ 93 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
94 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \ 94 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
95 case 5: l2|=((DES_LONG)(*(--(c)))); \ 95 case 5: l2|=((DES_LONG)(*(--(c)))); \
96 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \ 96 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
97 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \ 97 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
98 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \ 98 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
99 case 1: l1|=((DES_LONG)(*(--(c)))); \ 99 case 1: l1|=((DES_LONG)(*(--(c)))); \
100 } \ 100 } \
101 } 101 }
102 102
103#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ 103#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
104 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 104 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
105 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ 105 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
106 *((c)++)=(unsigned char)(((l)>>24L)&0xff)) 106 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
107 107
108/* replacements for htonl and ntohl since I have no idea what to do 108/* replacements for htonl and ntohl since I have no idea what to do
109 * when faced with machines with 8 byte longs. */ 109 * when faced with machines with 8 byte longs. */
110#define HDRSIZE 4 110#define HDRSIZE 4
111 111
112#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \ 112#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
113 l|=((DES_LONG)(*((c)++)))<<16L, \ 113 l|=((DES_LONG)(*((c)++)))<<16L, \
114 l|=((DES_LONG)(*((c)++)))<< 8L, \ 114 l|=((DES_LONG)(*((c)++)))<< 8L, \
115 l|=((DES_LONG)(*((c)++)))) 115 l|=((DES_LONG)(*((c)++))))
116 116
117#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ 117#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
118 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ 118 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
119 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 119 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
120 *((c)++)=(unsigned char)(((l) )&0xff)) 120 *((c)++)=(unsigned char)(((l) )&0xff))
121 121
122/* NOTE - c is not incremented as per l2c */ 122/* NOTE - c is not incremented as per l2c */
123#define l2cn(l1,l2,c,n) { \ 123#define l2cn(l1,l2,c,n) { \
124 c+=n; \ 124 c+=n; \
125 switch (n) { \ 125 switch (n) { \
126 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ 126 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff);\
127 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ 127 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff);\
128 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ 128 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff);\
129 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ 129 case 5: *(--(c))=(unsigned char)(((l2) )&0xff);\
130 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ 130 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff);\
131 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ 131 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff);\
132 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ 132 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff);\
133 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ 133 case 1: *(--(c))=(unsigned char)(((l1) )&0xff);\
134 } \ 134 } \
135 } 135 }
136 136
137static inline uint32_t ROTATE(uint32_t a, uint32_t n) 137static inline uint32_t
138ROTATE(uint32_t a, uint32_t n)
138{ 139{
139 return (a>>n)+(a<<(32-n)); 140 return (a >> n) + (a << (32 - n));
140} 141}
141 142
142/* Don't worry about the LOAD_DATA() stuff, that is used by 143/* Don't worry about the LOAD_DATA() stuff, that is used by
@@ -147,15 +148,15 @@ static inline uint32_t ROTATE(uint32_t a, uint32_t n)
147#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \ 148#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \
148 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); } 149 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); }
149 150
150#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \ 151#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
151 t=R^(R>>16L); \ 152 t=R^(R>>16L); \
152 u=t&E0; t&=E1; \ 153 u=t&E0; t&=E1; \
153 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \ 154 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \
154 tmp=(t<<16); t^=R^s[S+1]; t^=tmp 155 tmp=(t<<16); t^=R^s[S+1]; t^=tmp
155#else 156#else
156#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g) 157#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
157#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \ 158#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
158 u=R^s[S ]; \ 159 u=R^s[S ]; \
159 t=R^s[S+1] 160 t=R^s[S+1]
160#endif 161#endif
161 162
@@ -173,73 +174,73 @@ static inline uint32_t ROTATE(uint32_t a, uint32_t n)
173 174
174#if defined(DES_RISC1) || defined(DES_RISC2) 175#if defined(DES_RISC1) || defined(DES_RISC2)
175#ifdef DES_RISC1 176#ifdef DES_RISC1
176#define D_ENCRYPT(LL,R,S) { \ 177#define D_ENCRYPT(LL,R,S) { \
177 unsigned int u1,u2,u3; \ 178 unsigned int u1,u2,u3; \
178 LOAD_DATA(R,S,u,t,E0,E1,u1); \ 179 LOAD_DATA(R,S,u,t,E0,E1,u1); \
179 u2=(int)u>>8L; \ 180 u2=(int)u>>8L; \
180 u1=(int)u&0xfc; \ 181 u1=(int)u&0xfc; \
181 u2&=0xfc; \ 182 u2&=0xfc; \
182 t=ROTATE(t,4); \ 183 t=ROTATE(t,4); \
183 u>>=16L; \ 184 u>>=16L; \
184 LL^= *(const DES_LONG *)(des_SP +u1); \ 185 LL^= *(const DES_LONG *)(des_SP +u1); \
185 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \ 186 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
186 u3=(int)(u>>8L); \ 187 u3=(int)(u>>8L); \
187 u1=(int)u&0xfc; \ 188 u1=(int)u&0xfc; \
188 u3&=0xfc; \ 189 u3&=0xfc; \
189 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \ 190 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
190 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \ 191 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
191 u2=(int)t>>8L; \ 192 u2=(int)t>>8L; \
192 u1=(int)t&0xfc; \ 193 u1=(int)t&0xfc; \
193 u2&=0xfc; \ 194 u2&=0xfc; \
194 t>>=16L; \ 195 t>>=16L; \
195 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \ 196 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
196 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \ 197 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
197 u3=(int)t>>8L; \ 198 u3=(int)t>>8L; \
198 u1=(int)t&0xfc; \ 199 u1=(int)t&0xfc; \
199 u3&=0xfc; \ 200 u3&=0xfc; \
200 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \ 201 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
201 LL^= *(const DES_LONG *)(des_SP+0x700+u3); } 202 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
202#endif 203#endif
203#ifdef DES_RISC2 204#ifdef DES_RISC2
204#define D_ENCRYPT(LL,R,S) { \ 205#define D_ENCRYPT(LL,R,S) { \
205 unsigned int u1,u2,s1,s2; \ 206 unsigned int u1,u2,s1,s2; \
206 LOAD_DATA(R,S,u,t,E0,E1,u1); \ 207 LOAD_DATA(R,S,u,t,E0,E1,u1); \
207 u2=(int)u>>8L; \ 208 u2=(int)u>>8L; \
208 u1=(int)u&0xfc; \ 209 u1=(int)u&0xfc; \
209 u2&=0xfc; \ 210 u2&=0xfc; \
210 t=ROTATE(t,4); \ 211 t=ROTATE(t,4); \
211 LL^= *(const DES_LONG *)(des_SP +u1); \ 212 LL^= *(const DES_LONG *)(des_SP +u1); \
212 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \ 213 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
213 s1=(int)(u>>16L); \ 214 s1=(int)(u>>16L); \
214 s2=(int)(u>>24L); \ 215 s2=(int)(u>>24L); \
215 s1&=0xfc; \ 216 s1&=0xfc; \
216 s2&=0xfc; \ 217 s2&=0xfc; \
217 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \ 218 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
218 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \ 219 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
219 u2=(int)t>>8L; \ 220 u2=(int)t>>8L; \
220 u1=(int)t&0xfc; \ 221 u1=(int)t&0xfc; \
221 u2&=0xfc; \ 222 u2&=0xfc; \
222 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \ 223 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
223 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \ 224 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
224 s1=(int)(t>>16L); \ 225 s1=(int)(t>>16L); \
225 s2=(int)(t>>24L); \ 226 s2=(int)(t>>24L); \
226 s1&=0xfc; \ 227 s1&=0xfc; \
227 s2&=0xfc; \ 228 s2&=0xfc; \
228 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \ 229 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
229 LL^= *(const DES_LONG *)(des_SP+0x700+s2); } 230 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
230#endif 231#endif
231#else 232#else
232#define D_ENCRYPT(LL,R,S) { \ 233#define D_ENCRYPT(LL,R,S) { \
233 LOAD_DATA_tmp(R,S,u,t,E0,E1); \ 234 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
234 t=ROTATE(t,4); \ 235 t=ROTATE(t,4); \
235 LL^= \ 236 LL^= \
236 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \ 237 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
237 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \ 238 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
238 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \ 239 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
239 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \ 240 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
240 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \ 241 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
241 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \ 242 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
242 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \ 243 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
243 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); } 244 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
244#endif 245#endif
245 246
@@ -247,77 +248,77 @@ static inline uint32_t ROTATE(uint32_t a, uint32_t n)
247 248
248#if defined(DES_RISC1) || defined(DES_RISC2) 249#if defined(DES_RISC1) || defined(DES_RISC2)
249#ifdef DES_RISC1 250#ifdef DES_RISC1
250#define D_ENCRYPT(LL,R,S) {\ 251#define D_ENCRYPT(LL,R,S) { \
251 unsigned int u1,u2,u3; \ 252 unsigned int u1,u2,u3; \
252 LOAD_DATA(R,S,u,t,E0,E1,u1); \ 253 LOAD_DATA(R,S,u,t,E0,E1,u1); \
253 u>>=2L; \ 254 u>>=2L; \
254 t=ROTATE(t,6); \ 255 t=ROTATE(t,6); \
255 u2=(int)u>>8L; \ 256 u2=(int)u>>8L; \
256 u1=(int)u&0x3f; \ 257 u1=(int)u&0x3f; \
257 u2&=0x3f; \ 258 u2&=0x3f; \
258 u>>=16L; \ 259 u>>=16L; \
259 LL^=DES_SPtrans[0][u1]; \ 260 LL^=DES_SPtrans[0][u1]; \
260 LL^=DES_SPtrans[2][u2]; \ 261 LL^=DES_SPtrans[2][u2]; \
261 u3=(int)u>>8L; \ 262 u3=(int)u>>8L; \
262 u1=(int)u&0x3f; \ 263 u1=(int)u&0x3f; \
263 u3&=0x3f; \ 264 u3&=0x3f; \
264 LL^=DES_SPtrans[4][u1]; \ 265 LL^=DES_SPtrans[4][u1]; \
265 LL^=DES_SPtrans[6][u3]; \ 266 LL^=DES_SPtrans[6][u3]; \
266 u2=(int)t>>8L; \ 267 u2=(int)t>>8L; \
267 u1=(int)t&0x3f; \ 268 u1=(int)t&0x3f; \
268 u2&=0x3f; \ 269 u2&=0x3f; \
269 t>>=16L; \ 270 t>>=16L; \
270 LL^=DES_SPtrans[1][u1]; \ 271 LL^=DES_SPtrans[1][u1]; \
271 LL^=DES_SPtrans[3][u2]; \ 272 LL^=DES_SPtrans[3][u2]; \
272 u3=(int)t>>8L; \ 273 u3=(int)t>>8L; \
273 u1=(int)t&0x3f; \ 274 u1=(int)t&0x3f; \
274 u3&=0x3f; \ 275 u3&=0x3f; \
275 LL^=DES_SPtrans[5][u1]; \ 276 LL^=DES_SPtrans[5][u1]; \
276 LL^=DES_SPtrans[7][u3]; } 277 LL^=DES_SPtrans[7][u3]; }
277#endif 278#endif
278#ifdef DES_RISC2 279#ifdef DES_RISC2
279#define D_ENCRYPT(LL,R,S) {\ 280#define D_ENCRYPT(LL,R,S) { \
280 unsigned int u1,u2,s1,s2; \ 281 unsigned int u1,u2,s1,s2; \
281 LOAD_DATA(R,S,u,t,E0,E1,u1); \ 282 LOAD_DATA(R,S,u,t,E0,E1,u1); \
282 u>>=2L; \ 283 u>>=2L; \
283 t=ROTATE(t,6); \ 284 t=ROTATE(t,6); \
284 u2=(int)u>>8L; \ 285 u2=(int)u>>8L; \
285 u1=(int)u&0x3f; \ 286 u1=(int)u&0x3f; \
286 u2&=0x3f; \ 287 u2&=0x3f; \
287 LL^=DES_SPtrans[0][u1]; \ 288 LL^=DES_SPtrans[0][u1]; \
288 LL^=DES_SPtrans[2][u2]; \ 289 LL^=DES_SPtrans[2][u2]; \
289 s1=(int)u>>16L; \ 290 s1=(int)u>>16L; \
290 s2=(int)u>>24L; \ 291 s2=(int)u>>24L; \
291 s1&=0x3f; \ 292 s1&=0x3f; \
292 s2&=0x3f; \ 293 s2&=0x3f; \
293 LL^=DES_SPtrans[4][s1]; \ 294 LL^=DES_SPtrans[4][s1]; \
294 LL^=DES_SPtrans[6][s2]; \ 295 LL^=DES_SPtrans[6][s2]; \
295 u2=(int)t>>8L; \ 296 u2=(int)t>>8L; \
296 u1=(int)t&0x3f; \ 297 u1=(int)t&0x3f; \
297 u2&=0x3f; \ 298 u2&=0x3f; \
298 LL^=DES_SPtrans[1][u1]; \ 299 LL^=DES_SPtrans[1][u1]; \
299 LL^=DES_SPtrans[3][u2]; \ 300 LL^=DES_SPtrans[3][u2]; \
300 s1=(int)t>>16; \ 301 s1=(int)t>>16; \
301 s2=(int)t>>24L; \ 302 s2=(int)t>>24L; \
302 s1&=0x3f; \ 303 s1&=0x3f; \
303 s2&=0x3f; \ 304 s2&=0x3f; \
304 LL^=DES_SPtrans[5][s1]; \ 305 LL^=DES_SPtrans[5][s1]; \
305 LL^=DES_SPtrans[7][s2]; } 306 LL^=DES_SPtrans[7][s2]; }
306#endif 307#endif
307 308
308#else 309#else
309 310
310#define D_ENCRYPT(LL,R,S) {\ 311#define D_ENCRYPT(LL,R,S) { \
311 LOAD_DATA_tmp(R,S,u,t,E0,E1); \ 312 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
312 t=ROTATE(t,4); \ 313 t=ROTATE(t,4); \
313 LL^=\ 314 LL^= \
314 DES_SPtrans[0][(u>> 2L)&0x3f]^ \ 315 DES_SPtrans[0][(u>> 2L)&0x3f]^ \
315 DES_SPtrans[2][(u>>10L)&0x3f]^ \ 316 DES_SPtrans[2][(u>>10L)&0x3f]^ \
316 DES_SPtrans[4][(u>>18L)&0x3f]^ \ 317 DES_SPtrans[4][(u>>18L)&0x3f]^ \
317 DES_SPtrans[6][(u>>26L)&0x3f]^ \ 318 DES_SPtrans[6][(u>>26L)&0x3f]^ \
318 DES_SPtrans[1][(t>> 2L)&0x3f]^ \ 319 DES_SPtrans[1][(t>> 2L)&0x3f]^ \
319 DES_SPtrans[3][(t>>10L)&0x3f]^ \ 320 DES_SPtrans[3][(t>>10L)&0x3f]^ \
320 DES_SPtrans[5][(t>>18L)&0x3f]^ \ 321 DES_SPtrans[5][(t>>18L)&0x3f]^ \
321 DES_SPtrans[7][(t>>26L)&0x3f]; } 322 DES_SPtrans[7][(t>>26L)&0x3f]; }
322#endif 323#endif
323#endif 324#endif
@@ -359,34 +360,34 @@ static inline uint32_t ROTATE(uint32_t a, uint32_t n)
359 I first got ~42 operations without xors. When I remembered 360 I first got ~42 operations without xors. When I remembered
360 how to use xors :-) I got it to its final state. 361 how to use xors :-) I got it to its final state.
361 */ 362 */
362#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ 363#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)), \
363 (b)^=(t),\ 364 (b)^=(t), \
364 (a)^=((t)<<(n))) 365 (a)^=((t)<<(n)))
365 366
366#define IP(l,r) \ 367#define IP(l,r) \
367 { \ 368 { \
368 DES_LONG tt; \ 369 DES_LONG tt; \
369 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \ 370 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
370 PERM_OP(l,r,tt,16,0x0000ffffL); \ 371 PERM_OP(l,r,tt,16,0x0000ffffL); \
371 PERM_OP(r,l,tt, 2,0x33333333L); \ 372 PERM_OP(r,l,tt, 2,0x33333333L); \
372 PERM_OP(l,r,tt, 8,0x00ff00ffL); \ 373 PERM_OP(l,r,tt, 8,0x00ff00ffL); \
373 PERM_OP(r,l,tt, 1,0x55555555L); \ 374 PERM_OP(r,l,tt, 1,0x55555555L); \
374 } 375 }
375 376
376#define FP(l,r) \ 377#define FP(l,r) \
377 { \ 378 { \
378 DES_LONG tt; \ 379 DES_LONG tt; \
379 PERM_OP(l,r,tt, 1,0x55555555L); \ 380 PERM_OP(l,r,tt, 1,0x55555555L); \
380 PERM_OP(r,l,tt, 8,0x00ff00ffL); \ 381 PERM_OP(r,l,tt, 8,0x00ff00ffL); \
381 PERM_OP(l,r,tt, 2,0x33333333L); \ 382 PERM_OP(l,r,tt, 2,0x33333333L); \
382 PERM_OP(r,l,tt,16,0x0000ffffL); \ 383 PERM_OP(r,l,tt,16,0x0000ffffL); \
383 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \ 384 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
384 } 385 }
385 386
386extern const DES_LONG DES_SPtrans[8][64]; 387extern const DES_LONG DES_SPtrans[8][64];
387 388
388void fcrypt_body(DES_LONG *out,DES_key_schedule *ks, 389void fcrypt_body(DES_LONG *out, DES_key_schedule *ks,
389 DES_LONG Eswap0, DES_LONG Eswap1); 390 DES_LONG Eswap0, DES_LONG Eswap1);
390 391
391#ifdef OPENSSL_SMALL_FOOTPRINT 392#ifdef OPENSSL_SMALL_FOOTPRINT
392#undef DES_UNROLL 393#undef DES_UNROLL
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
index c2d8329fe0..129b5fafea 100644
--- a/src/lib/libcrypto/des/ecb3_enc.c
+++ b/src/lib/libcrypto/des/ecb3_enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: ecb3_enc.c,v 1.8 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: ecb3_enc.c,v 1.9 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
@@ -58,26 +58,27 @@
58 58
59#include "des_local.h" 59#include "des_local.h"
60 60
61void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, 61void
62 DES_key_schedule *ks1, DES_key_schedule *ks2, 62DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
63 DES_key_schedule *ks3, 63 DES_key_schedule *ks1, DES_key_schedule *ks2,
64 int enc) 64 DES_key_schedule *ks3,
65 { 65 int enc)
66 DES_LONG l0,l1; 66{
67 DES_LONG l0, l1;
67 DES_LONG ll[2]; 68 DES_LONG ll[2];
68 const unsigned char *in = &(*input)[0]; 69 const unsigned char *in = &(*input)[0];
69 unsigned char *out = &(*output)[0]; 70 unsigned char *out = &(*output)[0];
70 71
71 c2l(in,l0); 72 c2l(in, l0);
72 c2l(in,l1); 73 c2l(in, l1);
73 ll[0]=l0; 74 ll[0] = l0;
74 ll[1]=l1; 75 ll[1] = l1;
75 if (enc) 76 if (enc)
76 DES_encrypt3(ll,ks1,ks2,ks3); 77 DES_encrypt3(ll, ks1, ks2, ks3);
77 else 78 else
78 DES_decrypt3(ll,ks1,ks2,ks3); 79 DES_decrypt3(ll, ks1, ks2, ks3);
79 l0=ll[0]; 80 l0 = ll[0];
80 l1=ll[1]; 81 l1 = ll[1];
81 l2c(l0,out); 82 l2c(l0, out);
82 l2c(l1,out); 83 l2c(l1, out);
83 } 84}
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c
index 35ce711315..7cc8cc687f 100644
--- a/src/lib/libcrypto/des/ecb_enc.c
+++ b/src/lib/libcrypto/des/ecb_enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: ecb_enc.c,v 1.17 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: ecb_enc.c,v 1.18 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,59 +60,63 @@
60#include <openssl/opensslv.h> 60#include <openssl/opensslv.h>
61#include <openssl/bio.h> 61#include <openssl/bio.h>
62 62
63const char *DES_options(void) 63const char *
64 { 64DES_options(void)
65 static int init=1; 65{
66 static int init = 1;
66 static char buf[32]; 67 static char buf[32];
67 68
68 if (init) 69 if (init) {
69 { 70 const char *ptr, *unroll, *risc, *size;
70 const char *ptr,*unroll,*risc,*size;
71 71
72#ifdef DES_PTR 72#ifdef DES_PTR
73 ptr="ptr"; 73 ptr = "ptr";
74#else 74#else
75 ptr="idx"; 75 ptr = "idx";
76#endif 76#endif
77#if defined(DES_RISC1) || defined(DES_RISC2) 77#if defined(DES_RISC1) || defined(DES_RISC2)
78#ifdef DES_RISC1 78#ifdef DES_RISC1
79 risc="risc1"; 79 risc = "risc1";
80#endif 80#endif
81#ifdef DES_RISC2 81#ifdef DES_RISC2
82 risc="risc2"; 82 risc = "risc2";
83#endif 83#endif
84#else 84#else
85 risc="cisc"; 85 risc = "cisc";
86#endif 86#endif
87#ifdef DES_UNROLL 87#ifdef DES_UNROLL
88 unroll="16"; 88 unroll = "16";
89#else 89#else
90 unroll="2"; 90 unroll = "2";
91#endif 91#endif
92 if (sizeof(DES_LONG) != sizeof(long)) 92 if (sizeof(DES_LONG) != sizeof(long))
93 size="int"; 93 size = "int";
94 else 94 else
95 size="long"; 95 size = "long";
96 snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll, 96 snprintf(buf, sizeof buf, "des(%s,%s,%s,%s)", ptr, risc, unroll,
97 size); 97 size);
98 init=0; 98 init = 0;
99 }
100 return(buf);
101 } 99 }
102 100 return (buf);
101}
103 102
104void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, 103void
105 DES_key_schedule *ks, int enc) 104DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
106 { 105 DES_key_schedule *ks, int enc)
106{
107 DES_LONG l; 107 DES_LONG l;
108 DES_LONG ll[2]; 108 DES_LONG ll[2];
109 const unsigned char *in = &(*input)[0]; 109 const unsigned char *in = &(*input)[0];
110 unsigned char *out = &(*output)[0]; 110 unsigned char *out = &(*output)[0];
111 111
112 c2l(in,l); ll[0]=l; 112 c2l(in, l);
113 c2l(in,l); ll[1]=l; 113 ll[0] = l;
114 DES_encrypt1(ll,ks,enc); 114 c2l(in, l);
115 l=ll[0]; l2c(l,out); 115 ll[1] = l;
116 l=ll[1]; l2c(l,out); 116 DES_encrypt1(ll, ks, enc);
117 l=ll[0]=ll[1]=0; 117 l = ll[0];
118 } 118 l2c(l, out);
119 l = ll[1];
120 l2c(l, out);
121 l = ll[0] = ll[1] = 0;
122}
diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c
index 3f1609d745..d276009c60 100644
--- a/src/lib/libcrypto/des/ede_cbcm_enc.c
+++ b/src/lib/libcrypto/des/ede_cbcm_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ede_cbcm_enc.c,v 1.7 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: ede_cbcm_enc.c,v 1.8 2023/07/08 07:11:07 beck Exp $ */
2/* Written by Ben Laurie <ben@algroup.co.uk> for the OpenSSL 2/* Written by Ben Laurie <ben@algroup.co.uk> for the OpenSSL
3 * project 13 Feb 1999. 3 * project 13 Feb 1999.
4 */ 4 */
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -73,127 +73,119 @@ http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz
73#ifndef OPENSSL_NO_DESCBCM 73#ifndef OPENSSL_NO_DESCBCM
74#include "des_local.h" 74#include "des_local.h"
75 75
76void DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out, 76void
77 long length, DES_key_schedule *ks1, DES_key_schedule *ks2, 77DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
78 DES_key_schedule *ks3, DES_cblock *ivec1, DES_cblock *ivec2, 78 long length, DES_key_schedule *ks1, DES_key_schedule *ks2,
79 int enc) 79 DES_key_schedule *ks3, DES_cblock *ivec1, DES_cblock *ivec2,
80 { 80 int enc)
81 DES_LONG tin0,tin1; 81{
82 DES_LONG tout0,tout1,xor0,xor1,m0,m1; 82 DES_LONG tin0, tin1;
83 long l=length; 83 DES_LONG tout0, tout1, xor0, xor1, m0, m1;
84 DES_LONG tin[2]; 84 long l = length;
85 unsigned char *iv1,*iv2; 85 DES_LONG tin[2];
86 86 unsigned char *iv1, *iv2;
87 iv1 = &(*ivec1)[0]; 87
88 iv2 = &(*ivec2)[0]; 88 iv1 = &(*ivec1)[0];
89 89 iv2 = &(*ivec2)[0];
90 if (enc) 90
91 { 91 if (enc) {
92 c2l(iv1,m0); 92 c2l(iv1, m0);
93 c2l(iv1,m1); 93 c2l(iv1, m1);
94 c2l(iv2,tout0); 94 c2l(iv2, tout0);
95 c2l(iv2,tout1); 95 c2l(iv2, tout1);
96 for (l-=8; l>=-7; l-=8) 96 for (l -= 8; l >= -7; l -= 8)
97 {
98 tin[0]=m0;
99 tin[1]=m1;
100 DES_encrypt1(tin,ks3,1);
101 m0=tin[0];
102 m1=tin[1];
103
104 if(l < 0)
105 { 97 {
106 c2ln(in,tin0,tin1,l+8); 98 tin[0] = m0;
99 tin[1] = m1;
100 DES_encrypt1(tin, ks3, 1);
101 m0 = tin[0];
102 m1 = tin[1];
103
104 if (l < 0) {
105 c2ln(in, tin0, tin1, l + 8);
106 } else {
107 c2l(in, tin0);
108 c2l(in, tin1);
109 }
110 tin0 ^= tout0;
111 tin1 ^= tout1;
112
113 tin[0] = tin0;
114 tin[1] = tin1;
115 DES_encrypt1(tin, ks1, 1);
116 tin[0] ^= m0;
117 tin[1] ^= m1;
118 DES_encrypt1(tin, ks2, 0);
119 tin[0] ^= m0;
120 tin[1] ^= m1;
121 DES_encrypt1(tin, ks1, 1);
122 tout0 = tin[0];
123 tout1 = tin[1];
124
125 l2c(tout0, out);
126 l2c(tout1, out);
107 } 127 }
108 else 128 iv1 = &(*ivec1)[0];
129 l2c(m0, iv1);
130 l2c(m1, iv1);
131
132 iv2 = &(*ivec2)[0];
133 l2c(tout0, iv2);
134 l2c(tout1, iv2);
135 } else {
136 DES_LONG t0, t1;
137
138 c2l(iv1, m0);
139 c2l(iv1, m1);
140 c2l(iv2, xor0);
141 c2l(iv2, xor1);
142 for (l -= 8; l >= -7; l -= 8)
109 { 143 {
110 c2l(in,tin0); 144 tin[0] = m0;
111 c2l(in,tin1); 145 tin[1] = m1;
146 DES_encrypt1(tin, ks3, 1);
147 m0 = tin[0];
148 m1 = tin[1];
149
150 c2l(in, tin0);
151 c2l(in, tin1);
152
153 t0 = tin0;
154 t1 = tin1;
155
156 tin[0] = tin0;
157 tin[1] = tin1;
158 DES_encrypt1(tin, ks1, 0);
159 tin[0] ^= m0;
160 tin[1] ^= m1;
161 DES_encrypt1(tin, ks2, 1);
162 tin[0] ^= m0;
163 tin[1] ^= m1;
164 DES_encrypt1(tin, ks1, 0);
165 tout0 = tin[0];
166 tout1 = tin[1];
167
168 tout0 ^= xor0;
169 tout1 ^= xor1;
170 if (l < 0) {
171 l2cn(tout0, tout1, out, l + 8);
172 } else {
173 l2c(tout0, out);
174 l2c(tout1, out);
175 }
176 xor0 = t0;
177 xor1 = t1;
112 } 178 }
113 tin0^=tout0;
114 tin1^=tout1;
115
116 tin[0]=tin0;
117 tin[1]=tin1;
118 DES_encrypt1(tin,ks1,1);
119 tin[0]^=m0;
120 tin[1]^=m1;
121 DES_encrypt1(tin,ks2,0);
122 tin[0]^=m0;
123 tin[1]^=m1;
124 DES_encrypt1(tin,ks1,1);
125 tout0=tin[0];
126 tout1=tin[1];
127
128 l2c(tout0,out);
129 l2c(tout1,out);
130 }
131 iv1=&(*ivec1)[0];
132 l2c(m0,iv1);
133 l2c(m1,iv1);
134
135 iv2=&(*ivec2)[0];
136 l2c(tout0,iv2);
137 l2c(tout1,iv2);
138 }
139 else
140 {
141 DES_LONG t0,t1;
142
143 c2l(iv1,m0);
144 c2l(iv1,m1);
145 c2l(iv2,xor0);
146 c2l(iv2,xor1);
147 for (l-=8; l>=-7; l-=8)
148 {
149 tin[0]=m0;
150 tin[1]=m1;
151 DES_encrypt1(tin,ks3,1);
152 m0=tin[0];
153 m1=tin[1];
154
155 c2l(in,tin0);
156 c2l(in,tin1);
157
158 t0=tin0;
159 t1=tin1;
160
161 tin[0]=tin0;
162 tin[1]=tin1;
163 DES_encrypt1(tin,ks1,0);
164 tin[0]^=m0;
165 tin[1]^=m1;
166 DES_encrypt1(tin,ks2,1);
167 tin[0]^=m0;
168 tin[1]^=m1;
169 DES_encrypt1(tin,ks1,0);
170 tout0=tin[0];
171 tout1=tin[1];
172
173 tout0^=xor0;
174 tout1^=xor1;
175 if(l < 0)
176 {
177 l2cn(tout0,tout1,out,l+8);
178 }
179 else
180 {
181 l2c(tout0,out);
182 l2c(tout1,out);
183 }
184 xor0=t0;
185 xor1=t1;
186 }
187 179
188 iv1=&(*ivec1)[0]; 180 iv1 = &(*ivec1)[0];
189 l2c(m0,iv1); 181 l2c(m0, iv1);
190 l2c(m1,iv1); 182 l2c(m1, iv1);
191 183
192 iv2=&(*ivec2)[0]; 184 iv2 = &(*ivec2)[0];
193 l2c(xor0,iv2); 185 l2c(xor0, iv2);
194 l2c(xor1,iv2); 186 l2c(xor1, iv2);
195 } 187 }
196 tin0=tin1=tout0=tout1=xor0=xor1=0; 188 tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
197 tin[0]=tin[1]=0; 189 tin[0] = tin[1] = 0;
198 } 190}
199#endif 191#endif
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
index a9010f6f9e..8095f265c0 100644
--- a/src/lib/libcrypto/des/enc_read.c
+++ b/src/lib/libcrypto/des/enc_read.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: enc_read.c,v 1.16 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: enc_read.c,v 1.17 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
@@ -84,146 +84,139 @@ int DES_rw_mode = DES_PCBC_MODE;
84 * used on multiple files. 84 * used on multiple files.
85 */ 85 */
86 86
87 87int
88int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched, 88DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
89 DES_cblock *iv) 89 DES_cblock *iv)
90 { 90{
91 /* data to be unencrypted */ 91 /* data to be unencrypted */
92 int net_num=0; 92 int net_num = 0;
93 static unsigned char *net=NULL; 93 static unsigned char *net = NULL;
94 /* extra unencrypted data 94 /* extra unencrypted data
95 * for when a block of 100 comes in but is des_read one byte at 95 * for when a block of 100 comes in but is des_read one byte at
96 * a time. */ 96 * a time. */
97 static unsigned char *unnet=NULL; 97 static unsigned char *unnet = NULL;
98 static int unnet_start=0; 98 static int unnet_start = 0;
99 static int unnet_left=0; 99 static int unnet_left = 0;
100 static unsigned char *tmpbuf=NULL; 100 static unsigned char *tmpbuf = NULL;
101 int i; 101 int i;
102 long num=0,rnum; 102 long num = 0, rnum;
103 unsigned char *p; 103 unsigned char *p;
104 104
105 if (tmpbuf == NULL) 105 if (tmpbuf == NULL) {
106 { 106 tmpbuf = malloc(BSIZE);
107 tmpbuf=malloc(BSIZE); 107 if (tmpbuf == NULL)
108 if (tmpbuf == NULL) return(-1); 108 return (-1);
109 } 109 }
110 if (net == NULL) 110 if (net == NULL) {
111 { 111 net = malloc(BSIZE);
112 net=malloc(BSIZE); 112 if (net == NULL)
113 if (net == NULL) return(-1); 113 return (-1);
114 } 114 }
115 if (unnet == NULL) 115 if (unnet == NULL) {
116 { 116 unnet = malloc(BSIZE);
117 unnet=malloc(BSIZE); 117 if (unnet == NULL)
118 if (unnet == NULL) return(-1); 118 return (-1);
119 } 119 }
120 /* left over data from last decrypt */ 120 /* left over data from last decrypt */
121 if (unnet_left != 0) 121 if (unnet_left != 0) {
122 { 122 if (unnet_left < len) {
123 if (unnet_left < len)
124 {
125 /* we still still need more data but will return 123 /* we still still need more data but will return
126 * with the number of bytes we have - should always 124 * with the number of bytes we have - should always
127 * check the return value */ 125 * check the return value */
128 memcpy(buf,&(unnet[unnet_start]), 126 memcpy(buf, &(unnet[unnet_start]),
129 unnet_left); 127 unnet_left);
130 /* eay 26/08/92 I had the next 2 lines 128 /* eay 26/08/92 I had the next 2 lines
131 * reversed :-( */ 129 * reversed :-( */
132 i=unnet_left; 130 i = unnet_left;
133 unnet_start=unnet_left=0; 131 unnet_start = unnet_left = 0;
134 } 132 } else {
135 else 133 memcpy(buf, &(unnet[unnet_start]), len);
136 { 134 unnet_start += len;
137 memcpy(buf,&(unnet[unnet_start]),len); 135 unnet_left -= len;
138 unnet_start+=len; 136 i = len;
139 unnet_left-=len;
140 i=len;
141 }
142 return(i);
143 } 137 }
138 return (i);
139 }
144 140
145 /* We need to get more data. */ 141 /* We need to get more data. */
146 if (len > MAXWRITE) len=MAXWRITE; 142 if (len > MAXWRITE)
143 len = MAXWRITE;
147 144
148 /* first - get the length */ 145 /* first - get the length */
149 while (net_num < HDRSIZE) 146 while (net_num < HDRSIZE) {
150 { 147 i = read(fd, (void *)&(net[net_num]), HDRSIZE - net_num);
151 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
152#ifdef EINTR 148#ifdef EINTR
153 if ((i == -1) && (errno == EINTR)) continue; 149 if ((i == -1) && (errno == EINTR))
150 continue;
154#endif 151#endif
155 if (i <= 0) return(0); 152 if (i <= 0)
156 net_num+=i; 153 return (0);
157 } 154 net_num += i;
155 }
158 156
159 /* we now have at net_num bytes in net */ 157 /* we now have at net_num bytes in net */
160 p=net; 158 p = net;
161 /* num=0; */ 159 /* num=0; */
162 n2l(p,num); 160 n2l(p, num);
163 /* num should be rounded up to the next group of eight 161 /* num should be rounded up to the next group of eight
164 * we make sure that we have read a multiple of 8 bytes from the net. 162 * we make sure that we have read a multiple of 8 bytes from the net.
165 */ 163 */
166 if ((num > MAXWRITE) || (num < 0)) /* error */ 164 if ((num > MAXWRITE) || (num < 0)) /* error */
167 return(-1); 165 return (-1);
168 rnum=(num < 8)?8:((num+7)/8*8); 166 rnum = (num < 8) ? 8 : ((num + 7)/8*8);
169 167
170 net_num=0; 168 net_num = 0;
171 while (net_num < rnum) 169 while (net_num < rnum) {
172 { 170 i = read(fd, (void *)&(net[net_num]), rnum - net_num);
173 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
174#ifdef EINTR 171#ifdef EINTR
175 if ((i == -1) && (errno == EINTR)) continue; 172 if ((i == -1) && (errno == EINTR))
173 continue;
176#endif 174#endif
177 if (i <= 0) return(0); 175 if (i <= 0)
178 net_num+=i; 176 return (0);
179 } 177 net_num += i;
178 }
180 179
181 /* Check if there will be data left over. */ 180 /* Check if there will be data left over. */
182 if (len < num) 181 if (len < num) {
183 {
184 if (DES_rw_mode & DES_PCBC_MODE) 182 if (DES_rw_mode & DES_PCBC_MODE)
185 DES_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT); 183 DES_pcbc_encrypt(net, unnet, num, sched, iv,
184 DES_DECRYPT);
186 else 185 else
187 DES_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT); 186 DES_cbc_encrypt(net, unnet, num, sched, iv,
188 memcpy(buf,unnet,len); 187 DES_DECRYPT);
189 unnet_start=len; 188 memcpy(buf, unnet, len);
190 unnet_left=num-len; 189 unnet_start = len;
190 unnet_left = num - len;
191 191
192 /* The following line is done because we return num 192 /* The following line is done because we return num
193 * as the number of bytes read. */ 193 * as the number of bytes read. */
194 num=len; 194 num = len;
195 } 195 } else {
196 else
197 {
198 /* >output is a multiple of 8 byes, if len < rnum 196 /* >output is a multiple of 8 byes, if len < rnum
199 * >we must be careful. The user must be aware that this 197 * >we must be careful. The user must be aware that this
200 * >routine will write more bytes than he asked for. 198 * >routine will write more bytes than he asked for.
201 * >The length of the buffer must be correct. 199 * >The length of the buffer must be correct.
202 * FIXED - Should be ok now 18-9-90 - eay */ 200 * FIXED - Should be ok now 18-9-90 - eay */
203 if (len < rnum) 201 if (len < rnum) {
204 {
205
206 if (DES_rw_mode & DES_PCBC_MODE) 202 if (DES_rw_mode & DES_PCBC_MODE)
207 DES_pcbc_encrypt(net,tmpbuf,num,sched,iv, 203 DES_pcbc_encrypt(net, tmpbuf, num, sched, iv,
208 DES_DECRYPT); 204 DES_DECRYPT);
209 else 205 else
210 DES_cbc_encrypt(net,tmpbuf,num,sched,iv, 206 DES_cbc_encrypt(net, tmpbuf, num, sched, iv,
211 DES_DECRYPT); 207 DES_DECRYPT);
212 208
213 /* eay 26/08/92 fix a bug that returned more 209 /* eay 26/08/92 fix a bug that returned more
214 * bytes than you asked for (returned len bytes :-( */ 210 * bytes than you asked for (returned len bytes :-( */
215 memcpy(buf,tmpbuf,num); 211 memcpy(buf, tmpbuf, num);
216 } 212 } else {
217 else
218 {
219 if (DES_rw_mode & DES_PCBC_MODE) 213 if (DES_rw_mode & DES_PCBC_MODE)
220 DES_pcbc_encrypt(net,buf,num,sched,iv, 214 DES_pcbc_encrypt(net, buf, num, sched, iv,
221 DES_DECRYPT); 215 DES_DECRYPT);
222 else 216 else
223 DES_cbc_encrypt(net,buf,num,sched,iv, 217 DES_cbc_encrypt(net, buf, num, sched, iv,
224 DES_DECRYPT); 218 DES_DECRYPT);
225 }
226 } 219 }
227 return num;
228 } 220 }
229 221 return num;
222}
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
index 65fa720c1e..8a19fb84f9 100644
--- a/src/lib/libcrypto/des/enc_writ.c
+++ b/src/lib/libcrypto/des/enc_writ.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: enc_writ.c,v 1.15 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: enc_writ.c,v 1.16 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
@@ -79,95 +79,91 @@
79 * - This code cannot handle non-blocking sockets. 79 * - This code cannot handle non-blocking sockets.
80 */ 80 */
81 81
82int DES_enc_write(int fd, const void *_buf, int len, 82int
83 DES_key_schedule *sched, DES_cblock *iv) 83DES_enc_write(int fd, const void *_buf, int len,
84 { 84 DES_key_schedule *sched, DES_cblock *iv)
85{
85#ifdef _LIBC 86#ifdef _LIBC
86 extern unsigned long time(); 87 extern unsigned long time();
87 extern int write(); 88 extern int write();
88#endif 89#endif
89 const unsigned char *buf=_buf; 90 const unsigned char *buf = _buf;
90 long rnum; 91 long rnum;
91 int i,j,k,outnum; 92 int i, j, k, outnum;
92 static unsigned char *outbuf=NULL; 93 static unsigned char *outbuf = NULL;
93 unsigned char shortbuf[8]; 94 unsigned char shortbuf[8];
94 unsigned char *p; 95 unsigned char *p;
95 const unsigned char *cp; 96 const unsigned char *cp;
96 static int start=1; 97 static int start = 1;
97 98
98 if (outbuf == NULL) 99 if (outbuf == NULL) {
99 { 100 outbuf = malloc(BSIZE + HDRSIZE);
100 outbuf=malloc(BSIZE+HDRSIZE); 101 if (outbuf == NULL)
101 if (outbuf == NULL) return(-1); 102 return (-1);
102 } 103 }
103 /* If we are sending less than 8 bytes, the same char will look 104 /* If we are sending less than 8 bytes, the same char will look
104 * the same if we don't pad it out with random bytes */ 105 * the same if we don't pad it out with random bytes */
105 if (start) 106 if (start) {
106 { 107 start = 0;
107 start=0; 108 }
108 }
109 109
110 /* lets recurse if we want to send the data in small chunks */ 110 /* lets recurse if we want to send the data in small chunks */
111 if (len > MAXWRITE) 111 if (len > MAXWRITE) {
112 j = 0;
113 for (i = 0; i < len; i += k)
112 { 114 {
113 j=0; 115 k = DES_enc_write(fd, &(buf[i]),
114 for (i=0; i<len; i+=k) 116 ((len - i) > MAXWRITE) ? MAXWRITE : (len - i),
115 { 117 sched, iv);
116 k=DES_enc_write(fd,&(buf[i]),
117 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv);
118 if (k < 0) 118 if (k < 0)
119 return(k); 119 return (k);
120 else 120 else
121 j+=k; 121 j += k;
122 }
123 return(j);
124 } 122 }
123 return (j);
124 }
125 125
126 /* write length first */ 126 /* write length first */
127 p=outbuf; 127 p = outbuf;
128 l2n(len,p); 128 l2n(len, p);
129 129
130 /* pad short strings */ 130 /* pad short strings */
131 if (len < 8) 131 if (len < 8) {
132 { 132 cp = shortbuf;
133 cp=shortbuf; 133 memcpy(shortbuf, buf, len);
134 memcpy(shortbuf,buf,len); 134 arc4random_buf(shortbuf + len, 8 - len);
135 arc4random_buf(shortbuf+len, 8-len); 135 rnum = 8;
136 rnum=8; 136 } else {
137 } 137 cp = buf;
138 else 138 rnum = ((len + 7)/8*8); /* round up to nearest eight */
139 { 139 }
140 cp=buf;
141 rnum=((len+7)/8*8); /* round up to nearest eight */
142 }
143 140
144 if (DES_rw_mode & DES_PCBC_MODE) 141 if (DES_rw_mode & DES_PCBC_MODE)
145 DES_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv, 142 DES_pcbc_encrypt(cp, &(outbuf[HDRSIZE]), (len < 8) ? 8 : len,
146 DES_ENCRYPT); 143 sched, iv, DES_ENCRYPT);
147 else 144 else
148 DES_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv, 145 DES_cbc_encrypt(cp, &(outbuf[HDRSIZE]), (len < 8) ? 8 : len,
149 DES_ENCRYPT); 146 sched, iv, DES_ENCRYPT);
150 147
151 /* output */ 148 /* output */
152 outnum=rnum+HDRSIZE; 149 outnum = rnum + HDRSIZE;
153 150
154 for (j=0; j<outnum; j+=i) 151 for (j = 0; j < outnum; j += i)
155 { 152 {
156 /* eay 26/08/92 I was not doing writing from where we 153 /* eay 26/08/92 I was not doing writing from where we
157 * got up to. */ 154 * got up to. */
158 i=write(fd,(void *)&(outbuf[j]),outnum-j); 155 i = write(fd, (void *)&(outbuf[j]), outnum - j);
159 if (i == -1) 156 if (i == -1) {
160 {
161#ifdef EINTR 157#ifdef EINTR
162 if (errno == EINTR) 158 if (errno == EINTR)
163 i=0; 159 i = 0;
164 else 160 else
165#endif 161#endif
166 /* This is really a bad error - very bad 162 /* This is really a bad error - very bad
167 * It will stuff-up both ends. */ 163 * It will stuff-up both ends. */
168 return(-1); 164 return (-1);
169 }
170 } 165 }
171
172 return(len);
173 } 166 }
167
168 return (len);
169}
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
index 537562cd38..1e42ecbfe8 100644
--- a/src/lib/libcrypto/des/fcrypt.c
+++ b/src/lib/libcrypto/des/fcrypt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: fcrypt.c,v 1.13 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: fcrypt.c,v 1.14 2023/07/08 07:11:07 beck Exp $ */
2 2
3#include <stdio.h> 3#include <stdio.h>
4 4
@@ -18,57 +18,58 @@
18#include "des_local.h" 18#include "des_local.h"
19 19
20/* Added more values to handle illegal salt values the way normal 20/* Added more values to handle illegal salt values the way normal
21 * crypt() implementations do. The patch was sent by 21 * crypt() implementations do. The patch was sent by
22 * Bjorn Gronvall <bg@sics.se> 22 * Bjorn Gronvall <bg@sics.se>
23 */ 23 */
24static unsigned const char con_salt[128]={ 24static unsigned const char con_salt[128] = {
250xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9, 25 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9,
260xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1, 26 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1,
270xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9, 27 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9,
280xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1, 28 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1,
290xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9, 29 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9,
300xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01, 30 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x00, 0x01,
310x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, 31 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
320x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A, 32 0x0A, 0x0B, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
330x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12, 33 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12,
340x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A, 34 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
350x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22, 35 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
360x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24, 36 0x23, 0x24, 0x25, 0x20, 0x21, 0x22, 0x23, 0x24,
370x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C, 37 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C,
380x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34, 38 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34,
390x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C, 39 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C,
400x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44, 40 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44,
41}; 41};
42 42
43static unsigned const char cov_2char[64]={ 43static unsigned const char cov_2char[64] = {
440x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35, 44 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
450x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44, 45 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44,
460x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C, 46 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C,
470x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54, 47 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54,
480x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62, 48 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62,
490x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A, 49 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A,
500x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72, 50 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72,
510x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A 51 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A
52}; 52};
53 53
54char *DES_crypt(const char *buf, const char *salt) 54char *
55 { 55DES_crypt(const char *buf, const char *salt)
56{
56 static char buff[14]; 57 static char buff[14];
57 58
58 return(DES_fcrypt(buf,salt,buff)); 59 return (DES_fcrypt(buf, salt, buff));
59 } 60}
60
61 61
62char *DES_fcrypt(const char *buf, const char *salt, char *ret) 62char *
63 { 63DES_fcrypt(const char *buf, const char *salt, char *ret)
64 unsigned int i,j,x,y; 64{
65 DES_LONG Eswap0,Eswap1; 65 unsigned int i, j, x, y;
66 DES_LONG out[2],ll; 66 DES_LONG Eswap0, Eswap1;
67 DES_LONG out[2], ll;
67 DES_cblock key; 68 DES_cblock key;
68 DES_key_schedule ks; 69 DES_key_schedule ks;
69 unsigned char bb[9]; 70 unsigned char bb[9];
70 unsigned char *b=bb; 71 unsigned char *b = bb;
71 unsigned char c,u; 72 unsigned char c, u;
72 73
73 /* eay 25/08/92 74 /* eay 25/08/92
74 * If you call crypt("pwd","*") as often happens when you 75 * If you call crypt("pwd","*") as often happens when you
@@ -78,48 +79,50 @@ char *DES_fcrypt(const char *buf, const char *salt, char *ret)
78 * crypt to "*". This was found when replacing the crypt in 79 * crypt to "*". This was found when replacing the crypt in
79 * our shared libraries. People found that the disabled 80 * our shared libraries. People found that the disabled
80 * accounts effectively had no passwd :-(. */ 81 * accounts effectively had no passwd :-(. */
81 x=ret[0]=((salt[0] == '\0')?'A':salt[0]); 82 x = ret[0] = ((salt[0] == '\0') ? 'A' : salt[0]);
82 Eswap0=con_salt[x]<<2; 83 Eswap0 = con_salt[x] << 2;
83 x=ret[1]=((salt[1] == '\0')?'A':salt[1]); 84 x = ret[1] = ((salt[1] == '\0') ? 'A' : salt[1]);
84 Eswap1=con_salt[x]<<6; 85 Eswap1 = con_salt[x] << 6;
85/* EAY 86/* EAY
86r=strlen(buf); 87r=strlen(buf);
87r=(r+7)/8; 88r=(r+7)/8;
88*/ 89*/
89 for (i=0; i<8; i++) 90 for (i = 0; i < 8; i++)
90 { 91 {
91 c= *(buf++); 92 c = *(buf++);
92 if (!c) break; 93 if (!c)
93 key[i]=(c<<1); 94 break;
94 } 95 key[i] = (c << 1);
95 for (; i<8; i++) 96 }
96 key[i]=0; 97 for (; i < 8; i++)
98 key[i] = 0;
97 99
98 DES_set_key_unchecked(&key,&ks); 100 DES_set_key_unchecked(&key, &ks);
99 fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1); 101 fcrypt_body(&(out[0]), &ks, Eswap0, Eswap1);
100 102
101 ll=out[0]; l2c(ll,b); 103 ll = out[0];
102 ll=out[1]; l2c(ll,b); 104 l2c(ll, b);
103 y=0; 105 ll = out[1];
104 u=0x80; 106 l2c(ll, b);
105 bb[8]=0; 107 y = 0;
106 for (i=2; i<13; i++) 108 u = 0x80;
109 bb[8] = 0;
110 for (i = 2; i < 13; i++)
111 {
112 c = 0;
113 for (j = 0; j < 6; j++)
107 { 114 {
108 c=0; 115 c <<= 1;
109 for (j=0; j<6; j++) 116 if (bb[y] & u)
110 { 117 c |= 1;
111 c<<=1; 118 u >>= 1;
112 if (bb[y] & u) c|=1; 119 if (!u) {
113 u>>=1;
114 if (!u)
115 {
116 y++; 120 y++;
117 u=0x80; 121 u = 0x80;
118 }
119 } 122 }
120 ret[i]=cov_2char[c];
121 } 123 }
122 ret[13]='\0'; 124 ret[i] = cov_2char[c];
123 return(ret);
124 } 125 }
125 126 ret[13] = '\0';
127 return (ret);
128}
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
index 903c6de947..193ea34957 100644
--- a/src/lib/libcrypto/des/fcrypt_b.c
+++ b/src/lib/libcrypto/des/fcrypt_b.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: fcrypt_b.c,v 1.10 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: fcrypt_b.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
@@ -71,76 +71,77 @@
71#ifndef OPENBSD_DES_ASM 71#ifndef OPENBSD_DES_ASM
72 72
73#undef PERM_OP 73#undef PERM_OP
74#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ 74#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)), \
75 (b)^=(t),\ 75 (b)^=(t), \
76 (a)^=((t)<<(n))) 76 (a)^=((t)<<(n)))
77 77
78#undef HPERM_OP 78#undef HPERM_OP
79#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ 79#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)), \
80 (a)=(a)^(t)^(t>>(16-(n))))\ 80 (a)=(a)^(t)^(t>>(16-(n)))) \
81 81
82void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0, 82void
83 DES_LONG Eswap1) 83fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
84 { 84 DES_LONG Eswap1)
85 DES_LONG l,r,t,u; 85{
86 DES_LONG l, r, t, u;
86#ifdef DES_PTR 87#ifdef DES_PTR
87 const unsigned char *des_SP=(const unsigned char *)DES_SPtrans; 88 const unsigned char *des_SP = (const unsigned char *)DES_SPtrans;
88#endif 89#endif
89 DES_LONG *s; 90 DES_LONG *s;
90 int j; 91 int j;
91 DES_LONG E0,E1; 92 DES_LONG E0, E1;
92 93
93 l=0; 94 l = 0;
94 r=0; 95 r = 0;
95 96
96 s=(DES_LONG *)ks; 97 s = (DES_LONG *)ks;
97 E0=Eswap0; 98 E0 = Eswap0;
98 E1=Eswap1; 99 E1 = Eswap1;
99 100
100 for (j=0; j<25; j++) 101 for (j = 0; j < 25; j++)
101 { 102 {
102#ifndef DES_UNROLL 103#ifndef DES_UNROLL
103 int i; 104 int i;
104 105
105 for (i=0; i<32; i+=4) 106 for (i = 0; i < 32; i += 4)
106 { 107 {
107 D_ENCRYPT(l,r,i+0); /* 1 */ 108 D_ENCRYPT(l, r, i + 0); /* 1 */
108 D_ENCRYPT(r,l,i+2); /* 2 */ 109 D_ENCRYPT(r, l, i + 2); /* 2 */
109 } 110 }
110#else 111#else
111 D_ENCRYPT(l,r, 0); /* 1 */ 112 D_ENCRYPT(l, r, 0); /* 1 */
112 D_ENCRYPT(r,l, 2); /* 2 */ 113 D_ENCRYPT(r, l, 2); /* 2 */
113 D_ENCRYPT(l,r, 4); /* 3 */ 114 D_ENCRYPT(l, r, 4); /* 3 */
114 D_ENCRYPT(r,l, 6); /* 4 */ 115 D_ENCRYPT(r, l, 6); /* 4 */
115 D_ENCRYPT(l,r, 8); /* 5 */ 116 D_ENCRYPT(l, r, 8); /* 5 */
116 D_ENCRYPT(r,l,10); /* 6 */ 117 D_ENCRYPT(r, l, 10); /* 6 */
117 D_ENCRYPT(l,r,12); /* 7 */ 118 D_ENCRYPT(l, r, 12); /* 7 */
118 D_ENCRYPT(r,l,14); /* 8 */ 119 D_ENCRYPT(r, l, 14); /* 8 */
119 D_ENCRYPT(l,r,16); /* 9 */ 120 D_ENCRYPT(l, r, 16); /* 9 */
120 D_ENCRYPT(r,l,18); /* 10 */ 121 D_ENCRYPT(r, l, 18); /* 10 */
121 D_ENCRYPT(l,r,20); /* 11 */ 122 D_ENCRYPT(l, r, 20); /* 11 */
122 D_ENCRYPT(r,l,22); /* 12 */ 123 D_ENCRYPT(r, l, 22); /* 12 */
123 D_ENCRYPT(l,r,24); /* 13 */ 124 D_ENCRYPT(l, r, 24); /* 13 */
124 D_ENCRYPT(r,l,26); /* 14 */ 125 D_ENCRYPT(r, l, 26); /* 14 */
125 D_ENCRYPT(l,r,28); /* 15 */ 126 D_ENCRYPT(l, r, 28); /* 15 */
126 D_ENCRYPT(r,l,30); /* 16 */ 127 D_ENCRYPT(r, l, 30); /* 16 */
127#endif 128#endif
128 129
129 t=l; 130 t = l;
130 l=r; 131 l = r;
131 r=t; 132 r = t;
132 } 133 }
133 l=ROTATE(l,3)&0xffffffffL; 134 l = ROTATE(l, 3) & 0xffffffffL;
134 r=ROTATE(r,3)&0xffffffffL; 135 r = ROTATE(r, 3) & 0xffffffffL;
135 136
136 PERM_OP(l,r,t, 1,0x55555555L); 137 PERM_OP(l, r, t, 1, 0x55555555L);
137 PERM_OP(r,l,t, 8,0x00ff00ffL); 138 PERM_OP(r, l, t, 8, 0x00ff00ffL);
138 PERM_OP(l,r,t, 2,0x33333333L); 139 PERM_OP(l, r, t, 2, 0x33333333L);
139 PERM_OP(r,l,t,16,0x0000ffffL); 140 PERM_OP(r, l, t, 16, 0x0000ffffL);
140 PERM_OP(l,r,t, 4,0x0f0f0f0fL); 141 PERM_OP(l, r, t, 4, 0x0f0f0f0fL);
141 142
142 out[0]=r; 143 out[0] = r;
143 out[1]=l; 144 out[1] = l;
144 } 145}
145 146
146#endif /* OPENBSD_DES_ASM */ 147#endif /* OPENBSD_DES_ASM */
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c
index f2e1274b7e..d7e47813b3 100644
--- a/src/lib/libcrypto/des/ncbc_enc.c
+++ b/src/lib/libcrypto/des/ncbc_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ncbc_enc.c,v 1.8 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: ncbc_enc.c,v 1.9 2023/07/08 07:11:07 beck Exp $ */
2/* 2/*
3 * #included by: 3 * #included by:
4 * cbc_enc.c (DES_cbc_encrypt) 4 * cbc_enc.c (DES_cbc_encrypt)
@@ -10,21 +10,21 @@
10 * This package is an SSL implementation written 10 * This package is an SSL implementation written
11 * by Eric Young (eay@cryptsoft.com). 11 * by Eric Young (eay@cryptsoft.com).
12 * The implementation was written so as to conform with Netscapes SSL. 12 * The implementation was written so as to conform with Netscapes SSL.
13 * 13 *
14 * This library is free for commercial and non-commercial use as long as 14 * This library is free for commercial and non-commercial use as long as
15 * the following conditions are aheared to. The following conditions 15 * the following conditions are aheared to. The following conditions
16 * apply to all code found in this distribution, be it the RC4, RSA, 16 * apply to all code found in this distribution, be it the RC4, RSA,
17 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 17 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
18 * included with this distribution is covered by the same copyright terms 18 * included with this distribution is covered by the same copyright terms
19 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 19 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
20 * 20 *
21 * Copyright remains Eric Young's, and as such any Copyright notices in 21 * Copyright remains Eric Young's, and as such any Copyright notices in
22 * the code are not to be removed. 22 * the code are not to be removed.
23 * If this package is used in a product, Eric Young should be given attribution 23 * If this package is used in a product, Eric Young should be given attribution
24 * as the author of the parts of the library used. 24 * as the author of the parts of the library used.
25 * This can be in the form of a textual message at program startup or 25 * This can be in the form of a textual message at program startup or
26 * in documentation (online or textual) provided with the package. 26 * in documentation (online or textual) provided with the package.
27 * 27 *
28 * Redistribution and use in source and binary forms, with or without 28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions 29 * modification, are permitted provided that the following conditions
30 * are met: 30 * are met:
@@ -39,10 +39,10 @@
39 * Eric Young (eay@cryptsoft.com)" 39 * Eric Young (eay@cryptsoft.com)"
40 * The word 'cryptographic' can be left out if the rouines from the library 40 * The word 'cryptographic' can be left out if the rouines from the library
41 * being used are not cryptographic related :-). 41 * being used are not cryptographic related :-).
42 * 4. If you include any Windows specific code (or a derivative thereof) from 42 * 4. If you include any Windows specific code (or a derivative thereof) from
43 * the apps directory (application code) you must include an acknowledgement: 43 * the apps directory (application code) you must include an acknowledgement:
44 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 44 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
45 * 45 *
46 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 46 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -54,7 +54,7 @@
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE. 56 * SUCH DAMAGE.
57 * 57 *
58 * The licence and distribution terms for any publically available version or 58 * The licence and distribution terms for any publically available version or
59 * derivative of this code cannot be changed. i.e. this code cannot simply be 59 * derivative of this code cannot be changed. i.e. this code cannot simply be
60 * copied and put under another distribution licence 60 * copied and put under another distribution licence
@@ -64,85 +64,94 @@
64#include "des_local.h" 64#include "des_local.h"
65 65
66#ifdef CBC_ENC_C__DONT_UPDATE_IV 66#ifdef CBC_ENC_C__DONT_UPDATE_IV
67void DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, 67void
68 DES_key_schedule *_schedule, DES_cblock *ivec, int enc) 68DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
69 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
69#else 70#else
70void DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length, 71void
71 DES_key_schedule *_schedule, DES_cblock *ivec, int enc) 72DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
73 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
72#endif 74#endif
73 { 75{
74 DES_LONG tin0,tin1; 76 DES_LONG tin0, tin1;
75 DES_LONG tout0,tout1,xor0,xor1; 77 DES_LONG tout0, tout1, xor0, xor1;
76 long l=length; 78 long l = length;
77 DES_LONG tin[2]; 79 DES_LONG tin[2];
78 unsigned char *iv; 80 unsigned char *iv;
79 81
80 iv = &(*ivec)[0]; 82 iv = &(*ivec)[0];
81 83
82 if (enc) 84 if (enc) {
85 c2l(iv, tout0);
86 c2l(iv, tout1);
87 for (l -= 8; l >= 0; l -= 8)
83 { 88 {
84 c2l(iv,tout0); 89 c2l(in, tin0);
85 c2l(iv,tout1); 90 c2l(in, tin1);
86 for (l-=8; l>=0; l-=8) 91 tin0 ^= tout0;
87 { 92 tin[0] = tin0;
88 c2l(in,tin0); 93 tin1 ^= tout1;
89 c2l(in,tin1); 94 tin[1] = tin1;
90 tin0^=tout0; tin[0]=tin0; 95 DES_encrypt1((DES_LONG *)tin, _schedule, DES_ENCRYPT);
91 tin1^=tout1; tin[1]=tin1; 96 tout0 = tin[0];
92 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT); 97 l2c(tout0, out);
93 tout0=tin[0]; l2c(tout0,out); 98 tout1 = tin[1];
94 tout1=tin[1]; l2c(tout1,out); 99 l2c(tout1, out);
95 } 100 }
96 if (l != -8) 101 if (l != -8) {
97 { 102 c2ln(in, tin0, tin1, l + 8);
98 c2ln(in,tin0,tin1,l+8); 103 tin0 ^= tout0;
99 tin0^=tout0; tin[0]=tin0; 104 tin[0] = tin0;
100 tin1^=tout1; tin[1]=tin1; 105 tin1 ^= tout1;
101 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT); 106 tin[1] = tin1;
102 tout0=tin[0]; l2c(tout0,out); 107 DES_encrypt1((DES_LONG *)tin, _schedule, DES_ENCRYPT);
103 tout1=tin[1]; l2c(tout1,out); 108 tout0 = tin[0];
104 } 109 l2c(tout0, out);
110 tout1 = tin[1];
111 l2c(tout1, out);
112 }
105#ifndef CBC_ENC_C__DONT_UPDATE_IV 113#ifndef CBC_ENC_C__DONT_UPDATE_IV
106 iv = &(*ivec)[0]; 114 iv = &(*ivec)[0];
107 l2c(tout0,iv); 115 l2c(tout0, iv);
108 l2c(tout1,iv); 116 l2c(tout1, iv);
109#endif 117#endif
110 } 118 } else {
111 else 119 c2l(iv, xor0);
120 c2l(iv, xor1);
121 for (l -= 8; l >= 0; l -= 8)
112 { 122 {
113 c2l(iv,xor0); 123 c2l(in, tin0);
114 c2l(iv,xor1); 124 tin[0] = tin0;
115 for (l-=8; l>=0; l-=8) 125 c2l(in, tin1);
116 { 126 tin[1] = tin1;
117 c2l(in,tin0); tin[0]=tin0; 127 DES_encrypt1((DES_LONG *)tin, _schedule, DES_DECRYPT);
118 c2l(in,tin1); tin[1]=tin1; 128 tout0 = tin[0] ^ xor0;
119 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT); 129 tout1 = tin[1] ^ xor1;
120 tout0=tin[0]^xor0; 130 l2c(tout0, out);
121 tout1=tin[1]^xor1; 131 l2c(tout1, out);
122 l2c(tout0,out); 132 xor0 = tin0;
123 l2c(tout1,out); 133 xor1 = tin1;
124 xor0=tin0; 134 }
125 xor1=tin1; 135 if (l != -8) {
126 } 136 c2l(in, tin0);
127 if (l != -8) 137 tin[0] = tin0;
128 { 138 c2l(in, tin1);
129 c2l(in,tin0); tin[0]=tin0; 139 tin[1] = tin1;
130 c2l(in,tin1); tin[1]=tin1; 140 DES_encrypt1((DES_LONG *)tin, _schedule, DES_DECRYPT);
131 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT); 141 tout0 = tin[0] ^ xor0;
132 tout0=tin[0]^xor0; 142 tout1 = tin[1] ^ xor1;
133 tout1=tin[1]^xor1; 143 l2cn(tout0, tout1, out, l + 8);
134 l2cn(tout0,tout1,out,l+8);
135#ifndef CBC_ENC_C__DONT_UPDATE_IV 144#ifndef CBC_ENC_C__DONT_UPDATE_IV
136 xor0=tin0; 145 xor0 = tin0;
137 xor1=tin1; 146 xor1 = tin1;
138#endif 147#endif
139 } 148 }
140#ifndef CBC_ENC_C__DONT_UPDATE_IV 149#ifndef CBC_ENC_C__DONT_UPDATE_IV
141 iv = &(*ivec)[0]; 150 iv = &(*ivec)[0];
142 l2c(xor0,iv); 151 l2c(xor0, iv);
143 l2c(xor1,iv); 152 l2c(xor1, iv);
144#endif 153#endif
145 }
146 tin0=tin1=tout0=tout1=xor0=xor1=0;
147 tin[0]=tin[1]=0;
148 } 154 }
155 tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
156 tin[0] = tin[1] = 0;
157}
diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c
index 65969313ba..2922fc77fa 100644
--- a/src/lib/libcrypto/des/ofb64ede.c
+++ b/src/lib/libcrypto/des/ofb64ede.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: ofb64ede.c,v 1.7 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: ofb64ede.c,v 1.8 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
@@ -62,53 +62,51 @@
62 * used. The extra state information to record how much of the 62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65void DES_ede3_ofb64_encrypt(const unsigned char *in, 65void
66 unsigned char *out, long length, 66DES_ede3_ofb64_encrypt(const unsigned char *in,
67 DES_key_schedule *k1, DES_key_schedule *k2, 67 unsigned char *out, long length,
68 DES_key_schedule *k3, DES_cblock *ivec, 68 DES_key_schedule *k1, DES_key_schedule *k2,
69 int *num) 69 DES_key_schedule *k3, DES_cblock *ivec,
70 { 70 int *num)
71 DES_LONG v0,v1; 71{
72 int n= *num; 72 DES_LONG v0, v1;
73 long l=length; 73 int n = *num;
74 long l = length;
74 DES_cblock d; 75 DES_cblock d;
75 char *dp; 76 char *dp;
76 DES_LONG ti[2]; 77 DES_LONG ti[2];
77 unsigned char *iv; 78 unsigned char *iv;
78 int save=0; 79 int save = 0;
79 80
80 iv = &(*ivec)[0]; 81 iv = &(*ivec)[0];
81 c2l(iv,v0); 82 c2l(iv, v0);
82 c2l(iv,v1); 83 c2l(iv, v1);
83 ti[0]=v0; 84 ti[0] = v0;
84 ti[1]=v1; 85 ti[1] = v1;
85 dp=(char *)d; 86 dp = (char *)d;
86 l2c(v0,dp); 87 l2c(v0, dp);
87 l2c(v1,dp); 88 l2c(v1, dp);
88 while (l--) 89 while (l--) {
89 { 90 if (n == 0) {
90 if (n == 0)
91 {
92 /* ti[0]=v0; */ 91 /* ti[0]=v0; */
93 /* ti[1]=v1; */ 92 /* ti[1]=v1; */
94 DES_encrypt3(ti,k1,k2,k3); 93 DES_encrypt3(ti, k1, k2, k3);
95 v0=ti[0]; 94 v0 = ti[0];
96 v1=ti[1]; 95 v1 = ti[1];
97 96
98 dp=(char *)d; 97 dp = (char *)d;
99 l2c(v0,dp); 98 l2c(v0, dp);
100 l2c(v1,dp); 99 l2c(v1, dp);
101 save++; 100 save++;
102 }
103 *(out++)= *(in++)^d[n];
104 n=(n+1)&0x07;
105 } 101 }
106 if (save) 102 *(out++) = *(in++) ^ d[n];
107 { 103 n = (n + 1) & 0x07;
104 }
105 if (save) {
108 iv = &(*ivec)[0]; 106 iv = &(*ivec)[0];
109 l2c(v0,iv); 107 l2c(v0, iv);
110 l2c(v1,iv); 108 l2c(v1, iv);
111 }
112 v0=v1=ti[0]=ti[1]=0;
113 *num=n;
114 } 109 }
110 v0 = v1 = ti[0] = ti[1] = 0;
111 *num = n;
112}
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c
index 10deca00e7..c3b1b8af8b 100644
--- a/src/lib/libcrypto/des/ofb64enc.c
+++ b/src/lib/libcrypto/des/ofb64enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: ofb64enc.c,v 1.7 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: ofb64enc.c,v 1.8 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
@@ -62,49 +62,48 @@
62 * used. The extra state information to record how much of the 62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65void DES_ofb64_encrypt(const unsigned char *in, 65void
66 unsigned char *out, long length, 66DES_ofb64_encrypt(const unsigned char *in,
67 DES_key_schedule *schedule, DES_cblock *ivec, int *num) 67 unsigned char *out, long length,
68 { 68 DES_key_schedule *schedule, DES_cblock *ivec, int *num)
69 DES_LONG v0,v1,t; 69{
70 int n= *num; 70 DES_LONG v0, v1, t;
71 long l=length; 71 int n = *num;
72 long l = length;
72 DES_cblock d; 73 DES_cblock d;
73 unsigned char *dp; 74 unsigned char *dp;
74 DES_LONG ti[2]; 75 DES_LONG ti[2];
75 unsigned char *iv; 76 unsigned char *iv;
76 int save=0; 77 int save = 0;
77 78
78 iv = &(*ivec)[0]; 79 iv = &(*ivec)[0];
79 c2l(iv,v0); 80 c2l(iv, v0);
80 c2l(iv,v1); 81 c2l(iv, v1);
81 ti[0]=v0; 82 ti[0] = v0;
82 ti[1]=v1; 83 ti[1] = v1;
83 dp=d; 84 dp = d;
84 l2c(v0,dp); 85 l2c(v0, dp);
85 l2c(v1,dp); 86 l2c(v1, dp);
86 while (l--) 87 while (l--) {
87 { 88 if (n == 0) {
88 if (n == 0) 89 DES_encrypt1(ti, schedule, DES_ENCRYPT);
89 { 90 dp = d;
90 DES_encrypt1(ti,schedule,DES_ENCRYPT); 91 t = ti[0];
91 dp=d; 92 l2c(t, dp);
92 t=ti[0]; l2c(t,dp); 93 t = ti[1];
93 t=ti[1]; l2c(t,dp); 94 l2c(t, dp);
94 save++; 95 save++;
95 }
96 *(out++)= *(in++)^d[n];
97 n=(n+1)&0x07;
98 } 96 }
99 if (save) 97 *(out++) = *(in++) ^ d[n];
100 { 98 n = (n + 1) & 0x07;
101 v0=ti[0]; 99 }
102 v1=ti[1]; 100 if (save) {
101 v0 = ti[0];
102 v1 = ti[1];
103 iv = &(*ivec)[0]; 103 iv = &(*ivec)[0];
104 l2c(v0,iv); 104 l2c(v0, iv);
105 l2c(v1,iv); 105 l2c(v1, iv);
106 }
107 t=v0=v1=ti[0]=ti[1]=0;
108 *num=n;
109 } 106 }
110 107 t = v0 = v1 = ti[0] = ti[1] = 0;
108 *num = n;
109}
diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c
index 25abb6db95..990b927eb0 100644
--- a/src/lib/libcrypto/des/ofb_enc.c
+++ b/src/lib/libcrypto/des/ofb_enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: ofb_enc.c,v 1.7 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: ofb_enc.c,v 1.8 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
@@ -64,72 +64,70 @@
64 * the second. The second 12 bits will come from the 3rd and half the 4th 64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte. 65 * byte.
66 */ 66 */
67void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits, 67void
68 long length, DES_key_schedule *schedule, 68DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
69 DES_cblock *ivec) 69 long length, DES_key_schedule *schedule,
70 { 70 DES_cblock *ivec)
71 DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8; 71{
72 DES_LONG mask0,mask1; 72 DES_LONG d0, d1, vv0, vv1, v0, v1, n = (numbits + 7)/8;
73 long l=length; 73 DES_LONG mask0, mask1;
74 int num=numbits; 74 long l = length;
75 int num = numbits;
75 DES_LONG ti[2]; 76 DES_LONG ti[2];
76 unsigned char *iv; 77 unsigned char *iv;
77 78
78 if (num > 64) return; 79 if (num > 64)
79 if (num > 32) 80 return;
80 { 81 if (num > 32) {
81 mask0=0xffffffffL; 82 mask0 = 0xffffffffL;
82 if (num >= 64) 83 if (num >= 64)
83 mask1=mask0; 84 mask1 = mask0;
84 else 85 else
85 mask1=(1L<<(num-32))-1; 86 mask1 = (1L << (num - 32)) - 1;
86 } 87 } else {
87 else
88 {
89 if (num == 32) 88 if (num == 32)
90 mask0=0xffffffffL; 89 mask0 = 0xffffffffL;
91 else 90 else
92 mask0=(1L<<num)-1; 91 mask0 = (1L << num) - 1;
93 mask1=0x00000000L; 92 mask1 = 0x00000000L;
94 } 93 }
95 94
96 iv = &(*ivec)[0]; 95 iv = &(*ivec)[0];
97 c2l(iv,v0); 96 c2l(iv, v0);
98 c2l(iv,v1); 97 c2l(iv, v1);
99 ti[0]=v0; 98 ti[0] = v0;
100 ti[1]=v1; 99 ti[1] = v1;
101 while (l-- > 0) 100 while (l-- > 0) {
102 { 101 ti[0] = v0;
103 ti[0]=v0; 102 ti[1] = v1;
104 ti[1]=v1; 103 DES_encrypt1((DES_LONG *)ti, schedule, DES_ENCRYPT);
105 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT); 104 vv0 = ti[0];
106 vv0=ti[0]; 105 vv1 = ti[1];
107 vv1=ti[1]; 106 c2ln(in, d0, d1, n);
108 c2ln(in,d0,d1,n); 107 in += n;
109 in+=n; 108 d0 = (d0 ^ vv0) & mask0;
110 d0=(d0^vv0)&mask0; 109 d1 = (d1 ^ vv1) & mask1;
111 d1=(d1^vv1)&mask1; 110 l2cn(d0, d1, out, n);
112 l2cn(d0,d1,out,n); 111 out += n;
113 out+=n;
114 112
115 if (num == 32) 113 if (num == 32) {
116 { v0=v1; v1=vv0; } 114 v0 = v1;
117 else if (num == 64) 115 v1 = vv0;
118 { v0=vv0; v1=vv1; } 116 } else if (num == 64) {
119 else if (num > 32) /* && num != 64 */ 117 v0 = vv0;
120 { 118 v1 = vv1;
121 v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL; 119 } else if (num > 32) { /* && num != 64 */
122 v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL; 120 v0 = ((v1 >> (num - 32))|(vv0 << (64 - num))) &
123 } 121 0xffffffffL;
124 else /* num < 32 */ 122 v1 = ((vv0 >> (num - 32))|(vv1 << (64 - num))) &
125 { 123 0xffffffffL;
126 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL; 124 } else /* num < 32 */ {
127 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL; 125 v0 = ((v0 >> num)|(v1 << (32 - num))) & 0xffffffffL;
128 } 126 v1 = ((v1 >> num)|(vv0 << (32 - num))) & 0xffffffffL;
129 } 127 }
130 iv = &(*ivec)[0];
131 l2c(v0,iv);
132 l2c(v1,iv);
133 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0;
134 } 128 }
135 129 iv = &(*ivec)[0];
130 l2c(v0, iv);
131 l2c(v1, iv);
132 v0 = v1 = d0 = d1 = ti[0] = ti[1] = vv0 = vv1 = 0;
133}
diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c
index 1f8688d1f3..8574a44083 100644
--- a/src/lib/libcrypto/des/pcbc_enc.c
+++ b/src/lib/libcrypto/des/pcbc_enc.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: pcbc_enc.c,v 1.7 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: pcbc_enc.c,v 1.8 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
@@ -58,66 +58,61 @@
58 58
59#include "des_local.h" 59#include "des_local.h"
60 60
61void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output, 61void
62 long length, DES_key_schedule *schedule, 62DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
63 DES_cblock *ivec, int enc) 63 long length, DES_key_schedule *schedule,
64 { 64 DES_cblock *ivec, int enc)
65 DES_LONG sin0,sin1,xor0,xor1,tout0,tout1; 65{
66 DES_LONG sin0, sin1, xor0, xor1, tout0, tout1;
66 DES_LONG tin[2]; 67 DES_LONG tin[2];
67 const unsigned char *in; 68 const unsigned char *in;
68 unsigned char *out,*iv; 69 unsigned char *out, *iv;
69 70
70 in=input; 71 in = input;
71 out=output; 72 out = output;
72 iv = &(*ivec)[0]; 73 iv = &(*ivec)[0];
73 74
74 if (enc) 75 if (enc) {
76 c2l(iv, xor0);
77 c2l(iv, xor1);
78 for (; length > 0; length -= 8)
75 { 79 {
76 c2l(iv,xor0); 80 if (length >= 8) {
77 c2l(iv,xor1); 81 c2l(in, sin0);
78 for (; length>0; length-=8) 82 c2l(in, sin1);
79 { 83 } else
80 if (length >= 8) 84 c2ln(in, sin0, sin1, length);
81 { 85 tin[0] = sin0 ^ xor0;
82 c2l(in,sin0); 86 tin[1] = sin1 ^ xor1;
83 c2l(in,sin1); 87 DES_encrypt1((DES_LONG *)tin, schedule, DES_ENCRYPT);
84 } 88 tout0 = tin[0];
85 else 89 tout1 = tin[1];
86 c2ln(in,sin0,sin1,length); 90 xor0 = sin0 ^ tout0;
87 tin[0]=sin0^xor0; 91 xor1 = sin1 ^ tout1;
88 tin[1]=sin1^xor1; 92 l2c(tout0, out);
89 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT); 93 l2c(tout1, out);
90 tout0=tin[0];
91 tout1=tin[1];
92 xor0=sin0^tout0;
93 xor1=sin1^tout1;
94 l2c(tout0,out);
95 l2c(tout1,out);
96 }
97 } 94 }
98 else 95 } else {
96 c2l(iv, xor0);
97 c2l(iv, xor1);
98 for (; length > 0; length -= 8)
99 { 99 {
100 c2l(iv,xor0); c2l(iv,xor1); 100 c2l(in, sin0);
101 for (; length>0; length-=8) 101 c2l(in, sin1);
102 { 102 tin[0] = sin0;
103 c2l(in,sin0); 103 tin[1] = sin1;
104 c2l(in,sin1); 104 DES_encrypt1((DES_LONG *)tin, schedule, DES_DECRYPT);
105 tin[0]=sin0; 105 tout0 = tin[0] ^ xor0;
106 tin[1]=sin1; 106 tout1 = tin[1] ^ xor1;
107 DES_encrypt1((DES_LONG *)tin,schedule,DES_DECRYPT); 107 if (length >= 8) {
108 tout0=tin[0]^xor0; 108 l2c(tout0, out);
109 tout1=tin[1]^xor1; 109 l2c(tout1, out);
110 if (length >= 8) 110 } else
111 { 111 l2cn(tout0, tout1, out, length);
112 l2c(tout0,out); 112 xor0 = tout0 ^ sin0;
113 l2c(tout1,out); 113 xor1 = tout1 ^ sin1;
114 }
115 else
116 l2cn(tout0,tout1,out,length);
117 xor0=tout0^sin0;
118 xor1=tout1^sin1;
119 }
120 } 114 }
121 tin[0]=tin[1]=0;
122 sin0=sin1=xor0=xor1=tout0=tout1=0;
123 } 115 }
116 tin[0] = tin[1] = 0;
117 sin0 = sin1 = xor0 = xor1 = tout0 = tout1 = 0;
118}
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c
index 7ff43620a3..c9d2c01fa1 100644
--- a/src/lib/libcrypto/des/qud_cksm.c
+++ b/src/lib/libcrypto/des/qud_cksm.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: qud_cksm.c,v 1.8 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: qud_cksm.c,v 1.9 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
@@ -73,53 +73,54 @@
73/* Got the value MIT uses via brute force :-) 2/10/90 eay */ 73/* Got the value MIT uses via brute force :-) 2/10/90 eay */
74#define NOISE ((DES_LONG)83653421L) 74#define NOISE ((DES_LONG)83653421L)
75 75
76DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[], 76DES_LONG
77 long length, int out_count, DES_cblock *seed) 77DES_quad_cksum(const unsigned char *input, DES_cblock output[],
78 { 78 long length, int out_count, DES_cblock *seed)
79 DES_LONG z0,z1,t0,t1; 79{
80 DES_LONG z0, z1, t0, t1;
80 int i; 81 int i;
81 long l; 82 long l;
82 const unsigned char *cp; 83 const unsigned char *cp;
83 DES_LONG *lp; 84 DES_LONG *lp;
84 85
85 if (out_count < 1) out_count=1; 86 if (out_count < 1)
86 lp = (DES_LONG *) &(output[0])[0]; 87 out_count = 1;
88 lp = (DES_LONG *)&(output[0])[0];
87 89
88 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]); 90 z0 = Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3(
89 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]); 91 (*seed)[3]);
92 z1 = Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3(
93 (*seed)[7]);
90 94
91 for (i=0; ((i<4)&&(i<out_count)); i++) 95 for (i = 0; ((i < 4) && (i < out_count)); i++)
92 { 96 {
93 cp=input; 97 cp = input;
94 l=length; 98 l = length;
95 while (l > 0) 99 while (l > 0) {
96 { 100 if (l > 1) {
97 if (l > 1) 101 t0 = (DES_LONG)(*(cp++));
98 { 102 t0 |= (DES_LONG)Q_B1(*(cp++));
99 t0= (DES_LONG)(*(cp++));
100 t0|=(DES_LONG)Q_B1(*(cp++));
101 l--; 103 l--;
102 } 104 } else
103 else 105 t0 = (DES_LONG)(*(cp++));
104 t0= (DES_LONG)(*(cp++));
105 l--; 106 l--;
106 /* add */ 107 /* add */
107 t0+=z0; 108 t0 += z0;
108 t0&=0xffffffffL; 109 t0 &= 0xffffffffL;
109 t1=z1; 110 t1 = z1;
110 /* square, well sort of square */ 111 /* square, well sort of square */
111 z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL)) 112 z0 = ((((t0*t0) & 0xffffffffL) +
112 &0xffffffffL)%0x7fffffffL; 113 ((t1*t1) & 0xffffffffL)) & 0xffffffffL) %
113 z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL; 114 0x7fffffffL;
114 } 115 z1 = ((t0*((t1 + NOISE) & 0xffffffffL)) & 0xffffffffL) %
115 if (lp != NULL) 116 0x7fffffffL;
116 { 117 }
118 if (lp != NULL) {
117 /* The MIT library assumes that the checksum is 119 /* The MIT library assumes that the checksum is
118 * composed of 2*out_count 32 bit ints */ 120 * composed of 2*out_count 32 bit ints */
119 *lp++ = z0; 121 *lp++ = z0;
120 *lp++ = z1; 122 *lp++ = z1;
121 }
122 } 123 }
123 return(z0);
124 } 124 }
125 125 return (z0);
126}
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
index 7abb811df4..aba899fe0a 100644
--- a/src/lib/libcrypto/des/rand_key.c
+++ b/src/lib/libcrypto/des/rand_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rand_key.c,v 1.8 2014/10/22 13:02:04 jsing Exp $ */ 1/* $OpenBSD: rand_key.c,v 1.9 2023/07/08 07:11:07 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
index 5196a64f15..07b8d03da1 100644
--- a/src/lib/libcrypto/des/set_key.c
+++ b/src/lib/libcrypto/des/set_key.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: set_key.c,v 1.21 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: set_key.c,v 1.22 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
@@ -68,43 +68,45 @@
68 68
69int DES_check_key = 0; /* defaults to false */ 69int DES_check_key = 0; /* defaults to false */
70 70
71static const unsigned char odd_parity[256]={ 71static const unsigned char odd_parity[256] = {
72 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14, 72 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
73 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31, 73 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
74 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47, 74 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
75 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62, 75 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
76 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79, 76 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
77 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94, 77 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
78 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110, 78 97, 97, 98, 98, 100, 100, 103, 103, 104, 104, 107, 107, 109, 109, 110, 110,
79112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127, 79 112, 112, 115, 115, 117, 117, 118, 118, 121, 121, 122, 122, 124, 124, 127, 127,
80128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143, 80 128, 128, 131, 131, 133, 133, 134, 134, 137, 137, 138, 138, 140, 140, 143, 143,
81145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158, 81 145, 145, 146, 146, 148, 148, 151, 151, 152, 152, 155, 155, 157, 157, 158, 158,
82161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174, 82 161, 161, 162, 162, 164, 164, 167, 167, 168, 168, 171, 171, 173, 173, 174, 174,
83176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191, 83 176, 176, 179, 179, 181, 181, 182, 182, 185, 185, 186, 186, 188, 188, 191, 191,
84193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206, 84 193, 193, 194, 194, 196, 196, 199, 199, 200, 200, 203, 203, 205, 205, 206, 206,
85208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223, 85 208, 208, 211, 211, 213, 213, 214, 214, 217, 217, 218, 218, 220, 220, 223, 223,
86224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239, 86 224, 224, 227, 227, 229, 229, 230, 230, 233, 233, 234, 234, 236, 236, 239, 239,
87241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254}; 87 241, 241, 242, 242, 244, 244, 247, 247, 248, 248, 251, 251, 253, 253, 254, 254};
88 88
89void DES_set_odd_parity(DES_cblock *key) 89void
90 { 90DES_set_odd_parity(DES_cblock *key)
91{
91 unsigned int i; 92 unsigned int i;
92 93
93 for (i=0; i<DES_KEY_SZ; i++) 94 for (i = 0; i < DES_KEY_SZ; i++)
94 (*key)[i]=odd_parity[(*key)[i]]; 95 (*key)[i] = odd_parity[(*key)[i]];
95 } 96}
96 97
97int DES_check_key_parity(const_DES_cblock *key) 98int
98 { 99DES_check_key_parity(const_DES_cblock *key)
100{
99 unsigned int i; 101 unsigned int i;
100 102
101 for (i=0; i<DES_KEY_SZ; i++) 103 for (i = 0; i < DES_KEY_SZ; i++)
102 { 104 {
103 if ((*key)[i] != odd_parity[(*key)[i]]) 105 if ((*key)[i] != odd_parity[(*key)[i]])
104 return(0); 106 return (0);
105 }
106 return(1);
107 } 107 }
108 return (1);
109}
108 110
109/* Weak and semi weak keys as taken from 111/* Weak and semi weak keys as taken from
110 * %A D.W. Davies 112 * %A D.W. Davies
@@ -116,7 +118,7 @@ int DES_check_key_parity(const_DES_cblock *key)
116 * (and actual cblock values). 118 * (and actual cblock values).
117 */ 119 */
118#define NUM_WEAK_KEY 16 120#define NUM_WEAK_KEY 16
119static const DES_cblock weak_keys[NUM_WEAK_KEY]={ 121static const DES_cblock weak_keys[NUM_WEAK_KEY] = {
120 /* weak keys */ 122 /* weak keys */
121 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, 123 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
122 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, 124 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
@@ -148,193 +150,193 @@ DES_is_weak_key(const_DES_cblock *key)
148} 150}
149 151
150/* NOW DEFINED IN des_local.h 152/* NOW DEFINED IN des_local.h
151 * See ecb_encrypt.c for a pseudo description of these macros. 153 * See ecb_encrypt.c for a pseudo description of these macros.
152 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ 154 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
153 * (b)^=(t),\ 155 * (b)^=(t),\
154 * (a)=((a)^((t)<<(n)))) 156 * (a)=((a)^((t)<<(n))))
155 */ 157 */
156 158
157#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ 159#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)), \
158 (a)=(a)^(t)^(t>>(16-(n)))) 160 (a)=(a)^(t)^(t>>(16-(n))))
159 161
160static const DES_LONG des_skb[8][64]={ 162static const DES_LONG des_skb[8][64] = {
161 { 163 {
162 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ 164 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
163 0x00000000L,0x00000010L,0x20000000L,0x20000010L, 165 0x00000000L, 0x00000010L, 0x20000000L, 0x20000010L,
164 0x00010000L,0x00010010L,0x20010000L,0x20010010L, 166 0x00010000L, 0x00010010L, 0x20010000L, 0x20010010L,
165 0x00000800L,0x00000810L,0x20000800L,0x20000810L, 167 0x00000800L, 0x00000810L, 0x20000800L, 0x20000810L,
166 0x00010800L,0x00010810L,0x20010800L,0x20010810L, 168 0x00010800L, 0x00010810L, 0x20010800L, 0x20010810L,
167 0x00000020L,0x00000030L,0x20000020L,0x20000030L, 169 0x00000020L, 0x00000030L, 0x20000020L, 0x20000030L,
168 0x00010020L,0x00010030L,0x20010020L,0x20010030L, 170 0x00010020L, 0x00010030L, 0x20010020L, 0x20010030L,
169 0x00000820L,0x00000830L,0x20000820L,0x20000830L, 171 0x00000820L, 0x00000830L, 0x20000820L, 0x20000830L,
170 0x00010820L,0x00010830L,0x20010820L,0x20010830L, 172 0x00010820L, 0x00010830L, 0x20010820L, 0x20010830L,
171 0x00080000L,0x00080010L,0x20080000L,0x20080010L, 173 0x00080000L, 0x00080010L, 0x20080000L, 0x20080010L,
172 0x00090000L,0x00090010L,0x20090000L,0x20090010L, 174 0x00090000L, 0x00090010L, 0x20090000L, 0x20090010L,
173 0x00080800L,0x00080810L,0x20080800L,0x20080810L, 175 0x00080800L, 0x00080810L, 0x20080800L, 0x20080810L,
174 0x00090800L,0x00090810L,0x20090800L,0x20090810L, 176 0x00090800L, 0x00090810L, 0x20090800L, 0x20090810L,
175 0x00080020L,0x00080030L,0x20080020L,0x20080030L, 177 0x00080020L, 0x00080030L, 0x20080020L, 0x20080030L,
176 0x00090020L,0x00090030L,0x20090020L,0x20090030L, 178 0x00090020L, 0x00090030L, 0x20090020L, 0x20090030L,
177 0x00080820L,0x00080830L,0x20080820L,0x20080830L, 179 0x00080820L, 0x00080830L, 0x20080820L, 0x20080830L,
178 0x00090820L,0x00090830L,0x20090820L,0x20090830L, 180 0x00090820L, 0x00090830L, 0x20090820L, 0x20090830L,
179 },{ 181 }, {
180 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */ 182 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
181 0x00000000L,0x02000000L,0x00002000L,0x02002000L, 183 0x00000000L, 0x02000000L, 0x00002000L, 0x02002000L,
182 0x00200000L,0x02200000L,0x00202000L,0x02202000L, 184 0x00200000L, 0x02200000L, 0x00202000L, 0x02202000L,
183 0x00000004L,0x02000004L,0x00002004L,0x02002004L, 185 0x00000004L, 0x02000004L, 0x00002004L, 0x02002004L,
184 0x00200004L,0x02200004L,0x00202004L,0x02202004L, 186 0x00200004L, 0x02200004L, 0x00202004L, 0x02202004L,
185 0x00000400L,0x02000400L,0x00002400L,0x02002400L, 187 0x00000400L, 0x02000400L, 0x00002400L, 0x02002400L,
186 0x00200400L,0x02200400L,0x00202400L,0x02202400L, 188 0x00200400L, 0x02200400L, 0x00202400L, 0x02202400L,
187 0x00000404L,0x02000404L,0x00002404L,0x02002404L, 189 0x00000404L, 0x02000404L, 0x00002404L, 0x02002404L,
188 0x00200404L,0x02200404L,0x00202404L,0x02202404L, 190 0x00200404L, 0x02200404L, 0x00202404L, 0x02202404L,
189 0x10000000L,0x12000000L,0x10002000L,0x12002000L, 191 0x10000000L, 0x12000000L, 0x10002000L, 0x12002000L,
190 0x10200000L,0x12200000L,0x10202000L,0x12202000L, 192 0x10200000L, 0x12200000L, 0x10202000L, 0x12202000L,
191 0x10000004L,0x12000004L,0x10002004L,0x12002004L, 193 0x10000004L, 0x12000004L, 0x10002004L, 0x12002004L,
192 0x10200004L,0x12200004L,0x10202004L,0x12202004L, 194 0x10200004L, 0x12200004L, 0x10202004L, 0x12202004L,
193 0x10000400L,0x12000400L,0x10002400L,0x12002400L, 195 0x10000400L, 0x12000400L, 0x10002400L, 0x12002400L,
194 0x10200400L,0x12200400L,0x10202400L,0x12202400L, 196 0x10200400L, 0x12200400L, 0x10202400L, 0x12202400L,
195 0x10000404L,0x12000404L,0x10002404L,0x12002404L, 197 0x10000404L, 0x12000404L, 0x10002404L, 0x12002404L,
196 0x10200404L,0x12200404L,0x10202404L,0x12202404L, 198 0x10200404L, 0x12200404L, 0x10202404L, 0x12202404L,
197 },{ 199 }, {
198 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */ 200 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
199 0x00000000L,0x00000001L,0x00040000L,0x00040001L, 201 0x00000000L, 0x00000001L, 0x00040000L, 0x00040001L,
200 0x01000000L,0x01000001L,0x01040000L,0x01040001L, 202 0x01000000L, 0x01000001L, 0x01040000L, 0x01040001L,
201 0x00000002L,0x00000003L,0x00040002L,0x00040003L, 203 0x00000002L, 0x00000003L, 0x00040002L, 0x00040003L,
202 0x01000002L,0x01000003L,0x01040002L,0x01040003L, 204 0x01000002L, 0x01000003L, 0x01040002L, 0x01040003L,
203 0x00000200L,0x00000201L,0x00040200L,0x00040201L, 205 0x00000200L, 0x00000201L, 0x00040200L, 0x00040201L,
204 0x01000200L,0x01000201L,0x01040200L,0x01040201L, 206 0x01000200L, 0x01000201L, 0x01040200L, 0x01040201L,
205 0x00000202L,0x00000203L,0x00040202L,0x00040203L, 207 0x00000202L, 0x00000203L, 0x00040202L, 0x00040203L,
206 0x01000202L,0x01000203L,0x01040202L,0x01040203L, 208 0x01000202L, 0x01000203L, 0x01040202L, 0x01040203L,
207 0x08000000L,0x08000001L,0x08040000L,0x08040001L, 209 0x08000000L, 0x08000001L, 0x08040000L, 0x08040001L,
208 0x09000000L,0x09000001L,0x09040000L,0x09040001L, 210 0x09000000L, 0x09000001L, 0x09040000L, 0x09040001L,
209 0x08000002L,0x08000003L,0x08040002L,0x08040003L, 211 0x08000002L, 0x08000003L, 0x08040002L, 0x08040003L,
210 0x09000002L,0x09000003L,0x09040002L,0x09040003L, 212 0x09000002L, 0x09000003L, 0x09040002L, 0x09040003L,
211 0x08000200L,0x08000201L,0x08040200L,0x08040201L, 213 0x08000200L, 0x08000201L, 0x08040200L, 0x08040201L,
212 0x09000200L,0x09000201L,0x09040200L,0x09040201L, 214 0x09000200L, 0x09000201L, 0x09040200L, 0x09040201L,
213 0x08000202L,0x08000203L,0x08040202L,0x08040203L, 215 0x08000202L, 0x08000203L, 0x08040202L, 0x08040203L,
214 0x09000202L,0x09000203L,0x09040202L,0x09040203L, 216 0x09000202L, 0x09000203L, 0x09040202L, 0x09040203L,
215 },{ 217 }, {
216 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */ 218 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
217 0x00000000L,0x00100000L,0x00000100L,0x00100100L, 219 0x00000000L, 0x00100000L, 0x00000100L, 0x00100100L,
218 0x00000008L,0x00100008L,0x00000108L,0x00100108L, 220 0x00000008L, 0x00100008L, 0x00000108L, 0x00100108L,
219 0x00001000L,0x00101000L,0x00001100L,0x00101100L, 221 0x00001000L, 0x00101000L, 0x00001100L, 0x00101100L,
220 0x00001008L,0x00101008L,0x00001108L,0x00101108L, 222 0x00001008L, 0x00101008L, 0x00001108L, 0x00101108L,
221 0x04000000L,0x04100000L,0x04000100L,0x04100100L, 223 0x04000000L, 0x04100000L, 0x04000100L, 0x04100100L,
222 0x04000008L,0x04100008L,0x04000108L,0x04100108L, 224 0x04000008L, 0x04100008L, 0x04000108L, 0x04100108L,
223 0x04001000L,0x04101000L,0x04001100L,0x04101100L, 225 0x04001000L, 0x04101000L, 0x04001100L, 0x04101100L,
224 0x04001008L,0x04101008L,0x04001108L,0x04101108L, 226 0x04001008L, 0x04101008L, 0x04001108L, 0x04101108L,
225 0x00020000L,0x00120000L,0x00020100L,0x00120100L, 227 0x00020000L, 0x00120000L, 0x00020100L, 0x00120100L,
226 0x00020008L,0x00120008L,0x00020108L,0x00120108L, 228 0x00020008L, 0x00120008L, 0x00020108L, 0x00120108L,
227 0x00021000L,0x00121000L,0x00021100L,0x00121100L, 229 0x00021000L, 0x00121000L, 0x00021100L, 0x00121100L,
228 0x00021008L,0x00121008L,0x00021108L,0x00121108L, 230 0x00021008L, 0x00121008L, 0x00021108L, 0x00121108L,
229 0x04020000L,0x04120000L,0x04020100L,0x04120100L, 231 0x04020000L, 0x04120000L, 0x04020100L, 0x04120100L,
230 0x04020008L,0x04120008L,0x04020108L,0x04120108L, 232 0x04020008L, 0x04120008L, 0x04020108L, 0x04120108L,
231 0x04021000L,0x04121000L,0x04021100L,0x04121100L, 233 0x04021000L, 0x04121000L, 0x04021100L, 0x04121100L,
232 0x04021008L,0x04121008L,0x04021108L,0x04121108L, 234 0x04021008L, 0x04121008L, 0x04021108L, 0x04121108L,
233 },{ 235 }, {
234 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ 236 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
235 0x00000000L,0x10000000L,0x00010000L,0x10010000L, 237 0x00000000L, 0x10000000L, 0x00010000L, 0x10010000L,
236 0x00000004L,0x10000004L,0x00010004L,0x10010004L, 238 0x00000004L, 0x10000004L, 0x00010004L, 0x10010004L,
237 0x20000000L,0x30000000L,0x20010000L,0x30010000L, 239 0x20000000L, 0x30000000L, 0x20010000L, 0x30010000L,
238 0x20000004L,0x30000004L,0x20010004L,0x30010004L, 240 0x20000004L, 0x30000004L, 0x20010004L, 0x30010004L,
239 0x00100000L,0x10100000L,0x00110000L,0x10110000L, 241 0x00100000L, 0x10100000L, 0x00110000L, 0x10110000L,
240 0x00100004L,0x10100004L,0x00110004L,0x10110004L, 242 0x00100004L, 0x10100004L, 0x00110004L, 0x10110004L,
241 0x20100000L,0x30100000L,0x20110000L,0x30110000L, 243 0x20100000L, 0x30100000L, 0x20110000L, 0x30110000L,
242 0x20100004L,0x30100004L,0x20110004L,0x30110004L, 244 0x20100004L, 0x30100004L, 0x20110004L, 0x30110004L,
243 0x00001000L,0x10001000L,0x00011000L,0x10011000L, 245 0x00001000L, 0x10001000L, 0x00011000L, 0x10011000L,
244 0x00001004L,0x10001004L,0x00011004L,0x10011004L, 246 0x00001004L, 0x10001004L, 0x00011004L, 0x10011004L,
245 0x20001000L,0x30001000L,0x20011000L,0x30011000L, 247 0x20001000L, 0x30001000L, 0x20011000L, 0x30011000L,
246 0x20001004L,0x30001004L,0x20011004L,0x30011004L, 248 0x20001004L, 0x30001004L, 0x20011004L, 0x30011004L,
247 0x00101000L,0x10101000L,0x00111000L,0x10111000L, 249 0x00101000L, 0x10101000L, 0x00111000L, 0x10111000L,
248 0x00101004L,0x10101004L,0x00111004L,0x10111004L, 250 0x00101004L, 0x10101004L, 0x00111004L, 0x10111004L,
249 0x20101000L,0x30101000L,0x20111000L,0x30111000L, 251 0x20101000L, 0x30101000L, 0x20111000L, 0x30111000L,
250 0x20101004L,0x30101004L,0x20111004L,0x30111004L, 252 0x20101004L, 0x30101004L, 0x20111004L, 0x30111004L,
251 },{ 253 }, {
252 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */ 254 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
253 0x00000000L,0x08000000L,0x00000008L,0x08000008L, 255 0x00000000L, 0x08000000L, 0x00000008L, 0x08000008L,
254 0x00000400L,0x08000400L,0x00000408L,0x08000408L, 256 0x00000400L, 0x08000400L, 0x00000408L, 0x08000408L,
255 0x00020000L,0x08020000L,0x00020008L,0x08020008L, 257 0x00020000L, 0x08020000L, 0x00020008L, 0x08020008L,
256 0x00020400L,0x08020400L,0x00020408L,0x08020408L, 258 0x00020400L, 0x08020400L, 0x00020408L, 0x08020408L,
257 0x00000001L,0x08000001L,0x00000009L,0x08000009L, 259 0x00000001L, 0x08000001L, 0x00000009L, 0x08000009L,
258 0x00000401L,0x08000401L,0x00000409L,0x08000409L, 260 0x00000401L, 0x08000401L, 0x00000409L, 0x08000409L,
259 0x00020001L,0x08020001L,0x00020009L,0x08020009L, 261 0x00020001L, 0x08020001L, 0x00020009L, 0x08020009L,
260 0x00020401L,0x08020401L,0x00020409L,0x08020409L, 262 0x00020401L, 0x08020401L, 0x00020409L, 0x08020409L,
261 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L, 263 0x02000000L, 0x0A000000L, 0x02000008L, 0x0A000008L,
262 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L, 264 0x02000400L, 0x0A000400L, 0x02000408L, 0x0A000408L,
263 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L, 265 0x02020000L, 0x0A020000L, 0x02020008L, 0x0A020008L,
264 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L, 266 0x02020400L, 0x0A020400L, 0x02020408L, 0x0A020408L,
265 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L, 267 0x02000001L, 0x0A000001L, 0x02000009L, 0x0A000009L,
266 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L, 268 0x02000401L, 0x0A000401L, 0x02000409L, 0x0A000409L,
267 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L, 269 0x02020001L, 0x0A020001L, 0x02020009L, 0x0A020009L,
268 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L, 270 0x02020401L, 0x0A020401L, 0x02020409L, 0x0A020409L,
269 },{ 271 }, {
270 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */ 272 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
271 0x00000000L,0x00000100L,0x00080000L,0x00080100L, 273 0x00000000L, 0x00000100L, 0x00080000L, 0x00080100L,
272 0x01000000L,0x01000100L,0x01080000L,0x01080100L, 274 0x01000000L, 0x01000100L, 0x01080000L, 0x01080100L,
273 0x00000010L,0x00000110L,0x00080010L,0x00080110L, 275 0x00000010L, 0x00000110L, 0x00080010L, 0x00080110L,
274 0x01000010L,0x01000110L,0x01080010L,0x01080110L, 276 0x01000010L, 0x01000110L, 0x01080010L, 0x01080110L,
275 0x00200000L,0x00200100L,0x00280000L,0x00280100L, 277 0x00200000L, 0x00200100L, 0x00280000L, 0x00280100L,
276 0x01200000L,0x01200100L,0x01280000L,0x01280100L, 278 0x01200000L, 0x01200100L, 0x01280000L, 0x01280100L,
277 0x00200010L,0x00200110L,0x00280010L,0x00280110L, 279 0x00200010L, 0x00200110L, 0x00280010L, 0x00280110L,
278 0x01200010L,0x01200110L,0x01280010L,0x01280110L, 280 0x01200010L, 0x01200110L, 0x01280010L, 0x01280110L,
279 0x00000200L,0x00000300L,0x00080200L,0x00080300L, 281 0x00000200L, 0x00000300L, 0x00080200L, 0x00080300L,
280 0x01000200L,0x01000300L,0x01080200L,0x01080300L, 282 0x01000200L, 0x01000300L, 0x01080200L, 0x01080300L,
281 0x00000210L,0x00000310L,0x00080210L,0x00080310L, 283 0x00000210L, 0x00000310L, 0x00080210L, 0x00080310L,
282 0x01000210L,0x01000310L,0x01080210L,0x01080310L, 284 0x01000210L, 0x01000310L, 0x01080210L, 0x01080310L,
283 0x00200200L,0x00200300L,0x00280200L,0x00280300L, 285 0x00200200L, 0x00200300L, 0x00280200L, 0x00280300L,
284 0x01200200L,0x01200300L,0x01280200L,0x01280300L, 286 0x01200200L, 0x01200300L, 0x01280200L, 0x01280300L,
285 0x00200210L,0x00200310L,0x00280210L,0x00280310L, 287 0x00200210L, 0x00200310L, 0x00280210L, 0x00280310L,
286 0x01200210L,0x01200310L,0x01280210L,0x01280310L, 288 0x01200210L, 0x01200310L, 0x01280210L, 0x01280310L,
287 },{ 289 }, {
288 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */ 290 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
289 0x00000000L,0x04000000L,0x00040000L,0x04040000L, 291 0x00000000L, 0x04000000L, 0x00040000L, 0x04040000L,
290 0x00000002L,0x04000002L,0x00040002L,0x04040002L, 292 0x00000002L, 0x04000002L, 0x00040002L, 0x04040002L,
291 0x00002000L,0x04002000L,0x00042000L,0x04042000L, 293 0x00002000L, 0x04002000L, 0x00042000L, 0x04042000L,
292 0x00002002L,0x04002002L,0x00042002L,0x04042002L, 294 0x00002002L, 0x04002002L, 0x00042002L, 0x04042002L,
293 0x00000020L,0x04000020L,0x00040020L,0x04040020L, 295 0x00000020L, 0x04000020L, 0x00040020L, 0x04040020L,
294 0x00000022L,0x04000022L,0x00040022L,0x04040022L, 296 0x00000022L, 0x04000022L, 0x00040022L, 0x04040022L,
295 0x00002020L,0x04002020L,0x00042020L,0x04042020L, 297 0x00002020L, 0x04002020L, 0x00042020L, 0x04042020L,
296 0x00002022L,0x04002022L,0x00042022L,0x04042022L, 298 0x00002022L, 0x04002022L, 0x00042022L, 0x04042022L,
297 0x00000800L,0x04000800L,0x00040800L,0x04040800L, 299 0x00000800L, 0x04000800L, 0x00040800L, 0x04040800L,
298 0x00000802L,0x04000802L,0x00040802L,0x04040802L, 300 0x00000802L, 0x04000802L, 0x00040802L, 0x04040802L,
299 0x00002800L,0x04002800L,0x00042800L,0x04042800L, 301 0x00002800L, 0x04002800L, 0x00042800L, 0x04042800L,
300 0x00002802L,0x04002802L,0x00042802L,0x04042802L, 302 0x00002802L, 0x04002802L, 0x00042802L, 0x04042802L,
301 0x00000820L,0x04000820L,0x00040820L,0x04040820L, 303 0x00000820L, 0x04000820L, 0x00040820L, 0x04040820L,
302 0x00000822L,0x04000822L,0x00040822L,0x04040822L, 304 0x00000822L, 0x04000822L, 0x00040822L, 0x04040822L,
303 0x00002820L,0x04002820L,0x00042820L,0x04042820L, 305 0x00002820L, 0x04002820L, 0x00042820L, 0x04042820L,
304 0x00002822L,0x04002822L,0x00042822L,0x04042822L, 306 0x00002822L, 0x04002822L, 0x00042822L, 0x04042822L,
305 }}; 307 }};
306 308
307int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule) 309int
308 { 310DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
309 if (DES_check_key) 311{
310 { 312 if (DES_check_key) {
311 return DES_set_key_checked(key, schedule); 313 return DES_set_key_checked(key, schedule);
312 } 314 } else {
313 else
314 {
315 DES_set_key_unchecked(key, schedule); 315 DES_set_key_unchecked(key, schedule);
316 return 0; 316 return 0;
317 }
318 } 317 }
318}
319 319
320/* return 0 if key parity is odd (correct), 320/* return 0 if key parity is odd (correct),
321 * return -1 if key parity error, 321 * return -1 if key parity error,
322 * return -2 if illegal weak key. 322 * return -2 if illegal weak key.
323 */ 323 */
324int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule) 324int
325 { 325DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
326{
326 if (!DES_check_key_parity(key)) 327 if (!DES_check_key_parity(key))
327 return(-1); 328 return (-1);
328 if (DES_is_weak_key(key)) 329 if (DES_is_weak_key(key))
329 return(-2); 330 return (-2);
330 DES_set_key_unchecked(key, schedule); 331 DES_set_key_unchecked(key, schedule);
331 return 0; 332 return 0;
332 } 333}
333 334
334void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule) 335void
335 { 336DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
336 static const int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; 337{
337 DES_LONG c,d,t,s,t2; 338 static const int shifts2[16] = {0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
339 DES_LONG c, d, t, s, t2;
338 const unsigned char *in; 340 const unsigned char *in;
339 DES_LONG *k; 341 DES_LONG *k;
340 int i; 342 int i;
@@ -342,55 +344,59 @@ void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
342 k = &schedule->ks->deslong[0]; 344 k = &schedule->ks->deslong[0];
343 in = &(*key)[0]; 345 in = &(*key)[0];
344 346
345 c2l(in,c); 347 c2l(in, c);
346 c2l(in,d); 348 c2l(in, d);
347 349
348 /* do PC1 in 47 simple operations :-) 350 /* do PC1 in 47 simple operations :-)
349 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov) 351 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
350 * for the inspiration. :-) */ 352 * for the inspiration. :-) */
351 PERM_OP (d,c,t,4,0x0f0f0f0fL); 353 PERM_OP(d, c, t, 4, 0x0f0f0f0fL);
352 HPERM_OP(c,t,-2,0xcccc0000L); 354 HPERM_OP(c, t, -2, 0xcccc0000L);
353 HPERM_OP(d,t,-2,0xcccc0000L); 355 HPERM_OP(d, t, -2, 0xcccc0000L);
354 PERM_OP (d,c,t,1,0x55555555L); 356 PERM_OP(d, c, t, 1, 0x55555555L);
355 PERM_OP (c,d,t,8,0x00ff00ffL); 357 PERM_OP(c, d, t, 8, 0x00ff00ffL);
356 PERM_OP (d,c,t,1,0x55555555L); 358 PERM_OP(d, c, t, 1, 0x55555555L);
357 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) | 359 d = (((d & 0x000000ffL) << 16L) | (d & 0x0000ff00L) |
358 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L)); 360 ((d & 0x00ff0000L) >> 16L)|((c & 0xf0000000L) >> 4L));
359 c&=0x0fffffffL; 361 c &= 0x0fffffffL;
360 362
361 for (i=0; i<ITERATIONS; i++) 363 for (i = 0; i < ITERATIONS; i++)
362 { 364 {
363 if (shifts2[i]) 365 if (shifts2[i]) {
364 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); } 366 c = ((c >> 2L)|(c << 26L));
365 else 367 d = ((d >> 2L)|(d << 26L));
366 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); } 368 } else {
367 c&=0x0fffffffL; 369 c = ((c >> 1L)|(c << 27L));
368 d&=0x0fffffffL; 370 d = ((d >> 1L)|(d << 27L));
371 }
372 c &= 0x0fffffffL;
373 d &= 0x0fffffffL;
369 /* could be a few less shifts but I am to lazy at this 374 /* could be a few less shifts but I am to lazy at this
370 * point in time to investigate */ 375 * point in time to investigate */
371 s= des_skb[0][ (c )&0x3f ]| 376 s = des_skb[0][(c)&0x3f]|
372 des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]| 377 des_skb[1][((c >> 6L) & 0x03)|((c >> 7L) & 0x3c)]|
373 des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]| 378 des_skb[2][((c >> 13L) & 0x0f)|((c >> 14L) & 0x30)]|
374 des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) | 379 des_skb[3][((c >> 20L) & 0x01)|((c >> 21L) & 0x06) |
375 ((c>>22L)&0x38)]; 380 ((c >> 22L) & 0x38)];
376 t= des_skb[4][ (d )&0x3f ]| 381 t = des_skb[4][(d)&0x3f]|
377 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]| 382 des_skb[5][((d >> 7L) & 0x03)|((d >> 8L) & 0x3c)]|
378 des_skb[6][ (d>>15L)&0x3f ]| 383 des_skb[6][(d >> 15L) & 0x3f]|
379 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)]; 384 des_skb[7][((d >> 21L) & 0x0f)|((d >> 22L) & 0x30)];
380 385
381 /* table contained 0213 4657 */ 386 /* table contained 0213 4657 */
382 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL; 387 t2 = ((t << 16L)|(s & 0x0000ffffL)) & 0xffffffffL;
383 *(k++)=ROTATE(t2,30)&0xffffffffL; 388 *(k++) = ROTATE(t2, 30) & 0xffffffffL;
384 389
385 t2=((s>>16L)|(t&0xffff0000L)); 390 t2 = ((s >> 16L)|(t & 0xffff0000L));
386 *(k++)=ROTATE(t2,26)&0xffffffffL; 391 *(k++) = ROTATE(t2, 26) & 0xffffffffL;
387 }
388 } 392 }
393}
389 394
390int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule) 395int
391 { 396DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule)
392 return(DES_set_key(key,schedule)); 397{
393 } 398 return (DES_set_key(key, schedule));
399}
394/* 400/*
395#undef des_fixup_key_parity 401#undef des_fixup_key_parity
396void des_fixup_key_parity(des_cblock *key) 402void des_fixup_key_parity(des_cblock *key)
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h
index 5e717065fb..5e9b6d1e72 100644
--- a/src/lib/libcrypto/des/spr.h
+++ b/src/lib/libcrypto/des/spr.h
@@ -1,25 +1,25 @@
1/* $OpenBSD: spr.h,v 1.6 2016/12/21 15:49:29 jsing Exp $ */ 1/* $OpenBSD: spr.h,v 1.7 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
@@ -58,151 +58,151 @@
58 58
59__BEGIN_HIDDEN_DECLS 59__BEGIN_HIDDEN_DECLS
60 60
61const DES_LONG DES_SPtrans[8][64]={ 61const DES_LONG DES_SPtrans[8][64] = {
62{ 62 {
63/* nibble 0 */ 63/* nibble 0 */
640x02080800L, 0x00080000L, 0x02000002L, 0x02080802L, 64 0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
650x02000000L, 0x00080802L, 0x00080002L, 0x02000002L, 65 0x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
660x00080802L, 0x02080800L, 0x02080000L, 0x00000802L, 66 0x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
670x02000802L, 0x02000000L, 0x00000000L, 0x00080002L, 67 0x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
680x00080000L, 0x00000002L, 0x02000800L, 0x00080800L, 68 0x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
690x02080802L, 0x02080000L, 0x00000802L, 0x02000800L, 69 0x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
700x00000002L, 0x00000800L, 0x00080800L, 0x02080002L, 70 0x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
710x00000800L, 0x02000802L, 0x02080002L, 0x00000000L, 71 0x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
720x00000000L, 0x02080802L, 0x02000800L, 0x00080002L, 72 0x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
730x02080800L, 0x00080000L, 0x00000802L, 0x02000800L, 73 0x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
740x02080002L, 0x00000800L, 0x00080800L, 0x02000002L, 74 0x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
750x00080802L, 0x00000002L, 0x02000002L, 0x02080000L, 75 0x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
760x02080802L, 0x00080800L, 0x02080000L, 0x02000802L, 76 0x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
770x02000000L, 0x00000802L, 0x00080002L, 0x00000000L, 77 0x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
780x00080000L, 0x02000000L, 0x02000802L, 0x02080800L, 78 0x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
790x00000002L, 0x02080002L, 0x00000800L, 0x00080802L, 79 0x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
80},{ 80 }, {
81/* nibble 1 */ 81/* nibble 1 */
820x40108010L, 0x00000000L, 0x00108000L, 0x40100000L, 82 0x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
830x40000010L, 0x00008010L, 0x40008000L, 0x00108000L, 83 0x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
840x00008000L, 0x40100010L, 0x00000010L, 0x40008000L, 84 0x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
850x00100010L, 0x40108000L, 0x40100000L, 0x00000010L, 85 0x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
860x00100000L, 0x40008010L, 0x40100010L, 0x00008000L, 86 0x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
870x00108010L, 0x40000000L, 0x00000000L, 0x00100010L, 87 0x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
880x40008010L, 0x00108010L, 0x40108000L, 0x40000010L, 88 0x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
890x40000000L, 0x00100000L, 0x00008010L, 0x40108010L, 89 0x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
900x00100010L, 0x40108000L, 0x40008000L, 0x00108010L, 90 0x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
910x40108010L, 0x00100010L, 0x40000010L, 0x00000000L, 91 0x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
920x40000000L, 0x00008010L, 0x00100000L, 0x40100010L, 92 0x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
930x00008000L, 0x40000000L, 0x00108010L, 0x40008010L, 93 0x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
940x40108000L, 0x00008000L, 0x00000000L, 0x40000010L, 94 0x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
950x00000010L, 0x40108010L, 0x00108000L, 0x40100000L, 95 0x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
960x40100010L, 0x00100000L, 0x00008010L, 0x40008000L, 96 0x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
970x40008010L, 0x00000010L, 0x40100000L, 0x00108000L, 97 0x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
98},{ 98 }, {
99/* nibble 2 */ 99/* nibble 2 */
1000x04000001L, 0x04040100L, 0x00000100L, 0x04000101L, 100 0x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
1010x00040001L, 0x04000000L, 0x04000101L, 0x00040100L, 101 0x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
1020x04000100L, 0x00040000L, 0x04040000L, 0x00000001L, 102 0x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
1030x04040101L, 0x00000101L, 0x00000001L, 0x04040001L, 103 0x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
1040x00000000L, 0x00040001L, 0x04040100L, 0x00000100L, 104 0x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
1050x00000101L, 0x04040101L, 0x00040000L, 0x04000001L, 105 0x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
1060x04040001L, 0x04000100L, 0x00040101L, 0x04040000L, 106 0x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
1070x00040100L, 0x00000000L, 0x04000000L, 0x00040101L, 107 0x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
1080x04040100L, 0x00000100L, 0x00000001L, 0x00040000L, 108 0x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
1090x00000101L, 0x00040001L, 0x04040000L, 0x04000101L, 109 0x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
1100x00000000L, 0x04040100L, 0x00040100L, 0x04040001L, 110 0x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
1110x00040001L, 0x04000000L, 0x04040101L, 0x00000001L, 111 0x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
1120x00040101L, 0x04000001L, 0x04000000L, 0x04040101L, 112 0x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
1130x00040000L, 0x04000100L, 0x04000101L, 0x00040100L, 113 0x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
1140x04000100L, 0x00000000L, 0x04040001L, 0x00000101L, 114 0x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
1150x04000001L, 0x00040101L, 0x00000100L, 0x04040000L, 115 0x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
116},{ 116 }, {
117/* nibble 3 */ 117/* nibble 3 */
1180x00401008L, 0x10001000L, 0x00000008L, 0x10401008L, 118 0x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
1190x00000000L, 0x10400000L, 0x10001008L, 0x00400008L, 119 0x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
1200x10401000L, 0x10000008L, 0x10000000L, 0x00001008L, 120 0x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
1210x10000008L, 0x00401008L, 0x00400000L, 0x10000000L, 121 0x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
1220x10400008L, 0x00401000L, 0x00001000L, 0x00000008L, 122 0x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
1230x00401000L, 0x10001008L, 0x10400000L, 0x00001000L, 123 0x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
1240x00001008L, 0x00000000L, 0x00400008L, 0x10401000L, 124 0x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
1250x10001000L, 0x10400008L, 0x10401008L, 0x00400000L, 125 0x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
1260x10400008L, 0x00001008L, 0x00400000L, 0x10000008L, 126 0x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
1270x00401000L, 0x10001000L, 0x00000008L, 0x10400000L, 127 0x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
1280x10001008L, 0x00000000L, 0x00001000L, 0x00400008L, 128 0x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
1290x00000000L, 0x10400008L, 0x10401000L, 0x00001000L, 129 0x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
1300x10000000L, 0x10401008L, 0x00401008L, 0x00400000L, 130 0x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
1310x10401008L, 0x00000008L, 0x10001000L, 0x00401008L, 131 0x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
1320x00400008L, 0x00401000L, 0x10400000L, 0x10001008L, 132 0x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
1330x00001008L, 0x10000000L, 0x10000008L, 0x10401000L, 133 0x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
134},{ 134 }, {
135/* nibble 4 */ 135/* nibble 4 */
1360x08000000L, 0x00010000L, 0x00000400L, 0x08010420L, 136 0x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
1370x08010020L, 0x08000400L, 0x00010420L, 0x08010000L, 137 0x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
1380x00010000L, 0x00000020L, 0x08000020L, 0x00010400L, 138 0x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
1390x08000420L, 0x08010020L, 0x08010400L, 0x00000000L, 139 0x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
1400x00010400L, 0x08000000L, 0x00010020L, 0x00000420L, 140 0x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
1410x08000400L, 0x00010420L, 0x00000000L, 0x08000020L, 141 0x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
1420x00000020L, 0x08000420L, 0x08010420L, 0x00010020L, 142 0x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
1430x08010000L, 0x00000400L, 0x00000420L, 0x08010400L, 143 0x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
1440x08010400L, 0x08000420L, 0x00010020L, 0x08010000L, 144 0x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
1450x00010000L, 0x00000020L, 0x08000020L, 0x08000400L, 145 0x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
1460x08000000L, 0x00010400L, 0x08010420L, 0x00000000L, 146 0x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
1470x00010420L, 0x08000000L, 0x00000400L, 0x00010020L, 147 0x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
1480x08000420L, 0x00000400L, 0x00000000L, 0x08010420L, 148 0x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
1490x08010020L, 0x08010400L, 0x00000420L, 0x00010000L, 149 0x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
1500x00010400L, 0x08010020L, 0x08000400L, 0x00000420L, 150 0x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
1510x00000020L, 0x00010420L, 0x08010000L, 0x08000020L, 151 0x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
152},{ 152 }, {
153/* nibble 5 */ 153/* nibble 5 */
1540x80000040L, 0x00200040L, 0x00000000L, 0x80202000L, 154 0x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
1550x00200040L, 0x00002000L, 0x80002040L, 0x00200000L, 155 0x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
1560x00002040L, 0x80202040L, 0x00202000L, 0x80000000L, 156 0x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
1570x80002000L, 0x80000040L, 0x80200000L, 0x00202040L, 157 0x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
1580x00200000L, 0x80002040L, 0x80200040L, 0x00000000L, 158 0x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
1590x00002000L, 0x00000040L, 0x80202000L, 0x80200040L, 159 0x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
1600x80202040L, 0x80200000L, 0x80000000L, 0x00002040L, 160 0x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
1610x00000040L, 0x00202000L, 0x00202040L, 0x80002000L, 161 0x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
1620x00002040L, 0x80000000L, 0x80002000L, 0x00202040L, 162 0x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
1630x80202000L, 0x00200040L, 0x00000000L, 0x80002000L, 163 0x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
1640x80000000L, 0x00002000L, 0x80200040L, 0x00200000L, 164 0x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
1650x00200040L, 0x80202040L, 0x00202000L, 0x00000040L, 165 0x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
1660x80202040L, 0x00202000L, 0x00200000L, 0x80002040L, 166 0x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
1670x80000040L, 0x80200000L, 0x00202040L, 0x00000000L, 167 0x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
1680x00002000L, 0x80000040L, 0x80002040L, 0x80202000L, 168 0x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
1690x80200000L, 0x00002040L, 0x00000040L, 0x80200040L, 169 0x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
170},{ 170 }, {
171/* nibble 6 */ 171/* nibble 6 */
1720x00004000L, 0x00000200L, 0x01000200L, 0x01000004L, 172 0x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
1730x01004204L, 0x00004004L, 0x00004200L, 0x00000000L, 173 0x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
1740x01000000L, 0x01000204L, 0x00000204L, 0x01004000L, 174 0x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
1750x00000004L, 0x01004200L, 0x01004000L, 0x00000204L, 175 0x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
1760x01000204L, 0x00004000L, 0x00004004L, 0x01004204L, 176 0x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
1770x00000000L, 0x01000200L, 0x01000004L, 0x00004200L, 177 0x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
1780x01004004L, 0x00004204L, 0x01004200L, 0x00000004L, 178 0x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
1790x00004204L, 0x01004004L, 0x00000200L, 0x01000000L, 179 0x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
1800x00004204L, 0x01004000L, 0x01004004L, 0x00000204L, 180 0x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
1810x00004000L, 0x00000200L, 0x01000000L, 0x01004004L, 181 0x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
1820x01000204L, 0x00004204L, 0x00004200L, 0x00000000L, 182 0x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
1830x00000200L, 0x01000004L, 0x00000004L, 0x01000200L, 183 0x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
1840x00000000L, 0x01000204L, 0x01000200L, 0x00004200L, 184 0x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
1850x00000204L, 0x00004000L, 0x01004204L, 0x01000000L, 185 0x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
1860x01004200L, 0x00000004L, 0x00004004L, 0x01004204L, 186 0x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
1870x01000004L, 0x01004200L, 0x01004000L, 0x00004004L, 187 0x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
188},{ 188 }, {
189/* nibble 7 */ 189/* nibble 7 */
1900x20800080L, 0x20820000L, 0x00020080L, 0x00000000L, 190 0x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
1910x20020000L, 0x00800080L, 0x20800000L, 0x20820080L, 191 0x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
1920x00000080L, 0x20000000L, 0x00820000L, 0x00020080L, 192 0x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
1930x00820080L, 0x20020080L, 0x20000080L, 0x20800000L, 193 0x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
1940x00020000L, 0x00820080L, 0x00800080L, 0x20020000L, 194 0x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
1950x20820080L, 0x20000080L, 0x00000000L, 0x00820000L, 195 0x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
1960x20000000L, 0x00800000L, 0x20020080L, 0x20800080L, 196 0x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
1970x00800000L, 0x00020000L, 0x20820000L, 0x00000080L, 197 0x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
1980x00800000L, 0x00020000L, 0x20000080L, 0x20820080L, 198 0x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
1990x00020080L, 0x20000000L, 0x00000000L, 0x00820000L, 199 0x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
2000x20800080L, 0x20020080L, 0x20020000L, 0x00800080L, 200 0x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
2010x20820000L, 0x00000080L, 0x00800080L, 0x20020000L, 201 0x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
2020x20820080L, 0x00800000L, 0x20800000L, 0x20000080L, 202 0x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
2030x00820000L, 0x00020080L, 0x20020080L, 0x20800000L, 203 0x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
2040x00000080L, 0x20820000L, 0x00820080L, 0x00000000L, 204 0x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
2050x20000000L, 0x20800080L, 0x00020000L, 0x00820080L, 205 0x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
206}}; 206 }};
207 207
208__END_HIDDEN_DECLS 208__END_HIDDEN_DECLS
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
index 316e803927..c9bd9aad1b 100644
--- a/src/lib/libcrypto/des/str2key.c
+++ b/src/lib/libcrypto/des/str2key.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: str2key.c,v 1.11 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: str2key.c,v 1.12 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
@@ -59,116 +59,112 @@
59#include <openssl/crypto.h> 59#include <openssl/crypto.h>
60#include "des_local.h" 60#include "des_local.h"
61 61
62void DES_string_to_key(const char *str, DES_cblock *key) 62void
63 { 63DES_string_to_key(const char *str, DES_cblock *key)
64{
64 DES_key_schedule ks; 65 DES_key_schedule ks;
65 int i,length; 66 int i, length;
66 unsigned char j; 67 unsigned char j;
67 68
68 memset(key,0,8); 69 memset(key, 0, 8);
69 length=strlen(str); 70 length = strlen(str);
70#ifdef OLD_STR_TO_KEY 71#ifdef OLD_STR_TO_KEY
71 for (i=0; i<length; i++) 72 for (i = 0; i < length; i++)
72 (*key)[i%8]^=(str[i]<<1); 73 (*key)[i % 8] ^= (str[i] << 1);
73#else /* MIT COMPATIBLE */ 74#else /* MIT COMPATIBLE */
74 for (i=0; i<length; i++) 75 for (i = 0; i < length; i++)
75 { 76 {
76 j=str[i]; 77 j = str[i];
77 if ((i%16) < 8) 78 if ((i % 16) < 8)
78 (*key)[i%8]^=(j<<1); 79 (*key)[i % 8] ^= (j << 1);
79 else 80 else {
80 {
81 /* Reverse the bit order 05/05/92 eay */ 81 /* Reverse the bit order 05/05/92 eay */
82 j=((j<<4)&0xf0)|((j>>4)&0x0f); 82 j = ((j << 4) & 0xf0)|((j >> 4) & 0x0f);
83 j=((j<<2)&0xcc)|((j>>2)&0x33); 83 j = ((j << 2) & 0xcc)|((j >> 2) & 0x33);
84 j=((j<<1)&0xaa)|((j>>1)&0x55); 84 j = ((j << 1) & 0xaa)|((j >> 1) & 0x55);
85 (*key)[7-(i%8)]^=j; 85 (*key)[7 - (i % 8)] ^= j;
86 }
87 } 86 }
87 }
88#endif 88#endif
89 DES_set_odd_parity(key); 89 DES_set_odd_parity(key);
90#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY 90#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
91 if(DES_is_weak_key(key)) 91 if (DES_is_weak_key(key))
92 (*key)[7] ^= 0xF0; 92 (*key)[7] ^= 0xF0;
93 DES_set_key(key,&ks); 93 DES_set_key(key, &ks);
94#else 94#else
95 DES_set_key_unchecked(key,&ks); 95 DES_set_key_unchecked(key, &ks);
96#endif 96#endif
97 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key); 97 DES_cbc_cksum((const unsigned char *)str, key, length, &ks, key);
98 explicit_bzero(&ks,sizeof(ks)); 98 explicit_bzero(&ks, sizeof(ks));
99 DES_set_odd_parity(key); 99 DES_set_odd_parity(key);
100 } 100}
101 101
102void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2) 102void
103 { 103DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
104{
104 DES_key_schedule ks; 105 DES_key_schedule ks;
105 int i,length; 106 int i, length;
106 unsigned char j; 107 unsigned char j;
107 108
108 memset(key1,0,8); 109 memset(key1, 0, 8);
109 memset(key2,0,8); 110 memset(key2, 0, 8);
110 length=strlen(str); 111 length = strlen(str);
111#ifdef OLD_STR_TO_KEY 112#ifdef OLD_STR_TO_KEY
112 if (length <= 8) 113 if (length <= 8) {
114 for (i = 0; i < length; i++)
113 { 115 {
114 for (i=0; i<length; i++) 116 (*key2)[i] = (*key1)[i] = (str[i] << 1);
115 {
116 (*key2)[i]=(*key1)[i]=(str[i]<<1);
117 }
118 } 117 }
119 else 118 } else {
119 for (i = 0; i < length; i++)
120 { 120 {
121 for (i=0; i<length; i++) 121 if ((i/8) & 1)
122 { 122 (*key2)[i % 8] ^= (str[i] << 1);
123 if ((i/8)&1)
124 (*key2)[i%8]^=(str[i]<<1);
125 else 123 else
126 (*key1)[i%8]^=(str[i]<<1); 124 (*key1)[i % 8] ^= (str[i] << 1);
127 }
128 } 125 }
126 }
129#else /* MIT COMPATIBLE */ 127#else /* MIT COMPATIBLE */
130 for (i=0; i<length; i++) 128 for (i = 0; i < length; i++)
131 { 129 {
132 j=str[i]; 130 j = str[i];
133 if ((i%32) < 16) 131 if ((i % 32) < 16) {
134 { 132 if ((i % 16) < 8)
135 if ((i%16) < 8) 133 (*key1)[i % 8] ^= (j << 1);
136 (*key1)[i%8]^=(j<<1);
137 else 134 else
138 (*key2)[i%8]^=(j<<1); 135 (*key2)[i % 8] ^= (j << 1);
139 } 136 } else {
140 else 137 j = ((j << 4) & 0xf0)|((j >> 4) & 0x0f);
141 { 138 j = ((j << 2) & 0xcc)|((j >> 2) & 0x33);
142 j=((j<<4)&0xf0)|((j>>4)&0x0f); 139 j = ((j << 1) & 0xaa)|((j >> 1) & 0x55);
143 j=((j<<2)&0xcc)|((j>>2)&0x33); 140 if ((i % 16) < 8)
144 j=((j<<1)&0xaa)|((j>>1)&0x55); 141 (*key1)[7 - (i % 8)] ^= j;
145 if ((i%16) < 8)
146 (*key1)[7-(i%8)]^=j;
147 else 142 else
148 (*key2)[7-(i%8)]^=j; 143 (*key2)[7 - (i % 8)] ^= j;
149 }
150 } 144 }
151 if (length <= 8) memcpy(key2,key1,8); 145 }
146 if (length <= 8)
147 memcpy(key2, key1, 8);
152#endif 148#endif
153 DES_set_odd_parity(key1); 149 DES_set_odd_parity(key1);
154 DES_set_odd_parity(key2); 150 DES_set_odd_parity(key2);
155#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY 151#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
156 if(DES_is_weak_key(key1)) 152 if (DES_is_weak_key(key1))
157 (*key1)[7] ^= 0xF0; 153 (*key1)[7] ^= 0xF0;
158 DES_set_key(key1,&ks); 154 DES_set_key(key1, &ks);
159#else 155#else
160 DES_set_key_unchecked(key1,&ks); 156 DES_set_key_unchecked(key1, &ks);
161#endif 157#endif
162 DES_cbc_cksum((const unsigned char*)str,key1,length,&ks,key1); 158 DES_cbc_cksum((const unsigned char *)str, key1, length, &ks, key1);
163#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY 159#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
164 if(DES_is_weak_key(key2)) 160 if (DES_is_weak_key(key2))
165 (*key2)[7] ^= 0xF0; 161 (*key2)[7] ^= 0xF0;
166 DES_set_key(key2,&ks); 162 DES_set_key(key2, &ks);
167#else 163#else
168 DES_set_key_unchecked(key2,&ks); 164 DES_set_key_unchecked(key2, &ks);
169#endif 165#endif
170 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2); 166 DES_cbc_cksum((const unsigned char *)str, key2, length, &ks, key2);
171 explicit_bzero(&ks,sizeof(ks)); 167 explicit_bzero(&ks, sizeof(ks));
172 DES_set_odd_parity(key1); 168 DES_set_odd_parity(key1);
173 DES_set_odd_parity(key2); 169 DES_set_odd_parity(key2);
174 } 170}
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}