[crypto] Expose the (prime) group order as an elliptic curve property

ECDSA requires knowledge of the group order of the base point, and is
defined only for curves with a prime group order (e.g. the NIST
curves).

Add the group order as an explicit property of an elliptic curve, and
add tests to verify that the order is correct.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-12-05 14:47:55 +00:00
parent 80e98dc0d1
commit d3adea8380
8 changed files with 82 additions and 3 deletions

View File

@@ -183,6 +183,8 @@ struct elliptic_curve {
size_t keysize;
/** Generator base point */
const void *base;
/** Order of the generator (if prime) */
const void *order;
/** Multiply scalar by curve point
*
* @v base Base point

View File

@@ -128,7 +128,8 @@ extern int weierstrass_multiply ( struct weierstrass_curve *curve,
void *result );
/** Define a Weierstrass curve */
#define WEIERSTRASS_CURVE( _name, _curve, _len, _prime, _a, _b, _base ) \
#define WEIERSTRASS_CURVE( _name, _curve, _len, _prime, _a, _b, _base, \
_order ) \
static bigint_t ( weierstrass_size(_len) ) \
_name ## _cache[WEIERSTRASS_NUM_CACHED]; \
static struct weierstrass_curve _name ## _weierstrass = { \
@@ -161,6 +162,7 @@ extern int weierstrass_multiply ( struct weierstrass_curve *curve,
.pointsize = ( WEIERSTRASS_AXES * (_len) ), \
.keysize = (_len), \
.base = (_base), \
.order = (_order), \
.multiply = _name ## _multiply, \
}