---
name: "libressl-EC_GROUP_new_curve_GFp"
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_curve_GFp"
---

# libressl-EC\_GROUP\_new\_curve\_GFp(3)

define elliptic curves and retrieve information from them

## NAME

**EC\_GROUP\_new\_curve\_GFp**, **EC\_GROUP\_set\_curve**, **EC\_GROUP\_get\_curve**, **EC\_GROUP\_set\_generator**, **EC\_GROUP\_get0\_generator**, **EC\_GROUP\_get\_degree**, **EC\_GROUP\_get\_order**, **EC\_GROUP\_order\_bits**, **EC\_GROUP\_get\_cofactor**, **EC\_GROUP\_clear\_free**, **EC\_GROUP\_set\_curve\_GFp**, **EC\_GROUP\_get\_curve\_GFp** – define elliptic curves and retrieve information from them

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

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

*EC\_GROUP* *\**\

**EC\_GROUP\_new\_curve\_GFp**(*const BIGNUM \*p*, *const BIGNUM \*a*, *const BIGNUM \*b*, *BN\_CTX \*ctx*);

*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\_generator**(*EC\_GROUP \*group*, *const EC\_POINT \*generator*, *const BIGNUM \*order*, *const BIGNUM \*cofactor*);

*const* *EC\_POINT* *\**\

**EC\_GROUP\_get0\_generator**(*const EC\_GROUP \*group*);

*int*\

**EC\_GROUP\_get\_degree**(*const EC\_GROUP \**);

*int*\

**EC\_GROUP\_get\_order**(*const EC\_GROUP \*group*, *BIGNUM \*order*, *BN\_CTX \*ctx*);

*int*\

**EC\_GROUP\_order\_bits**(*const EC\_GROUP \*group*);

*int*\

**EC\_GROUP\_get\_cofactor**(*const EC\_GROUP \*group*, *BIGNUM \*cofactor*, *BN\_CTX \*ctx*);

Deprecated:

*void*\

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

*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*);

## DESCRIPTION

With the exception of the getters the functions in this manual should not be used. Use EC\_GROUP\_new\_by\_curve\_name(3) instead.

The EC library uses *EC\_GROUP* objects to represent elliptic curves in Weierstrass form. These curves are defined over the prime field of order *p* via the Weierstrass equation

```
y^2 = x^3 + ax + b
```

where *a* and *b* are such that the discriminant 4a^3 - 27b^2 is non-zero. They consist of *affine* *points*, which are pairs of field elements (x, y) satisfying the Weierstrass equation, and an extra *point* *at* *infinity*.

The points on an elliptic curve form a group. Cryptographic applications usually depend on the choice of a *generator* whose multiples form a cyclic subgroup of a certain *order*. By Lagrange's theorem, the number of points on the elliptic curve is the product of *order* and another integer called the *cofactor*. Hasse's theorem is the inequality

```
|order * cofactor - (p + 1)| <= 2 sqrt(p)
```

which implies an upper bound on *order* in terms of *p* and allows the computation of *cofactor* provided that *order* is large enough.

**EC\_GROUP\_new\_curve\_GFp**() instantiates a new *EC\_GROUP* object over the prime field of size *p* with Weierstrass equation given by the coefficients *a* and *b*. The optional *ctx* is used to transform the other arguments into internal representation. It is the caller's responsibility to ensure that *p* is a prime number greater than three and that the discriminant is non-zero. This can be done with EC\_GROUP\_check\_discriminant(3) or as part of EC\_GROUP\_check(3) after **EC\_GROUP\_set\_generator**().

**EC\_GROUP\_set\_curve**() sets the curve parameters of *group* to *p*, *a*, *b* using the optional *ctx* and the comments in **EC\_GROUP\_new\_curve\_GFp**() apply. Existing *generator*, *order*, or *cofactor* on *group* are left unmodified and become most likely invalid. They must therefore be set to legitimate values using **EC\_GROUP\_set\_generator**().

**EC\_GROUP\_get\_curve**() copies the curve parameters of *group* into the caller-owned *p*, *a*, and *b*, possibly making use of the *ctx* for conversion from internal representations. Except for *group*, all arguments are optional.

**EC\_GROUP\_set\_generator**() performs sanity checks based on Hasse's theorem and copies *generator*, *order* and the optional *cofactor* into *group*, replacing all existing entries. It is the caller's responsibility to ensure that *generator* is a point on the curve and that *order* is its order, which can partially be accomplished with a subsequent call to EC\_GROUP\_check(3). If *cofactor* is NULL, it can be computed on curves of cryptographic interest, in which case *cofactor* is set to the computed value, otherwise it is set to zero.

**EC\_GROUP\_get0\_generator**() returns an internal pointer to the *group*'s *generator*, which may be NULL if no generator was set.

**EC\_GROUP\_get\_degree**() returns the bit length of the prime *p* set on *group*.

**EC\_GROUP\_get\_order**() copies the value of the *group*'s *order* into the caller-owned *order*, returning failure if the *group*'s *order* is zero. The *ctx* argument is ignored.

**EC\_GROUP\_order\_bits**() returns the number of bits in the *group*'s *order*, which is the result of calling BN\_num\_bits(3) on *order*. Unlike **EC\_GROUP\_get\_order**(), it does not fail if *order* is zero.

**EC\_GROUP\_get\_cofactor**() copies the value of the *group*'s *cofactor* into the caller-owned *cofactor*, returning failure if the *group*'s *cofactor* is zero. The *ctx* argument is ignored.

The deprecated **EC\_GROUP\_clear\_free**() uses [explicit\_bzero(3)](/explicit_bzero/3.md) and freezero(3) to clear and free all data associated with *group*. If *group* is NULL, no action occurs. Since there is no secret data in *group*, this API is useless. In LibreSSL, EC\_GROUP\_free(3) and **EC\_GROUP\_clear\_free**() behave identically.

**EC\_GROUP\_set\_curve\_GFp**() and **EC\_GROUP\_get\_curve\_GFp**() are deprecated aliases for **EC\_GROUP\_set\_curve**() and **EC\_GROUP\_get\_curve**(), respectively.

## RETURN VALUES

**EC\_GROUP\_new\_curve\_GFp**() returns a newly allocated group or NULL if memory allocation fails, or if some minimal sanity checks on *p*, *a*, and *b* fail.

**EC\_GROUP\_set\_curve**() and **EC\_GROUP\_set\_curve\_GFp**() return 1 on success and 0 on failure. Failure conditions include that *p* is smaller than or equal to three, or even, or memory allocation failure.

**EC\_GROUP\_get\_curve**() and **EC\_GROUP\_get\_curve\_GFp**() return 1 on success and 0 on memory allocation failure.

**EC\_GROUP\_set\_generator**() returns 1 on success and 0 on memory allocation failure, or if *order* or *cofactor* are larger than Hasse's theorem allows.

**EC\_GROUP\_get0\_generator**() returns an internal pointer to the *generator* or NULL if none was set on *group*.

**EC\_GROUP\_get\_order**() returns 1 on success or 0 on memory allocation failure or if the *order* is zero.

**EC\_GROUP\_get\_cofactor**() returns 1 on success or 0 on memory allocation failure or if the *cofactor* is zero.

**EC\_GROUP\_get\_degree**(), and **EC\_GROUP\_order\_bits**() return the number of bits in the *group*'s *p*, and *order*, respectively.

## SEE ALSO

BN\_new(3), BN\_num\_bits(3), [crypto(3)](/crypto/3.md), d2i\_ECPKParameters(3), EC\_GROUP\_check(3), EC\_GROUP\_get\_curve\_name(3), EC\_GROUP\_new\_by\_curve\_name(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)

## 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\_new\_curve\_GFp**(), **EC\_GROUP\_clear\_free**(), **EC\_GROUP\_set\_curve\_GFp**(), **EC\_GROUP\_get\_curve\_GFp**(), **EC\_GROUP\_set\_generator**(), **EC\_GROUP\_get0\_generator**(), **EC\_GROUP\_get\_order**(), and **EC\_GROUP\_get\_cofactor**() first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2.

**EC\_GROUP\_get\_degree**() first appeared in OpenSSL 0.9.8 and has been available since OpenBSD 4.5.

**EC\_GROUP\_set\_curve**(), **EC\_GROUP\_get\_curve**(), and **EC\_GROUP\_order\_bits**() first appeared in OpenSSL 1.1.1 and have been available since OpenBSD 7.0

## BUGS

Too many. The API is unergonomic and the design is very poor even by OpenSSL's standards. Naming is inconsistent, especially in regard to the \_GFp suffix and the \_get\_ infix. Function signatures are inconsistent. In particular, functions that should have a *BN\_CTX* argument don't have one and functions that don't need it have one.
