---
name: "libressl-EC_GROUP_new_by_curve_name"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-EC_GROUP_new_by_curve_name"
---

# libressl-EC\_GROUP\_new\_by\_curve\_name(3)

instantiate named curves built into libcrypto

## NAME

**EC\_GROUP\_new\_by\_curve\_name**, **EC\_GROUP\_free**, **EC\_GROUP\_dup**, **EC\_GROUP\_cmp**, **EC\_get\_builtin\_curves**, **EC\_curve\_nid2nist**, **EC\_curve\_nist2nid** – instantiate named curves built into libcrypto

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/bn.h\>**

**#include \<openssl/ec.h\>**

**#include \<openssl/objects.h\>**

*EC\_GROUP* *\**\

**EC\_GROUP\_new\_by\_curve\_name**(*int nid*);

*void*\

**EC\_GROUP\_free**(*EC\_GROUP \*group*);

*EC\_GROUP* *\**\

**EC\_GROUP\_dup**(*const EC\_GROUP \*group*);

*int*\

**EC\_GROUP\_cmp**(*const EC\_GROUP \*group1*, *const EC\_GROUP \*group2*, *BN\_CTX \*ctx*);

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

*size\_t*\

**EC\_get\_builtin\_curves**(*EC\_builtin\_curve \*curves*, *size\_t ncurves*);

*int*\

**EC\_curve\_nist2nid**(*const char \*name*);

*const* *char* *\**\

**EC\_curve\_nid2nist**(*int nid*);

## DESCRIPTION

Most elliptic curves used in cryptographic protocols have a standardized representation as a *named* *curve*, where an ASN.1 Object Identifier (OID) is used instead of detailed domain parameters. This OID is represented internally by a Numerical Identifier (NID), and the parameters themselves must be built into the library. In the EC library the *curve* *name* refers to this NID.

**EC\_GROUP\_new\_by\_curve\_name**() returns a new *EC\_GROUP* object representing the named curve corresponding to *nid*, using the parameters built into the library. It is equivalent to passing the appropriate parameters to EC\_GROUP\_new\_curve\_GFp(3), EC\_GROUP\_set\_curve\_name(3), EC\_GROUP\_set\_generator(3) and EC\_GROUP\_set\_seed(3).

**EC\_GROUP\_free**() frees *group* and all the memory associated with it. If *group* is NULL, no action occurs.

**EC\_GROUP\_dup**() creates a deep copy of *group*.

**EC\_GROUP\_cmp**() is intended to determine whether *group1* and *group2* represent the same elliptic curve, making use of the optional *ctx*. If the curve name is set on both curves, they are compared as integers, then the prime field, the coefficients of the Weierstrass equation, the generators, their order and their cofactors are compared using BN\_cmp(3) or EC\_POINT\_cmp(3), respectively.

**EC\_get\_builtin\_curves**() returns the number of builtin curves. If *curves* is NULL or *ncurves* is zero, it performs no other action. Otherwise, after reducing *ncurves* to the number of builtin curves if necessary, it copies the *nid* and a pointer to the *comment* of the first *ncurves* built-in curves to the array of *EC\_builtin\_curve* objects pointed to by *curves* and leaves the remainder of the array uninitialized.

Some curves can be identified by their NIST name in addition to the numerical identifier (NID). **EC\_curve\_nist2nid**() and **EC\_curve\_nid2nist**() translate between the two. The builtin NIST curves over a prime field are:

| | | |
| --- | --- | --- |
| NIST *name* | *ASN.1* *NID* | *notes* |
| "P-224" | NID\_secp224r1 |  |
| "P-256" | NID\_X9\_62\_prime256v1 | also known as secp256r1 |
| "P-384" | NID\_secp384r1 |  |
| "P-521" | NID\_secp521r1 |  |

**EC\_curve\_nist2nid**() and **EC\_curve\_nid2nist**() also accept the binary curves defined in FIPS 186-4 and deprecated in SP800-186, as well as "P-192" and NID\_X9\_62\_prime192v1, although all these no longer correspond to builtin curves in LibreSSL.

## RETURN VALUES

**EC\_GROUP\_new\_by\_curve\_name**() returns a newly allocated group or NULL if there is no built-in group with NID *nid*, or if memory allocation fails.

**EC\_GROUP\_dup**() returns a newly allocated group or NULL if memory allocation fails.

**EC\_GROUP\_cmp**() returns 1 if the groups are distinct, 0 if the groups are considered identical and -1 on memory allocation error.

**EC\_get\_builtin\_curves**() returns the number of builtin curves.

**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.

## EXAMPLES

Print the list of builtin curves, their NIDs, their NIST name and a comment describing each curve:

```
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <openssl/ec.h>
int
main(void)
{
	EC_builtin_curve *curves;
	size_t ncurves, i;
	if (pledge("stdio", NULL) == -1)
		err(1, "pledge");
	ncurves = EC_get_builtin_curves(NULL, 0);
	if ((curves = calloc(ncurves, sizeof(*curves))) == NULL)
		err(1, NULL);
	(void)EC_get_builtin_curves(curves, ncurves);
	printf("curve\tnid\tNIST\tcomment\n");
	for (i = 0; i < ncurves; i++) {
		const char *nist_name = EC_curve_nid2nist(curves[i].nid);
		printf("%2zu\t%d\t%s\t%s\n", i, curves[i].nid,
		    nist_name != NULL ? nist_name : "", curves[i].comment);
	}
	free(curves);
	return 0;
}
```

## SEE ALSO

[crypto(3)](/crypto/3.md), d2i\_ECPKParameters(3), EC\_GROUP\_check(3), EC\_GROUP\_get\_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\_nid2obj(3)

## STANDARDS

*SEC 1: Elliptic Curve Cryptography, Version 2.0*, May 21, 2009, https://www.secg.org/sec1-v2.pdf.

*SEC 2: Recommended Elliptic Curve Domain Parameters, Version 2.0*, Jan 27, 2010, https://www.secg.org/sec2-v2.pdf.

## HISTORY

**EC\_GROUP\_free**() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2.

**EC\_GROUP\_new\_by\_curve\_name**(), **EC\_GROUP\_cmp**(), **EC\_GROUP\_dup**(), 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.

## BUGS

**EC\_GROUP\_cmp**() compares the coefficients of the Weierstrass equation as integers, not as elements of the prime field. It also treats the generator as mandatory while it is generally optional in the EC library. Aspects of the ASN.1 encoding controlled by the functions in EC\_GROUP\_get\_asn1\_flag(3), in particular seed, ASN.1 flag, and point conversion form, are ignored in the comparison. Group objects may therefore compare as equal and produce completely different ASN.1 encodings via i2d\_ECPKParameters(3) and related functions. In fact, either of these encodings might be valid or not, accepted or rejected by d2i\_ECPKParameters(3), or the encoding might fail on one or both of the group objects.
