diff options
-rw-r--r-- | src/lib/libcrypto/evp/e_bf.c | 40 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_cast.c | 40 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_des.c | 63 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_des3.c | 67 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_idea.c | 43 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_rc2.c | 36 |
6 files changed, 120 insertions, 169 deletions
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c index f97f9ed1e4..4632b523e2 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.13 2022/09/10 17:39:47 jsing Exp $ */ | 1 | /* $OpenBSD: e_bf.c,v 1.14 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 | * |
@@ -86,14 +86,13 @@ bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
86 | static int | 86 | static int |
87 | 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) |
88 | { | 88 | { |
89 | if (inl > LONG_MAX) | 89 | size_t chunk = LONG_MAX & ~0xff; |
90 | return 0; | 90 | |
91 | 91 | while (inl >= chunk) { | |
92 | while (inl >= EVP_MAXCHUNK) { | 92 | BF_cbc_encrypt(in, out, (long)chunk, &((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); | 93 | inl -= chunk; |
94 | inl -= EVP_MAXCHUNK; | 94 | in += chunk; |
95 | in += EVP_MAXCHUNK; | 95 | out += chunk; |
96 | out += EVP_MAXCHUNK; | ||
97 | } | 96 | } |
98 | 97 | ||
99 | if (inl) | 98 | if (inl) |
@@ -105,10 +104,7 @@ bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
105 | static int | 104 | static int |
106 | bf_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 105 | bf_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
107 | { | 106 | { |
108 | size_t chunk = EVP_MAXCHUNK; | 107 | size_t chunk = LONG_MAX & ~0xff; |
109 | |||
110 | if (inl > LONG_MAX) | ||
111 | return 0; | ||
112 | 108 | ||
113 | if (inl < chunk) | 109 | if (inl < chunk) |
114 | chunk = inl; | 110 | chunk = inl; |
@@ -130,9 +126,6 @@ bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
130 | { | 126 | { |
131 | size_t i, bl; | 127 | size_t i, bl; |
132 | 128 | ||
133 | if (inl > LONG_MAX) | ||
134 | return 0; | ||
135 | |||
136 | bl = ctx->cipher->block_size; | 129 | bl = ctx->cipher->block_size; |
137 | 130 | ||
138 | if (inl < bl) | 131 | if (inl < bl) |
@@ -149,14 +142,13 @@ bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
149 | static int | 142 | static int |
150 | bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 143 | bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
151 | { | 144 | { |
152 | if (inl > LONG_MAX) | 145 | size_t chunk = LONG_MAX & ~0xff; |
153 | return 0; | 146 | |
154 | 147 | while (inl >= chunk) { | |
155 | while (inl >= EVP_MAXCHUNK) { | 148 | BF_ofb64_encrypt(in, out, (long)chunk, &((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); | 149 | inl -= chunk; |
157 | inl -= EVP_MAXCHUNK; | 150 | in += chunk; |
158 | in += EVP_MAXCHUNK; | 151 | out += chunk; |
159 | out += EVP_MAXCHUNK; | ||
160 | } | 152 | } |
161 | 153 | ||
162 | if (inl) | 154 | if (inl) |
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c index f5654d9f3e..702c26e0c3 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.12 2022/09/10 17:39:47 jsing Exp $ */ | 1 | /* $OpenBSD: e_cast.c,v 1.13 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 | * |
@@ -86,14 +86,13 @@ cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
86 | static int | 86 | static int |
87 | 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) |
88 | { | 88 | { |
89 | if (inl > LONG_MAX) | 89 | size_t chunk = LONG_MAX & ~0xff; |
90 | return 0; | 90 | |
91 | 91 | while (inl >= chunk) { | |
92 | while (inl >= EVP_MAXCHUNK) { | 92 | CAST_cbc_encrypt(in, out, (long)chunk, &((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); | 93 | inl -= chunk; |
94 | inl -= EVP_MAXCHUNK; | 94 | in += chunk; |
95 | in += EVP_MAXCHUNK; | 95 | out += chunk; |
96 | out += EVP_MAXCHUNK; | ||
97 | } | 96 | } |
98 | 97 | ||
99 | if (inl) | 98 | if (inl) |
@@ -105,10 +104,7 @@ cast5_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *i | |||
105 | static int | 104 | static int |
106 | cast5_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 105 | cast5_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
107 | { | 106 | { |
108 | size_t chunk = EVP_MAXCHUNK; | 107 | size_t chunk = LONG_MAX & ~0xff; |
109 | |||
110 | if (inl > LONG_MAX) | ||
111 | return 0; | ||
112 | 108 | ||
113 | if (inl < chunk) | 109 | if (inl < chunk) |
114 | chunk = inl; | 110 | chunk = inl; |
@@ -130,9 +126,6 @@ cast5_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *i | |||
130 | { | 126 | { |
131 | size_t i, bl; | 127 | size_t i, bl; |
132 | 128 | ||
133 | if (inl > LONG_MAX) | ||
134 | return 0; | ||
135 | |||
136 | bl = ctx->cipher->block_size; | 129 | bl = ctx->cipher->block_size; |
137 | 130 | ||
138 | if (inl < bl) | 131 | if (inl < bl) |
@@ -149,14 +142,13 @@ cast5_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *i | |||
149 | static int | 142 | static int |
150 | cast5_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 143 | cast5_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
151 | { | 144 | { |
152 | if (inl > LONG_MAX) | 145 | size_t chunk = LONG_MAX & ~0xff; |
153 | return 0; | 146 | |
154 | 147 | while (inl >= chunk) { | |
155 | while (inl >= EVP_MAXCHUNK) { | 148 | CAST_ofb64_encrypt(in, out, (long)chunk, &((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); | 149 | inl -= chunk; |
157 | inl -= EVP_MAXCHUNK; | 150 | in += chunk; |
158 | in += EVP_MAXCHUNK; | 151 | out += chunk; |
159 | out += EVP_MAXCHUNK; | ||
160 | } | 152 | } |
161 | 153 | ||
162 | if (inl) | 154 | if (inl) |
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c index 9205128cf4..8fcab72e6b 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.18 2022/09/04 15:45:25 jsing Exp $ */ | 1 | /* $OpenBSD: e_des.c,v 1.19 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 | * |
@@ -99,9 +99,6 @@ des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
99 | { | 99 | { |
100 | size_t i, bl; | 100 | size_t i, bl; |
101 | 101 | ||
102 | if (inl > LONG_MAX) | ||
103 | return 0; | ||
104 | |||
105 | bl = ctx->cipher->block_size; | 102 | bl = ctx->cipher->block_size; |
106 | 103 | ||
107 | if (inl < bl) | 104 | if (inl < bl) |
@@ -120,15 +117,14 @@ static int | |||
120 | des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 117 | des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
121 | const unsigned char *in, size_t inl) | 118 | const unsigned char *in, size_t inl) |
122 | { | 119 | { |
123 | if (inl > LONG_MAX) | 120 | size_t chunk = LONG_MAX & ~0xff; |
124 | return 0; | ||
125 | 121 | ||
126 | while (inl >= EVP_MAXCHUNK) { | 122 | while (inl >= chunk) { |
127 | DES_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data, | 123 | DES_ofb64_encrypt(in, out, (long)chunk, ctx->cipher_data, |
128 | (DES_cblock *)ctx->iv, &ctx->num); | 124 | (DES_cblock *)ctx->iv, &ctx->num); |
129 | inl -= EVP_MAXCHUNK; | 125 | inl -= chunk; |
130 | in += EVP_MAXCHUNK; | 126 | in += chunk; |
131 | out += EVP_MAXCHUNK; | 127 | out += chunk; |
132 | } | 128 | } |
133 | if (inl) | 129 | if (inl) |
134 | DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, | 130 | DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, |
@@ -140,15 +136,14 @@ static int | |||
140 | des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 136 | des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
141 | const unsigned char *in, size_t inl) | 137 | const unsigned char *in, size_t inl) |
142 | { | 138 | { |
143 | if (inl > LONG_MAX) | 139 | size_t chunk = LONG_MAX & ~0xff; |
144 | return 0; | ||
145 | 140 | ||
146 | while (inl >= EVP_MAXCHUNK) { | 141 | while (inl >= chunk) { |
147 | DES_ncbc_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data, | 142 | DES_ncbc_encrypt(in, out, (long)chunk, ctx->cipher_data, |
148 | (DES_cblock *)ctx->iv, ctx->encrypt); | 143 | (DES_cblock *)ctx->iv, ctx->encrypt); |
149 | inl -= EVP_MAXCHUNK; | 144 | inl -= chunk; |
150 | in += EVP_MAXCHUNK; | 145 | in += chunk; |
151 | out += EVP_MAXCHUNK; | 146 | out += chunk; |
152 | } | 147 | } |
153 | if (inl) | 148 | if (inl) |
154 | DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data, | 149 | DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data, |
@@ -160,15 +155,14 @@ static int | |||
160 | des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 155 | des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
161 | const unsigned char *in, size_t inl) | 156 | const unsigned char *in, size_t inl) |
162 | { | 157 | { |
163 | if (inl > LONG_MAX) | 158 | size_t chunk = LONG_MAX & ~0xff; |
164 | return 0; | ||
165 | 159 | ||
166 | while (inl >= EVP_MAXCHUNK) { | 160 | while (inl >= chunk) { |
167 | DES_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, ctx->cipher_data, | 161 | DES_cfb64_encrypt(in, out, (long)chunk, ctx->cipher_data, |
168 | (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt); | 162 | (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt); |
169 | inl -= EVP_MAXCHUNK; | 163 | inl -= chunk; |
170 | in += EVP_MAXCHUNK; | 164 | in += chunk; |
171 | out += EVP_MAXCHUNK; | 165 | out += chunk; |
172 | } | 166 | } |
173 | if (inl) | 167 | if (inl) |
174 | DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data, | 168 | DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data, |
@@ -182,11 +176,9 @@ static int | |||
182 | des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 176 | des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
183 | const unsigned char *in, size_t inl) | 177 | const unsigned char *in, size_t inl) |
184 | { | 178 | { |
185 | size_t n, chunk = EVP_MAXCHUNK/8; | ||
186 | unsigned char c[1], d[1]; | 179 | unsigned char c[1], d[1]; |
187 | 180 | size_t chunk = LONG_MAX / 8; | |
188 | if (inl > LONG_MAX) | 181 | size_t n; |
189 | return 0; | ||
190 | 182 | ||
191 | if (inl < chunk) | 183 | if (inl < chunk) |
192 | chunk = inl; | 184 | chunk = inl; |
@@ -214,15 +206,14 @@ static int | |||
214 | des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 206 | des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
215 | const unsigned char *in, size_t inl) | 207 | const unsigned char *in, size_t inl) |
216 | { | 208 | { |
217 | if (inl > LONG_MAX) | 209 | size_t chunk = LONG_MAX & ~0xff; |
218 | return 0; | ||
219 | 210 | ||
220 | while (inl >= EVP_MAXCHUNK) { | 211 | while (inl >= chunk) { |
221 | DES_cfb_encrypt(in, out, 8, (long)EVP_MAXCHUNK, | 212 | DES_cfb_encrypt(in, out, 8, (long)chunk, |
222 | ctx->cipher_data, (DES_cblock *)ctx->iv, ctx->encrypt); | 213 | ctx->cipher_data, (DES_cblock *)ctx->iv, ctx->encrypt); |
223 | inl -= EVP_MAXCHUNK; | 214 | inl -= chunk; |
224 | in += EVP_MAXCHUNK; | 215 | in += chunk; |
225 | out += EVP_MAXCHUNK; | 216 | out += chunk; |
226 | } | 217 | } |
227 | if (inl) | 218 | if (inl) |
228 | DES_cfb_encrypt(in, out, 8, (long)inl, ctx->cipher_data, | 219 | DES_cfb_encrypt(in, out, 8, (long)inl, ctx->cipher_data, |
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 | |||
150 | des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 148 | des_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 | |||
173 | des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 170 | des_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 | |||
195 | des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 191 | des_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 | |||
219 | des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 214 | des_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 | |||
244 | des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 236 | des_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, |
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c index 8696fb2450..b45ffd5696 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.16 2022/09/10 17:39:47 jsing Exp $ */ | 1 | /* $OpenBSD: e_idea.c,v 1.17 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 | * |
@@ -103,9 +103,6 @@ idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
103 | { | 103 | { |
104 | size_t i, bl; | 104 | size_t i, bl; |
105 | 105 | ||
106 | if (inl > LONG_MAX) | ||
107 | return 0; | ||
108 | |||
109 | bl = ctx->cipher->block_size; | 106 | bl = ctx->cipher->block_size; |
110 | 107 | ||
111 | if (inl < bl) | 108 | if (inl < bl) |
@@ -114,7 +111,8 @@ idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
114 | inl -= bl; | 111 | inl -= bl; |
115 | 112 | ||
116 | for (i = 0; i <= inl; i += bl) | 113 | for (i = 0; i <= inl; i += bl) |
117 | idea_ecb_encrypt(in + i, out + i, ctx->cipher_data); | 114 | idea_ecb_encrypt(in + i, out + i, ctx->cipher_data); |
115 | |||
118 | return 1; | 116 | return 1; |
119 | } | 117 | } |
120 | 118 | ||
@@ -125,14 +123,13 @@ typedef struct { | |||
125 | static int | 123 | static int |
126 | idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 124 | idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
127 | { | 125 | { |
128 | if (inl > LONG_MAX) | 126 | size_t chunk = LONG_MAX & ~0xff; |
129 | return 0; | 127 | |
130 | 128 | while (inl >= chunk) { | |
131 | while (inl >= EVP_MAXCHUNK) { | 129 | idea_cbc_encrypt(in, out, (long)chunk, &((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); | 130 | inl -= chunk; |
133 | inl -= EVP_MAXCHUNK; | 131 | in += chunk; |
134 | in += EVP_MAXCHUNK; | 132 | out += chunk; |
135 | out += EVP_MAXCHUNK; | ||
136 | } | 133 | } |
137 | 134 | ||
138 | if (inl) | 135 | if (inl) |
@@ -144,14 +141,13 @@ idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in | |||
144 | static int | 141 | static int |
145 | idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 142 | idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
146 | { | 143 | { |
147 | if (inl > LONG_MAX) | 144 | size_t chunk = LONG_MAX & ~0xff; |
148 | return 0; | 145 | |
149 | 146 | while (inl >= chunk) { | |
150 | while (inl >= EVP_MAXCHUNK) { | 147 | idea_ofb64_encrypt(in, out, (long)chunk, &((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); | 148 | inl -= chunk; |
152 | inl -= EVP_MAXCHUNK; | 149 | in += chunk; |
153 | in += EVP_MAXCHUNK; | 150 | out += chunk; |
154 | out += EVP_MAXCHUNK; | ||
155 | } | 151 | } |
156 | 152 | ||
157 | if (inl) | 153 | if (inl) |
@@ -163,10 +159,7 @@ idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in | |||
163 | static int | 159 | static int |
164 | idea_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 160 | idea_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
165 | { | 161 | { |
166 | size_t chunk = EVP_MAXCHUNK; | 162 | size_t chunk = LONG_MAX & ~0xff; |
167 | |||
168 | if (inl > LONG_MAX) | ||
169 | return 0; | ||
170 | 163 | ||
171 | if (inl < chunk) | 164 | if (inl < chunk) |
172 | chunk = inl; | 165 | chunk = inl; |
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c index 4f92365e7e..1af17a7c41 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.18 2022/09/10 17:39:47 jsing Exp $ */ | 1 | /* $OpenBSD: e_rc2.c,v 1.19 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 | * |
@@ -88,14 +88,13 @@ typedef struct { | |||
88 | static int | 88 | static int |
89 | 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) |
90 | { | 90 | { |
91 | if (inl > LONG_MAX) | 91 | size_t chunk = LONG_MAX & ~0xff; |
92 | return 0; | ||
93 | 92 | ||
94 | while (inl >= EVP_MAXCHUNK) { | 93 | while (inl >= chunk) { |
95 | RC2_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); | 94 | RC2_cbc_encrypt(in, out, (long)chunk, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); |
96 | inl -= EVP_MAXCHUNK; | 95 | inl -= chunk; |
97 | in += EVP_MAXCHUNK; | 96 | in += chunk; |
98 | out += EVP_MAXCHUNK; | 97 | out += chunk; |
99 | } | 98 | } |
100 | 99 | ||
101 | if (inl) | 100 | if (inl) |
@@ -107,10 +106,7 @@ rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
107 | static int | 106 | static int |
108 | rc2_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 107 | rc2_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
109 | { | 108 | { |
110 | size_t chunk = EVP_MAXCHUNK; | 109 | size_t chunk = LONG_MAX & ~0xff; |
111 | |||
112 | if (inl > LONG_MAX) | ||
113 | return 0; | ||
114 | 110 | ||
115 | if (inl < chunk) | 111 | if (inl < chunk) |
116 | chunk = inl; | 112 | chunk = inl; |
@@ -132,9 +128,6 @@ rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
132 | { | 128 | { |
133 | size_t i, bl; | 129 | size_t i, bl; |
134 | 130 | ||
135 | if (inl > LONG_MAX) | ||
136 | return 0; | ||
137 | |||
138 | bl = ctx->cipher->block_size; | 131 | bl = ctx->cipher->block_size; |
139 | 132 | ||
140 | if (inl < bl) | 133 | if (inl < bl) |
@@ -151,14 +144,13 @@ rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, | |||
151 | static int | 144 | static int |
152 | rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 145 | rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
153 | { | 146 | { |
154 | if (inl > LONG_MAX) | 147 | size_t chunk = LONG_MAX & ~0xff; |
155 | return 0; | ||
156 | 148 | ||
157 | while (inl >= EVP_MAXCHUNK) { | 149 | while (inl >= chunk) { |
158 | RC2_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); | 150 | RC2_ofb64_encrypt(in, out, (long)chunk, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); |
159 | inl -= EVP_MAXCHUNK; | 151 | inl -= chunk; |
160 | in += EVP_MAXCHUNK; | 152 | in += chunk; |
161 | out += EVP_MAXCHUNK; | 153 | out += chunk; |
162 | } | 154 | } |
163 | 155 | ||
164 | if (inl) | 156 | if (inl) |