Rename diffie_hellman_t to key_exchange_t and change the interface etc.

This makes it more generic so we can use it for QSKE methods.
This commit is contained in:
Tobias Brunner
2022-06-29 10:28:50 +02:00
parent ec95fd9b93
commit 3af7c6db87
130 changed files with 1379 additions and 1384 deletions
@@ -41,7 +41,7 @@ struct private_gmp_diffie_hellman_t {
/**
* Diffie Hellman group number.
*/
diffie_hellman_group_t group;
key_exchange_method_t group;
/*
* Generator value.
@@ -84,12 +84,12 @@ struct private_gmp_diffie_hellman_t {
bool computed;
};
METHOD(diffie_hellman_t, set_other_public_value, bool,
METHOD(key_exchange_t, set_public_key, bool,
private_gmp_diffie_hellman_t *this, chunk_t value)
{
mpz_t p_min_1;
if (!diffie_hellman_verify_value(this->group, value))
if (!key_exchange_verify_pubkey(this->group, value))
{
return FALSE;
}
@@ -149,7 +149,7 @@ METHOD(diffie_hellman_t, set_other_public_value, bool,
return this->computed;
}
METHOD(diffie_hellman_t, get_my_public_value, bool,
METHOD(key_exchange_t, get_public_key, bool,
private_gmp_diffie_hellman_t *this,chunk_t *value)
{
value->len = this->p_len;
@@ -161,7 +161,7 @@ METHOD(diffie_hellman_t, get_my_public_value, bool,
return TRUE;
}
METHOD(diffie_hellman_t, set_private_value, bool,
METHOD(key_exchange_t, set_private_key, bool,
private_gmp_diffie_hellman_t *this, chunk_t value)
{
mpz_import(this->xa, value.len, 1, 1, 1, 0, value.ptr);
@@ -170,7 +170,7 @@ METHOD(diffie_hellman_t, set_private_value, bool,
return TRUE;
}
METHOD(diffie_hellman_t, get_shared_secret, bool,
METHOD(key_exchange_t, get_shared_secret, bool,
private_gmp_diffie_hellman_t *this, chunk_t *secret)
{
if (!this->computed)
@@ -186,13 +186,13 @@ METHOD(diffie_hellman_t, get_shared_secret, bool,
return TRUE;
}
METHOD(diffie_hellman_t, get_dh_group, diffie_hellman_group_t,
METHOD(key_exchange_t, get_method, key_exchange_method_t,
private_gmp_diffie_hellman_t *this)
{
return this->group;
}
METHOD(diffie_hellman_t, destroy, void,
METHOD(key_exchange_t, destroy, void,
private_gmp_diffie_hellman_t *this)
{
mpz_clear(this->p);
@@ -207,7 +207,7 @@ METHOD(diffie_hellman_t, destroy, void,
/**
* Generic internal constructor
*/
static gmp_diffie_hellman_t *create_generic(diffie_hellman_group_t group,
static gmp_diffie_hellman_t *create_generic(key_exchange_method_t group,
size_t exp_len, chunk_t g, chunk_t p)
{
private_gmp_diffie_hellman_t *this;
@@ -216,12 +216,12 @@ static gmp_diffie_hellman_t *create_generic(diffie_hellman_group_t group,
INIT(this,
.public = {
.dh = {
.ke = {
.get_shared_secret = _get_shared_secret,
.set_other_public_value = _set_other_public_value,
.get_my_public_value = _get_my_public_value,
.set_private_value = _set_private_value,
.get_dh_group = _get_dh_group,
.set_public_key = _set_public_key,
.get_public_key = _get_public_key,
.set_private_key = _set_private_key,
.get_method = _get_method,
.destroy = _destroy,
},
},
@@ -273,7 +273,7 @@ static gmp_diffie_hellman_t *create_generic(diffie_hellman_group_t group,
/*
* Described in header
*/
gmp_diffie_hellman_t *gmp_diffie_hellman_create(diffie_hellman_group_t group)
gmp_diffie_hellman_t *gmp_diffie_hellman_create(key_exchange_method_t group)
{
diffie_hellman_params_t *params;
@@ -290,7 +290,7 @@ gmp_diffie_hellman_t *gmp_diffie_hellman_create(diffie_hellman_group_t group)
* Described in header
*/
gmp_diffie_hellman_t *gmp_diffie_hellman_create_custom(
diffie_hellman_group_t group, ...)
key_exchange_method_t group, ...)
{
if (group == MODP_CUSTOM)
{
@@ -31,9 +31,9 @@ typedef struct gmp_diffie_hellman_t gmp_diffie_hellman_t;
struct gmp_diffie_hellman_t {
/**
* Implements diffie_hellman_t interface.
* Implements key_exchange_t interface.
*/
diffie_hellman_t dh;
key_exchange_t ke;
};
/**
@@ -42,7 +42,7 @@ struct gmp_diffie_hellman_t {
* @param group Diffie Hellman group number to use
* @return gmp_diffie_hellman_t object, NULL if not supported
*/
gmp_diffie_hellman_t *gmp_diffie_hellman_create(diffie_hellman_group_t group);
gmp_diffie_hellman_t *gmp_diffie_hellman_create(key_exchange_method_t group);
/**
* Creates a new gmp_diffie_hellman_t object for MODP_CUSTOM.
@@ -52,7 +52,7 @@ gmp_diffie_hellman_t *gmp_diffie_hellman_create(diffie_hellman_group_t group);
* @return gmp_diffie_hellman_t object, NULL if not supported
*/
gmp_diffie_hellman_t *gmp_diffie_hellman_create_custom(
diffie_hellman_group_t group, ...);
key_exchange_method_t group, ...);
#endif /** GMP_DIFFIE_HELLMAN_H_ @}*/
+14 -14
View File
@@ -43,31 +43,31 @@ METHOD(plugin_t, get_features, int,
{
static plugin_feature_t f[] = {
/* DH groups */
PLUGIN_REGISTER(DH, gmp_diffie_hellman_create),
PLUGIN_PROVIDE(DH, MODP_3072_BIT),
PLUGIN_REGISTER(KE, gmp_diffie_hellman_create),
PLUGIN_PROVIDE(KE, MODP_3072_BIT),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_4096_BIT),
PLUGIN_PROVIDE(KE, MODP_4096_BIT),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_6144_BIT),
PLUGIN_PROVIDE(KE, MODP_6144_BIT),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_8192_BIT),
PLUGIN_PROVIDE(KE, MODP_8192_BIT),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_2048_BIT),
PLUGIN_PROVIDE(KE, MODP_2048_BIT),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_2048_224),
PLUGIN_PROVIDE(KE, MODP_2048_224),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_2048_256),
PLUGIN_PROVIDE(KE, MODP_2048_256),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_1536_BIT),
PLUGIN_PROVIDE(KE, MODP_1536_BIT),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_1024_BIT),
PLUGIN_PROVIDE(KE, MODP_1024_BIT),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_1024_160),
PLUGIN_PROVIDE(KE, MODP_1024_160),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_PROVIDE(DH, MODP_768_BIT),
PLUGIN_PROVIDE(KE, MODP_768_BIT),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
PLUGIN_REGISTER(DH, gmp_diffie_hellman_create_custom),
PLUGIN_PROVIDE(DH, MODP_CUSTOM),
PLUGIN_REGISTER(KE, gmp_diffie_hellman_create_custom),
PLUGIN_PROVIDE(KE, MODP_CUSTOM),
PLUGIN_DEPENDS(RNG, RNG_STRONG),
/* private/public keys */
PLUGIN_REGISTER(PRIVKEY, gmp_rsa_private_key_load, TRUE),