summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2022-09-10 17:39:47 +0000
committerjsing <>2022-09-10 17:39:47 +0000
commitbb3c52398649c1e41080621f529dbb1d1cee3afb (patch)
tree80e430face99f2837d3b687cded293385ab116a5
parentb9b7e24dd08d9f1c9b144d42e8f56eacfefeb36b (diff)
downloadopenbsd-bb3c52398649c1e41080621f529dbb1d1cee3afb.tar.gz
openbsd-bb3c52398649c1e41080621f529dbb1d1cee3afb.tar.bz2
openbsd-bb3c52398649c1e41080621f529dbb1d1cee3afb.zip
Use correct length for EVP CFB mode ciphers.
The BLOCK_CIPHER_* macros contained a bug where the total length is passed to the underlying cipher implementation, rather than the length of the current chunk. Correct this and use the chunk length instead. Should address the remaining issues reported by Coverity. ok tb@
-rw-r--r--src/lib/libcrypto/evp/e_bf.c4
-rw-r--r--src/lib/libcrypto/evp/e_camellia.c20
-rw-r--r--src/lib/libcrypto/evp/e_cast.c4
-rw-r--r--src/lib/libcrypto/evp/e_gost2814789.c4
-rw-r--r--src/lib/libcrypto/evp/e_idea.c4
-rw-r--r--src/lib/libcrypto/evp/e_rc2.c4
-rw-r--r--src/lib/libcrypto/evp/e_sm4.c4
7 files changed, 22 insertions, 22 deletions
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c
index 4122f701da..f97f9ed1e4 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.12 2022/09/04 15:45:25 jsing Exp $ */ 1/* $OpenBSD: e_bf.c,v 1.13 2022/09/10 17:39:47 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 *
@@ -114,7 +114,7 @@ bf_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in
114 chunk = inl; 114 chunk = inl;
115 115
116 while (inl && inl >= chunk) { 116 while (inl && inl >= chunk) {
117 BF_cfb64_encrypt(in, out, (long)inl, &((EVP_BF_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 117 BF_cfb64_encrypt(in, out, (long)chunk, &((EVP_BF_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
118 inl -= chunk; 118 inl -= chunk;
119 in += chunk; 119 in += chunk;
120 out += chunk; 120 out += chunk;
diff --git a/src/lib/libcrypto/evp/e_camellia.c b/src/lib/libcrypto/evp/e_camellia.c
index bff323b932..3976baaa48 100644
--- a/src/lib/libcrypto/evp/e_camellia.c
+++ b/src/lib/libcrypto/evp/e_camellia.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_camellia.c,v 1.14 2022/09/06 06:17:11 jsing Exp $ */ 1/* $OpenBSD: e_camellia.c,v 1.15 2022/09/10 17:39:47 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -113,7 +113,7 @@ camellia_128_cfb128_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsign
113 chunk = inl; 113 chunk = inl;
114 114
115 while (inl && inl >= chunk) { 115 while (inl && inl >= chunk) {
116 Camellia_cfb128_encrypt(in, out, inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 116 Camellia_cfb128_encrypt(in, out, chunk, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
117 inl -= chunk; 117 inl -= chunk;
118 in += chunk; 118 in += chunk;
119 out += chunk; 119 out += chunk;
@@ -271,7 +271,7 @@ camellia_192_cfb128_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsign
271 chunk = inl; 271 chunk = inl;
272 272
273 while (inl && inl >= chunk) { 273 while (inl && inl >= chunk) {
274 Camellia_cfb128_encrypt(in, out, inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 274 Camellia_cfb128_encrypt(in, out, chunk, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
275 inl -= chunk; 275 inl -= chunk;
276 in += chunk; 276 in += chunk;
277 out += chunk; 277 out += chunk;
@@ -429,7 +429,7 @@ camellia_256_cfb128_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsign
429 chunk = inl; 429 chunk = inl;
430 430
431 while (inl && inl >= chunk) { 431 while (inl && inl >= chunk) {
432 Camellia_cfb128_encrypt(in, out, inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 432 Camellia_cfb128_encrypt(in, out, chunk, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
433 inl -= chunk; 433 inl -= chunk;
434 in += chunk; 434 in += chunk;
435 out += chunk; 435 out += chunk;
@@ -573,7 +573,7 @@ camellia_128_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned
573 chunk = inl; 573 chunk = inl;
574 574
575 while (inl && inl >= chunk) { 575 while (inl && inl >= chunk) {
576 Camellia_cfb1_encrypt(in, out, ((1 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 576 Camellia_cfb1_encrypt(in, out, ((1 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? chunk * 8 : chunk), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
577 inl -= chunk; 577 inl -= chunk;
578 in += chunk; 578 in += chunk;
579 out += chunk; 579 out += chunk;
@@ -617,7 +617,7 @@ camellia_192_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned
617 chunk = inl; 617 chunk = inl;
618 618
619 while (inl && inl >= chunk) { 619 while (inl && inl >= chunk) {
620 Camellia_cfb1_encrypt(in, out, ((1 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 620 Camellia_cfb1_encrypt(in, out, ((1 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? chunk * 8 : chunk), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
621 inl -= chunk; 621 inl -= chunk;
622 in += chunk; 622 in += chunk;
623 out += chunk; 623 out += chunk;
@@ -661,7 +661,7 @@ camellia_256_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned
661 chunk = inl; 661 chunk = inl;
662 662
663 while (inl && inl >= chunk) { 663 while (inl && inl >= chunk) {
664 Camellia_cfb1_encrypt(in, out, ((1 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 664 Camellia_cfb1_encrypt(in, out, ((1 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? chunk * 8 : chunk), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
665 inl -= chunk; 665 inl -= chunk;
666 in += chunk; 666 in += chunk;
667 out += chunk; 667 out += chunk;
@@ -704,7 +704,7 @@ camellia_128_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned
704 chunk = inl; 704 chunk = inl;
705 705
706 while (inl && inl >= chunk) { 706 while (inl && inl >= chunk) {
707 Camellia_cfb8_encrypt(in, out, inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 707 Camellia_cfb8_encrypt(in, out, chunk, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
708 inl -= chunk; 708 inl -= chunk;
709 in += chunk; 709 in += chunk;
710 out += chunk; 710 out += chunk;
@@ -746,7 +746,7 @@ camellia_192_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned
746 chunk = inl; 746 chunk = inl;
747 747
748 while (inl && inl >= chunk) { 748 while (inl && inl >= chunk) {
749 Camellia_cfb8_encrypt(in, out, inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 749 Camellia_cfb8_encrypt(in, out, chunk, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
750 inl -= chunk; 750 inl -= chunk;
751 in += chunk; 751 in += chunk;
752 out += chunk; 752 out += chunk;
@@ -788,7 +788,7 @@ camellia_256_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned
788 chunk = inl; 788 chunk = inl;
789 789
790 while (inl && inl >= chunk) { 790 while (inl && inl >= chunk) {
791 Camellia_cfb8_encrypt(in, out, inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 791 Camellia_cfb8_encrypt(in, out, chunk, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
792 inl -= chunk; 792 inl -= chunk;
793 in += chunk; 793 in += chunk;
794 out += chunk; 794 out += chunk;
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c
index e654962c75..f5654d9f3e 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.11 2022/09/04 15:45:25 jsing Exp $ */ 1/* $OpenBSD: e_cast.c,v 1.12 2022/09/10 17:39:47 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 *
@@ -114,7 +114,7 @@ cast5_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char
114 chunk = inl; 114 chunk = inl;
115 115
116 while (inl && inl >= chunk) { 116 while (inl && inl >= chunk) {
117 CAST_cfb64_encrypt(in, out, (long)inl, &((EVP_CAST_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 117 CAST_cfb64_encrypt(in, out, (long)chunk, &((EVP_CAST_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
118 inl -= chunk; 118 inl -= chunk;
119 in += chunk; 119 in += chunk;
120 out += chunk; 120 out += chunk;
diff --git a/src/lib/libcrypto/evp/e_gost2814789.c b/src/lib/libcrypto/evp/e_gost2814789.c
index f4b903b913..cff66e8c79 100644
--- a/src/lib/libcrypto/evp/e_gost2814789.c
+++ b/src/lib/libcrypto/evp/e_gost2814789.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_gost2814789.c,v 1.9 2022/09/06 06:17:11 jsing Exp $ */ 1/* $OpenBSD: e_gost2814789.c,v 1.10 2022/09/10 17:39:47 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -213,7 +213,7 @@ gost2814789_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned
213 chunk = inl; 213 chunk = inl;
214 214
215 while (inl && inl >= chunk) { 215 while (inl && inl >= chunk) {
216 Gost2814789_cfb64_encrypt(in, out, inl, &((EVP_GOST2814789_CTX *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 216 Gost2814789_cfb64_encrypt(in, out, chunk, &((EVP_GOST2814789_CTX *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
217 inl -= chunk; 217 inl -= chunk;
218 in += chunk; 218 in += chunk;
219 out += chunk; 219 out += chunk;
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c
index c7f2b30a44..8696fb2450 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.15 2022/09/04 15:45:25 jsing Exp $ */ 1/* $OpenBSD: e_idea.c,v 1.16 2022/09/10 17:39:47 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 *
@@ -172,7 +172,7 @@ idea_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *
172 chunk = inl; 172 chunk = inl;
173 173
174 while (inl && inl >= chunk) { 174 while (inl && inl >= chunk) {
175 idea_cfb64_encrypt(in, out, (long)inl, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 175 idea_cfb64_encrypt(in, out, (long)chunk, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
176 inl -= chunk; 176 inl -= chunk;
177 in += chunk; 177 in += chunk;
178 out += chunk; 178 out += chunk;
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c
index 72e582d5e0..4f92365e7e 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.17 2022/09/04 15:45:25 jsing Exp $ */ 1/* $OpenBSD: e_rc2.c,v 1.18 2022/09/10 17:39:47 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 *
@@ -116,7 +116,7 @@ rc2_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *i
116 chunk = inl; 116 chunk = inl;
117 117
118 while (inl && inl >= chunk) { 118 while (inl && inl >= chunk) {
119 RC2_cfb64_encrypt(in, out, (long)inl, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 119 RC2_cfb64_encrypt(in, out, (long)chunk, &((EVP_RC2_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
120 inl -= chunk; 120 inl -= chunk;
121 in += chunk; 121 in += chunk;
122 out += chunk; 122 out += chunk;
diff --git a/src/lib/libcrypto/evp/e_sm4.c b/src/lib/libcrypto/evp/e_sm4.c
index 4fecae9671..11e9a74d69 100644
--- a/src/lib/libcrypto/evp/e_sm4.c
+++ b/src/lib/libcrypto/evp/e_sm4.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_sm4.c,v 1.5 2022/09/06 06:17:11 jsing Exp $ */ 1/* $OpenBSD: e_sm4.c,v 1.6 2022/09/10 17:39:47 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2017, 2019 Ribose Inc 3 * Copyright (c) 2017, 2019 Ribose Inc
4 * 4 *
@@ -99,7 +99,7 @@ sm4_cfb128_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *
99 chunk = inl; 99 chunk = inl;
100 100
101 while (inl && inl >= chunk) { 101 while (inl && inl >= chunk) {
102 sm4_cfb128_encrypt(in, out, inl, &((EVP_SM4_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); 102 sm4_cfb128_encrypt(in, out, chunk, &((EVP_SM4_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
103 inl -= chunk; 103 inl -= chunk;
104 in += chunk; 104 in += chunk;
105 out += chunk; 105 out += chunk;