summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_idea.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/e_idea.c')
-rw-r--r--src/lib/libcrypto/evp/e_idea.c16
1 files changed, 14 insertions, 2 deletions
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 {
121static int 125static int
122idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) 126idea_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
137static int 144static int
138idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) 145idea_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
174static const EVP_CIPHER idea_cbc = { 186static const EVP_CIPHER idea_cbc = {
175 .nid = NID_idea_cbc, 187 .nid = NID_idea_cbc,
176 .block_size = 8, 188 .block_size = 8,