[crypto] Expose the base point as an explicit elliptic curve property

Add the generator base point as an explicit property of an elliptic
curve, and remove the ability to pass a NULL to elliptic_multiply() to
imply the use of the generator base point.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-12-05 13:00:12 +00:00
parent 88c3e68dfb
commit e50e30a7f8
6 changed files with 11 additions and 14 deletions

View File

@@ -55,7 +55,7 @@ int ecdhe_key ( struct elliptic_curve *curve, const void *partner,
}
/* Construct public key */
if ( ( rc = elliptic_multiply ( curve, NULL, private,
if ( ( rc = elliptic_multiply ( curve, curve->base, private,
public ) ) != 0 ) {
DBGC ( curve, "CURVE %s could not generate public key: %s\n",
curve->name, strerror ( rc ) );

View File

@@ -762,7 +762,7 @@ static int weierstrass_verify_raw ( const struct weierstrass_curve *curve,
* Multiply curve point by scalar
*
* @v curve Weierstrass curve
* @v base Base point (or NULL to use generator)
* @v base Base point
* @v scalar Scalar multiple
* @v result Result point to fill in
* @ret rc Return status code
@@ -806,10 +806,6 @@ int weierstrass_multiply ( struct weierstrass_curve *curve, const void *base,
if ( ! prime2->element[0] )
weierstrass_init ( curve );
/* Use generator if applicable */
if ( ! base )
base = curve->base;
/* Convert input to projective coordinates in Montgomery form */
DBGC ( curve, "WEIERSTRASS %s base (", curve->name );
for ( i = 0, offset = 0 ; i < WEIERSTRASS_AXES ; i++, offset += len ) {

View File

@@ -822,7 +822,7 @@ int x25519_key ( const struct x25519_value *base,
/**
* Multiply scalar by curve point
*
* @v base Base point (or NULL to use generator)
* @v base Base point
* @v scalar Scalar multiple
* @v result Result point to fill in
* @ret rc Return status code
@@ -830,10 +830,6 @@ int x25519_key ( const struct x25519_value *base,
static int x25519_curve_multiply ( const void *base, const void *scalar,
void *result ) {
/* Use base point if applicable */
if ( ! base )
base = &x25519_generator;
return x25519_key ( base, scalar, result );
}
@@ -842,5 +838,6 @@ struct elliptic_curve x25519_curve = {
.name = "x25519",
.pointsize = sizeof ( struct x25519_value ),
.keysize = sizeof ( struct x25519_value ),
.base = x25519_generator.raw,
.multiply = x25519_curve_multiply,
};

View File

@@ -181,9 +181,11 @@ struct elliptic_curve {
size_t pointsize;
/** Scalar (and private key) size */
size_t keysize;
/** Generator base point */
const void *base;
/** Multiply scalar by curve point
*
* @v base Base point (or NULL to use generator)
* @v base Base point
* @v scalar Scalar multiple
* @v result Result point to fill in
* @ret rc Return status code

View File

@@ -160,6 +160,7 @@ extern int weierstrass_multiply ( struct weierstrass_curve *curve,
.name = #_name, \
.pointsize = ( WEIERSTRASS_AXES * (_len) ), \
.keysize = (_len), \
.base = (_base), \
.multiply = _name ## _multiply, \
}

View File

@@ -52,6 +52,7 @@ void elliptic_okx ( struct elliptic_test *test, const char *file,
size_t pointsize = curve->pointsize;
size_t keysize = curve->keysize;
uint8_t actual[pointsize];
const void *base;
int rc;
/* Sanity checks */
@@ -62,8 +63,8 @@ void elliptic_okx ( struct elliptic_test *test, const char *file,
file, line );
/* Perform point multiplication */
rc = elliptic_multiply ( curve, ( test->base_len ? test->base : NULL ),
test->scalar, actual );
base = ( test->base_len ? test->base : curve->base );
rc = elliptic_multiply ( curve, base, test->scalar, actual );
if ( test->expected_len ) {
okx ( rc == 0, file, line );
} else {