diff options
author | jsing <> | 2022-09-04 15:45:25 +0000 |
---|---|---|
committer | jsing <> | 2022-09-04 15:45:25 +0000 |
commit | 0dba8d0b642d3c82e3cd754e1bf070bf7605f174 (patch) | |
tree | ba2ba0d0fb3b66a11531af5f3a417e903e75a241 /src | |
parent | 0ace47e359750ce9915e94dedcd1129b9d8017fe (diff) | |
download | openbsd-0dba8d0b642d3c82e3cd754e1bf070bf7605f174.tar.gz openbsd-0dba8d0b642d3c82e3cd754e1bf070bf7605f174.tar.bz2 openbsd-0dba8d0b642d3c82e3cd754e1bf070bf7605f174.zip |
Add bounds checks for various EVP cipher implementations.
The EVP cipher API uses size_t, however a number of the underlying
implementations use long in their API. This means that an input with
size > LONG_MAX will go negative.
Found by Coverity, hiding under a large pile of macros.
ok tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/evp/e_bf.c | 15 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_cast.c | 15 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_des.c | 22 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_des3.c | 22 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_idea.c | 16 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_rc2.c | 15 |
6 files changed, 98 insertions, 7 deletions
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c index ab6dc4f7de..4122f701da 100644 --- a/src/lib/libcrypto/evp/e_bf.c +++ b/src/lib/libcrypto/evp/e_bf.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_bf.c,v 1.11 2022/09/04 13:55:39 jsing Exp $ */ | 1 | /* $OpenBSD: e_bf.c,v 1.12 2022/09/04 15:45:25 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 | * |
@@ -56,6 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <limits.h> | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | 61 | ||
61 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
@@ -85,6 +86,9 @@ bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
85 | static int | 86 | static int |
86 | bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 87 | bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
87 | { | 88 | { |
89 | if (inl > LONG_MAX) | ||
90 | return 0; | ||
91 | |||
88 | while (inl >= EVP_MAXCHUNK) { | 92 | while (inl >= EVP_MAXCHUNK) { |
89 | BF_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_BF_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); | 93 | BF_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_BF_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); |
90 | inl -= EVP_MAXCHUNK; | 94 | inl -= EVP_MAXCHUNK; |
@@ -103,6 +107,9 @@ bf_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in | |||
103 | { | 107 | { |
104 | size_t chunk = EVP_MAXCHUNK; | 108 | size_t chunk = EVP_MAXCHUNK; |
105 | 109 | ||
110 | if (inl > LONG_MAX) | ||
111 | return 0; | ||
112 | |||
106 | if (inl < chunk) | 113 | if (inl < chunk) |
107 | chunk = inl; | 114 | chunk = inl; |
108 | 115 | ||
@@ -123,6 +130,9 @@ bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
123 | { | 130 | { |
124 | size_t i, bl; | 131 | size_t i, bl; |
125 | 132 | ||
133 | if (inl > LONG_MAX) | ||
134 | return 0; | ||
135 | |||
126 | bl = ctx->cipher->block_size; | 136 | bl = ctx->cipher->block_size; |
127 | 137 | ||
128 | if (inl < bl) | 138 | if (inl < bl) |
@@ -139,6 +149,9 @@ bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
139 | static int | 149 | static int |
140 | bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 150 | bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
141 | { | 151 | { |
152 | if (inl > LONG_MAX) | ||
153 | return 0; | ||
154 | |||
142 | while (inl >= EVP_MAXCHUNK) { | 155 | while (inl >= EVP_MAXCHUNK) { |
143 | BF_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_BF_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); | 156 | BF_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_BF_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); |
144 | inl -= EVP_MAXCHUNK; | 157 | inl -= EVP_MAXCHUNK; |
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c index d6f1b1d1a0..e654962c75 100644 --- a/src/lib/libcrypto/evp/e_cast.c +++ b/src/lib/libcrypto/evp/e_cast.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_cast.c,v 1.10 2022/09/04 13:55:39 jsing Exp $ */ | 1 | /* $OpenBSD: e_cast.c,v 1.11 2022/09/04 15:45:25 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 | * |
@@ -56,6 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <limits.h> | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | 61 | ||
61 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
@@ -85,6 +86,9 @@ cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
85 | static int | 86 | static int |
86 | cast5_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 87 | cast5_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
87 | { | 88 | { |
89 | if (inl > LONG_MAX) | ||
90 | return 0; | ||
91 | |||
88 | while (inl >= EVP_MAXCHUNK) { | 92 | while (inl >= EVP_MAXCHUNK) { |
89 | CAST_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAST_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); | 93 | CAST_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAST_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); |
90 | inl -= EVP_MAXCHUNK; | 94 | inl -= EVP_MAXCHUNK; |
@@ -103,6 +107,9 @@ cast5_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char | |||
103 | { | 107 | { |
104 | size_t chunk = EVP_MAXCHUNK; | 108 | size_t chunk = EVP_MAXCHUNK; |
105 | 109 | ||
110 | if (inl > LONG_MAX) | ||
111 | return 0; | ||
112 | |||
106 | if (inl < chunk) | 113 | if (inl < chunk) |
107 | chunk = inl; | 114 | chunk = inl; |
108 | 115 | ||
@@ -123,6 +130,9 @@ cast5_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *i | |||
123 | { | 130 | { |
124 | size_t i, bl; | 131 | size_t i, bl; |
125 | 132 | ||
133 | if (inl > LONG_MAX) | ||
134 | return 0; | ||
135 | |||
126 | bl = ctx->cipher->block_size; | 136 | bl = ctx->cipher->block_size; |
127 | 137 | ||
128 | if (inl < bl) | 138 | if (inl < bl) |
@@ -139,6 +149,9 @@ cast5_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *i | |||
139 | static int | 149 | static int |
140 | cast5_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 150 | cast5_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
141 | { | 151 | { |
152 | if (inl > LONG_MAX) | ||
153 | return 0; | ||
154 | |||
142 | while (inl >= EVP_MAXCHUNK) { | 155 | while (inl >= EVP_MAXCHUNK) { |
143 | CAST_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAST_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); | 156 | CAST_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAST_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); |
144 | inl -= EVP_MAXCHUNK; | 157 | inl -= EVP_MAXCHUNK; |
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c index bf037591be..9205128cf4 100644 --- a/src/lib/libcrypto/evp/e_des.c +++ b/src/lib/libcrypto/evp/e_des.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_des.c,v 1.17 2022/09/04 13:17:18 jsing Exp $ */ | 1 | /* $OpenBSD: e_des.c,v 1.18 2022/09/04 15:45:25 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 | * |
@@ -56,6 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <limits.h> | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | 61 | ||
61 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
@@ -98,6 +99,9 @@ des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
98 | { | 99 | { |
99 | size_t i, bl; | 100 | size_t i, bl; |
100 | 101 | ||
102 | if (inl > LONG_MAX) | ||
103 | return 0; | ||
104 | |||
101 | bl = ctx->cipher->block_size; | 105 | bl = ctx->cipher->block_size; |
102 | 106 | ||
103 | if (inl < bl) | 107 | if (inl < bl) |
@@ -108,6 +112,7 @@ des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
108 | for (i = 0; i <= inl; i += bl) | 112 | for (i = 0; i <= inl; i += bl) |
109 | DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), | 113 | DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), |
110 | ctx->cipher_data, ctx->encrypt); | 114 | ctx->cipher_data, ctx->encrypt); |
115 | |||
111 | return 1; | 116 | return 1; |
112 | } | 117 | } |
113 | 118 | ||
@@ -115,6 +120,9 @@ static int | |||
115 | des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 120 | des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
116 | const unsigned char *in, size_t inl) | 121 | const unsigned char *in, size_t inl) |
117 | { | 122 | { |
123 | if (inl > LONG_MAX) | ||
124 | return 0; | ||
125 | |||
118 | while (inl >= EVP_MAXCHUNK) { | 126 | while (inl >= EVP_MAXCHUNK) { |
119 | DES_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data, | 127 | DES_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data, |
120 | (DES_cblock *)ctx->iv, &ctx->num); | 128 | (DES_cblock *)ctx->iv, &ctx->num); |
@@ -132,6 +140,9 @@ static int | |||
132 | des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 140 | des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
133 | const unsigned char *in, size_t inl) | 141 | const unsigned char *in, size_t inl) |
134 | { | 142 | { |
143 | if (inl > LONG_MAX) | ||
144 | return 0; | ||
145 | |||
135 | while (inl >= EVP_MAXCHUNK) { | 146 | while (inl >= EVP_MAXCHUNK) { |
136 | DES_ncbc_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data, | 147 | DES_ncbc_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data, |
137 | (DES_cblock *)ctx->iv, ctx->encrypt); | 148 | (DES_cblock *)ctx->iv, ctx->encrypt); |
@@ -149,6 +160,9 @@ static int | |||
149 | des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 160 | des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
150 | const unsigned char *in, size_t inl) | 161 | const unsigned char *in, size_t inl) |
151 | { | 162 | { |
163 | if (inl > LONG_MAX) | ||
164 | return 0; | ||
165 | |||
152 | while (inl >= EVP_MAXCHUNK) { | 166 | while (inl >= EVP_MAXCHUNK) { |
153 | DES_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data, | 167 | DES_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data, |
154 | (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt); | 168 | (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt); |
@@ -171,6 +185,9 @@ des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
171 | size_t n, chunk = EVP_MAXCHUNK/8; | 185 | size_t n, chunk = EVP_MAXCHUNK/8; |
172 | unsigned char c[1], d[1]; | 186 | unsigned char c[1], d[1]; |
173 | 187 | ||
188 | if (inl > LONG_MAX) | ||
189 | return 0; | ||
190 | |||
174 | if (inl < chunk) | 191 | if (inl < chunk) |
175 | chunk = inl; | 192 | chunk = inl; |
176 | 193 | ||
@@ -197,6 +214,9 @@ static int | |||
197 | des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 214 | des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
198 | const unsigned char *in, size_t inl) | 215 | const unsigned char *in, size_t inl) |
199 | { | 216 | { |
217 | if (inl > LONG_MAX) | ||
218 | return 0; | ||
219 | |||
200 | while (inl >= EVP_MAXCHUNK) { | 220 | while (inl >= EVP_MAXCHUNK) { |
201 | DES_cfb_encrypt(in, out, 8, (long)EVP_MAXCHUNK, | 221 | DES_cfb_encrypt(in, out, 8, (long)EVP_MAXCHUNK, |
202 | ctx->cipher_data, (DES_cblock *)ctx->iv, ctx->encrypt); | 222 | ctx->cipher_data, (DES_cblock *)ctx->iv, ctx->encrypt); |
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c index e9d7f56809..1171a53b74 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.23 2022/09/04 13:17:18 jsing Exp $ */ | 1 | /* $OpenBSD: e_des3.c,v 1.24 2022/09/04 15:45:25 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 | * |
@@ -56,6 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <limits.h> | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
@@ -129,6 +130,9 @@ des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
129 | { | 130 | { |
130 | size_t i, bl; | 131 | size_t i, bl; |
131 | 132 | ||
133 | if (inl > LONG_MAX) | ||
134 | return 0; | ||
135 | |||
132 | bl = ctx->cipher->block_size; | 136 | bl = ctx->cipher->block_size; |
133 | 137 | ||
134 | if (inl < bl) | 138 | if (inl < bl) |
@@ -146,6 +150,9 @@ static int | |||
146 | des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 150 | des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
147 | const unsigned char *in, size_t inl) | 151 | const unsigned char *in, size_t inl) |
148 | { | 152 | { |
153 | if (inl > LONG_MAX) | ||
154 | return 0; | ||
155 | |||
149 | while (inl >= EVP_MAXCHUNK) { | 156 | while (inl >= EVP_MAXCHUNK) { |
150 | DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, | 157 | DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, |
151 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, | 158 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, |
@@ -166,6 +173,9 @@ static int | |||
166 | des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 173 | des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
167 | const unsigned char *in, size_t inl) | 174 | const unsigned char *in, size_t inl) |
168 | { | 175 | { |
176 | if (inl > LONG_MAX) | ||
177 | return 0; | ||
178 | |||
169 | while (inl >= EVP_MAXCHUNK) { | 179 | while (inl >= EVP_MAXCHUNK) { |
170 | DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, | 180 | DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, |
171 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, | 181 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, |
@@ -185,6 +195,9 @@ static int | |||
185 | des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 195 | des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
186 | const unsigned char *in, size_t inl) | 196 | const unsigned char *in, size_t inl) |
187 | { | 197 | { |
198 | if (inl > LONG_MAX) | ||
199 | return 0; | ||
200 | |||
188 | while (inl >= EVP_MAXCHUNK) { | 201 | while (inl >= EVP_MAXCHUNK) { |
189 | DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, | 202 | DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, |
190 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, | 203 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, |
@@ -208,6 +221,10 @@ des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
208 | { | 221 | { |
209 | size_t n; | 222 | size_t n; |
210 | unsigned char c[1], d[1]; | 223 | unsigned char c[1], d[1]; |
224 | |||
225 | if (inl > LONG_MAX) | ||
226 | return 0; | ||
227 | |||
211 | if (!(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS)) | 228 | if (!(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS)) |
212 | inl *= 8; | 229 | inl *= 8; |
213 | 230 | ||
@@ -227,6 +244,9 @@ static int | |||
227 | des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 244 | des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
228 | const unsigned char *in, size_t inl) | 245 | const unsigned char *in, size_t inl) |
229 | { | 246 | { |
247 | if (inl > LONG_MAX) | ||
248 | return 0; | ||
249 | |||
230 | while (inl >= EVP_MAXCHUNK) { | 250 | while (inl >= EVP_MAXCHUNK) { |
231 | DES_ede3_cfb_encrypt(in, out, 8, (long)EVP_MAXCHUNK, | 251 | DES_ede3_cfb_encrypt(in, out, 8, (long)EVP_MAXCHUNK, |
232 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, | 252 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, |
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c index c25f031871..c7f2b30a44 100644 --- a/src/lib/libcrypto/evp/e_idea.c +++ b/src/lib/libcrypto/evp/e_idea.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_idea.c,v 1.14 2022/09/04 13:55:39 jsing Exp $ */ | 1 | /* $OpenBSD: e_idea.c,v 1.15 2022/09/04 15:45:25 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 | * |
@@ -56,6 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <limits.h> | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
@@ -102,6 +103,9 @@ idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
102 | { | 103 | { |
103 | size_t i, bl; | 104 | size_t i, bl; |
104 | 105 | ||
106 | if (inl > LONG_MAX) | ||
107 | return 0; | ||
108 | |||
105 | bl = ctx->cipher->block_size; | 109 | bl = ctx->cipher->block_size; |
106 | 110 | ||
107 | if (inl < bl) | 111 | if (inl < bl) |
@@ -121,6 +125,9 @@ typedef struct { | |||
121 | static int | 125 | static int |
122 | idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 126 | idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
123 | { | 127 | { |
128 | if (inl > LONG_MAX) | ||
129 | return 0; | ||
130 | |||
124 | while (inl >= EVP_MAXCHUNK) { | 131 | while (inl >= EVP_MAXCHUNK) { |
125 | idea_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); | 132 | idea_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); |
126 | inl -= EVP_MAXCHUNK; | 133 | inl -= EVP_MAXCHUNK; |
@@ -137,6 +144,9 @@ idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in | |||
137 | static int | 144 | static int |
138 | idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 145 | idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
139 | { | 146 | { |
147 | if (inl > LONG_MAX) | ||
148 | return 0; | ||
149 | |||
140 | while (inl >= EVP_MAXCHUNK) { | 150 | while (inl >= EVP_MAXCHUNK) { |
141 | idea_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); | 151 | idea_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); |
142 | inl -= EVP_MAXCHUNK; | 152 | inl -= EVP_MAXCHUNK; |
@@ -155,6 +165,9 @@ idea_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char * | |||
155 | { | 165 | { |
156 | size_t chunk = EVP_MAXCHUNK; | 166 | size_t chunk = EVP_MAXCHUNK; |
157 | 167 | ||
168 | if (inl > LONG_MAX) | ||
169 | return 0; | ||
170 | |||
158 | if (inl < chunk) | 171 | if (inl < chunk) |
159 | chunk = inl; | 172 | chunk = inl; |
160 | 173 | ||
@@ -170,7 +183,6 @@ idea_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char * | |||
170 | return 1; | 183 | return 1; |
171 | } | 184 | } |
172 | 185 | ||
173 | |||
174 | static const EVP_CIPHER idea_cbc = { | 186 | static const EVP_CIPHER idea_cbc = { |
175 | .nid = NID_idea_cbc, | 187 | .nid = NID_idea_cbc, |
176 | .block_size = 8, | 188 | .block_size = 8, |
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c index 6567e75b0c..72e582d5e0 100644 --- a/src/lib/libcrypto/evp/e_rc2.c +++ b/src/lib/libcrypto/evp/e_rc2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_rc2.c,v 1.16 2022/09/04 13:55:39 jsing Exp $ */ | 1 | /* $OpenBSD: e_rc2.c,v 1.17 2022/09/04 15:45:25 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 | * |
@@ -56,6 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <limits.h> | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | 61 | ||
61 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
@@ -87,6 +88,9 @@ typedef struct { | |||
87 | static int | 88 | static int |
88 | rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 89 | rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
89 | { | 90 | { |
91 | if (inl > LONG_MAX) | ||
92 | return 0; | ||
93 | |||
90 | while (inl >= EVP_MAXCHUNK) { | 94 | while (inl >= EVP_MAXCHUNK) { |
91 | RC2_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); | 95 | RC2_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); |
92 | inl -= EVP_MAXCHUNK; | 96 | inl -= EVP_MAXCHUNK; |
@@ -105,6 +109,9 @@ rc2_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *i | |||
105 | { | 109 | { |
106 | size_t chunk = EVP_MAXCHUNK; | 110 | size_t chunk = EVP_MAXCHUNK; |
107 | 111 | ||
112 | if (inl > LONG_MAX) | ||
113 | return 0; | ||
114 | |||
108 | if (inl < chunk) | 115 | if (inl < chunk) |
109 | chunk = inl; | 116 | chunk = inl; |
110 | 117 | ||
@@ -125,6 +132,9 @@ rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
125 | { | 132 | { |
126 | size_t i, bl; | 133 | size_t i, bl; |
127 | 134 | ||
135 | if (inl > LONG_MAX) | ||
136 | return 0; | ||
137 | |||
128 | bl = ctx->cipher->block_size; | 138 | bl = ctx->cipher->block_size; |
129 | 139 | ||
130 | if (inl < bl) | 140 | if (inl < bl) |
@@ -141,6 +151,9 @@ rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
141 | static int | 151 | static int |
142 | rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 152 | rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
143 | { | 153 | { |
154 | if (inl > LONG_MAX) | ||
155 | return 0; | ||
156 | |||
144 | while (inl >= EVP_MAXCHUNK) { | 157 | while (inl >= EVP_MAXCHUNK) { |
145 | RC2_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); | 158 | RC2_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); |
146 | inl -= EVP_MAXCHUNK; | 159 | inl -= EVP_MAXCHUNK; |