EC_GROUP_GET_CURVE_NAME(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’– EC_GROUP_GET_CURVE_NAME(3) β€” like, the whole curve-vibes manual, bestie πŸ’–

okay so this is a page from the Library Functions Manual, and honestly? it's giving "backstage pass to how your elliptic curves get ASN.1-ified." buckle up πŸŽ€


✨ NAME ✨

EC_GROUP_get_curve_name, EC_GROUP_set_curve_name, EC_GROUP_get_asn1_flag, EC_GROUP_set_asn1_flag, EC_GROUP_get0_seed, EC_GROUP_get_seed_len, EC_GROUP_set_seed, EC_GROUP_get_point_conversion_form, EC_GROUP_set_point_conversion_form, EC_GROUP_get_basis_type β€” these are the little guys that configure and inspect the deets of the ASN.1 encoding of EC_GROUP and related objects 🫢


🌸 SYNOPSIS 🌸

the library is libcrypto, and you're gonna need this include, no cap:

#include <openssl/ec.h>

then the whole squad of function signatures, verbatim, because we do NOT paraphrase code:

int
EC_GROUP_get_curve_name(const EC_GROUP *group);

void
EC_GROUP_set_curve_name(EC_GROUP *group, int nid);

int
EC_GROUP_get_asn1_flag(const EC_GROUP *group);

void
EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);

unsigned char *
EC_GROUP_get0_seed(const EC_GROUP *group);

size_t
EC_GROUP_get_seed_len(const EC_GROUP *group);

size_t
EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *seed,
    size_t len);

and this very iconic enum β€” please memorize the numbers, they're literally on the exam πŸ’…:

typedef enum {
        POINT_CONVERSION_COMPRESSED = 2,
        POINT_CONVERSION_UNCOMPRESSED = 4,
        POINT_CONVERSION_HYBRID = 6
} point_conversion_form_t;
point_conversion_form_t
EC_GROUP_get_point_conversion_form(const EC_GROUP *group);

void
EC_GROUP_set_point_conversion_form(EC_GROUP *group,
    point_conversion_form_t form);

and then there's the deprecated one, living its retired main-character era:

int
EC_GROUP_get_basis_type(const EC_GROUP *group);
yeah, it's flagged Deprecated. we still mention it because we're thorough, not because we're recommending it πŸ™ˆ

πŸ¦‹ DESCRIPTION πŸ¦‹

so every function on this page either tweaks or peeks at the details of the ASN.1 encoding that the i2d_ECPKParameters(3) family of functions spits out. that's the whole vibe. and like, modern applications use named curves with uncompressed point encoding β€” which, fun fact, is the default for EC_GROUP_new_by_curve_name(3). so if you're doing normal stuff, the defaults already ate πŸ”₯

in this library, elliptic curve parameters get encoded in one of two ways:

  • as a named curve, using an ASN.1 Object Identifier (OID) to refer to standardized parameters that need to be built into the library, or
  • as explicit curve parameters, where the field, the curve equation, the base point's coordinates and other data are encoded explicitly.

the implicitly CA variant? yeah, that one isn't supported. not invited to the party πŸ’€

EC_GROUP_get_curve_name() gets the Numerical Identifier (NID) representation of the ASN.1 Object Identifier used for the named curve encoding of group. EC_GROUP_set_curve_name() sets it to nid. simple as πŸ“

EC_GROUP_get_asn1_flag() retrieves the value of the asn1_flag member of group. if the bit corresponding to OPENSSL_EC_NAMED_CURVE is set, named curve encoding is used for group; otherwise it's explicit encoding, periodt. EC_GROUP_set_asn1_flag() sets the asn1_flag member of group to flag, which should be either OPENSSL_EC_NAMED_CURVE (for named curve encoding) or OPENSSL_EC_EXPLICIT_CURVE (for explicit encoding). pick your fighter ✨

the ASN.1 encoding of explicit curve parameters includes an optional seed value for parameters generated verifiably at random. if a seed value is set on group, EC_GROUP_get0_seed() returns a pointer to the internal byte string whose length is returned by EC_GROUP_get_seed_len() πŸŽ€

EC_GROUP_set_seed() first clears any seed and length already stored in group. if seed is not NULL and len is not zero, it stores a copy of them in group. the seed should be a random byte string of len at least 20 bytes. you can unset the seed by passing NULL as a seed and a len of zero. and here's the thing, bestie β€” the library does not perform any computation or validation with this seed, it only includes it in its ASN.1 encoded parameters, whether it contains a sensible value or not. so like, it's not checking your work. it's just vibes πŸ’€

points on an elliptic curve β€” like the generator or a public key β€” can be encoded in compressed form, uncompressed form, or in a hybrid form that encompasses both, see EC_POINT_point2oct(3). EC_GROUP_get_point_conversion_form() retrieves the encoding used for points on group, and EC_GROUP_set_point_conversion_form() sets it to form. slay πŸ¦‹

the deprecated EC_GROUP_get_basis_type() only makes sense for curves over binary fields. it is provided for compatibility only. that's it. that's the whole personality 😭


πŸ‘‘ RETURN VALUES πŸ‘‘

lowkey the most important section, let's go:

  • EC_GROUP_get_curve_name() returns the NID to be used for named curve encoding of group, or NID_undef if no NID is set.
  • EC_GROUP_get_asn1_flag() returns the value most recently set by EC_GROUP_set_asn1_flag() on group.
  • EC_GROUP_get0_seed() returns an internal pointer to the seed on group, or NULL if none is set.
  • EC_GROUP_get_seed_len() returns the byte length of the seed set on group, or zero if none is set.
  • EC_GROUP_set_seed() returns 0 on memory allocation failure. it returns len on success, unless seed is NULL or len is zero β€” in which case it returns 1.
  • EC_GROUP_get_point_conversion_form() returns the point conversion form last set by EC_GROUP_set_point_conversion_form() on group.
  • EC_GROUP_get_basis_type() always returns NID_undef. always. no notes πŸ’€

🌈 SEE ALSO 🌈

go read these too, iykyk:

crypto(3), d2i_ECPKParameters(3), EC_GROUP_check(3), EC_GROUP_new_by_curve_name(3), EC_GROUP_new_curve_GFp(3), EC_KEY_METHOD_new(3), EC_KEY_new(3), EC_POINT_add(3), EC_POINT_get_affine_coordinates(3), EC_POINT_new(3), EC_POINT_point2oct(3), ECDH_compute_key(3), ECDSA_SIG_new(3), OBJ_obj2nid(3)


⭐ HISTORY ⭐

these functions first appeared in OpenSSL 0.9.8 and have been available since OpenBSD 4.5. vintage. iconic. still here πŸ‘‘


πŸ’€ BUGS πŸ’€

okay so this part is a little rough ngl β€” most of the setters cannot report errors, and none of them perform proper input validation and accept most of the values passed in. 😭 which means you can absolutely end up with invalid or nonsensical ASN.1 encoding produced by i2d_ECPKParameters(3) and related functions. so like, garbage in, garbage out, but make it cryptography πŸ™ˆ

fr fr: validate your own inputs, bestie. the library is not gonna do it for you.

mwah πŸ’œ this page was brought to you by Debian, dated June 13, 2025, and the letters E, C, and the entire concept of curve names. go forth and encode responsibly 🧚✨

πŸ“¦ where this page comes from