[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
+4 -4
View File
@@ -255,13 +255,13 @@ static int ffdhe ( struct ffdhe_group *group, const void *public,
}
/**
* Calculate public key
* Share public key
*
* @v exchange Key exchange algorithm
* @v private Private key
* @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 ) {
struct ffdhe_group *group = exchange->priv;
@@ -269,7 +269,7 @@ void ffdhe_public ( struct exchange_algorithm *exchange, const void *private,
}
/**
* Calculate shared secret
* Agree shared secret
*
* @v exchange Key exchange algorithm
* @v private Private key
@@ -277,7 +277,7 @@ void ffdhe_public ( struct exchange_algorithm *exchange, const void *private,
* @v shared Shared secret to fill in
* @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 ) {
struct ffdhe_group *group = exchange->priv;
+4 -4
View File
@@ -1028,13 +1028,13 @@ int weierstrass_add_once ( struct weierstrass_curve *curve,
}
/**
* Calculate public key
* Share public key
*
* @v exchange Key exchange algorithm
* @v private Private key
* @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 ) {
struct weierstrass_curve *curve = exchange->priv;
size_t len = curve->len;
@@ -1051,7 +1051,7 @@ void weierstrass_public ( struct exchange_algorithm *exchange,
}
/**
* Calculate shared secret
* Agree shared secret
*
* @v exchange Key exchange algorithm
* @v private Private key
@@ -1059,7 +1059,7 @@ void weierstrass_public ( struct exchange_algorithm *exchange,
* @v shared Shared secret to fill in
* @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,
void *shared ) {
struct weierstrass_curve *curve = exchange->priv;
+6 -6
View File
@@ -831,13 +831,13 @@ void x25519_key ( const struct x25519_value *base,
}
/**
* Calculate public key
* Share public key
*
* @v exchange Key exchange algorithm
* @v private Private key
* @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 ) {
/* Calculate public key */
@@ -845,7 +845,7 @@ static void x25519_public ( struct exchange_algorithm *exchange __unused,
}
/**
* Calculate shared secret
* Agree shared secret
*
* @v exchange Key exchange algorithm
* @v private Private key
@@ -853,7 +853,7 @@ static void x25519_public ( struct exchange_algorithm *exchange __unused,
* @v shared Shared secret to fill in
* @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,
void *shared ) {
@@ -873,6 +873,6 @@ struct exchange_algorithm x25519_algorithm = {
.privsize = sizeof ( struct x25519_value ),
.pubsize = sizeof ( struct x25519_value ),
.sharedsize = sizeof ( struct x25519_value ),
.public = x25519_public,
.shared = x25519_shared,
.share = x25519_share,
.agree = x25519_agree,
};
+8 -8
View File
@@ -185,16 +185,16 @@ struct exchange_algorithm {
/** Shared secret size */
size_t sharedsize;
/**
* Calculate public key
* Share public key
*
* @v exchange Key exchange algorithm
* @v private Private key
* @v public Public key to fill in
*/
void ( * public ) ( struct exchange_algorithm *exchange,
void ( * share ) ( struct exchange_algorithm *exchange,
const void *private, void *public );
/**
* Calculate shared secret
* Agree shared secret
*
* @v exchange Key exchange algorithm
* @v private Private key
@@ -202,7 +202,7 @@ struct exchange_algorithm {
* @v shared Shared secret to fill in
* @ret rc Return status code
*/
int ( * shared ) ( struct exchange_algorithm *exchange,
int ( * agree ) ( struct exchange_algorithm *exchange,
const void *private, const void *partner,
void *shared );
/** Algorithm private data */
@@ -354,15 +354,15 @@ pubkey_match ( struct pubkey_algorithm *pubkey,
}
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 ) {
exchange->public ( exchange, private, public );
exchange->share ( exchange, private, public );
}
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 ) {
return exchange->shared ( exchange, private, partner, shared );
return exchange->agree ( exchange, private, partner, shared );
}
static inline __attribute__ (( always_inline )) int
+5 -5
View File
@@ -33,9 +33,9 @@ struct ffdhe_group {
uint32_t lsb32;
};
extern void ffdhe_public ( struct exchange_algorithm *exchange,
extern void ffdhe_share ( struct exchange_algorithm *exchange,
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,
void *shared );
extern int ffdhe_has_params ( struct exchange_algorithm *exchange,
@@ -51,7 +51,7 @@ extern int ffdhe_has_params ( struct exchange_algorithm *exchange,
static inline __attribute__ (( always_inline )) int
is_ffdhe ( struct exchange_algorithm *exchange ) {
return ( exchange->public == ffdhe_public );
return ( exchange->share == ffdhe_share );
}
/** Define a finite field DHE group */
@@ -70,8 +70,8 @@ is_ffdhe ( struct exchange_algorithm *exchange ) {
.privsize = ( ( _expbits + 7 ) / 8 ), \
.pubsize = ( _bits / 8 ), \
.sharedsize = ( _bits / 8 ), \
.public = ffdhe_public, \
.shared = ffdhe_shared, \
.share = ffdhe_share, \
.agree = ffdhe_agree, \
.priv = &_name ## _group, \
}
+4 -4
View File
@@ -164,9 +164,9 @@ extern int weierstrass_multiply ( struct weierstrass_curve *curve,
extern int weierstrass_add_once ( struct weierstrass_curve *curve,
const void *addend, const void *augend,
void *result );
extern void weierstrass_public ( struct exchange_algorithm *exchange,
extern void weierstrass_share ( struct exchange_algorithm *exchange,
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,
void *shared );
@@ -224,8 +224,8 @@ extern int weierstrass_shared ( struct exchange_algorithm *exchange,
.privsize = (_len), \
.pubsize = sizeof ( weierstrass_uncompressed_t(_len) ), \
.sharedsize = (_len), \
.public = weierstrass_public, \
.shared = weierstrass_shared, \
.share = weierstrass_share, \
.agree = weierstrass_agree, \
.priv = &_name ## _weierstrass, \
}
+2 -2
View File
@@ -1762,7 +1762,7 @@ static int tls_send_client_key_exchange_ecdhe ( struct tls_connection *tls ) {
htonl ( sizeof ( key_xchg ) -
sizeof ( key_xchg.type_length ) ) );
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 */
if ( ( rc = tls_send_handshake ( tls, &key_xchg,
@@ -1771,7 +1771,7 @@ static int tls_send_client_key_exchange_ecdhe ( struct tls_connection *tls ) {
}
/* Generate pre-master secret */
if ( ( rc = exchange_shared ( exchange, private, ecdh->public,
if ( ( rc = exchange_agree ( exchange, private, ecdh->public,
pre_master_secret ) ) != 0 ) {
DBGC ( tls, "TLS %p could not exchange keys: %s\n",
tls, strerror ( rc ) );
+2 -2
View File
@@ -67,7 +67,7 @@ void exchange_okx ( struct exchange_test *test, const char *file,
/* Verify calculation of public key */
DBGC ( test, "KEX %s private key:\n", exchange->name );
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_HDA ( test, 0, actual->public, exchange->pubsize );
okx ( memcmp ( actual->public, test->public, exchange->pubsize ) == 0,
@@ -76,7 +76,7 @@ void exchange_okx ( struct exchange_test *test, const char *file,
/* Verify calculation of shared secret */
DBGC ( test, "KEX %s partner key:\n", exchange->name );
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 );
if ( test->shared_len ) {
/* Verify successful calculation */