From e50e30a7f8eafea0a1975c555a6fdcab35d8243a Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 5 Dec 2025 13:00:12 +0000 Subject: [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 --- src/crypto/ecdhe.c | 2 +- src/crypto/weierstrass.c | 6 +----- src/crypto/x25519.c | 7 ++----- 3 files changed, 4 insertions(+), 11 deletions(-) (limited to 'src/crypto') diff --git a/src/crypto/ecdhe.c b/src/crypto/ecdhe.c index 5481b02eb..592c8ca1a 100644 --- a/src/crypto/ecdhe.c +++ b/src/crypto/ecdhe.c @@ -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 ) ); diff --git a/src/crypto/weierstrass.c b/src/crypto/weierstrass.c index c149c7b21..4974e5252 100644 --- a/src/crypto/weierstrass.c +++ b/src/crypto/weierstrass.c @@ -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 ) { diff --git a/src/crypto/x25519.c b/src/crypto/x25519.c index 41bc5fc5e..00a791877 100644 --- a/src/crypto/x25519.c +++ b/src/crypto/x25519.c @@ -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, }; -- cgit v1.2.3-55-g7522