[crypto] Use verbs in key exchange method names

Almost all cryptographic algorithm method names are currently verbs
(e.g. pubkey_sign(), cipher_encrypt(), digest_update(), etc).

Rename the two key exchange methods to also use verbs, for the sake of
consistency and to better match the TLS usage of "key_share".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2026-06-18 12:11:31 +01:00
parent bbb6477be3
commit 38fc660d8b
8 changed files with 56 additions and 56 deletions
+6 -6
View File
@@ -255,21 +255,21 @@ static int ffdhe ( struct ffdhe_group *group, const void *public,
} }
/** /**
* Calculate public key * Share public key
* *
* @v exchange Key exchange algorithm * @v exchange Key exchange algorithm
* @v private Private key * @v private Private key
* @v public Public key to fill in * @v public Public key to fill in
*/ */
void ffdhe_public ( struct exchange_algorithm *exchange, const void *private, void ffdhe_share ( struct exchange_algorithm *exchange, const void *private,
void *public ) { void *public ) {
struct ffdhe_group *group = exchange->priv; struct ffdhe_group *group = exchange->priv;
ffdhe ( group, NULL, private, public ); ffdhe ( group, NULL, private, public );
} }
/** /**
* Calculate shared secret * Agree shared secret
* *
* @v exchange Key exchange algorithm * @v exchange Key exchange algorithm
* @v private Private key * @v private Private key
@@ -277,8 +277,8 @@ void ffdhe_public ( struct exchange_algorithm *exchange, const void *private,
* @v shared Shared secret to fill in * @v shared Shared secret to fill in
* @ret rc Return status code * @ret rc Return status code
*/ */
int ffdhe_shared ( struct exchange_algorithm *exchange, const void *private, int ffdhe_agree ( struct exchange_algorithm *exchange, const void *private,
const void *partner, void *shared ) { const void *partner, void *shared ) {
struct ffdhe_group *group = exchange->priv; struct ffdhe_group *group = exchange->priv;
return ffdhe ( group, partner, private, shared ); return ffdhe ( group, partner, private, shared );
+7 -7
View File
@@ -1028,14 +1028,14 @@ int weierstrass_add_once ( struct weierstrass_curve *curve,
} }
/** /**
* Calculate public key * Share public key
* *
* @v exchange Key exchange algorithm * @v exchange Key exchange algorithm
* @v private Private key * @v private Private key
* @v public Public key to fill in * @v public Public key to fill in
*/ */
void weierstrass_public ( struct exchange_algorithm *exchange, void weierstrass_share ( struct exchange_algorithm *exchange,
const void *private, void *public ) { const void *private, void *public ) {
struct weierstrass_curve *curve = exchange->priv; struct weierstrass_curve *curve = exchange->priv;
size_t len = curve->len; size_t len = curve->len;
weierstrass_uncompressed_t ( len ) *uncompressed = public; weierstrass_uncompressed_t ( len ) *uncompressed = public;
@@ -1051,7 +1051,7 @@ void weierstrass_public ( struct exchange_algorithm *exchange,
} }
/** /**
* Calculate shared secret * Agree shared secret
* *
* @v exchange Key exchange algorithm * @v exchange Key exchange algorithm
* @v private Private key * @v private Private key
@@ -1059,9 +1059,9 @@ void weierstrass_public ( struct exchange_algorithm *exchange,
* @v shared Shared secret to fill in * @v shared Shared secret to fill in
* @ret rc Return status code * @ret rc Return status code
*/ */
int weierstrass_shared ( struct exchange_algorithm *exchange, int weierstrass_agree ( struct exchange_algorithm *exchange,
const void *private, const void *partner, const void *private, const void *partner,
void *shared ) { void *shared ) {
struct weierstrass_curve *curve = exchange->priv; struct weierstrass_curve *curve = exchange->priv;
size_t len = curve->len; size_t len = curve->len;
const weierstrass_uncompressed_t ( len ) *uncompressed = partner; const weierstrass_uncompressed_t ( len ) *uncompressed = partner;
+9 -9
View File
@@ -831,21 +831,21 @@ void x25519_key ( const struct x25519_value *base,
} }
/** /**
* Calculate public key * Share public key
* *
* @v exchange Key exchange algorithm * @v exchange Key exchange algorithm
* @v private Private key * @v private Private key
* @v public Public key to fill in * @v public Public key to fill in
*/ */
static void x25519_public ( struct exchange_algorithm *exchange __unused, static void x25519_share ( struct exchange_algorithm *exchange __unused,
const void *private, void *public ) { const void *private, void *public ) {
/* Calculate public key */ /* Calculate public key */
x25519_key ( &x25519_generator, private, public ); x25519_key ( &x25519_generator, private, public );
} }
/** /**
* Calculate shared secret * Agree shared secret
* *
* @v exchange Key exchange algorithm * @v exchange Key exchange algorithm
* @v private Private key * @v private Private key
@@ -853,9 +853,9 @@ static void x25519_public ( struct exchange_algorithm *exchange __unused,
* @v shared Shared secret to fill in * @v shared Shared secret to fill in
* @ret rc Return status code * @ret rc Return status code
*/ */
static int x25519_shared ( struct exchange_algorithm *exchange __unused, static int x25519_agree ( struct exchange_algorithm *exchange __unused,
const void *private, const void *partner, const void *private, const void *partner,
void *shared ) { void *shared ) {
/* Calculate shared secret */ /* Calculate shared secret */
x25519_key ( partner, private, shared ); x25519_key ( partner, private, shared );
@@ -873,6 +873,6 @@ struct exchange_algorithm x25519_algorithm = {
.privsize = sizeof ( struct x25519_value ), .privsize = sizeof ( struct x25519_value ),
.pubsize = sizeof ( struct x25519_value ), .pubsize = sizeof ( struct x25519_value ),
.sharedsize = sizeof ( struct x25519_value ), .sharedsize = sizeof ( struct x25519_value ),
.public = x25519_public, .share = x25519_share,
.shared = x25519_shared, .agree = x25519_agree,
}; };
+13 -13
View File
@@ -185,16 +185,16 @@ struct exchange_algorithm {
/** Shared secret size */ /** Shared secret size */
size_t sharedsize; size_t sharedsize;
/** /**
* Calculate public key * Share public key
* *
* @v exchange Key exchange algorithm * @v exchange Key exchange algorithm
* @v private Private key * @v private Private key
* @v public Public key to fill in * @v public Public key to fill in
*/ */
void ( * public ) ( struct exchange_algorithm *exchange, void ( * share ) ( struct exchange_algorithm *exchange,
const void *private, void *public ); const void *private, void *public );
/** /**
* Calculate shared secret * Agree shared secret
* *
* @v exchange Key exchange algorithm * @v exchange Key exchange algorithm
* @v private Private key * @v private Private key
@@ -202,9 +202,9 @@ struct exchange_algorithm {
* @v shared Shared secret to fill in * @v shared Shared secret to fill in
* @ret rc Return status code * @ret rc Return status code
*/ */
int ( * shared ) ( struct exchange_algorithm *exchange, int ( * agree ) ( struct exchange_algorithm *exchange,
const void *private, const void *partner, const void *private, const void *partner,
void *shared ); void *shared );
/** Algorithm private data */ /** Algorithm private data */
void *priv; void *priv;
}; };
@@ -354,15 +354,15 @@ pubkey_match ( struct pubkey_algorithm *pubkey,
} }
static inline __attribute__ (( always_inline )) void static inline __attribute__ (( always_inline )) void
exchange_public ( struct exchange_algorithm *exchange, const void *private, exchange_share ( struct exchange_algorithm *exchange, const void *private,
void *public ) { void *public ) {
exchange->public ( exchange, private, public ); exchange->share ( exchange, private, public );
} }
static inline __attribute__ (( always_inline )) int static inline __attribute__ (( always_inline )) int
exchange_shared ( struct exchange_algorithm *exchange, const void *private, exchange_agree ( struct exchange_algorithm *exchange, const void *private,
const void *partner, void *shared ) { const void *partner, void *shared ) {
return exchange->shared ( exchange, private, partner, shared ); return exchange->agree ( exchange, private, partner, shared );
} }
static inline __attribute__ (( always_inline )) int static inline __attribute__ (( always_inline )) int
+8 -8
View File
@@ -33,11 +33,11 @@ struct ffdhe_group {
uint32_t lsb32; uint32_t lsb32;
}; };
extern void ffdhe_public ( struct exchange_algorithm *exchange, extern void ffdhe_share ( struct exchange_algorithm *exchange,
const void *private, void *public ); const void *private, void *public );
extern int ffdhe_shared ( struct exchange_algorithm *exchange, extern int ffdhe_agree ( struct exchange_algorithm *exchange,
const void *private, const void *partner, const void *private, const void *partner,
void *shared ); void *shared );
extern int ffdhe_has_params ( struct exchange_algorithm *exchange, extern int ffdhe_has_params ( struct exchange_algorithm *exchange,
const void *modulus, size_t len, const void *modulus, size_t len,
const void *generator, size_t generator_len ); const void *generator, size_t generator_len );
@@ -51,7 +51,7 @@ extern int ffdhe_has_params ( struct exchange_algorithm *exchange,
static inline __attribute__ (( always_inline )) int static inline __attribute__ (( always_inline )) int
is_ffdhe ( struct exchange_algorithm *exchange ) { is_ffdhe ( struct exchange_algorithm *exchange ) {
return ( exchange->public == ffdhe_public ); return ( exchange->share == ffdhe_share );
} }
/** Define a finite field DHE group */ /** Define a finite field DHE group */
@@ -70,8 +70,8 @@ is_ffdhe ( struct exchange_algorithm *exchange ) {
.privsize = ( ( _expbits + 7 ) / 8 ), \ .privsize = ( ( _expbits + 7 ) / 8 ), \
.pubsize = ( _bits / 8 ), \ .pubsize = ( _bits / 8 ), \
.sharedsize = ( _bits / 8 ), \ .sharedsize = ( _bits / 8 ), \
.public = ffdhe_public, \ .share = ffdhe_share, \
.shared = ffdhe_shared, \ .agree = ffdhe_agree, \
.priv = &_name ## _group, \ .priv = &_name ## _group, \
} }
+7 -7
View File
@@ -164,11 +164,11 @@ extern int weierstrass_multiply ( struct weierstrass_curve *curve,
extern int weierstrass_add_once ( struct weierstrass_curve *curve, extern int weierstrass_add_once ( struct weierstrass_curve *curve,
const void *addend, const void *augend, const void *addend, const void *augend,
void *result ); void *result );
extern void weierstrass_public ( struct exchange_algorithm *exchange, extern void weierstrass_share ( struct exchange_algorithm *exchange,
const void *private, void *public ); const void *private, void *public );
extern int weierstrass_shared ( struct exchange_algorithm *exchange, extern int weierstrass_agree ( struct exchange_algorithm *exchange,
const void *private, const void *partner, const void *private, const void *partner,
void *shared ); void *shared );
/** Define a Weierstrass curve */ /** Define a Weierstrass curve */
#define WEIERSTRASS_CURVE( _name, _curve, _exchange, _len, _prime, \ #define WEIERSTRASS_CURVE( _name, _curve, _exchange, _len, _prime, \
@@ -224,8 +224,8 @@ extern int weierstrass_shared ( struct exchange_algorithm *exchange,
.privsize = (_len), \ .privsize = (_len), \
.pubsize = sizeof ( weierstrass_uncompressed_t(_len) ), \ .pubsize = sizeof ( weierstrass_uncompressed_t(_len) ), \
.sharedsize = (_len), \ .sharedsize = (_len), \
.public = weierstrass_public, \ .share = weierstrass_share, \
.shared = weierstrass_shared, \ .agree = weierstrass_agree, \
.priv = &_name ## _weierstrass, \ .priv = &_name ## _weierstrass, \
} }
+3 -3
View File
@@ -1762,7 +1762,7 @@ static int tls_send_client_key_exchange_ecdhe ( struct tls_connection *tls ) {
htonl ( sizeof ( key_xchg ) - htonl ( sizeof ( key_xchg ) -
sizeof ( key_xchg.type_length ) ) ); sizeof ( key_xchg.type_length ) ) );
key_xchg.public_len = sizeof ( key_xchg.public ); key_xchg.public_len = sizeof ( key_xchg.public );
exchange_public ( exchange, private, key_xchg.public ); exchange_share ( exchange, private, key_xchg.public );
/* Transmit Client Key Exchange record */ /* Transmit Client Key Exchange record */
if ( ( rc = tls_send_handshake ( tls, &key_xchg, if ( ( rc = tls_send_handshake ( tls, &key_xchg,
@@ -1771,8 +1771,8 @@ static int tls_send_client_key_exchange_ecdhe ( struct tls_connection *tls ) {
} }
/* Generate pre-master secret */ /* Generate pre-master secret */
if ( ( rc = exchange_shared ( exchange, private, ecdh->public, if ( ( rc = exchange_agree ( exchange, private, ecdh->public,
pre_master_secret ) ) != 0 ) { pre_master_secret ) ) != 0 ) {
DBGC ( tls, "TLS %p could not exchange keys: %s\n", DBGC ( tls, "TLS %p could not exchange keys: %s\n",
tls, strerror ( rc ) ); tls, strerror ( rc ) );
return rc; return rc;
+3 -3
View File
@@ -67,7 +67,7 @@ void exchange_okx ( struct exchange_test *test, const char *file,
/* Verify calculation of public key */ /* Verify calculation of public key */
DBGC ( test, "KEX %s private key:\n", exchange->name ); DBGC ( test, "KEX %s private key:\n", exchange->name );
DBGC_HDA ( test, 0, test->private, exchange->privsize ); DBGC_HDA ( test, 0, test->private, exchange->privsize );
exchange_public ( exchange, test->private, actual->public ); exchange_share ( exchange, test->private, actual->public );
DBGC ( test, "KEX %s public key:\n", exchange->name ); DBGC ( test, "KEX %s public key:\n", exchange->name );
DBGC_HDA ( test, 0, actual->public, exchange->pubsize ); DBGC_HDA ( test, 0, actual->public, exchange->pubsize );
okx ( memcmp ( actual->public, test->public, exchange->pubsize ) == 0, okx ( memcmp ( actual->public, test->public, exchange->pubsize ) == 0,
@@ -76,8 +76,8 @@ void exchange_okx ( struct exchange_test *test, const char *file,
/* Verify calculation of shared secret */ /* Verify calculation of shared secret */
DBGC ( test, "KEX %s partner key:\n", exchange->name ); DBGC ( test, "KEX %s partner key:\n", exchange->name );
DBGC_HDA ( test, 0, test->partner, exchange->pubsize ); DBGC_HDA ( test, 0, test->partner, exchange->pubsize );
rc = exchange_shared ( exchange, test->private, test->partner, rc = exchange_agree ( exchange, test->private, test->partner,
actual->shared ); actual->shared );
if ( test->shared_len ) { if ( test->shared_len ) {
/* Verify successful calculation */ /* Verify successful calculation */
okx ( rc == 0, file, line ); okx ( rc == 0, file, line );