mirror of
https://github.com/ipxe/ipxe
synced 2026-06-29 00:07:28 +03:00
[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:
+6
-6
@@ -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 private Private key
|
||||
* @v public Public key to fill in
|
||||
*/
|
||||
void ffdhe_public ( struct exchange_algorithm *exchange, const void *private,
|
||||
void *public ) {
|
||||
void ffdhe_share ( struct exchange_algorithm *exchange, const void *private,
|
||||
void *public ) {
|
||||
struct ffdhe_group *group = exchange->priv;
|
||||
|
||||
ffdhe ( group, NULL, private, public );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate shared secret
|
||||
* Agree shared secret
|
||||
*
|
||||
* @v exchange Key exchange algorithm
|
||||
* @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
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int ffdhe_shared ( struct exchange_algorithm *exchange, const void *private,
|
||||
const void *partner, void *shared ) {
|
||||
int ffdhe_agree ( struct exchange_algorithm *exchange, const void *private,
|
||||
const void *partner, void *shared ) {
|
||||
struct ffdhe_group *group = exchange->priv;
|
||||
|
||||
return ffdhe ( group, partner, private, shared );
|
||||
|
||||
@@ -1028,14 +1028,14 @@ 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,
|
||||
const void *private, void *public ) {
|
||||
void weierstrass_share ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public ) {
|
||||
struct weierstrass_curve *curve = exchange->priv;
|
||||
size_t len = curve->len;
|
||||
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 private Private key
|
||||
@@ -1059,9 +1059,9 @@ 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,
|
||||
const void *private, const void *partner,
|
||||
void *shared ) {
|
||||
int weierstrass_agree ( struct exchange_algorithm *exchange,
|
||||
const void *private, const void *partner,
|
||||
void *shared ) {
|
||||
struct weierstrass_curve *curve = exchange->priv;
|
||||
size_t len = curve->len;
|
||||
const weierstrass_uncompressed_t ( len ) *uncompressed = partner;
|
||||
|
||||
+9
-9
@@ -831,21 +831,21 @@ 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,
|
||||
const void *private, void *public ) {
|
||||
static void x25519_share ( struct exchange_algorithm *exchange __unused,
|
||||
const void *private, void *public ) {
|
||||
|
||||
/* Calculate public key */
|
||||
x25519_key ( &x25519_generator, private, public );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate shared secret
|
||||
* Agree shared secret
|
||||
*
|
||||
* @v exchange Key exchange algorithm
|
||||
* @v private Private key
|
||||
@@ -853,9 +853,9 @@ 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,
|
||||
const void *private, const void *partner,
|
||||
void *shared ) {
|
||||
static int x25519_agree ( struct exchange_algorithm *exchange __unused,
|
||||
const void *private, const void *partner,
|
||||
void *shared ) {
|
||||
|
||||
/* Calculate shared secret */
|
||||
x25519_key ( partner, private, 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,
|
||||
};
|
||||
|
||||
+13
-13
@@ -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,
|
||||
const void *private, void *public );
|
||||
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,9 +202,9 @@ struct exchange_algorithm {
|
||||
* @v shared Shared secret to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int ( * shared ) ( struct exchange_algorithm *exchange,
|
||||
const void *private, const void *partner,
|
||||
void *shared );
|
||||
int ( * agree ) ( struct exchange_algorithm *exchange,
|
||||
const void *private, const void *partner,
|
||||
void *shared );
|
||||
/** Algorithm private data */
|
||||
void *priv;
|
||||
};
|
||||
@@ -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,
|
||||
void *public ) {
|
||||
exchange->public ( exchange, private, public );
|
||||
exchange_share ( struct exchange_algorithm *exchange, const void *private,
|
||||
void *public ) {
|
||||
exchange->share ( exchange, private, public );
|
||||
}
|
||||
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
exchange_shared ( struct exchange_algorithm *exchange, const void *private,
|
||||
const void *partner, void *shared ) {
|
||||
return exchange->shared ( exchange, private, partner, shared );
|
||||
exchange_agree ( struct exchange_algorithm *exchange, const void *private,
|
||||
const void *partner, void *shared ) {
|
||||
return exchange->agree ( exchange, private, partner, shared );
|
||||
}
|
||||
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
|
||||
@@ -33,11 +33,11 @@ struct ffdhe_group {
|
||||
uint32_t lsb32;
|
||||
};
|
||||
|
||||
extern void ffdhe_public ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public );
|
||||
extern int ffdhe_shared ( struct exchange_algorithm *exchange,
|
||||
const void *private, const void *partner,
|
||||
void *shared );
|
||||
extern void ffdhe_share ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public );
|
||||
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,
|
||||
const void *modulus, size_t 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
|
||||
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, \
|
||||
}
|
||||
|
||||
|
||||
@@ -164,11 +164,11 @@ 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,
|
||||
const void *private, void *public );
|
||||
extern int weierstrass_shared ( struct exchange_algorithm *exchange,
|
||||
const void *private, const void *partner,
|
||||
void *shared );
|
||||
extern void weierstrass_share ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public );
|
||||
extern int weierstrass_agree ( struct exchange_algorithm *exchange,
|
||||
const void *private, const void *partner,
|
||||
void *shared );
|
||||
|
||||
/** Define a Weierstrass curve */
|
||||
#define WEIERSTRASS_CURVE( _name, _curve, _exchange, _len, _prime, \
|
||||
@@ -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, \
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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,8 +1771,8 @@ static int tls_send_client_key_exchange_ecdhe ( struct tls_connection *tls ) {
|
||||
}
|
||||
|
||||
/* Generate pre-master secret */
|
||||
if ( ( rc = exchange_shared ( exchange, private, ecdh->public,
|
||||
pre_master_secret ) ) != 0 ) {
|
||||
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 ) );
|
||||
return rc;
|
||||
|
||||
@@ -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,8 +76,8 @@ 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,
|
||||
actual->shared );
|
||||
rc = exchange_agree ( exchange, test->private, test->partner,
|
||||
actual->shared );
|
||||
if ( test->shared_len ) {
|
||||
/* Verify successful calculation */
|
||||
okx ( rc == 0, file, line );
|
||||
|
||||
Reference in New Issue
Block a user