Migrated keymat to INIT/METHOD macros

This commit is contained in:
Martin Willi
2010-08-19 12:35:53 +02:00
parent 6c620d5ee0
commit 5555b900b2
+40 -71
View File
@@ -134,23 +134,16 @@ static int lookup_keylen(keylen_entry_t *list, int algo)
return 0; return 0;
} }
/** METHOD(keymat_t, create_dh, diffie_hellman_t*,
* Implementation of keymat_t.create_dh private_keymat_t *this, diffie_hellman_group_t group)
*/
static diffie_hellman_t* create_dh(private_keymat_t *this,
diffie_hellman_group_t group)
{ {
return lib->crypto->create_dh(lib->crypto, group);; return lib->crypto->create_dh(lib->crypto, group);;
} }
/** METHOD(keymat_t, derive_ike_keys, bool,
* Implementation of keymat_t.derive_keys private_keymat_t *this, proposal_t *proposal, diffie_hellman_t *dh,
*/ chunk_t nonce_i, chunk_t nonce_r, ike_sa_id_t *id,
static bool derive_ike_keys(private_keymat_t *this, proposal_t *proposal, pseudo_random_function_t rekey_function, chunk_t rekey_skd)
diffie_hellman_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)
{ {
chunk_t skeyseed, key, secret, full_nonce, fixed_nonce, prf_plus_seed; chunk_t skeyseed, key, secret, full_nonce, fixed_nonce, prf_plus_seed;
chunk_t spi_i, spi_r; chunk_t spi_i, spi_r;
@@ -374,14 +367,10 @@ static bool derive_ike_keys(private_keymat_t *this, proposal_t *proposal,
return TRUE; return TRUE;
} }
/** METHOD(keymat_t, derive_child_keys, bool,
* Implementation of keymat_t.derive_child_keys private_keymat_t *this, proposal_t *proposal, diffie_hellman_t *dh,
*/ chunk_t nonce_i, chunk_t nonce_r, chunk_t *encr_i, chunk_t *integ_i,
static bool derive_child_keys(private_keymat_t *this, chunk_t *encr_r, chunk_t *integ_r)
proposal_t *proposal, diffie_hellman_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)
{ {
u_int16_t enc_alg, int_alg, enc_size = 0, int_size = 0; u_int16_t enc_alg, int_alg, enc_size = 0, int_size = 0;
chunk_t seed, secret = chunk_empty; chunk_t seed, secret = chunk_empty;
@@ -483,37 +472,28 @@ static bool derive_child_keys(private_keymat_t *this,
return TRUE; return TRUE;
} }
/** METHOD(keymat_t, get_skd, pseudo_random_function_t,
* Implementation of keymat_t.get_skd private_keymat_t *this, chunk_t *skd)
*/
static pseudo_random_function_t get_skd(private_keymat_t *this, chunk_t *skd)
{ {
*skd = this->skd; *skd = this->skd;
return this->prf_alg; return this->prf_alg;
} }
/** METHOD(keymat_t, get_signer, signer_t*,
* Implementation of keymat_t.get_signer private_keymat_t *this, bool in)
*/
static signer_t* get_signer(private_keymat_t *this, bool in)
{ {
return in ? this->signer_in : this->signer_out; return in ? this->signer_in : this->signer_out;
} }
/** METHOD(keymat_t, get_crypter, crypter_t*,
* Implementation of keymat_t.get_crypter private_keymat_t *this, bool in)
*/
static crypter_t* get_crypter(private_keymat_t *this, bool in)
{ {
return in ? this->crypter_in : this->crypter_out; return in ? this->crypter_in : this->crypter_out;
} }
/** METHOD(keymat_t, get_auth_octets, chunk_t,
* Implementation of keymat_t.get_auth_octets private_keymat_t *this, bool verify, chunk_t ike_sa_init,
*/ chunk_t nonce, identification_t *id)
static chunk_t get_auth_octets(private_keymat_t *this, bool verify,
chunk_t ike_sa_init, chunk_t nonce,
identification_t *id)
{ {
chunk_t chunk, idx, octets; chunk_t chunk, idx, octets;
chunk_t skp; chunk_t skp;
@@ -541,12 +521,9 @@ static chunk_t get_auth_octets(private_keymat_t *this, bool verify,
#define IKEV2_KEY_PAD "Key Pad for IKEv2" #define IKEV2_KEY_PAD "Key Pad for IKEv2"
#define IKEV2_KEY_PAD_LENGTH 17 #define IKEV2_KEY_PAD_LENGTH 17
/** METHOD(keymat_t, get_psk_sig, chunk_t,
* Implementation of keymat_t.get_psk_sig private_keymat_t *this, bool verify, chunk_t ike_sa_init,
*/ chunk_t nonce, chunk_t secret, identification_t *id)
static chunk_t get_psk_sig(private_keymat_t *this, bool verify,
chunk_t ike_sa_init, chunk_t nonce, chunk_t secret,
identification_t *id)
{ {
chunk_t key_pad, key, sig, octets; chunk_t key_pad, key, sig, octets;
@@ -570,10 +547,8 @@ static chunk_t get_psk_sig(private_keymat_t *this, bool verify,
return sig; return sig;
} }
/** METHOD(keymat_t, destroy, void,
* Implementation of keymat_t.destroy. private_keymat_t *this)
*/
static void destroy(private_keymat_t *this)
{ {
DESTROY_IF(this->signer_in); DESTROY_IF(this->signer_in);
DESTROY_IF(this->signer_out); DESTROY_IF(this->signer_out);
@@ -591,29 +566,23 @@ static void destroy(private_keymat_t *this)
*/ */
keymat_t *keymat_create(bool initiator) keymat_t *keymat_create(bool initiator)
{ {
private_keymat_t *this = malloc_thing(private_keymat_t); private_keymat_t *this;
this->public.create_dh = (diffie_hellman_t*(*)(keymat_t*, diffie_hellman_group_t group))create_dh; INIT(this,
this->public.derive_ike_keys = (bool(*)(keymat_t*, proposal_t *proposal, diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r, ike_sa_id_t *id, pseudo_random_function_t,chunk_t))derive_ike_keys; .public = {
this->public.derive_child_keys = (bool(*)(keymat_t*, proposal_t *proposal, diffie_hellman_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))derive_child_keys; .create_dh = _create_dh,
this->public.get_skd = (pseudo_random_function_t(*)(keymat_t*, chunk_t *skd))get_skd; .derive_ike_keys = _derive_ike_keys,
this->public.get_signer = (signer_t*(*)(keymat_t*, bool in))get_signer; .derive_child_keys = _derive_child_keys,
this->public.get_crypter = (crypter_t*(*)(keymat_t*, bool in))get_crypter; .get_skd = _get_skd,
this->public.get_auth_octets = (chunk_t(*)(keymat_t *, bool verify, chunk_t ike_sa_init, chunk_t nonce, identification_t *id))get_auth_octets; .get_signer = _get_signer,
this->public.get_psk_sig = (chunk_t(*)(keymat_t*, bool verify, chunk_t ike_sa_init, chunk_t nonce, chunk_t secret, identification_t *id))get_psk_sig; .get_crypter = _get_crypter,
this->public.destroy = (void(*)(keymat_t*))destroy; .get_auth_octets = _get_auth_octets,
.get_psk_sig = _get_psk_sig,
this->initiator = initiator; .destroy = _destroy,
},
this->signer_in = NULL; .initiator = initiator,
this->signer_out = NULL; .prf_alg = PRF_UNDEFINED,
this->crypter_in = NULL; );
this->crypter_out = NULL;
this->prf = NULL;
this->prf_alg = PRF_UNDEFINED;
this->skd = chunk_empty;
this->skp_verify = chunk_empty;
this->skp_build = chunk_empty;
return &this->public; return &this->public;
} }