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
+2 -2
View File
@@ -574,7 +574,7 @@ METHOD(bus_t, message, void,
}
METHOD(bus_t, ike_keys, void,
private_bus_t *this, ike_sa_t *ike_sa, diffie_hellman_t *dh,
private_bus_t *this, ike_sa_t *ike_sa, key_exchange_t *dh,
chunk_t dh_other, chunk_t nonce_i, chunk_t nonce_r,
ike_sa_t *rekey, shared_key_t *shared, auth_method_t method)
{
@@ -639,7 +639,7 @@ METHOD(bus_t, ike_derived_keys, void,
METHOD(bus_t, child_keys, void,
private_bus_t *this, child_sa_t *child_sa, bool initiator,
diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r)
key_exchange_t *dh, chunk_t nonce_i, chunk_t nonce_r)
{
enumerator_t *enumerator;
ike_sa_t *ike_sa;
+2 -2
View File
@@ -356,7 +356,7 @@ struct bus_t {
* @param shared shared key used for key derivation (IKEv1-PSK only)
* @param method auth method for key derivation (IKEv1-non-PSK only)
*/
void (*ike_keys)(bus_t *this, ike_sa_t *ike_sa, diffie_hellman_t *dh,
void (*ike_keys)(bus_t *this, ike_sa_t *ike_sa, key_exchange_t *dh,
chunk_t dh_other, chunk_t nonce_i, chunk_t nonce_r,
ike_sa_t *rekey, shared_key_t *shared,
auth_method_t method);
@@ -386,7 +386,7 @@ struct bus_t {
* @param nonce_r responder's nonce
*/
void (*child_keys)(bus_t *this, child_sa_t *child_sa, bool initiator,
diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r);
key_exchange_t *dh, chunk_t nonce_i, chunk_t nonce_r);
/**
* CHILD_SA derived keys hook.
+2 -2
View File
@@ -92,7 +92,7 @@ struct listener_t {
* @param method auth method for key derivation (IKEv1-non-PSK only)
* @return TRUE to stay registered, FALSE to unregister
*/
bool (*ike_keys)(listener_t *this, ike_sa_t *ike_sa, diffie_hellman_t *dh,
bool (*ike_keys)(listener_t *this, ike_sa_t *ike_sa, key_exchange_t *dh,
chunk_t dh_other, chunk_t nonce_i, chunk_t nonce_r,
ike_sa_t *rekey, shared_key_t *shared,
auth_method_t method);
@@ -125,7 +125,7 @@ struct listener_t {
* @return TRUE to stay registered, FALSE to unregister
*/
bool (*child_keys)(listener_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa,
bool initiator, diffie_hellman_t *dh,
bool initiator, key_exchange_t *dh,
chunk_t nonce_i, chunk_t nonce_r);
/**
+9 -8
View File
@@ -216,16 +216,16 @@ CALLBACK(match_proposal, bool,
}
METHOD(child_cfg_t, get_proposals, linked_list_t*,
private_child_cfg_t *this, bool strip_dh)
private_child_cfg_t *this, bool strip_ke)
{
enumerator_t *enumerator;
proposal_t *current;
proposal_selection_flag_t flags = 0;
linked_list_t *proposals = linked_list_create();
if (strip_dh)
if (strip_ke)
{
flags |= PROPOSAL_SKIP_DH;
flags |= PROPOSAL_SKIP_KE;
}
enumerator = this->proposals->create_enumerator(this->proposals);
@@ -484,23 +484,24 @@ METHOD(child_cfg_t, get_close_action, action_t,
return this->close_action;
}
METHOD(child_cfg_t, get_dh_group, diffie_hellman_group_t,
METHOD(child_cfg_t, get_ke_method, key_exchange_method_t,
private_child_cfg_t *this)
{
enumerator_t *enumerator;
proposal_t *proposal;
uint16_t dh_group = MODP_NONE;
uint16_t method = MODP_NONE;
enumerator = this->proposals->create_enumerator(this->proposals);
while (enumerator->enumerate(enumerator, &proposal))
{
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP, &dh_group, NULL))
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD, &method,
NULL))
{
break;
}
}
enumerator->destroy(enumerator);
return dh_group;
return method;
}
METHOD(child_cfg_t, get_inactivity, uint32_t,
@@ -758,7 +759,7 @@ child_cfg_t *child_cfg_create(char *name, child_cfg_create_t *data)
.get_dpd_action = _get_dpd_action,
.get_close_action = _get_close_action,
.get_lifetime = _get_lifetime,
.get_dh_group = _get_dh_group,
.get_ke_method = _get_ke_method,
.get_inactivity = _get_inactivity,
.get_reqid = _get_reqid,
.get_if_id = _get_if_id,
+5 -5
View File
@@ -89,10 +89,10 @@ struct child_cfg_t {
*
* Resulting list and all of its proposals must be freed after use.
*
* @param strip_dh TRUE strip out diffie hellman groups
* @param strip_ke TRUE strip out key exchange methods
* @return list of proposals
*/
linked_list_t* (*get_proposals)(child_cfg_t *this, bool strip_dh);
linked_list_t* (*get_proposals)(child_cfg_t *this, bool strip_ke);
/**
* Select a proposal from a supplied list.
@@ -204,11 +204,11 @@ struct child_cfg_t {
action_t (*get_close_action) (child_cfg_t *this);
/**
* Get the DH group to use for CHILD_SA setup.
* Get the key exchange method to use for CHILD_SA setup.
*
* @return dh group to use
* @return key exchange method to use
*/
diffie_hellman_group_t (*get_dh_group)(child_cfg_t *this);
key_exchange_method_t (*get_ke_method)(child_cfg_t *this);
/**
* Get the inactivity timeout value.
+6 -5
View File
@@ -348,23 +348,24 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
return proposal_select(this->proposals, proposals, flags);
}
METHOD(ike_cfg_t, get_dh_group, diffie_hellman_group_t,
METHOD(ike_cfg_t, get_ke_method, key_exchange_method_t,
private_ike_cfg_t *this)
{
enumerator_t *enumerator;
proposal_t *proposal;
uint16_t dh_group = MODP_NONE;
uint16_t method = MODP_NONE;
enumerator = this->proposals->create_enumerator(this->proposals);
while (enumerator->enumerate(enumerator, &proposal))
{
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP, &dh_group, NULL))
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD, &method,
NULL))
{
break;
}
}
enumerator->destroy(enumerator);
return dh_group;
return method;
}
METHOD(ike_cfg_t, equals, bool,
@@ -603,7 +604,7 @@ ike_cfg_t *ike_cfg_create(ike_cfg_create_t *data)
.get_proposals = _get_proposals,
.select_proposal = _select_proposal,
.has_proposal = _has_proposal,
.get_dh_group = _get_dh_group,
.get_ke_method = _get_ke_method,
.equals = _equals,
.get_ref = _get_ref,
.destroy = _destroy,
+4 -4
View File
@@ -35,7 +35,7 @@ typedef struct ike_cfg_create_t ike_cfg_create_t;
#include <collections/linked_list.h>
#include <utils/identification.h>
#include <crypto/proposal/proposal.h>
#include <crypto/diffie_hellman.h>
#include <crypto/key_exchange.h>
/**
* IKE version.
@@ -231,11 +231,11 @@ struct ike_cfg_t {
childless_t (*childless)(ike_cfg_t *this);
/**
* Get the DH group to use for IKE_SA setup.
* Get the key exchange method to use for IKE_SA setup.
*
* @return dh group to use for initialization
* @return key exchange method to use for initialization
*/
diffie_hellman_group_t (*get_dh_group)(ike_cfg_t *this);
key_exchange_method_t (*get_ke_method)(ike_cfg_t *this);
/**
* Check if two IKE configs are equal.
+13 -13
View File
@@ -59,9 +59,9 @@ struct private_ke_payload_t {
uint16_t payload_length;
/**
* DH Group Number.
* Key exchange method number.
*/
uint16_t dh_group_number;
uint16_t ke_method;
/**
* Key Exchange Data of this KE payload.
@@ -92,8 +92,8 @@ static encoding_rule_t encodings_v2[] = {
{ RESERVED_BIT, offsetof(private_ke_payload_t, reserved_bit[6]) },
/* Length of the whole payload*/
{ PAYLOAD_LENGTH, offsetof(private_ke_payload_t, payload_length) },
/* DH Group number as 16 bit field*/
{ U_INT_16, offsetof(private_ke_payload_t, dh_group_number) },
/* Key exchange method number as 16 bit field*/
{ U_INT_16, offsetof(private_ke_payload_t, ke_method) },
/* 2 reserved bytes */
{ RESERVED_BYTE, offsetof(private_ke_payload_t, reserved_byte[0])},
{ RESERVED_BYTE, offsetof(private_ke_payload_t, reserved_byte[1])},
@@ -107,7 +107,7 @@ static encoding_rule_t encodings_v2[] = {
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
! Next Payload !C! RESERVED ! Payload Length !
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
! DH Group # ! RESERVED !
! KE method # ! RESERVED !
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
! !
~ Key Exchange Data ~
@@ -197,10 +197,10 @@ METHOD(ke_payload_t, get_key_exchange_data, chunk_t,
return this->key_exchange_data;
}
METHOD(ke_payload_t, get_dh_group_number, diffie_hellman_group_t,
METHOD(ke_payload_t, get_key_exchange_method, key_exchange_method_t,
private_ke_payload_t *this)
{
return this->dh_group_number;
return this->ke_method;
}
METHOD2(payload_t, ke_payload_t, destroy, void,
@@ -230,11 +230,11 @@ ke_payload_t *ke_payload_create(payload_type_t type)
.destroy = _destroy,
},
.get_key_exchange_data = _get_key_exchange_data,
.get_dh_group_number = _get_dh_group_number,
.get_key_exchange_method = _get_key_exchange_method,
.destroy = _destroy,
},
.next_payload = PL_NONE,
.dh_group_number = MODP_NONE,
.ke_method = MODP_NONE,
.type = type,
);
this->payload_length = get_header_length(this);
@@ -244,19 +244,19 @@ ke_payload_t *ke_payload_create(payload_type_t type)
/*
* Described in header
*/
ke_payload_t *ke_payload_create_from_diffie_hellman(payload_type_t type,
diffie_hellman_t *dh)
ke_payload_t *ke_payload_create_from_key_exchange(payload_type_t type,
key_exchange_t *ke)
{
private_ke_payload_t *this;
chunk_t value;
if (!dh->get_my_public_value(dh, &value))
if (!ke->get_public_key(ke, &value))
{
return NULL;
}
this = (private_ke_payload_t*)ke_payload_create(type);
this->key_exchange_data = value;
this->dh_group_number = dh->get_dh_group(dh);
this->ke_method = ke->get_method(ke);
this->payload_length += this->key_exchange_data.len;
return &this->public;
+8 -8
View File
@@ -29,7 +29,7 @@ typedef struct ke_payload_t ke_payload_t;
#include <encoding/payloads/payload.h>
#include <encoding/payloads/transform_substructure.h>
#include <collections/linked_list.h>
#include <crypto/diffie_hellman.h>
#include <crypto/key_exchange.h>
/**
* Class representing an IKEv1 or IKEv2 key exchange payload.
@@ -49,11 +49,11 @@ struct ke_payload_t {
chunk_t (*get_key_exchange_data) (ke_payload_t *this);
/**
* Gets the Diffie-Hellman Group Number of this KE payload (IKEv2 only).
* Gets the key exchange method of this KE payload (IKEv2 only).
*
* @return DH Group Number of this payload
* @return key exchange method of this payload
*/
diffie_hellman_group_t (*get_dh_group_number) (ke_payload_t *this);
key_exchange_method_t (*get_key_exchange_method)(ke_payload_t *this);
/**
* Destroys a ke_payload_t object.
@@ -70,13 +70,13 @@ struct ke_payload_t {
ke_payload_t *ke_payload_create(payload_type_t type);
/**
* Creates a ke_payload_t from a diffie_hellman_t.
* Creates a ke_payload_t from a key_exchange_t.
*
* @param type PLV2_KEY_EXCHANGE or PLV1_KEY_EXCHANGE
* @param dh diffie hellman object containing group and key
* @param ke key exchange object containing method and public key
* @return ke_payload_t object, NULL on error
*/
ke_payload_t *ke_payload_create_from_diffie_hellman(payload_type_t type,
diffie_hellman_t *dh);
ke_payload_t *ke_payload_create_from_key_exchange(payload_type_t type,
key_exchange_t *ke);
#endif /** KE_PAYLOAD_H_ @}*/
@@ -904,7 +904,7 @@ static void add_to_proposal_v1_ike(proposal_t *proposal,
get_alg_from_ikev1(PSEUDO_RANDOM_FUNCTION, value), 0);
break;
case TATTR_PH1_GROUP:
proposal->add_algorithm(proposal, DIFFIE_HELLMAN_GROUP,
proposal->add_algorithm(proposal, KEY_EXCHANGE_METHOD,
value, 0);
break;
default:
@@ -951,7 +951,7 @@ static void add_to_proposal_v1(proposal_t *proposal,
get_alg_from_ikev1_auth(value), 0);
break;
case TATTR_PH2_GROUP:
proposal->add_algorithm(proposal, DIFFIE_HELLMAN_GROUP,
proposal->add_algorithm(proposal, KEY_EXCHANGE_METHOD,
value, 0);
break;
case TATTR_PH2_EXT_SEQ_NUMBER:
@@ -1318,7 +1318,7 @@ static void set_from_proposal_v1_ike(private_proposal_substructure_t *this,
}
enumerator->destroy(enumerator);
enumerator = proposal->create_enumerator(proposal, DIFFIE_HELLMAN_GROUP);
enumerator = proposal->create_enumerator(proposal, KEY_EXCHANGE_METHOD);
if (enumerator->enumerate(enumerator, &alg, &key_size))
{
transform->add_transform_attribute(transform,
@@ -1396,7 +1396,7 @@ static void set_from_proposal_v1(private_proposal_substructure_t *this,
return;
}
enumerator = proposal->create_enumerator(proposal, DIFFIE_HELLMAN_GROUP);
enumerator = proposal->create_enumerator(proposal, KEY_EXCHANGE_METHOD);
if (enumerator->enumerate(enumerator, &alg, &key_size))
{
transform->add_transform_attribute(transform,
@@ -1489,11 +1489,11 @@ static void set_from_proposal_v2(private_proposal_substructure_t *this,
enumerator->destroy(enumerator);
/* dh groups */
enumerator = proposal->create_enumerator(proposal, DIFFIE_HELLMAN_GROUP);
enumerator = proposal->create_enumerator(proposal, KEY_EXCHANGE_METHOD);
while (enumerator->enumerate(enumerator, &alg, NULL))
{
transform = transform_substructure_create_type(PLV2_TRANSFORM_SUBSTRUCTURE,
DIFFIE_HELLMAN_GROUP, alg);
KEY_EXCHANGE_METHOD, alg);
add_transform_substructure(this, transform);
}
enumerator->destroy(enumerator);
@@ -29,7 +29,7 @@ typedef struct transform_substructure_t transform_substructure_t;
#include <encoding/payloads/payload.h>
#include <encoding/payloads/transform_attribute.h>
#include <collections/linked_list.h>
#include <crypto/diffie_hellman.h>
#include <crypto/key_exchange.h>
#include <crypto/signers/signer.h>
#include <crypto/prfs/prf.h>
#include <crypto/crypters/crypter.h>
+2 -2
View File
@@ -51,7 +51,7 @@ struct private_ha_child_t {
METHOD(listener_t, child_keys, bool,
private_ha_child_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa,
bool initiator, diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r)
bool initiator, key_exchange_t *dh, chunk_t nonce_i, chunk_t nonce_r)
{
ha_message_t *m;
chunk_t secret;
@@ -92,7 +92,7 @@ METHOD(listener_t, child_keys, bool,
{
m->add_attribute(m, HA_ALG_INTEG, alg);
}
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP, &alg, NULL))
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD, &alg, NULL))
{
m->add_attribute(m, HA_ALG_DH, alg);
}
+11 -11
View File
@@ -67,9 +67,9 @@ struct private_ha_dispatcher_t {
struct ha_diffie_hellman_t {
/**
* Implements diffie_hellman_t
* Implements key_exchange_t
*/
diffie_hellman_t dh;
key_exchange_t dh;
/**
* Shared secret
@@ -82,21 +82,21 @@ struct ha_diffie_hellman_t {
chunk_t pub;
};
METHOD(diffie_hellman_t, dh_get_shared_secret, bool,
METHOD(key_exchange_t, dh_get_shared_secret, bool,
ha_diffie_hellman_t *this, chunk_t *secret)
{
*secret = chunk_clone(this->secret);
return TRUE;
}
METHOD(diffie_hellman_t, dh_get_my_public_value, bool,
METHOD(key_exchange_t, dh_get_public_key, bool,
ha_diffie_hellman_t *this, chunk_t *value)
{
*value = chunk_clone(this->pub);
return TRUE;
}
METHOD(diffie_hellman_t, dh_destroy, void,
METHOD(key_exchange_t, dh_destroy, void,
ha_diffie_hellman_t *this)
{
free(this);
@@ -105,14 +105,14 @@ METHOD(diffie_hellman_t, dh_destroy, void,
/**
* Create a HA synced DH implementation
*/
static diffie_hellman_t *ha_diffie_hellman_create(chunk_t secret, chunk_t pub)
static key_exchange_t *ha_diffie_hellman_create(chunk_t secret, chunk_t pub)
{
ha_diffie_hellman_t *this;
INIT(this,
.dh = {
.get_shared_secret = _dh_get_shared_secret,
.get_my_public_value = _dh_get_my_public_value,
.get_public_key = _dh_get_public_key,
.destroy = _dh_destroy,
},
.secret = secret,
@@ -210,7 +210,7 @@ static void process_ike_add(private_ha_dispatcher_t *this, ha_message_t *message
if (ike_sa)
{
proposal_t *proposal;
diffie_hellman_t *dh;
key_exchange_t *dh;
proposal = proposal_create(PROTO_IKE, 0);
if (integ)
@@ -227,7 +227,7 @@ static void process_ike_add(private_ha_dispatcher_t *this, ha_message_t *message
}
if (dh_grp)
{
proposal->add_algorithm(proposal, DIFFIE_HELLMAN_GROUP, dh_grp, 0);
proposal->add_algorithm(proposal, KEY_EXCHANGE_METHOD, dh_grp, 0);
}
charon->bus->set_sa(charon->bus, ike_sa);
dh = ha_diffie_hellman_create(secret, dh_local);
@@ -662,7 +662,7 @@ static void process_child_add(private_ha_dispatcher_t *this,
chunk_t nonce_i = chunk_empty, nonce_r = chunk_empty, secret = chunk_empty;
chunk_t encr_i, integ_i, encr_r, integ_r;
linked_list_t *local_ts, *remote_ts;
diffie_hellman_t *dh = NULL;
key_exchange_t *dh = NULL;
enumerator = message->create_attribute_enumerator(message);
while (enumerator->enumerate(enumerator, &attribute, &value))
@@ -762,7 +762,7 @@ static void process_child_add(private_ha_dispatcher_t *this,
}
if (dh_grp)
{
proposal->add_algorithm(proposal, DIFFIE_HELLMAN_GROUP, dh_grp, 0);
proposal->add_algorithm(proposal, KEY_EXCHANGE_METHOD, dh_grp, 0);
}
proposal->add_algorithm(proposal, EXTENDED_SEQUENCE_NUMBERS, esn, 0);
if (secret.len)
+3 -3
View File
@@ -82,7 +82,7 @@ static void copy_extensions(ha_message_t *m, ike_sa_t *ike_sa)
}
METHOD(listener_t, ike_keys, bool,
private_ha_ike_t *this, ike_sa_t *ike_sa, diffie_hellman_t *dh,
private_ha_ike_t *this, ike_sa_t *ike_sa, key_exchange_t *dh,
chunk_t dh_other, chunk_t nonce_i, chunk_t nonce_r, ike_sa_t *rekey,
shared_key_t *shared, auth_method_t method)
{
@@ -132,7 +132,7 @@ METHOD(listener_t, ike_keys, bool,
{
m->add_attribute(m, HA_ALG_PRF, alg);
}
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP, &alg, NULL))
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD, &alg, NULL))
{
m->add_attribute(m, HA_ALG_DH, alg);
}
@@ -142,7 +142,7 @@ METHOD(listener_t, ike_keys, bool,
chunk_clear(&secret);
if (ike_sa->get_version(ike_sa) == IKEV1)
{
if (dh->get_my_public_value(dh, &secret))
if (dh->get_public_key(dh, &secret))
{
m->add_attribute(m, HA_LOCAL_DH, secret);
chunk_free(&secret);
@@ -16,33 +16,33 @@
#include "load_tester_diffie_hellman.h"
METHOD(diffie_hellman_t, get_my_public_value, bool,
METHOD(key_exchange_t, get_public_key, bool,
load_tester_diffie_hellman_t *this, chunk_t *value)
{
*value = chunk_empty;
return TRUE;
}
METHOD(diffie_hellman_t, set_other_public_value, bool,
METHOD(key_exchange_t, set_public_key, bool,
load_tester_diffie_hellman_t *this, chunk_t value)
{
return TRUE;
}
METHOD(diffie_hellman_t, get_shared_secret, bool,
METHOD(key_exchange_t, get_shared_secret, bool,
load_tester_diffie_hellman_t *this, chunk_t *secret)
{
*secret = chunk_empty;
return TRUE;
}
METHOD(diffie_hellman_t, get_dh_group, diffie_hellman_group_t,
METHOD(key_exchange_t, get_method, key_exchange_method_t,
load_tester_diffie_hellman_t *this)
{
return MODP_NULL;
}
METHOD(diffie_hellman_t, destroy, void,
METHOD(key_exchange_t, destroy, void,
load_tester_diffie_hellman_t *this)
{
free(this);
@@ -52,7 +52,7 @@ METHOD(diffie_hellman_t, destroy, void,
* See header
*/
load_tester_diffie_hellman_t *load_tester_diffie_hellman_create(
diffie_hellman_group_t group)
key_exchange_method_t group)
{
load_tester_diffie_hellman_t *this;
@@ -62,11 +62,11 @@ load_tester_diffie_hellman_t *load_tester_diffie_hellman_create(
}
INIT(this,
.dh = {
.ke = {
.get_shared_secret = _get_shared_secret,
.set_other_public_value = _set_other_public_value,
.get_my_public_value = _get_my_public_value,
.get_dh_group = _get_dh_group,
.set_public_key = _set_public_key,
.get_public_key = _get_public_key,
.get_method = _get_method,
.destroy = _destroy,
}
);
@@ -22,7 +22,7 @@
#ifndef LOAD_TESTER_DIFFIE_HELLMAN_H_
#define LOAD_TESTER_DIFFIE_HELLMAN_H_
#include <crypto/diffie_hellman.h>
#include <crypto/key_exchange.h>
typedef struct load_tester_diffie_hellman_t load_tester_diffie_hellman_t;
@@ -32,18 +32,18 @@ typedef struct load_tester_diffie_hellman_t load_tester_diffie_hellman_t;
struct load_tester_diffie_hellman_t {
/**
* Implements diffie_hellman_t interface.
* Implements key_exchange_t interface.
*/
diffie_hellman_t dh;
key_exchange_t ke;
};
/**
* Creates a new gmp_diffie_hellman_t object.
* Creates a new load_tester_diffie_hellman_t object.
*
* @param group Diffie Hellman group, supports MODP_NULL only
* @return gmp_diffie_hellman_t object
* @return load_tester_diffie_hellman_t object
*/
load_tester_diffie_hellman_t *load_tester_diffie_hellman_create(
diffie_hellman_group_t group);
key_exchange_method_t group);
#endif /** LOAD_TESTER_DIFFIE_HELLMAN_H_ @}*/
@@ -231,8 +231,8 @@ METHOD(plugin_t, get_features, int,
private_load_tester_plugin_t *this, plugin_feature_t *features[])
{
static plugin_feature_t f[] = {
PLUGIN_REGISTER(DH, load_tester_diffie_hellman_create),
PLUGIN_PROVIDE(DH, MODP_NULL),
PLUGIN_REGISTER(KE, load_tester_diffie_hellman_create),
PLUGIN_PROVIDE(KE, MODP_NULL),
PLUGIN_DEPENDS(CUSTOM, "load-tester"),
PLUGIN_CALLBACK((plugin_feature_callback_t)register_load_tester, NULL),
PLUGIN_PROVIDE(CUSTOM, "load-tester"),
+5 -5
View File
@@ -266,10 +266,10 @@ static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)
fprintf(out, "_%u", ks);
}
}
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP,
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD,
&alg, NULL))
{
fprintf(out, "/%N", diffie_hellman_group_names, alg);
fprintf(out, "/%N", key_exchange_method_names, alg);
}
if (proposal->get_algorithm(proposal, EXTENDED_SEQUENCE_NUMBERS,
&alg, NULL) && alg == EXT_SEQ_NUMBERS)
@@ -855,7 +855,7 @@ static void list_algs(FILE *out)
ext_out_function_t xof;
key_derivation_function_t kdf;
drbg_type_t drbg;
diffie_hellman_group_t group;
key_exchange_method_t group;
rng_quality_t quality;
const char *plugin_name;
int len;
@@ -928,10 +928,10 @@ static void list_algs(FILE *out)
enumerator->destroy(enumerator);
fprintf(out, "\n dh-group: ");
len = 13;
enumerator = lib->crypto->create_dh_enumerator(lib->crypto);
enumerator = lib->crypto->create_ke_enumerator(lib->crypto);
while (enumerator->enumerate(enumerator, &group, &plugin_name))
{
print_alg(out, &len, diffie_hellman_group_names, group, plugin_name);
print_alg(out, &len, key_exchange_method_names, group, plugin_name);
}
enumerator->destroy(enumerator);
fprintf(out, "\n random-gen:");
+7 -7
View File
@@ -230,10 +230,10 @@ static void list_child_ipsec(vici_builder_t *b, child_sa_t *child)
b->add_kv(b, "integ-keysize", "%u", ks);
}
}
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP,
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD,
&alg, NULL))
{
b->add_kv(b, "dh-group", "%N", diffie_hellman_group_names, alg);
b->add_kv(b, "dh-group", "%N", key_exchange_method_names, alg);
}
if (proposal->get_algorithm(proposal, EXTENDED_SEQUENCE_NUMBERS,
&alg, NULL) && alg == EXT_SEQ_NUMBERS)
@@ -489,9 +489,9 @@ static void list_ike(private_vici_query_t *this, vici_builder_t *b,
{
b->add_kv(b, "prf-alg", "%N", pseudo_random_function_names, alg);
}
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP, &alg, NULL))
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD, &alg, NULL))
{
b->add_kv(b, "dh-group", "%N", diffie_hellman_group_names, alg);
b->add_kv(b, "dh-group", "%N", key_exchange_method_names, alg);
}
}
add_condition(b, ike_sa, "ppk", COND_PPK);
@@ -1304,7 +1304,7 @@ CALLBACK(get_algorithms, vici_message_t*,
ext_out_function_t xof;
key_derivation_function_t kdf;
drbg_type_t drbg;
diffie_hellman_group_t group;
key_exchange_method_t group;
rng_quality_t quality;
const char *plugin_name;
@@ -1383,10 +1383,10 @@ CALLBACK(get_algorithms, vici_message_t*,
b->end_section(b);
b->begin_section(b, "dh");
enumerator = lib->crypto->create_dh_enumerator(lib->crypto);
enumerator = lib->crypto->create_ke_enumerator(lib->crypto);
while (enumerator->enumerate(enumerator, &group, &plugin_name))
{
add_algorithm(b, diffie_hellman_group_names, group, plugin_name);
add_algorithm(b, key_exchange_method_names, group, plugin_name);
}
enumerator->destroy(enumerator);
b->end_section(b);
+1 -1
View File
@@ -121,7 +121,7 @@ authenticator_t *authenticator_create_verifier(
* Described in header.
*/
authenticator_t *authenticator_create_v1(ike_sa_t *ike_sa, bool initiator,
auth_method_t auth_method, diffie_hellman_t *dh,
auth_method_t auth_method, key_exchange_t *dh,
chunk_t dh_value, chunk_t sa_payload,
chunk_t id_payload)
{
+1 -1
View File
@@ -238,7 +238,7 @@ authenticator_t *authenticator_create_verifier(
* @return authenticator, NULL if not supported
*/
authenticator_t *authenticator_create_v1(ike_sa_t *ike_sa, bool initiator,
auth_method_t auth_method, diffie_hellman_t *dh,
auth_method_t auth_method, key_exchange_t *dh,
chunk_t dh_value, chunk_t sa_payload,
chunk_t id_payload);
@@ -78,7 +78,7 @@ METHOD(authenticator_t, destroy, void,
* Described in header.
*/
hybrid_authenticator_t *hybrid_authenticator_create(ike_sa_t *ike_sa,
bool initiator, diffie_hellman_t *dh,
bool initiator, key_exchange_t *dh,
chunk_t dh_value, chunk_t sa_payload,
chunk_t id_payload)
{
@@ -50,7 +50,7 @@ struct hybrid_authenticator_t {
* @return hybrid authenticator
*/
hybrid_authenticator_t *hybrid_authenticator_create(ike_sa_t *ike_sa,
bool initiator, diffie_hellman_t *dh,
bool initiator, key_exchange_t *dh,
chunk_t dh_value, chunk_t sa_payload,
chunk_t id_payload);
@@ -45,7 +45,7 @@ struct private_psk_v1_authenticator_t {
/**
* DH key exchange
*/
diffie_hellman_t *dh;
key_exchange_t *dh;
/**
* Others DH public value
@@ -75,7 +75,7 @@ METHOD(authenticator_t, build, status_t,
keymat_v1_t *keymat;
chunk_t hash, dh;
if (!this->dh->get_my_public_value(this->dh, &dh))
if (!this->dh->get_public_key(this->dh, &dh))
{
return FAILED;
}
@@ -112,7 +112,7 @@ METHOD(authenticator_t, process, status_t,
return FAILED;
}
if (!this->dh->get_my_public_value(this->dh, &dh))
if (!this->dh->get_public_key(this->dh, &dh))
{
return FAILED;
}
@@ -151,7 +151,7 @@ METHOD(authenticator_t, destroy, void,
* Described in header.
*/
psk_v1_authenticator_t *psk_v1_authenticator_create(ike_sa_t *ike_sa,
bool initiator, diffie_hellman_t *dh,
bool initiator, key_exchange_t *dh,
chunk_t dh_value, chunk_t sa_payload,
chunk_t id_payload, bool hybrid)
{
@@ -51,7 +51,7 @@ struct psk_v1_authenticator_t {
* @return PSK authenticator
*/
psk_v1_authenticator_t *psk_v1_authenticator_create(ike_sa_t *ike_sa,
bool initiator, diffie_hellman_t *dh,
bool initiator, key_exchange_t *dh,
chunk_t dh_value, chunk_t sa_payload,
chunk_t id_payload, bool hybrid);
@@ -46,7 +46,7 @@ struct private_pubkey_v1_authenticator_t {
/**
* DH key exchange
*/
diffie_hellman_t *dh;
key_exchange_t *dh;
/**
* Others DH public value
@@ -96,7 +96,7 @@ METHOD(authenticator_t, build, status_t,
return NOT_FOUND;
}
if (!this->dh->get_my_public_value(this->dh, &dh))
if (!this->dh->get_public_key(this->dh, &dh))
{
private->destroy(private);
return FAILED;
@@ -181,7 +181,7 @@ METHOD(authenticator_t, process, status_t,
}
id = this->ike_sa->get_other_id(this->ike_sa);
if (!this->dh->get_my_public_value(this->dh, &dh))
if (!this->dh->get_public_key(this->dh, &dh))
{
return FAILED;
}
@@ -238,7 +238,7 @@ METHOD(authenticator_t, destroy, void,
* Described in header.
*/
pubkey_v1_authenticator_t *pubkey_v1_authenticator_create(ike_sa_t *ike_sa,
bool initiator, diffie_hellman_t *dh,
bool initiator, key_exchange_t *dh,
chunk_t dh_value, chunk_t sa_payload,
chunk_t id_payload, key_type_t type)
{
@@ -51,7 +51,7 @@ struct pubkey_v1_authenticator_t {
* @return pubkey authenticator
*/
pubkey_v1_authenticator_t *pubkey_v1_authenticator_create(ike_sa_t *ike_sa,
bool initiator, diffie_hellman_t *dh,
bool initiator, key_exchange_t *dh,
chunk_t dh_value, chunk_t sa_payload,
chunk_t id_payload, key_type_t type);
+7 -7
View File
@@ -314,7 +314,7 @@ static void adjust_keylen(uint16_t alg, chunk_t *key)
}
METHOD(keymat_v1_t, derive_ike_keys, bool,
private_keymat_v1_t *this, proposal_t *proposal, diffie_hellman_t *dh,
private_keymat_v1_t *this, proposal_t *proposal, key_exchange_t *dh,
chunk_t dh_other, chunk_t nonce_i, chunk_t nonce_r, ike_sa_id_t *id,
auth_method_t auth, shared_key_t *shared_key)
{
@@ -494,7 +494,7 @@ METHOD(keymat_v1_t, derive_ike_keys, bool,
return FALSE;
}
if (!dh->get_my_public_value(dh, &dh_me))
if (!dh->get_public_key(dh, &dh_me))
{
return FALSE;
}
@@ -539,7 +539,7 @@ static bool derive_child_keymat(private_keymat_v1_t *this, chunk_t seed,
}
METHOD(keymat_v1_t, derive_child_keys, bool,
private_keymat_v1_t *this, proposal_t *proposal, diffie_hellman_t *dh,
private_keymat_v1_t *this, proposal_t *proposal, key_exchange_t *dh,
uint32_t spi_i, uint32_t spi_r, chunk_t nonce_i, chunk_t nonce_r,
chunk_t *encr_i, chunk_t *integ_i, chunk_t *encr_r, chunk_t *integ_r)
{
@@ -914,10 +914,10 @@ METHOD(keymat_t, get_version, ike_version_t,
return IKEV1;
}
METHOD(keymat_t, create_dh, diffie_hellman_t*,
private_keymat_v1_t *this, diffie_hellman_group_t group)
METHOD(keymat_t, create_ke, key_exchange_t*,
private_keymat_v1_t *this, key_exchange_method_t method)
{
return lib->crypto->create_dh(lib->crypto, group);
return lib->crypto->create_ke(lib->crypto, method);
}
METHOD(keymat_t, create_nonce_gen, nonce_gen_t*,
@@ -956,7 +956,7 @@ keymat_v1_t *keymat_v1_create(bool initiator)
.public = {
.keymat = {
.get_version = _get_version,
.create_dh = _create_dh,
.create_ke = _create_ke,
.create_nonce_gen = _create_nonce_gen,
.get_aead = _get_aead,
.destroy = _destroy,
+3 -3
View File
@@ -44,7 +44,7 @@ struct keymat_v1_t {
* crypters and authentication functions.
*
* @param proposal selected algorithms
* @param dh diffie hellman key allocated by create_dh()
* @param dh diffie hellman key allocated by create_ke()
* @param dh_other public DH value from other peer
* @param nonce_i initiators nonce value
* @param nonce_r responders nonce value
@@ -54,7 +54,7 @@ struct keymat_v1_t {
* @return TRUE on success
*/
bool (*derive_ike_keys)(keymat_v1_t *this, proposal_t *proposal,
diffie_hellman_t *dh, chunk_t dh_other,
key_exchange_t *dh, chunk_t dh_other,
chunk_t nonce_i, chunk_t nonce_r, ike_sa_id_t *id,
auth_method_t auth, shared_key_t *shared_key);
@@ -73,7 +73,7 @@ struct keymat_v1_t {
* @param integ_r allocated responders integrity key
*/
bool (*derive_child_keys)(keymat_v1_t *this, proposal_t *proposal,
diffie_hellman_t *dh, uint32_t spi_i, uint32_t spi_r,
key_exchange_t *dh, uint32_t spi_i, uint32_t spi_r,
chunk_t nonce_i, chunk_t nonce_r,
chunk_t *encr_i, chunk_t *integ_i,
chunk_t *encr_r, chunk_t *integ_r);
+6 -6
View File
@@ -63,7 +63,7 @@ struct private_phase1_t {
/**
* DH exchange
*/
diffie_hellman_t *dh;
key_exchange_t *dh;
/**
* Keymat derivation (from SA)
@@ -210,9 +210,9 @@ METHOD(phase1_t, create_hasher, bool,
}
METHOD(phase1_t, create_dh, bool,
private_phase1_t *this, diffie_hellman_group_t group)
private_phase1_t *this, key_exchange_method_t group)
{
this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat, group);
this->dh = this->keymat->keymat.create_ke(&this->keymat->keymat, group);
return this->dh != NULL;
}
@@ -705,8 +705,8 @@ METHOD(phase1_t, add_nonce_ke, bool,
nonce_gen_t *nonceg;
chunk_t nonce;
ke_payload = ke_payload_create_from_diffie_hellman(PLV1_KEY_EXCHANGE,
this->dh);
ke_payload = ke_payload_create_from_key_exchange(PLV1_KEY_EXCHANGE,
this->dh);
if (!ke_payload)
{
DBG1(DBG_IKE, "creating KE payload failed");
@@ -756,7 +756,7 @@ METHOD(phase1_t, get_nonce_ke, bool,
return FALSE;
}
this->dh_value = chunk_clone(ke_payload->get_key_exchange_data(ke_payload));
if (!this->dh->set_other_public_value(this->dh, this->dh_value))
if (!this->dh->set_public_key(this->dh, this->dh_value))
{
DBG1(DBG_IKE, "unable to apply received KE value");
return FALSE;
+2 -2
View File
@@ -25,7 +25,7 @@
typedef struct phase1_t phase1_t;
#include <sa/ike_sa.h>
#include <crypto/diffie_hellman.h>
#include <crypto/key_exchange.h>
/**
* Common phase 1 helper for main and aggressive mode.
@@ -45,7 +45,7 @@ struct phase1_t {
* @param group negotiated DH group
* @return TRUE if group supported
*/
bool (*create_dh)(phase1_t *this, diffie_hellman_group_t group);
bool (*create_dh)(phase1_t *this, key_exchange_method_t group);
/**
* Derive key material.
@@ -252,7 +252,7 @@ METHOD(task_t, build_i, status_t,
message->add_payload(message, &sa_payload->payload_interface);
group = this->ike_cfg->get_dh_group(this->ike_cfg);
group = this->ike_cfg->get_ke_method(this->ike_cfg);
if (group == MODP_NONE)
{
DBG1(DBG_IKE, "DH group selection failed");
@@ -261,7 +261,7 @@ METHOD(task_t, build_i, status_t,
if (!this->ph1->create_dh(this->ph1, group))
{
DBG1(DBG_IKE, "DH group %N not supported",
diffie_hellman_group_names, group);
key_exchange_method_names, group);
return FAILED;
}
if (!this->ph1->add_nonce_ke(this->ph1, message))
@@ -438,7 +438,7 @@ METHOD(task_t, process_r, status_t,
}
if (!this->proposal->get_algorithm(this->proposal,
DIFFIE_HELLMAN_GROUP, &group, NULL))
KEY_EXCHANGE_METHOD, &group, NULL))
{
DBG1(DBG_IKE, "DH group selection failed");
return send_notify(this, INVALID_KEY_INFORMATION);
+2 -2
View File
@@ -314,7 +314,7 @@ METHOD(task_t, build_i, status_t,
return send_notify(this, NO_PROPOSAL_CHOSEN);
}
if (!this->proposal->get_algorithm(this->proposal,
DIFFIE_HELLMAN_GROUP, &group, NULL))
KEY_EXCHANGE_METHOD, &group, NULL))
{
DBG1(DBG_IKE, "DH group selection failed");
return send_notify(this, NO_PROPOSAL_CHOSEN);
@@ -428,7 +428,7 @@ METHOD(task_t, process_r, status_t,
return send_notify(this, INVALID_KEY_INFORMATION);
}
if (!this->proposal->get_algorithm(this->proposal,
DIFFIE_HELLMAN_GROUP, &group, NULL))
KEY_EXCHANGE_METHOD, &group, NULL))
{
DBG1(DBG_IKE, "DH group selection failed");
return send_notify(this, INVALID_KEY_INFORMATION);
+15 -15
View File
@@ -137,7 +137,7 @@ struct private_quick_mode_t {
/**
* DH exchange, when PFS is in use
*/
diffie_hellman_t *dh;
key_exchange_t *dh;
/**
* Negotiated lifetime of new SA
@@ -486,8 +486,8 @@ static bool add_ke(private_quick_mode_t *this, message_t *message)
{
ke_payload_t *ke_payload;
ke_payload = ke_payload_create_from_diffie_hellman(PLV1_KEY_EXCHANGE,
this->dh);
ke_payload = ke_payload_create_from_key_exchange(PLV1_KEY_EXCHANGE,
this->dh);
if (!ke_payload)
{
DBG1(DBG_IKE, "creating KE payload failed");
@@ -510,7 +510,7 @@ static bool get_ke(private_quick_mode_t *this, message_t *message)
DBG1(DBG_IKE, "KE payload missing");
return FALSE;
}
if (!this->dh->set_other_public_value(this->dh,
if (!this->dh->set_public_key(this->dh,
ke_payload->get_key_exchange_data(ke_payload)))
{
DBG1(DBG_IKE, "unable to apply received KE value");
@@ -785,7 +785,7 @@ static status_t send_notify(private_quick_mode_t *this, notify_type_t type)
* DH group, unless it is set to MODP_NONE.
*/
static linked_list_t *get_proposals(private_quick_mode_t *this,
diffie_hellman_group_t group)
key_exchange_method_t group)
{
linked_list_t *list;
proposal_t *proposal;
@@ -797,13 +797,13 @@ static linked_list_t *get_proposals(private_quick_mode_t *this,
{
if (group != MODP_NONE)
{
if (!proposal->has_dh_group(proposal, group))
if (!proposal->has_ke_method(proposal, group))
{
list->remove_at(list, enumerator);
proposal->destroy(proposal);
continue;
}
proposal->promote_dh_group(proposal, group);
proposal->promote_ke_method(proposal, group);
}
proposal->set_spi(proposal, this->spi_i);
}
@@ -822,7 +822,7 @@ METHOD(task_t, build_i, status_t,
sa_payload_t *sa_payload;
linked_list_t *list, *tsi, *tsr;
proposal_t *proposal;
diffie_hellman_group_t group;
key_exchange_method_t group;
encap_t encap;
this->mode = this->config->get_mode(this->config);
@@ -866,14 +866,14 @@ METHOD(task_t, build_i, status_t,
return FAILED;
}
group = this->config->get_dh_group(this->config);
group = this->config->get_ke_method(this->config);
if (group != MODP_NONE)
{
proposal_t *proposal;
uint16_t preferred_group;
proposal = this->ike_sa->get_proposal(this->ike_sa);
proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP,
proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD,
&preferred_group, NULL);
/* try the negotiated DH group from IKE_SA */
list = get_proposals(this, preferred_group);
@@ -888,12 +888,12 @@ METHOD(task_t, build_i, status_t,
list = get_proposals(this, group);
}
this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
this->dh = this->keymat->keymat.create_ke(&this->keymat->keymat,
group);
if (!this->dh)
{
DBG1(DBG_IKE, "configured DH group %N not supported",
diffie_hellman_group_names, group);
key_exchange_method_names, group);
list->destroy_offset(list, offsetof(proposal_t, destroy));
return FAILED;
}
@@ -1165,14 +1165,14 @@ METHOD(task_t, process_r, status_t,
}
if (this->proposal->get_algorithm(this->proposal,
DIFFIE_HELLMAN_GROUP, &group, NULL))
KEY_EXCHANGE_METHOD, &group, NULL))
{
this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
this->dh = this->keymat->keymat.create_ke(&this->keymat->keymat,
group);
if (!this->dh)
{
DBG1(DBG_IKE, "negotiated DH group %N not supported",
diffie_hellman_group_names, group);
key_exchange_method_names, group);
return send_notify(this, INVALID_KEY_INFORMATION);
}
if (!get_ke(this, message))
+6 -6
View File
@@ -84,10 +84,10 @@ METHOD(keymat_t, get_version, ike_version_t,
return IKEV2;
}
METHOD(keymat_t, create_dh, diffie_hellman_t*,
private_keymat_v2_t *this, diffie_hellman_group_t group)
METHOD(keymat_t, create_ke, key_exchange_t*,
private_keymat_v2_t *this, key_exchange_method_t method)
{
return lib->crypto->create_dh(lib->crypto, group);
return lib->crypto->create_ke(lib->crypto, method);
}
METHOD(keymat_t, create_nonce_gen, nonce_gen_t*,
@@ -237,7 +237,7 @@ static bool set_aead_keys(private_keymat_v2_t *this, uint16_t enc_alg,
}
METHOD(keymat_v2_t, derive_ike_keys, bool,
private_keymat_v2_t *this, proposal_t *proposal, diffie_hellman_t *dh,
private_keymat_v2_t *this, proposal_t *proposal, key_exchange_t *dh,
chunk_t nonce_i, chunk_t nonce_r, ike_sa_id_t *id,
pseudo_random_function_t rekey_function, chunk_t rekey_skd)
{
@@ -523,7 +523,7 @@ METHOD(keymat_v2_t, derive_ike_keys_ppk, bool,
}
METHOD(keymat_v2_t, derive_child_keys, bool,
private_keymat_v2_t *this, proposal_t *proposal, diffie_hellman_t *dh,
private_keymat_v2_t *this, proposal_t *proposal, key_exchange_t *dh,
chunk_t nonce_i, chunk_t nonce_r, chunk_t *encr_i, chunk_t *integ_i,
chunk_t *encr_r, chunk_t *integ_r)
{
@@ -796,7 +796,7 @@ keymat_v2_t *keymat_v2_create(bool initiator)
.public = {
.keymat = {
.get_version = _get_version,
.create_dh = _create_dh,
.create_ke = _create_ke,
.create_nonce_gen = _create_nonce_gen,
.get_aead = _get_aead,
.destroy = _destroy,
+4 -4
View File
@@ -44,7 +44,7 @@ struct keymat_v2_t {
* crypters and authentication functions.
*
* @param proposal selected algorithms
* @param dh diffie hellman key allocated by create_dh()
* @param dh diffie hellman key allocated by create_ke()
* @param nonce_i initiators nonce value
* @param nonce_r responders nonce value
* @param id IKE_SA identifier
@@ -53,7 +53,7 @@ struct keymat_v2_t {
* @return TRUE on success
*/
bool (*derive_ike_keys)(keymat_v2_t *this, proposal_t *proposal,
diffie_hellman_t *dh, chunk_t nonce_i,
key_exchange_t *dh, chunk_t nonce_i,
chunk_t nonce_r, ike_sa_id_t *id,
pseudo_random_function_t rekey_function,
chunk_t rekey_skd);
@@ -77,7 +77,7 @@ struct keymat_v2_t {
* If no PFS is used for the CHILD_SA, dh can be NULL.
*
* @param proposal selected algorithms
* @param dh diffie hellman key allocated by create_dh(), or NULL
* @param dh diffie hellman key allocated by create_ke(), or NULL
* @param nonce_i initiators nonce value
* @param nonce_r responders nonce value
* @param encr_i chunk to write initiators encryption key to
@@ -87,7 +87,7 @@ struct keymat_v2_t {
* @return TRUE on success
*/
bool (*derive_child_keys)(keymat_v2_t *this,
proposal_t *proposal, diffie_hellman_t *dh,
proposal_t *proposal, key_exchange_t *dh,
chunk_t nonce_i, chunk_t nonce_r,
chunk_t *encr_i, chunk_t *integ_i,
chunk_t *encr_r, chunk_t *integ_r);
+25 -24
View File
@@ -20,7 +20,7 @@
#include <daemon.h>
#include <sa/ikev2/keymat_v2.h>
#include <crypto/diffie_hellman.h>
#include <crypto/key_exchange.h>
#include <credentials/certificates/x509.h>
#include <encoding/payloads/sa_payload.h>
#include <encoding/payloads/ke_payload.h>
@@ -117,7 +117,7 @@ struct private_child_create_t {
/**
* optional diffie hellman exchange
*/
diffie_hellman_t *dh;
key_exchange_t *dh;
/**
* Applying DH public value failed?
@@ -127,7 +127,7 @@ struct private_child_create_t {
/**
* group used for DH exchange
*/
diffie_hellman_group_t dh_group;
key_exchange_method_t dh_group;
/**
* IKE_SAs keymat
@@ -328,7 +328,7 @@ static bool update_and_check_proposals(private_child_create_t *this)
if (this->dh_group != MODP_NONE)
{ /* proposals that don't contain the selected group are
* moved to the back */
if (!proposal->promote_dh_group(proposal, this->dh_group))
if (!proposal->promote_ke_method(proposal, this->dh_group))
{
this->proposals->remove_at(this->proposals, enumerator);
other_dh_groups->insert_last(other_dh_groups, proposal);
@@ -518,7 +518,7 @@ static status_t select_and_install(private_child_create_t *this,
if (no_dh)
{
flags |= PROPOSAL_SKIP_DH;
flags |= PROPOSAL_SKIP_KE;
}
if (!this->ike_sa->supports_extension(this->ike_sa, EXT_STRONGSWAN) &&
!lib->settings->get_bool(lib->settings, "%s.accept_private_algs",
@@ -554,16 +554,16 @@ static status_t select_and_install(private_child_create_t *this,
}
this->child_sa->set_proposal(this->child_sa, this->proposal);
if (!this->proposal->has_dh_group(this->proposal, this->dh_group))
if (!this->proposal->has_ke_method(this->proposal, this->dh_group))
{
uint16_t group;
if (this->proposal->get_algorithm(this->proposal, DIFFIE_HELLMAN_GROUP,
if (this->proposal->get_algorithm(this->proposal, KEY_EXCHANGE_METHOD,
&group, NULL))
{
DBG1(DBG_IKE, "DH group %N unacceptable, requesting %N",
diffie_hellman_group_names, this->dh_group,
diffie_hellman_group_names, group);
key_exchange_method_names, this->dh_group,
key_exchange_method_names, group);
this->dh_group = group;
return INVALID_ARG;
}
@@ -836,8 +836,8 @@ static bool build_payloads(private_child_create_t *this, message_t *message)
/* diffie hellman exchange, if PFS enabled */
if (this->dh)
{
ke_payload = ke_payload_create_from_diffie_hellman(PLV2_KEY_EXCHANGE,
this->dh);
ke_payload = ke_payload_create_from_key_exchange(PLV2_KEY_EXCHANGE,
this->dh);
if (!ke_payload)
{
DBG1(DBG_IKE, "creating KE payload failed");
@@ -979,18 +979,19 @@ static void process_payloads(private_child_create_t *this, message_t *message)
ke_payload = (ke_payload_t*)payload;
if (!this->initiator)
{
this->dh_group = ke_payload->get_dh_group_number(ke_payload);
this->dh = this->keymat->keymat.create_dh(
this->dh_group = ke_payload->get_key_exchange_method(
ke_payload);
this->dh = this->keymat->keymat.create_ke(
&this->keymat->keymat, this->dh_group);
}
else if (this->dh)
{
this->dh_failed = this->dh->get_dh_group(this->dh) !=
ke_payload->get_dh_group_number(ke_payload);
this->dh_failed = this->dh->get_method(this->dh) !=
ke_payload->get_key_exchange_method(ke_payload);
}
if (this->dh && !this->dh_failed)
{
this->dh_failed = !this->dh->set_other_public_value(this->dh,
this->dh_failed = !this->dh->set_public_key(this->dh,
ke_payload->get_key_exchange_data(ke_payload));
}
break;
@@ -1157,7 +1158,7 @@ METHOD(task_t, build_i, status_t,
}
if (!this->retry && this->dh_group == MODP_NONE)
{ /* during a rekeying the group might already be set */
this->dh_group = this->config->get_dh_group(this->config);
this->dh_group = this->config->get_ke_method(this->config);
}
break;
case IKE_AUTH:
@@ -1287,13 +1288,13 @@ METHOD(task_t, build_i, status_t,
{
DBG1(DBG_IKE, "requested DH group %N not contained in any of our "
"proposals",
diffie_hellman_group_names, this->dh_group);
key_exchange_method_names, this->dh_group);
return FAILED;
}
if (this->dh_group != MODP_NONE)
{
this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
this->dh = this->keymat->keymat.create_ke(&this->keymat->keymat,
this->dh_group);
}
@@ -1829,15 +1830,15 @@ METHOD(task_t, process_i, status_t,
if (this->retry)
{
DBG1(DBG_IKE, "already retried with DH group %N, "
"ignore requested %N", diffie_hellman_group_names,
this->dh_group, diffie_hellman_group_names, group);
"ignore requested %N", key_exchange_method_names,
this->dh_group, key_exchange_method_names, group);
handle_child_sa_failure(this, message);
/* an error in CHILD_SA creation is not critical */
return SUCCESS;
}
DBG1(DBG_IKE, "peer didn't accept DH group %N, "
"it requested %N", diffie_hellman_group_names,
this->dh_group, diffie_hellman_group_names, group);
"it requested %N", key_exchange_method_names,
this->dh_group, key_exchange_method_names, group);
this->retry = TRUE;
this->dh_group = group;
this->child_sa->set_state(this->child_sa, CHILD_RETRYING);
@@ -1945,7 +1946,7 @@ METHOD(child_create_t, use_label, void,
}
METHOD(child_create_t, use_dh_group, void,
private_child_create_t *this, diffie_hellman_group_t dh_group)
private_child_create_t *this, key_exchange_method_t dh_group)
{
this->dh_group = dh_group;
}
+1 -1
View File
@@ -83,7 +83,7 @@ struct child_create_t {
*
* @param dh_group DH group to use
*/
void (*use_dh_group)(child_create_t *this, diffie_hellman_group_t dh_group);
void (*use_dh_group)(child_create_t *this, key_exchange_method_t dh_group);
/**
* Get the lower of the two nonces, used for rekey collisions.
+1 -1
View File
@@ -197,7 +197,7 @@ METHOD(task_t, build_i, status_t,
config->get_ref(config), TRUE, NULL, NULL);
proposal = this->child_sa->get_proposal(this->child_sa);
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP,
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD,
&dh_group, NULL))
{ /* reuse the DH group negotiated previously */
this->child_create->use_dh_group(this->child_create, dh_group);
+27 -27
View File
@@ -24,7 +24,7 @@
#include <bio/bio_reader.h>
#include <bio/bio_writer.h>
#include <sa/ikev2/keymat_v2.h>
#include <crypto/diffie_hellman.h>
#include <crypto/key_exchange.h>
#include <crypto/hashers/hash_algorithm_set.h>
#include <encoding/payloads/sa_payload.h>
#include <encoding/payloads/ke_payload.h>
@@ -58,12 +58,12 @@ struct private_ike_init_t {
/**
* diffie hellman group to use
*/
diffie_hellman_group_t dh_group;
key_exchange_method_t dh_group;
/**
* diffie hellman key exchange
*/
diffie_hellman_t *dh;
key_exchange_t *dh;
/**
* Applying DH public value failed?
@@ -333,7 +333,7 @@ static bool build_payloads(private_ike_init_t *this, message_t *message)
proposal->set_spi(proposal, id->get_initiator_spi(id));
}
/* move the selected DH group to the front of the proposal */
if (!proposal->promote_dh_group(proposal, this->dh_group))
if (!proposal->promote_ke_method(proposal, this->dh_group))
{ /* the proposal does not include the group, move to the back */
proposal_list->remove_at(proposal_list, enumerator);
other_dh_groups->insert_last(other_dh_groups, proposal);
@@ -363,8 +363,8 @@ static bool build_payloads(private_ike_init_t *this, message_t *message)
}
message->add_payload(message, (payload_t*)sa_payload);
ke_payload = ke_payload_create_from_diffie_hellman(PLV2_KEY_EXCHANGE,
this->dh);
ke_payload = ke_payload_create_from_key_exchange(PLV2_KEY_EXCHANGE,
this->dh);
if (!ke_payload)
{
DBG1(DBG_IKE, "creating KE payload failed");
@@ -535,7 +535,7 @@ static void process_payloads(private_ike_init_t *this, message_t *message)
{
ke_payload = (ke_payload_t*)payload;
this->dh_group = ke_payload->get_dh_group_number(ke_payload);
this->dh_group = ke_payload->get_key_exchange_method(ke_payload);
break;
}
case PLV2_NONCE:
@@ -617,20 +617,20 @@ static void process_payloads(private_ike_init_t *this, message_t *message)
}
if (ke_payload && this->proposal &&
this->proposal->has_dh_group(this->proposal, this->dh_group))
this->proposal->has_ke_method(this->proposal, this->dh_group))
{
if (!this->initiator)
{
this->dh = this->keymat->keymat.create_dh(
this->dh = this->keymat->keymat.create_ke(
&this->keymat->keymat, this->dh_group);
}
else if (this->dh)
{
this->dh_failed = this->dh->get_dh_group(this->dh) != this->dh_group;
this->dh_failed = this->dh->get_method(this->dh) != this->dh_group;
}
if (this->dh && !this->dh_failed)
{
this->dh_failed = !this->dh->set_other_public_value(this->dh,
this->dh_failed = !this->dh->set_public_key(this->dh,
ke_payload->get_key_exchange_data(ke_payload));
}
}
@@ -665,38 +665,38 @@ METHOD(task_t, build_i, status_t,
uint16_t dh_group;
proposal = this->old_sa->get_proposal(this->old_sa);
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP,
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD,
&dh_group, NULL))
{
this->dh_group = dh_group;
}
else
{ /* this shouldn't happen, but let's be safe */
this->dh_group = ike_cfg->get_dh_group(ike_cfg);
this->dh_group = ike_cfg->get_ke_method(ike_cfg);
}
}
else
{
this->dh_group = ike_cfg->get_dh_group(ike_cfg);
this->dh_group = ike_cfg->get_ke_method(ike_cfg);
}
this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
this->dh = this->keymat->keymat.create_ke(&this->keymat->keymat,
this->dh_group);
if (!this->dh)
{
DBG1(DBG_IKE, "configured DH group %N not supported",
diffie_hellman_group_names, this->dh_group);
key_exchange_method_names, this->dh_group);
return FAILED;
}
}
else if (this->dh->get_dh_group(this->dh) != this->dh_group)
else if (this->dh->get_method(this->dh) != this->dh_group)
{ /* reset DH instance if group changed (INVALID_KE_PAYLOAD) */
this->dh->destroy(this->dh);
this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
this->dh = this->keymat->keymat.create_ke(&this->keymat->keymat,
this->dh_group);
if (!this->dh)
{
DBG1(DBG_IKE, "requested DH group %N not supported",
diffie_hellman_group_names, this->dh_group);
key_exchange_method_names, this->dh_group);
return FAILED;
}
}
@@ -829,16 +829,16 @@ METHOD(task_t, build_r, status_t,
}
if (this->dh == NULL ||
!this->proposal->has_dh_group(this->proposal, this->dh_group))
!this->proposal->has_ke_method(this->proposal, this->dh_group))
{
uint16_t group;
if (this->proposal->get_algorithm(this->proposal, DIFFIE_HELLMAN_GROUP,
if (this->proposal->get_algorithm(this->proposal, KEY_EXCHANGE_METHOD,
&group, NULL))
{
DBG1(DBG_IKE, "DH group %N unacceptable, requesting %N",
diffie_hellman_group_names, this->dh_group,
diffie_hellman_group_names, group);
key_exchange_method_names, this->dh_group,
key_exchange_method_names, group);
this->dh_group = group;
group = htons(group);
message->add_notify(message, FALSE, INVALID_KE_PAYLOAD,
@@ -976,14 +976,14 @@ METHOD(task_t, process_i, status_t,
case INVALID_KE_PAYLOAD:
{
chunk_t data;
diffie_hellman_group_t bad_group;
key_exchange_method_t bad_group;
bad_group = this->dh_group;
data = notify->get_notification_data(notify);
this->dh_group = ntohs(*((uint16_t*)data.ptr));
DBG1(DBG_IKE, "peer didn't accept DH group %N, "
"it requested %N", diffie_hellman_group_names,
bad_group, diffie_hellman_group_names, this->dh_group);
"it requested %N", key_exchange_method_names,
bad_group, key_exchange_method_names, this->dh_group);
if (this->old_sa == NULL)
{ /* reset the IKE_SA if we are not rekeying */
@@ -1064,7 +1064,7 @@ METHOD(task_t, process_i, status_t,
}
if (this->dh == NULL ||
!this->proposal->has_dh_group(this->proposal, this->dh_group))
!this->proposal->has_ke_method(this->proposal, this->dh_group))
{
DBG1(DBG_IKE, "peer DH group selection invalid");
return FAILED;
+10 -11
View File
@@ -53,22 +53,21 @@ struct keymat_t {
ike_version_t (*get_version)(keymat_t *this);
/**
* Create a diffie hellman object for key agreement.
* Create a key exchange object for key agreement.
*
* The diffie hellman is either for IKE negotiation/rekeying or
* CHILD_SA rekeying (using PFS). The resulting DH object must be passed
* to derive_keys or to derive_child_keys and destroyed after use.
* The key exchange is either for IKE negotiation/rekeying or
* CHILD_SA rekeying (using PFS). The resulting object must be passed
* to derive_ike_keys() or to derive_child_keys() and destroyed after use.
*
* Only DH objects allocated through this method are passed to other
* keymat_t methods, allowing private DH implementations. In some cases
* (such as retrying with a COOKIE), a DH object allocated from a different
* Only objects allocated through this method are passed to other
* keymat_t methods, allowing private KE implementations. In some cases
* (such as retrying with a COOKIE), a KE object allocated from a different
* keymat_t instance may be passed to other methods.
*
* @param group diffie hellman group
* @return DH object, NULL if group not supported
* @param method key exchange method
* @return key exchange object, NULL if method not supported
*/
diffie_hellman_t* (*create_dh)(keymat_t *this,
diffie_hellman_group_t group);
key_exchange_t* (*create_ke)(keymat_t *this, key_exchange_method_t method);
/**
* Create a nonce generator object.
@@ -74,7 +74,7 @@ START_TEST(test_chacha20poly1305)
chunk_t chunk, exp;
keymat_t keymat = {
.get_version = _get_version,
.create_dh = (void*)return_null,
.create_ke = (void*)return_null,
.create_nonce_gen = (void*)return_null,
.get_aead = _get_aead,
};
@@ -332,11 +332,11 @@ void exchange_test_helper_init(char *plugins)
private_exchange_test_helper_t *this;
private_backend_t *backend;
plugin_feature_t features[] = {
PLUGIN_REGISTER(DH, mock_dh_create),
PLUGIN_REGISTER(KE, mock_dh_create),
/* we only need to support a limited number of DH groups */
PLUGIN_PROVIDE(DH, MODP_2048_BIT),
PLUGIN_PROVIDE(DH, MODP_3072_BIT),
PLUGIN_PROVIDE(DH, ECP_256_BIT),
PLUGIN_PROVIDE(KE, MODP_2048_BIT),
PLUGIN_PROVIDE(KE, MODP_3072_BIT),
PLUGIN_PROVIDE(KE, ECP_256_BIT),
PLUGIN_REGISTER(NONCE_GEN, create_nonce_gen),
PLUGIN_PROVIDE(NONCE_GEN),
PLUGIN_DEPENDS(RNG, RNG_WEAK),
+14 -14
View File
@@ -34,41 +34,41 @@ struct private_diffie_hellman_t {
/**
* Public interface
*/
diffie_hellman_t public;
key_exchange_t public;
/**
* Instantiated DH group
* Instantiated key exchagne method
*/
diffie_hellman_group_t group;
key_exchange_method_t method;
};
METHOD(diffie_hellman_t, get_my_public_value, bool,
METHOD(key_exchange_t, get_public_key, bool,
private_diffie_hellman_t *this, chunk_t *value)
{
*value = chunk_clone(mock_key);
return TRUE;
}
METHOD(diffie_hellman_t, set_other_public_value, bool,
METHOD(key_exchange_t, set_public_key, bool,
private_diffie_hellman_t *this, chunk_t value)
{
return TRUE;
}
METHOD(diffie_hellman_t, get_shared_secret, bool,
METHOD(key_exchange_t, get_shared_secret, bool,
private_diffie_hellman_t *this, chunk_t *secret)
{
*secret = chunk_clone(mock_key);
return TRUE;
}
METHOD(diffie_hellman_t, get_dh_group, diffie_hellman_group_t,
METHOD(key_exchange_t, get_method, key_exchange_method_t,
private_diffie_hellman_t *this)
{
return this->group;
return this->method;
}
METHOD(diffie_hellman_t, destroy, void,
METHOD(key_exchange_t, destroy, void,
private_diffie_hellman_t *this)
{
free(this);
@@ -77,19 +77,19 @@ METHOD(diffie_hellman_t, destroy, void,
/**
* See header
*/
diffie_hellman_t *mock_dh_create(diffie_hellman_group_t group)
key_exchange_t *mock_dh_create(key_exchange_method_t method)
{
private_diffie_hellman_t *this;
INIT(this,
.public = {
.get_shared_secret = _get_shared_secret,
.set_other_public_value = _set_other_public_value,
.get_my_public_value = _get_my_public_value,
.get_dh_group = _get_dh_group,
.set_public_key = _set_public_key,
.get_public_key = _get_public_key,
.get_method = _get_method,
.destroy = _destroy,
},
.group = group,
.method = method,
);
return &this->public;
}
+4 -4
View File
@@ -25,14 +25,14 @@
#ifndef MOCK_DH_H_
#define MOCK_DH_H_
#include <crypto/diffie_hellman.h>
#include <crypto/key_exchange.h>
/**
* Creates a diffie_hellman_t object.
* Creates a key_exchange_t object.
*
* @param group Diffie Hellman group, supports MODP_NULL only
* @param method key_exchange method, supports MODP_NULL only
* @return created object
*/
diffie_hellman_t *mock_dh_create(diffie_hellman_group_t group);
key_exchange_t *mock_dh_create(key_exchange_method_t method);
#endif /** MOCK_DH_H_ @}*/