summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-07-26 19:50:06 +0000
committertb <>2022-07-26 19:50:06 +0000
commit452e0d9e8ea01c3483f30eff266286eb6a5a3c31 (patch)
treebaf4feb67c41f926be93866eea17663749b733db /src
parent7535f3659ad4907402c99ae736e3307129e9502e (diff)
downloadopenbsd-452e0d9e8ea01c3483f30eff266286eb6a5a3c31.tar.gz
openbsd-452e0d9e8ea01c3483f30eff266286eb6a5a3c31.tar.bz2
openbsd-452e0d9e8ea01c3483f30eff266286eb6a5a3c31.zip
Do not pass input length <= 0 to the cipher handlers
Input length < 0 is an error and input length == 0 can result in strange effects in some ciphers, except in CCM mode, which is extra special. Based on OpenSSL 420cb707 by Matt Caswell and Richard Levitte found by & ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index 896b9e1a16..d925ed77d7 100644
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_enc.c,v 1.44 2021/02/18 19:12:29 tb Exp $ */ 1/* $OpenBSD: evp_enc.c,v 1.45 2022/07/26 19:50:06 tb 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 *
@@ -300,6 +300,14 @@ EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
300{ 300{
301 int i, j, bl; 301 int i, j, bl;
302 302
303 *outl = 0;
304
305 if (inl < 0)
306 return 0;
307
308 if (inl == 0 && EVP_CIPHER_mode(ctx->cipher) != EVP_CIPH_CCM_MODE)
309 return 1;
310
303 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { 311 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
304 i = M_do_cipher(ctx, out, in, inl); 312 i = M_do_cipher(ctx, out, in, inl);
305 if (i < 0) 313 if (i < 0)
@@ -309,11 +317,6 @@ EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
309 return 1; 317 return 1;
310 } 318 }
311 319
312 if (inl <= 0) {
313 *outl = 0;
314 return inl == 0;
315 }
316
317 if (ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) { 320 if (ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) {
318 if (M_do_cipher(ctx, out, in, inl)) { 321 if (M_do_cipher(ctx, out, in, inl)) {
319 *outl = inl; 322 *outl = inl;
@@ -438,6 +441,14 @@ EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
438 int fix_len; 441 int fix_len;
439 unsigned int b; 442 unsigned int b;
440 443
444 *outl = 0;
445
446 if (inl < 0)
447 return 0;
448
449 if (inl == 0 && EVP_CIPHER_mode(ctx->cipher) != EVP_CIPH_CCM_MODE)
450 return 1;
451
441 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { 452 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
442 fix_len = M_do_cipher(ctx, out, in, inl); 453 fix_len = M_do_cipher(ctx, out, in, inl);
443 if (fix_len < 0) { 454 if (fix_len < 0) {
@@ -448,11 +459,6 @@ EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
448 return 1; 459 return 1;
449 } 460 }
450 461
451 if (inl <= 0) {
452 *outl = 0;
453 return inl == 0;
454 }
455
456 if (ctx->flags & EVP_CIPH_NO_PADDING) 462 if (ctx->flags & EVP_CIPH_NO_PADDING)
457 return EVP_EncryptUpdate(ctx, out, outl, in, inl); 463 return EVP_EncryptUpdate(ctx, out, outl, in, inl);
458 464