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, }; diff --git a/src/include/ipxe/crypto.h b/src/include/ipxe/crypto.h index ee63423c9..d2adea5d6 100644 --- a/src/include/ipxe/crypto.h +++ b/src/include/ipxe/crypto.h @@ -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 diff --git a/src/include/ipxe/weierstrass.h b/src/include/ipxe/weierstrass.h index fb09fa6fa..e5e411499 100644 --- a/src/include/ipxe/weierstrass.h +++ b/src/include/ipxe/weierstrass.h @@ -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, \ } diff --git a/src/tests/elliptic_test.c b/src/tests/elliptic_test.c index 4c42e5848..d8cdf2c0f 100644 --- a/src/tests/elliptic_test.c +++ b/src/tests/elliptic_test.c @@ -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 {