Skip to content

openssl: avoid function pointer typdefs and casts - #1991

Closed
vszakats wants to merge 22 commits into
libssh2:masterfrom
vszakats:func-ptr-cast
Closed

vszakats wants to merge 22 commits into
libssh2:masterfrom
vszakats:func-ptr-cast

Conversation

@vszakats

@vszakats vszakats commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

Drop local worker functions, to avoid passing around function pointers,
with a local typedef that needs to be different (and matching upstream
exactly) dependening on crypto backend/version and key type.

Also:

  • fix ed25519 callback function for non-OpenSSL3.
    (detected by MSVC after dropping casts.)
  • drop local compiler warning silencing.
  • tried to use local macros. It saved 30 lines of code, but I opted for
    the simplicity/clarity of duplicating the BIO calls around each call.

Follow-up to 04ecdb2 #1972
Follow-up to 784446b #1484
Follow-up to b0ab005 #1207
Follow-up to 231a97a


https://github.com/libssh2/libssh2/pull/1991/files?w=1

@vszakats vszakats changed the title openssl: avoid function pointer casts openssl: avoid function pointer typdefs and casts Jun 7, 2026
@vszakats
vszakats marked this pull request as draft June 7, 2026 15:03
vszakats added 10 commits June 7, 2026 17:56
```
/home/runner/work/libssh2/libssh2/src/openssl.c:1193:9: error: cast from 'WOLFSSL_RSA *(*)(WOLFSSL_BIO *, WOLFSSL_RSA **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_RSA *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_RSA **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [clang-diagnostic-cast-function-type-strict,-warnings-as-errors]
 1193 |         (pem_read_bio_func)&PEM_read_bio_RSAPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/openssl.c:1587:9: error: cast from 'WOLFSSL_RSA *(*)(WOLFSSL_BIO *, WOLFSSL_RSA **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_RSA *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_RSA **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [clang-diagnostic-cast-function-type-strict,-warnings-as-errors]
 1587 |         (pem_read_bio_func)&PEM_read_bio_RSAPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/openssl.c:1959:9: error: cast from 'WOLFSSL_EC_KEY *(*)(WOLFSSL_BIO *, WOLFSSL_EC_KEY **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_EC_KEY *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_EC_KEY **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [clang-diagnostic-cast-function-type-strict,-warnings-as-errors]
 1959 |         (pem_read_bio_func)&PEM_read_bio_ECPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/openssl.c:3998:9: error: cast from 'WOLFSSL_EC_KEY *(*)(WOLFSSL_BIO *, WOLFSSL_EC_KEY **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_EC_KEY *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_EC_KEY **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [clang-diagnostic-cast-function-type-strict,-warnings-as-errors]
 3998 |         (pem_read_bio_func)&PEM_read_bio_ECPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/openssl.c:4030:9: error: cast from 'WOLFSSL_EC_KEY *(*)(WOLFSSL_BIO *, WOLFSSL_EC_KEY **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_EC_KEY *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_EC_KEY **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [clang-diagnostic-cast-function-type-strict,-warnings-as-errors]
 4030 |         (pem_read_bio_func)&PEM_read_bio_ECPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42 warnings generated.
```
https://github.com/libssh2/libssh2/actions/runs/26970353164/job/79583680999?pr=1972

```
/home/runner/work/libssh2/libssh2/src/openssl.c:1193:9: error: cast from 'WOLFSSL_RSA *(*)(WOLFSSL_BIO *, WOLFSSL_RSA **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_RSA *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_RSA **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 1193 |         (pem_read_bio_func)&PEM_read_bio_RSAPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/openssl.c:1587:9: error: cast from 'WOLFSSL_RSA *(*)(WOLFSSL_BIO *, WOLFSSL_RSA **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_RSA *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_RSA **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 1587 |         (pem_read_bio_func)&PEM_read_bio_RSAPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/openssl.c:1959:9: error: cast from 'WOLFSSL_EC_KEY *(*)(WOLFSSL_BIO *, WOLFSSL_EC_KEY **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_EC_KEY *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_EC_KEY **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 1959 |         (pem_read_bio_func)&PEM_read_bio_ECPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/openssl.c:3998:9: error: cast from 'WOLFSSL_EC_KEY *(*)(WOLFSSL_BIO *, WOLFSSL_EC_KEY **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_EC_KEY *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_EC_KEY **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 3998 |         (pem_read_bio_func)&PEM_read_bio_ECPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/openssl.c:4030:9: error: cast from 'WOLFSSL_EC_KEY *(*)(WOLFSSL_BIO *, WOLFSSL_EC_KEY **, wc_pem_password_cb *, void *)' (aka 'struct WOLFSSL_EC_KEY *(*)(struct WOLFSSL_BIO *, struct WOLFSSL_EC_KEY **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct WOLFSSL_BIO *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 4030 |         (pem_read_bio_func)&PEM_read_bio_ECPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 errors generated.
```
https://github.com/libssh2/libssh2/actions/runs/26970353164/job/79583680928?pr=1972
```
../../src/openssl.c:1587:9: error: cast from 'RSA *(*)(BIO *, RSA **, pem_password_cb *, void *)' (aka 'struct rsa_st *(*)(struct bio_st *, struct rsa_st **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct bio_st *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 1587 |         (pem_read_bio_func)&PEM_read_bio_RSAPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../src/openssl.c:1959:9: error: cast from 'EC_KEY *(*)(BIO *, EC_KEY **, pem_password_cb *, void *)' (aka 'struct ec_key_st *(*)(struct bio_st *, struct ec_key_st **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct bio_st *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 1959 |         (pem_read_bio_func)&PEM_read_bio_ECPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../src/openssl.c:2575:37: error: cast from 'EVP_PKEY *(*)(BIO *, EVP_PKEY **, pem_password_cb *, void *)' (aka 'struct evp_pkey_st *(*)(struct bio_st *, struct evp_pkey_st **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct bio_st *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 2575 |                                     (pem_read_bio_func)
      |                                     ^~~~~~~~~~~~~~~~~~~
 2576 |                                     &PEM_read_bio_PrivateKey,
      |                                     ~~~~~~~~~~~~~~~~~~~~~~~~
../../src/openssl.c:3998:9: error: cast from 'EC_KEY *(*)(BIO *, EC_KEY **, pem_password_cb *, void *)' (aka 'struct ec_key_st *(*)(struct bio_st *, struct ec_key_st **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct bio_st *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 3998 |         (pem_read_bio_func)&PEM_read_bio_ECPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../src/openssl.c:4030:9: error: cast from 'EC_KEY *(*)(BIO *, EC_KEY **, pem_password_cb *, void *)' (aka 'struct ec_key_st *(*)(struct bio_st *, struct ec_key_st **, int (*)(char *, int, int, void *), void *)') to 'pem_read_bio_func' (aka 'void *(*)(struct bio_st *, void **, int (*)(char *, int, int, void *), void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 4030 |         (pem_read_bio_func)&PEM_read_bio_ECPrivateKey;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 errors generated.
```
https://github.com/libssh2/libssh2/actions/runs/26970353164/job/79583680642?pr=1972
```
src/openssl.c(2506): error C2220: warning treated as error - no 'object' file generated [C:\projects\libssh2\_bld\src\libssh2_shared.vcxproj]
src/openssl.c(2506): warning C4133: '=': incompatible types - from 'EC_KEY *' to 'EVP_PKEY *' [C:\projects\libssh2\_bld\src\libssh2_shared.vcxproj]
src/openssl.c(2506): error C2220: warning treated as error - no 'object' file generated [C:\projects\libssh2\_bld\src\libssh2_static.vcxproj]
src/openssl.c(2506): warning C4133: '=': incompatible types - from 'EC_KEY *' to 'EVP_PKEY *' [C:\projects\libssh2\_bld\src\libssh2_static.vcxproj]
```
https://ci.appveyor.com/project/libssh2org/libssh2/builds/54174319/job/rlvjmtxsvkkxo7r9
@vszakats
vszakats marked this pull request as ready for review June 7, 2026 20:35
@vszakats vszakats closed this in 4a3b0b2 Jun 7, 2026
@vszakats
vszakats deleted the func-ptr-cast branch June 7, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant