summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des/cfb_enc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/des/cfb_enc.c')
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c192
1 files changed, 96 insertions, 96 deletions
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}