EC_GROUP_NEW(3)

πŸ“¦
version 4.1.0 Β· 3 versions
, in opensuse-leap 16.0

πŸ’– EC_GROUP_NEW(3) β€” like, the whole elliptic-curve group saga πŸ’–

okay bestie, so this is a page out of the Library Functions Manual, and it's literally all about making and destroying EC_GROUP objects. buckle up, it's giving crypto-girlie ✨


🌸 NAME 🌸

EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_new_curve_GFp, EC_GROUP_new_by_curve_name, EC_GROUP_set_curve, EC_GROUP_get_curve, EC_GROUP_set_curve_GFp, EC_GROUP_get_curve_GFp, EC_get_builtin_curves, EC_curve_nid2nist, EC_curve_nist2nid β€” create and destroy EC_GROUP objects 🫢


✨ SYNOPSIS ✨

#include <openssl/ec.h>
#include <openssl/bn.h>

EC_GROUP *
EC_GROUP_new(const EC_METHOD *meth);

void
EC_GROUP_free(EC_GROUP *group);

void
EC_GROUP_clear_free(EC_GROUP *group);

EC_GROUP *
EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
    const BIGNUM *b, BN_CTX *ctx);

EC_GROUP *
EC_GROUP_new_by_curve_name(int nid);

int
EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
    const BIGNUM *b, BN_CTX *ctx);

int
EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
    BIGNUM *b, BN_CTX *ctx);

int
EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p,
    const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);

int
EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
    BIGNUM *b, BN_CTX *ctx);

size_t
EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);

const char *
EC_curve_nid2nist(int nid);

int
EC_curve_nist2nid(const char *name);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the EC library hands you functions for doing operations on elliptic curves in Weierstrass form. these curves live over the prime field of order p and they satisfy the Weierstrass equation with coefficients a and b, and the equation is literally:

y^2 = x^3 + ax + b

an EC_GROUP structure is what represents the definition of an elliptic curve. you can build a brand-new curve by calling EC_GROUP_new(), using the implementation that meth gives you. and then β€” bestie, this is the part people forget β€” it is necessary to call EC_GROUP_set_curve() to actually set the curve parameters. no cap.

EC_GROUP_set_curve() sets the curve parameters p, a, and b, where a and b are the coefficients of the curve equation. πŸ’…

EC_GROUP_set_curve_GFp() is a deprecated synonym for EC_GROUP_set_curve(). it's giving legacy, we don't stan, but it exists.

EC_GROUP_get_curve() obtains the curve parameters that were previously set.

EC_GROUP_get_curve_GFp() is a deprecated synonym for EC_GROUP_get_curve().

the function EC_GROUP_new_curve_GFp() is a shortcut for calling EC_GROUP_new() and EC_GROUP_set_curve() together β€” an appropriate default implementation method gets used. lazy-girl math, iconic πŸŽ€


🌈 the builtin curves arc 🌈

whilst (yes, whilst) the library can be used to create any curve using the functions described above, there are also a number of predefined curves that are available. to get a list of all of the predefined curves, call EC_get_builtin_curves().

the parameter r should be an array of EC_builtin_cure structures of size nitems. the function will populate the r array with information about the builtin curves. if nitems is less than the total number of curves available, then the first nitems curves will be returned. otherwise the total number of curves will be provided. the return value is the total number of curves available (whether that number has been populated in r or not). passing a NULL r, or setting nitems to 0, will do nothing other than return the total number of curves available. so chill, it's harmless.

the EC_builtin_curve structure is defined as follows:

typedef struct {
        int nid;
        const char *comment;
} EC_builtin_curve;

each EC_builtin_curve item has a unique integer ID (nid) and a human readable comment string describing the curve. πŸ“

to construct a builtin curve, use the function EC_GROUP_new_by_curve_name() and provide the nid of the curve to be constructed.

EC_GROUP_free() frees the memory associated with the EC_GROUP. if group is a NULL pointer, no action occurs. (polite king behavior πŸ‘‘)

EC_GROUP_clear_free() destroys any sensitive data held within the EC_GROUP and then frees its memory. if group is a NULL pointer, no action occurs. use this one when the data is spicy and you don't want it just sitting there β€” πŸ”₯


🧚 NIST names, NIDs, and the translation pipeline 🧚

some builtin curves can be identified by their NIST name in addition to a numerical identifier (NID). EC_curve_nid2nist() and EC_curve_nist2nid() translate between the two. iykyk.

the five built-in prime curves are:

  • NIST name "P-192, ASN.1 NID NID_X9_62_prime192v1, notes deprecated in SP800-186
  • NIST name "P-224, ASN.1 NID NID_secp224r1, notes (none)
  • NIST name "P-256, ASN.1 NID NID_X9_62_prime256v1, notes (none)
  • NIST name "P-384, ASN.1 NID NID_secp384r1, notes (none)
  • NIST name "P-521, ASN.1 NID NID_secp521r1, notes (none)

EC_curve_nid2nist() and EC_curve_nist2nid() also accept the ten binary curves defined in FIPS 186-4 and deprecated in SP800-186, although they no longer correspond to builtin curves in LibreSSL. so heads up: name translation works, but you're not getting a builtin group out of those. πŸ’€


πŸ’œ RETURN VALUES πŸ’œ

  • all EC_GROUP_new*() functions return a pointer to the newly constructed group, or NULL on error.
  • EC_get_builtin_curves() returns the number of builtin curves that are available.
  • EC_curve_nid2nist() returns a string constant containing the NIST name if nid identifies a NIST curve, or NULL otherwise.
  • EC_curve_nist2nid() returns the NID corresponding to the NIST curve name, or NID_undef.
  • EC_GROUP_set_curve(), EC_GROUP_get_curve(), EC_GROUP_set_curve_GFp(), and EC_GROUP_get_curve_GFp() return 1 on success or 0 on error. (yes bestie, zero means something went wrong β€” check it πŸ™ˆ)

⭐ SEE ALSO ⭐

crypto(3), d2i_ECPKParameters(3), EC_GROUP_copy(3), EC_KEY_new(3), EC_POINT_add(3), EC_POINT_new(3), ECDH_compute_key(3), ECDSA_SIG_new(3)


πŸ•°οΈ HISTORY πŸ•°οΈ

  • EC_GROUP_new(), EC_GROUP_free(), EC_GROUP_clear_free(), EC_GROUP_new_curve_GFp(), EC_GROUP_set_curve_GFp(), and EC_GROUP_get_curve_GFp() first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2.
  • EC_GROUP_new_by_curve_name() and EC_get_builtin_curves() first appeared in OpenSSL 0.9.8 and have been available since OpenBSD 4.5.
  • EC_curve_nid2nist(), and EC_curve_nist2nid() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 5.8.
  • EC_GROUP_set_curve() and EC_GROUP_get_curve() first appeared in OpenSSL 1.1.1 and have been available since OpenBSD 7.0.

πŸ’Œ and that's the whole page, bestie! this edition is the Debian one from March 8, 2025 πŸ’– go forth and construct your groups responsibly, mwah 🫢✨🌸
πŸ“¦ where this page comes from