Skip to content

Commit

Permalink
Enabled OpenSSL to manage and free EVP_PKEY_METHOD resources by remov…
Browse files Browse the repository at this point in the history
…ing manual flag handling
  • Loading branch information
olszomal committed Oct 25, 2024
1 parent 5467178 commit fe72f06
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions src/p11_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,49 +36,6 @@ static int (*orig_pkey_ec_sign) (EVP_PKEY_CTX *ctx,
const unsigned char *tbs, size_t tbslen);
#endif /* OPENSSL_NO_EC */

struct evp_pkey_method_st {
int pkey_id;
int flags;
int (*init) (EVP_PKEY_CTX *ctx);
int (*copy) (EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src);
void (*cleanup) (EVP_PKEY_CTX *ctx);
int (*paramgen_init) (EVP_PKEY_CTX *ctx);
int (*paramgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
int (*keygen_init) (EVP_PKEY_CTX *ctx);
int (*keygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
int (*sign_init) (EVP_PKEY_CTX *ctx);
int (*sign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
const unsigned char *tbs, size_t tbslen);
int (*verify_init) (EVP_PKEY_CTX *ctx);
int (*verify) (EVP_PKEY_CTX *ctx,
const unsigned char *sig, size_t siglen,
const unsigned char *tbs, size_t tbslen);
int (*verify_recover_init) (EVP_PKEY_CTX *ctx);
int (*verify_recover) (EVP_PKEY_CTX *ctx,
unsigned char *rout, size_t *routlen,
const unsigned char *sig, size_t siglen);
int (*signctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
int (*signctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
EVP_MD_CTX *mctx);
int (*verifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
int (*verifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen,
EVP_MD_CTX *mctx);
int (*encrypt_init) (EVP_PKEY_CTX *ctx);
int (*encrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
const unsigned char *in, size_t inlen);
int (*decrypt_init) (EVP_PKEY_CTX *ctx);
int (*decrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
const unsigned char *in, size_t inlen);
int (*derive_init) (EVP_PKEY_CTX *ctx);
int (*derive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2);
int (*ctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value);
} /* EVP_PKEY_METHOD */ ;

#if OPENSSL_VERSION_NUMBER >= 0x10000000L
#define EVP_PKEY_FLAG_DYNAMIC 1
#endif

#if OPENSSL_VERSION_NUMBER < 0x10002000L || defined(LIBRESSL_VERSION_NUMBER)

typedef struct {
Expand Down Expand Up @@ -534,11 +491,6 @@ static EVP_PKEY_METHOD *pkcs11_pkey_method_rsa()
new_meth = EVP_PKEY_meth_new(EVP_PKEY_RSA,
EVP_PKEY_FLAG_AUTOARGLEN);

#ifdef EVP_PKEY_FLAG_DYNAMIC
/* do not allow OpenSSL to free this object */
new_meth->flags &= ~EVP_PKEY_FLAG_DYNAMIC;
#endif

EVP_PKEY_meth_copy(new_meth, orig_meth);

EVP_PKEY_meth_set_sign(new_meth,
Expand Down Expand Up @@ -676,11 +628,6 @@ static EVP_PKEY_METHOD *pkcs11_pkey_method_ec()

new_meth = EVP_PKEY_meth_new(EVP_PKEY_EC, 0);

#ifdef EVP_PKEY_FLAG_DYNAMIC
/* do not allow OpenSSL to free this object */
new_meth->flags &= ~EVP_PKEY_FLAG_DYNAMIC;
#endif

EVP_PKEY_meth_copy(new_meth, orig_meth);

EVP_PKEY_meth_set_sign(new_meth,
Expand Down

0 comments on commit fe72f06

Please sign in to comment.