Skip to content

Commit a421e94

Browse files
flichtenheldcron2
authored andcommitted
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 <[email protected]> Acked-by: Arne Schwabe <[email protected]> Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg28498.html Signed-off-by: Gert Doering <[email protected]> (cherry picked from commit 4d907bf)
1 parent b9ad768 commit a421e94

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

src/openvpn/crypto_backend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ void cipher_ctx_free(cipher_ctx_t *ctx);
347347
* @param key Buffer containing the key to use
348348
* @param ciphername Ciphername of the cipher to use
349349
* @param enc Whether to encrypt or decrypt (either
350-
* \c MBEDTLS_OP_ENCRYPT or \c MBEDTLS_OP_DECRYPT).
350+
* \c OPENVPN_OP_ENCRYPT or \c OPENVPN_OP_DECRYPT).
351351
*/
352352
void cipher_ctx_init(cipher_ctx_t *ctx, const uint8_t *key,
353-
const char *cipername, int enc);
353+
const char *cipername, crypto_operation_t enc);
354354

355355
/**
356356
* Returns the size of the IV used by the cipher, in bytes, or 0 if no IV is

src/openvpn/crypto_mbedtls.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ cipher_ctx_free(mbedtls_cipher_context_t *ctx)
566566

567567
void
568568
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)
570570
{
571571
ASSERT(NULL != ciphername && NULL != ctx);
572572
CLEAR(*ctx);
@@ -580,7 +580,7 @@ cipher_ctx_init(mbedtls_cipher_context_t *ctx, const uint8_t *key,
580580
msg(M_FATAL, "mbed TLS cipher context init #1");
581581
}
582582

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)))
584584
{
585585
msg(M_FATAL, "mbed TLS cipher set key");
586586
}

src/openvpn/crypto_mbedtls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ typedef void provider_t;
6363
/** Cipher is in GCM mode */
6464
#define OPENVPN_MODE_GCM MBEDTLS_MODE_GCM
6565

66+
typedef mbedtls_operation_t crypto_operation_t;
67+
6668
/** Cipher should encrypt */
6769
#define OPENVPN_OP_ENCRYPT MBEDTLS_ENCRYPT
6870

src/openvpn/crypto_openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ cipher_ctx_free(EVP_CIPHER_CTX *ctx)
863863

864864
void
865865
cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *key,
866-
const char *ciphername, int enc)
866+
const char *ciphername, crypto_operation_t enc)
867867
{
868868
ASSERT(NULL != ciphername && NULL != ctx);
869869
evp_cipher_type *kt = cipher_get(ciphername);

src/openvpn/crypto_openssl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ typedef EVP_MD evp_md_type;
8585
/** Cipher is in GCM mode */
8686
#define OPENVPN_MODE_GCM EVP_CIPH_GCM_MODE
8787

88+
typedef int crypto_operation_t;
89+
8890
/** Cipher should encrypt */
8991
#define OPENVPN_OP_ENCRYPT 1
9092

0 commit comments

Comments
 (0)