EC_KEY_METHOD_NEW(3)
π NAME π
okay so bestie, this is EC_KEY_METHOD_NEW(3) from the Library Functions Manual, and it's literally the whole custom EC_KEY implementation starter pack. like, all of it:
EC_KEY_METHOD_new, EC_KEY_METHOD_free, EC_KEY_METHOD_set_init, EC_KEY_METHOD_get_init, EC_KEY_METHOD_set_sign, EC_KEY_METHOD_get_sign, EC_KEY_METHOD_set_verify, EC_KEY_METHOD_get_verify, EC_KEY_METHOD_set_keygen, EC_KEY_METHOD_get_keygen, EC_KEY_METHOD_set_compute_key, EC_KEY_METHOD_get_compute_key, EC_KEY_OpenSSL, EC_KEY_set_default_method, EC_KEY_get_default_method, EC_KEY_new_method, EC_KEY_set_method, EC_KEY_get_method β custom EC_KEY implementations. periodt. π
β¨ SYNOPSIS β¨
library:
library βlibcryptoβ #include <openssl/ec.h>
EC_KEY_METHOD *
EC_KEY_METHOD_new(const EC_KEY_METHOD *meth);
void
EC_KEY_METHOD_free(EC_KEY_METHOD *meth);
void
EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, int (*init)(EC_KEY *key),
void (*finish)(EC_KEY *key),
int (*copy)(EC_KEY *dest, const EC_KEY *src),
int (*set_group)(EC_KEY *key, const EC_GROUP *grp),
int (*set_private)(EC_KEY *key, const BIGNUM *priv_key),
int (*set_public)(EC_KEY *key, const EC_POINT *pub_key));
void
EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth,
int (**pinit)(EC_KEY *key), void (**pfinish)(EC_KEY *key),
int (**pcopy)(EC_KEY *dest, const EC_KEY *src),
int (**pset_group)(EC_KEY *key, const EC_GROUP *grp),
int (**pset_private)(EC_KEY *key, const BIGNUM *priv_key),
int (**pset_public)(EC_KEY *key, const EC_POINT *pub_key));
void
EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth,
int (*sign)(int type, const unsigned char *dgst, int dgstlen, unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey),
int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp),
ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, int dgstlen, const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey));
void
EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth,
int (**psign)(int type, const unsigned char *dgst, int dgstlen, unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey),
int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp),
ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, int dgstlen, const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey));
void
EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth,
int (*verify)(int type, const unsigned char *dgst, int dgst_len, const unsigned char *sigbuf, int sig_len, EC_KEY *eckey),
int (*verify_sig)(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, EC_KEY *eckey));
void
EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth,
int (**pverify)(int type, const unsigned char *dgst, int dgst_len, const unsigned char *sigbuf, int sig_len, EC_KEY *eckey),
int (**pverify_sig)(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, EC_KEY *eckey));
void
EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth,
int (*keygen)(EC_KEY *key));
void
EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth,
int (**pkeygen)(EC_KEY *key));
void
EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth,
int (*ckey)(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen)));
void
EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth,
int (**pck)(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen)));
const EC_KEY_METHOD *
EC_KEY_OpenSSL(void);
void
EC_KEY_set_default_method(const EC_KEY_METHOD *meth);
const EC_KEY_METHOD *
EC_KEY_get_default_method(void);
EC_KEY *
EC_KEY_new_method(ENGINE *engine);
int
EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth);
const EC_KEY_METHOD *
EC_KEY_get_method(const EC_KEY *key);
πΈ DESCRIPTION πΈ
okay so picture this: an EC_KEY_METHOD object is basically a little bag of function pointers, and those pointers are what get used for EC_KEY operations. it's giving "build-your-own-implementation" energy. π
EC_KEY_METHOD_new()β makes a shallow copy ofmeth. nometh? no problem, you get an emptyEC_KEY_METHODobject instead (i.e. whenmethisNULL).EC_KEY_METHOD_free()β freesmeth. but like, ifmethisNULL, or if it's the return value ofEC_KEY_OpenSSL(), then nothing happens. no action, zero drama. π«Ά
π¦ the init/finish crew
EC_KEY_METHOD_set_init() and EC_KEY_METHOD_get_init() set and retrieve the optional callback functions, and these cuties get called at very specific places:
initβ at the end ofEC_KEY_new_method()andEC_KEY_set_method()finishβ at the beginning ofEC_KEY_free(3),EC_KEY_copy(3), andEC_KEY_set_method()copyβ at the end ofEC_KEY_copy(3)set_groupβ at the end ofEC_KEY_set_group(3)andEC_KEY_new_by_curve_name(3)set_privateβ at the beginning ofEC_KEY_set_private_key(3)set_publicβ at the beginning ofEC_KEY_set_public_key(3)
β οΈ if any of these callbacks returns 0, the calling function fails. that's the rule, bestie.
by default, all these callbacks are NULL. and the arguments of EC_KEY_METHOD_get_init() can be set to NULL so you can selectively retrieve callback function pointers β like picking only the ones you want out of the group chat. π
π the sign + verify girlies
EC_KEY_METHOD_set_sign()andEC_KEY_METHOD_get_sign()β set and retrieve the functions implementingECDSA_sign(3)andECDSA_do_sign(3).EC_KEY_METHOD_set_verify()andEC_KEY_METHOD_get_verify()β set and retrieve the functions implementingECDSA_verify(3)andECDSA_do_verify(3).
β keygen + compute_key
EC_KEY_METHOD_set_keygen()andEC_KEY_METHOD_get_keygen()β set and retrieve the function implementingEC_KEY_generate_key(3).EC_KEY_METHOD_set_compute_key()andEC_KEY_METHOD_get_compute_key()β set and retrieve the function implementingECDH_compute_key(3).
π default method behaviour
EC_KEY_set_default_method()β chooses themeththat future invocations ofEC_KEY_new_method()will use when creating newEC_KEYobjects. and ifmethisNULL? it reverts to the default implementation. iconic.EC_KEY_new_method()β creates and initializes a newEC_KEYobject using theEC_KEY_METHODset withEC_KEY_set_default_method(). theENGINE *engineargument is always ignored, and passingNULLis recommended. literally just passNULL, it's not that deep. πEC_KEY_set_method()β dissociates the key from theENGINEit's using (if any), and causes it to usemethin the future.
π RETURN VALUES π
EC_KEY_METHOD_new()β returns the newly allocatedEC_KEY_METHODobject, orNULLif an error occurs.EC_KEY_OpenSSL()β returns a static object representing the defaultEC_KEYimplementation.EC_KEY_get_default_method()β returns theEC_KEY_METHODthatEC_KEY_new_method()will use for the creation of newEC_KEYobjects in the future.EC_KEY_new_method()β returns the newly allocatedEC_KEYobject, orNULLif an error occurs.EC_KEY_set_method()β returns1for success or0for failure.EC_KEY_get_method()β returns theEC_KEYimplementation used by the given key.
π SEE ALSO π
crypto(3), EC_GROUP_check(3), EC_GROUP_get_curve_name(3), EC_GROUP_new_by_curve_name(3), EC_GROUP_new_curve_GFp(3), EC_KEY_new(3), EC_POINT_add(3), EC_POINT_get_affine_coordinates(3), EC_POINT_new(3), EC_POINT_point2oct(3), ECDSA_sign(3)
π¦ HISTORY π¦
these functions first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.5. vintage but make it current, yk? β¨
mwah π that's the whole page β brought to you by the Debian crew, dated June 8, 2025, and yes the page title is literally EC_KEY_METHOD_NEW(3) again because some things never change. go forth and implement your own EC_KEY, bestie, you're gonna slay π«Ά
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms