Skip to content

Commit

Permalink
Fix mismatch of OpenSSL function signatures that cause errors with gc…
Browse files Browse the repository at this point in the history
…c-14

Building with gcc-14 fails with diagnostics like this:

```
src/tpm2-tss-engine-rsa.c:805:46: error: passing argument 2 of 'EVP_PKEY_meth_set_copy' from incompatible pointer type [-Wincompatible-pointer-types]
  805 |     EVP_PKEY_meth_set_copy(pkey_rsa_methods, rsa_pkey_copy);
      |                                              ^~~~~~~~~~~~~
      |                                              |
      |                                              int (*)(EVP_PKEY_CTX *, EVP_PKEY_CTX *) {aka int (*)(struct evp_pkey_ctx_st *, struct evp_pkey_ctx_st *)}
/usr/include/openssl/evp.h:2005:36: note: expected 'int (*)(EVP_PKEY_CTX *, const EVP_PKEY_CTX *)' {aka 'int (*)(struct evp_pkey_ctx_st *, const struct evp_pkey_ctx_st *)'} but argument is of type 'int (*)(EVP_PKEY_CTX *, EVP_PKEY_CTX *)' {aka 'int (*)(struct evp_pkey_ctx_st *, struct evp_pkey_ctx_st *)'}
```

A look into OpenSSL upstream shows that these functions have always had const
`src` parameters. Thus this error was simply not detected by earlier compiler
versions.

Signed-off-by: Matthias Gerstner <[email protected]>
  • Loading branch information
mgerstner committed Aug 12, 2024
1 parent af8b26e commit b5ac6c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/tpm2-tss-engine-ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ EC_KEY_METHOD *ecc_methods = NULL;
#endif /* OPENSSL_VERSION_NUMBER < 0x10100000 */

#ifdef HAVE_OPENSSL_DIGEST_SIGN
static int (*ecdsa_pkey_orig_copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src);
static int (*ecdsa_pkey_orig_copy)(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src);
static void (*ecdsa_pkey_orig_cleanup)(EVP_PKEY_CTX *ctx);
#endif /* HAVE_OPENSSL_DIGEST_SIGN */

Expand Down Expand Up @@ -405,7 +405,7 @@ ecdsa_ec_key_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,

#ifdef HAVE_OPENSSL_DIGEST_SIGN
static int
ecdsa_pkey_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
ecdsa_pkey_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)
{
if (ecdsa_pkey_orig_copy && !ecdsa_pkey_orig_copy(dst, src))
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/tpm2-tss-engine-rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ RSA_METHOD *rsa_methods = NULL;
#endif /* OPENSSL_VERSION_NUMBER < 0x10100000 */

#ifdef HAVE_OPENSSL_DIGEST_SIGN
static int (*rsa_pkey_orig_copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src);
static int (*rsa_pkey_orig_copy)(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src);
static void (*rsa_pkey_orig_cleanup)(EVP_PKEY_CTX *ctx);
#endif /* HAVE_OPENSSL_DIGEST_SIGN */

Expand Down Expand Up @@ -637,7 +637,7 @@ RSA_METHOD rsa_methods = {

#ifdef HAVE_OPENSSL_DIGEST_SIGN
static int
rsa_pkey_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
rsa_pkey_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)
{
if (rsa_pkey_orig_copy && !rsa_pkey_orig_copy(dst, src))
return 0;
Expand Down

0 comments on commit b5ac6c5

Please sign in to comment.