summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_des3.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/e_des3.c')
-rw-r--r--src/lib/libcrypto/evp/e_des3.c67
1 files changed, 29 insertions, 38 deletions
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c
index 1171a53b74..6a5d03fe99 100644
--- a/src/lib/libcrypto/evp/e_des3.c
+++ b/src/lib/libcrypto/evp/e_des3.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_des3.c,v 1.24 2022/09/04 15:45:25 jsing Exp $ */ 1/* $OpenBSD: e_des3.c,v 1.25 2022/09/15 07:04:19 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -130,9 +130,6 @@ des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
130{ 130{
131 size_t i, bl; 131 size_t i, bl;
132 132
133 if (inl > LONG_MAX)
134 return 0;
135
136 bl = ctx->cipher->block_size; 133 bl = ctx->cipher->block_size;
137 134
138 if (inl < bl) 135 if (inl < bl)
@@ -141,8 +138,9 @@ des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
141 inl -= bl; 138 inl -= bl;
142 139
143 for (i = 0; i <= inl; i += bl) 140 for (i = 0; i <= inl; i += bl)
144 DES_ecb3_encrypt((const_DES_cblock *)(in + i), (DES_cblock *)(out + i), 141 DES_ecb3_encrypt((const_DES_cblock *)(in + i), (DES_cblock *)(out + i),
145 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, ctx->encrypt); 142 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, ctx->encrypt);
143
146 return 1; 144 return 1;
147} 145}
148 146
@@ -150,16 +148,15 @@ static int
150des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 148des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
151 const unsigned char *in, size_t inl) 149 const unsigned char *in, size_t inl)
152{ 150{
153 if (inl > LONG_MAX) 151 size_t chunk = LONG_MAX & ~0xff;
154 return 0;
155 152
156 while (inl >= EVP_MAXCHUNK) { 153 while (inl >= chunk) {
157 DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, 154 DES_ede3_ofb64_encrypt(in, out, (long)chunk,
158 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, 155 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
159 (DES_cblock *)ctx->iv, &ctx->num); 156 (DES_cblock *)ctx->iv, &ctx->num);
160 inl -= EVP_MAXCHUNK; 157 inl -= chunk;
161 in += EVP_MAXCHUNK; 158 in += chunk;
162 out += EVP_MAXCHUNK; 159 out += chunk;
163 } 160 }
164 if (inl) 161 if (inl)
165 DES_ede3_ofb64_encrypt(in, out, (long)inl, 162 DES_ede3_ofb64_encrypt(in, out, (long)inl,
@@ -173,16 +170,15 @@ static int
173des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 170des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
174 const unsigned char *in, size_t inl) 171 const unsigned char *in, size_t inl)
175{ 172{
176 if (inl > LONG_MAX) 173 size_t chunk = LONG_MAX & ~0xff;
177 return 0;
178 174
179 while (inl >= EVP_MAXCHUNK) { 175 while (inl >= chunk) {
180 DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, 176 DES_ede3_cbc_encrypt(in, out, (long)chunk,
181 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, 177 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
182 (DES_cblock *)ctx->iv, ctx->encrypt); 178 (DES_cblock *)ctx->iv, ctx->encrypt);
183 inl -= EVP_MAXCHUNK; 179 inl -= chunk;
184 in += EVP_MAXCHUNK; 180 in += chunk;
185 out += EVP_MAXCHUNK; 181 out += chunk;
186 } 182 }
187 if (inl) 183 if (inl)
188 DES_ede3_cbc_encrypt(in, out, (long)inl, 184 DES_ede3_cbc_encrypt(in, out, (long)inl,
@@ -195,16 +191,15 @@ static int
195des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 191des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
196 const unsigned char *in, size_t inl) 192 const unsigned char *in, size_t inl)
197{ 193{
198 if (inl > LONG_MAX) 194 size_t chunk = LONG_MAX & ~0xff;
199 return 0;
200 195
201 while (inl >= EVP_MAXCHUNK) { 196 while (inl >= chunk) {
202 DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, 197 DES_ede3_cfb64_encrypt(in, out, (long)chunk,
203 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, 198 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
204 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt); 199 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
205 inl -= EVP_MAXCHUNK; 200 inl -= chunk;
206 in += EVP_MAXCHUNK; 201 in += chunk;
207 out += EVP_MAXCHUNK; 202 out += chunk;
208 } 203 }
209 if (inl) 204 if (inl)
210 DES_ede3_cfb64_encrypt(in, out, (long)inl, 205 DES_ede3_cfb64_encrypt(in, out, (long)inl,
@@ -219,11 +214,8 @@ static int
219des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 214des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
220 const unsigned char *in, size_t inl) 215 const unsigned char *in, size_t inl)
221{ 216{
222 size_t n;
223 unsigned char c[1], d[1]; 217 unsigned char c[1], d[1];
224 218 size_t n;
225 if (inl > LONG_MAX)
226 return 0;
227 219
228 if (!(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS)) 220 if (!(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS))
229 inl *= 8; 221 inl *= 8;
@@ -244,16 +236,15 @@ static int
244des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 236des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
245 const unsigned char *in, size_t inl) 237 const unsigned char *in, size_t inl)
246{ 238{
247 if (inl > LONG_MAX) 239 size_t chunk = LONG_MAX & ~0xff;
248 return 0;
249 240
250 while (inl >= EVP_MAXCHUNK) { 241 while (inl >= chunk) {
251 DES_ede3_cfb_encrypt(in, out, 8, (long)EVP_MAXCHUNK, 242 DES_ede3_cfb_encrypt(in, out, 8, (long)chunk,
252 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, 243 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
253 (DES_cblock *)ctx->iv, ctx->encrypt); 244 (DES_cblock *)ctx->iv, ctx->encrypt);
254 inl -= EVP_MAXCHUNK; 245 inl -= chunk;
255 in += EVP_MAXCHUNK; 246 in += chunk;
256 out += EVP_MAXCHUNK; 247 out += chunk;
257 } 248 }
258 if (inl) 249 if (inl)
259 DES_ede3_cfb_encrypt(in, out, 8, (long)inl, 250 DES_ede3_cfb_encrypt(in, out, 8, (long)inl,