diff options
Diffstat (limited to 'src/lib/libcrypto/evp/e_des.c')
| -rw-r--r-- | src/lib/libcrypto/evp/e_des.c | 63 |
1 files changed, 27 insertions, 36 deletions
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, |
