summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-01-04 09:47:54 +0000
committertb <>2024-01-04 09:47:54 +0000
commit5476a9d1ff0475bb9440b5e67a3837b7ed91fd7c (patch)
treebfe6ee8e2ba60c88926a794b82a3568c4d257a07 /src
parent1c6d12a18927be32f24e3dd8c0cb0d33de676d66 (diff)
downloadopenbsd-5476a9d1ff0475bb9440b5e67a3837b7ed91fd7c.tar.gz
openbsd-5476a9d1ff0475bb9440b5e67a3837b7ed91fd7c.tar.bz2
openbsd-5476a9d1ff0475bb9440b5e67a3837b7ed91fd7c.zip
Improve length checks for oiv and iv
There are two unsigned char arrays of size EVP_MAX_IV_LENGTH to store the IVs of block ciphers. In most modes, only iv is used, but in some modes iv is modified and oiv is used to store the original IV. At the moment nothing enforces that they are of the same length. Therefore make sure the correct one or both are checked before writing to or reading from them. ok miod
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/evp_cipher.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/lib/libcrypto/evp/evp_cipher.c b/src/lib/libcrypto/evp/evp_cipher.c
index c3e2cd45f3..81e3f637f5 100644
--- a/src/lib/libcrypto/evp/evp_cipher.c
+++ b/src/lib/libcrypto/evp/evp_cipher.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_cipher.c,v 1.14 2024/01/03 09:13:32 tb Exp $ */ 1/* $OpenBSD: evp_cipher.c,v 1.15 2024/01/04 09:47:54 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 *
@@ -204,7 +204,8 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *engine,
204 204
205 case EVP_CIPH_CBC_MODE: 205 case EVP_CIPH_CBC_MODE:
206 iv_len = EVP_CIPHER_CTX_iv_length(ctx); 206 iv_len = EVP_CIPHER_CTX_iv_length(ctx);
207 if (iv_len < 0 || iv_len > sizeof(ctx->oiv)) { 207 if (iv_len < 0 || iv_len > sizeof(ctx->oiv) ||
208 iv_len > sizeof(ctx->iv)) {
208 EVPerror(EVP_R_IV_TOO_LARGE); 209 EVPerror(EVP_R_IV_TOO_LARGE);
209 return 0; 210 return 0;
210 } 211 }
@@ -906,7 +907,7 @@ EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type)
906 907
907 if (type != NULL) { 908 if (type != NULL) {
908 l = EVP_CIPHER_CTX_iv_length(ctx); 909 l = EVP_CIPHER_CTX_iv_length(ctx);
909 if (l < 0 || l > sizeof(ctx->iv)) { 910 if (l < 0 || l > sizeof(ctx->oiv) || l > sizeof(ctx->iv)) {
910 EVPerror(EVP_R_IV_TOO_LARGE); 911 EVPerror(EVP_R_IV_TOO_LARGE);
911 return 0; 912 return 0;
912 } 913 }
@@ -939,7 +940,7 @@ EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type)
939 940
940 if (type != NULL) { 941 if (type != NULL) {
941 j = EVP_CIPHER_CTX_iv_length(ctx); 942 j = EVP_CIPHER_CTX_iv_length(ctx);
942 if (j < 0 || j > sizeof(ctx->iv)) { 943 if (j < 0 || j > sizeof(ctx->oiv)) {
943 EVPerror(EVP_R_IV_TOO_LARGE); 944 EVPerror(EVP_R_IV_TOO_LARGE);
944 return 0; 945 return 0;
945 } 946 }