The usual practical solution is to use a precomputed set of parameters. You'll find some in sec2v2 section 2. A popular choice for IT security is secp256r1. That gives p
, a
, b
, and a standard G
. The order of that G
is the prime n
.
For Gx
and Gy
strip the leading 04
byte in the uncompressed version of G
, and split the remaining 64 bytes into two 32-byte bytestring, which are Gx
and Gy
in big-endian binary.
How should the point G
be selected on it?
Since the cofactor h
for that curbe is 1 (as for all the curves in sec2v2 section 2), any point on the curve that is not the point at infinity also has order the prime n
. One can be found by taking a random x
, computing y**2 mod p
by applying the curve equation, until that's a quadratic residue as testable by the Legendre symbol. One of two suitable y
can then be found by extracting a modular square root e.g. with Tonelli–Shanks.
Coming up with your own parameters of cryptographic interest usually involves the Schoof–Elkies–Atkin algorithm. It's build into PARI/GP, and from that available in SageMath. Beware there are other desirable criteria beyond cofactor 1 and prime order to choose a secure Elliptic Curve.
For toy parameters, one option is to find the order of a random point on a random Elliptic Curve (determined as for G
) until finding one of prime order.
FIPS 186-3
. Found there:"value of G should be generated canonically (verifiably random)." Are you sure about:"Not every elliptic curve group has a generator"? # about the question in the end: trying to implement curve generation for ECDSA; – Abridgecofactor
= (curve cardinality)/(point order), where cardinality is a number of the points on the curve. – Abridge