diff options
author | jsing <> | 2022-09-15 07:04:19 +0000 |
---|---|---|
committer | jsing <> | 2022-09-15 07:04:19 +0000 |
commit | eb8c72ebbdf63c499f36d2304eaeea78cc947403 (patch) | |
tree | 1c7afa8ea8df0921bd154e4d6c5a2402edf4beb7 /src/lib/libcrypto/evp/e_rc2.c | |
parent | 1d6e66f8d2d6bdd1973ab33ca3f3b7f7d3a85498 (diff) | |
download | openbsd-eb8c72ebbdf63c499f36d2304eaeea78cc947403.tar.gz openbsd-eb8c72ebbdf63c499f36d2304eaeea78cc947403.tar.bz2 openbsd-eb8c72ebbdf63c499f36d2304eaeea78cc947403.zip |
Use LONG_MAX as the limit for ciphers with long based APIs.
These ciphers have long based APIs, while EVP has a size_t based API. The
intent of these loops is to handle sizes that are bigger than LONG_MAX.
Rather than using the rather crazy EVP_MAXCHUNK construct, use LONG_MAX
rounded down to a large block size, ensuring that it is a block size
multiple. Revert the recently added overflow checks now that this is
handled more appropriately.
ok tb@
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/evp/e_rc2.c | 36 |
1 files changed, 14 insertions, 22 deletions
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) |