Skip to contentSkip to conversation

crypto: respect ECB argument type from prototype

PATCH In review Antonio Quartulli 3 participants 3 messages Apr 28, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: respect ECB argument type from prototype

From: Antonio Quartulli <[email protected]...>

Crypto backends are implementing the cipher_des_encrypt_ecb() function without fully respecting the type of the argumentis as described in the function prototype.

All ECB arguments (key, input block and output block) are expected to be 8 bytes long, for this reason the prototype specifies the arguments as 3 arrays of 8 bytes in size.

Convert the implementations to also explicitly mention the size of the array they expect to receive in input.

Fixes these warnings:

crypto_openssl.c:866:39: warning: argument 2 of type ‘unsigned char *’ declared as a pointer [-Warray-parameter=]

  866 |                        unsigned char *src,
      |                        ~~~~~~~~~~~~~~~^~~
In file included from crypto.h:125,
                 from crypto_openssl.c:42:
crypto_backend.h:202:43: note: previously declared as an array ‘unsigned char[8]’
  202 |                             unsigned char src[DES_KEY_LENGTH],
      |                             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
crypto_openssl.c:867:39: warning: argument 3 of type ‘unsigned char *’ declared as a pointer [-Warray-parameter=]
  867 |                        unsigned char *dst)
      |                        ~~~~~~~~~~~~~~~^~~
In file included from crypto.h:125,
                 from crypto_openssl.c:42:
crypto_backend.h:203:43: note: previously declared as an array ‘unsigned char[8]’
  203 |                             unsigned char dst[DES_KEY_LENGTH]);
      |                             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
---
 src/openvpn/crypto_mbedtls.c | 4 ++--
 src/openvpn/crypto_openssl.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
src/openvpn/crypto_mbedtls.c +2 -2
index f960d0ae..836e80ac 100644
@@ -768,8 +768,8 @@ cipher_ctx_final_check_tag(mbedtls_cipher_context_t *ctx, uint8_t *dst,
 
 void
 cipher_des_encrypt_ecb(const unsigned char key[DES_KEY_LENGTH],
-                       unsigned char *src,
-                       unsigned char *dst)
+                       unsigned char src[DES_KEY_LENGTH],
+                       unsigned char dst[DES_KEY_LENGTH])
 {
     mbedtls_des_context ctx;
 
src/openvpn/crypto_openssl.c +2 -2
index f8b36bf8..af7311ec 100644
@@ -863,8 +863,8 @@ cipher_ctx_final_check_tag(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len,
 
 void
 cipher_des_encrypt_ecb(const unsigned char key[DES_KEY_LENGTH],
-                       unsigned char *src,
-                       unsigned char *dst)
+                       unsigned char src[DES_KEY_LENGTH],
+                       unsigned char dst[DES_KEY_LENGTH])
 {
     DES_key_schedule sched;
 
Signature · 1 line
2.26.3
Acked-by on v1 1/1
#1 lore raw

Am 28.04.21 um 10:10 schrieb Antonio Quartulli:

Quoted 6 lines

From: Antonio Quartulli <[email protected]...>

Crypto backends are implementing the cipher_des_encrypt_ecb() function without fully respecting the type of the argumentis as described in the function prototype.

Quoted 7 lines

All ECB arguments (key, input block and output block) are expected to be 8 bytes long, for this reason the prototype specifies the arguments as 3 arrays of 8 bytes in size.

Convert the implementations to also explicitly mention the size of the array they expect to receive in input.

In case someone wonders. We use *single* DES in ECB mode for NTLM. And this was found by GCC 11.

Arne

#2 lore raw
In reply to Antonio Quartulli

Interesting find from gcc11 :-)

Your patch has been applied to the master branch.

commit 6a3cbb43a3d09dbf0b5df33c741455f34bde2440

Author: Antonio Quartulli
Date:   Wed Apr 28 10:10:54 2021 +0200
     crypto: respect ECB argument type from prototype

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/search?l=mid&[email protected]...
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering