Browse code

crypto_backend: fix type of enc parameter

We had parts of a abstraction, but it wasn't consistent.
GCC 13 now complains about the type mismatch with mbedtls now:

crypto_mbedtls.c:568:1: error:
conflicting types for ‘cipher_ctx_init’ due to enum/integer mismatch;
have ‘void(mbedtls_cipher_context_t *, const uint8_t *, const char *, const mbedtls_operation_t)’
[...] [-Werror=enum-int-mismatch]
crypto_backend.h:341:6: note:
previous declaration of ‘cipher_ctx_init’ with type
‘void(cipher_ctx_t *, const uint8_t *, const char *, int)’ [...]

Previous compiler versions did not complain.

v2:
- clean solution instead of quick solution. Fix the actual API
definition

Change-Id: If0dcdde30879fd6185efb2ad31399c1629c04d22
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Message-Id: <20240327162621.1792414-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28498.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Frank Lichtenheld authored on 2024/03/28 01:26:21
Showing 5 changed files
... ...
@@ -336,10 +336,10 @@ void cipher_ctx_free(cipher_ctx_t *ctx);
336 336
  * @param key           Buffer containing the key to use
337 337
  * @param ciphername    Ciphername of the cipher to use
338 338
  * @param enc           Whether to encrypt or decrypt (either
339
- *                      \c MBEDTLS_OP_ENCRYPT or \c MBEDTLS_OP_DECRYPT).
339
+ *                      \c OPENVPN_OP_ENCRYPT or \c OPENVPN_OP_DECRYPT).
340 340
  */
341 341
 void cipher_ctx_init(cipher_ctx_t *ctx, const uint8_t *key,
342
-                     const char *cipername, int enc);
342
+                     const char *cipername, crypto_operation_t enc);
343 343
 
344 344
 /**
345 345
  * Returns the size of the IV used by the cipher, in bytes, or 0 if no IV is
... ...
@@ -566,7 +566,7 @@ cipher_ctx_free(mbedtls_cipher_context_t *ctx)
566 566
 
567 567
 void
568 568
 cipher_ctx_init(mbedtls_cipher_context_t *ctx, const uint8_t *key,
569
-                const char *ciphername, const mbedtls_operation_t operation)
569
+                const char *ciphername, crypto_operation_t enc)
570 570
 {
571 571
     ASSERT(NULL != ciphername && NULL != ctx);
572 572
     CLEAR(*ctx);
... ...
@@ -580,7 +580,7 @@ cipher_ctx_init(mbedtls_cipher_context_t *ctx, const uint8_t *key,
580 580
         msg(M_FATAL, "mbed TLS cipher context init #1");
581 581
     }
582 582
 
583
-    if (!mbed_ok(mbedtls_cipher_setkey(ctx, key, (int)key_bitlen, operation)))
583
+    if (!mbed_ok(mbedtls_cipher_setkey(ctx, key, (int)key_bitlen, enc)))
584 584
     {
585 585
         msg(M_FATAL, "mbed TLS cipher set key");
586 586
     }
... ...
@@ -63,6 +63,8 @@ typedef void provider_t;
63 63
 /** Cipher is in GCM mode */
64 64
 #define OPENVPN_MODE_GCM        MBEDTLS_MODE_GCM
65 65
 
66
+typedef mbedtls_operation_t crypto_operation_t;
67
+
66 68
 /** Cipher should encrypt */
67 69
 #define OPENVPN_OP_ENCRYPT      MBEDTLS_ENCRYPT
68 70
 
... ...
@@ -840,7 +840,7 @@ cipher_ctx_free(EVP_CIPHER_CTX *ctx)
840 840
 
841 841
 void
842 842
 cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *key,
843
-                const char *ciphername, int enc)
843
+                const char *ciphername, crypto_operation_t enc)
844 844
 {
845 845
     ASSERT(NULL != ciphername && NULL != ctx);
846 846
     evp_cipher_type *kt = cipher_get(ciphername);
... ...
@@ -85,6 +85,8 @@ typedef EVP_MD evp_md_type;
85 85
 /** Cipher is in GCM mode */
86 86
 #define OPENVPN_MODE_GCM        EVP_CIPH_GCM_MODE
87 87
 
88
+typedef int crypto_operation_t;
89
+
88 90
 /** Cipher should encrypt */
89 91
 #define OPENVPN_OP_ENCRYPT      1
90 92