Skip to content

Commit

Permalink
Fixed typo in function name and handle dynamic RSA/EC_KEY methods fre…
Browse files Browse the repository at this point in the history
…eing for older OpenSSL versions
  • Loading branch information
olszomal committed Oct 21, 2024
1 parent 9b20ef7 commit 679b06c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libp11-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ extern void pkcs11_rsa_method_free(void);
extern void pkcs11_ec_key_method_free(void);

/* Free the global ECDSA_METHOD */
extern void pkcs11_ecda_method_free(void);
extern void pkcs11_ecdsa_method_free(void);

/* Free the global ECDH_METHOD */
extern void pkcs11_ecdh_method_free(void);
Expand Down
17 changes: 17 additions & 0 deletions src/p11_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ typedef ECDSA_SIG *(*sign_sig_fn)(const unsigned char *, int,

#if OPENSSL_VERSION_NUMBER < 0x10100000L

#define EC_KEY_METHOD_DYNAMIC 1

/* ecdsa_method maintains unchanged layout between 0.9.8 and 1.0.2 */

/* Data pointers and function pointers may have different sizes on some
Expand Down Expand Up @@ -802,7 +804,12 @@ void pkcs11_ec_key_method_free(void)
{
if (pkcs11_ec_key_method) {
free_ec_ex_index();
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
if (meth->pkcs11_ecdh_method & EC_KEY_METHOD_DYNAMIC)
OPENSSL_free(pkcs11_ec_key_method);
#else
EC_KEY_METHOD_free(pkcs11_ec_key_method);
#endif
pkcs11_ec_key_method = NULL;
}
}
Expand Down Expand Up @@ -840,7 +847,12 @@ void pkcs11_ecdsa_method_free(void)
{
if (pkcs11_ecdsa_method) {
free_ec_ex_index();
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
if (pkcs11_ecdsa_method->flags & EC_KEY_METHOD_DYNAMIC)
OPENSSL_free(pkcs11_ecdsa_method);
#else
EC_KEY_METHOD_free(pkcs11_ecdsa_method);
#endif
pkcs11_ecdsa_method = NULL;
}
}
Expand All @@ -860,7 +872,12 @@ void pkcs11_ecdh_method_free(void)
{
if (pkcs11_ecdh_method) {
free_ec_ex_index();
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
if (pkcs11_ecdh_method->flags & EC_KEY_METHOD_DYNAMIC)
OPENSSL_free(pkcs11_ecdh_method);
#else
EC_KEY_METHOD_free(pkcs11_ecdh_method);
#endif
pkcs11_ecdh_method = NULL;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/p11_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,12 @@ void pkcs11_rsa_method_free(void)
{
if (!pkcs11_rsa_method) {
free_rsa_ex_index();
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
RSA_meth_free(pkcs11_rsa_method);
#else
OPENSSL_free((char *)pkcs11_rsa_method->name);
OPENSSL_free(pkcs11_rsa_method);
#endif
pkcs11_rsa_method = NULL;
}
}
Expand Down

0 comments on commit 679b06c

Please sign in to comment.