Migratd simaka_crypto to INIT/METHOD macros

This commit is contained in:
Martin Willi
2011-08-08 13:36:56 +02:00
parent efee3ed80f
commit d1196ffe58
+38 -54
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 Martin Willi * Copyright (C) 2009-2011 Martin Willi
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
@@ -76,26 +76,20 @@ struct private_simaka_crypto_t {
bool derived; bool derived;
}; };
/** METHOD(simaka_crypto_t, get_signer, signer_t*,
* Implementation of simaka_crypto_t.get_signer private_simaka_crypto_t *this)
*/
static signer_t* get_signer(private_simaka_crypto_t *this)
{ {
return this->derived ? this->signer : NULL; return this->derived ? this->signer : NULL;
} }
/** METHOD(simaka_crypto_t, get_crypter, crypter_t*,
* Implementation of simaka_crypto_t.get_crypter private_simaka_crypto_t *this)
*/
static crypter_t* get_crypter(private_simaka_crypto_t *this)
{ {
return this->derived ? this->crypter : NULL; return this->derived ? this->crypter : NULL;
} }
/** METHOD(simaka_crypto_t, get_rng, rng_t*,
* Implementation of simaka_crypto_t.get_rng private_simaka_crypto_t *this)
*/
static rng_t* get_rng(private_simaka_crypto_t *this)
{ {
return this->rng; return this->rng;
} }
@@ -121,11 +115,9 @@ static void call_hook(private_simaka_crypto_t *this, chunk_t encr, chunk_t auth)
mgr->key_hook(mgr, encr, auth); mgr->key_hook(mgr, encr, auth);
} }
/** METHOD(simaka_crypto_t, derive_keys_full, chunk_t,
* Implementation of simaka_crypto_t.derive_keys_full private_simaka_crypto_t *this, identification_t *id,
*/ chunk_t data, chunk_t *mk)
static chunk_t derive_keys_full(private_simaka_crypto_t *this,
identification_t *id, chunk_t data, chunk_t *mk)
{ {
chunk_t str, msk, k_encr, k_auth; chunk_t str, msk, k_encr, k_auth;
int i; int i;
@@ -158,10 +150,8 @@ static chunk_t derive_keys_full(private_simaka_crypto_t *this,
return chunk_clone(msk); return chunk_clone(msk);
} }
/** METHOD(simaka_crypto_t, derive_keys_reauth, void,
* Implementation of simaka_crypto_t.derive_keys_reauth private_simaka_crypto_t *this, chunk_t mk)
*/
static void derive_keys_reauth(private_simaka_crypto_t *this, chunk_t mk)
{ {
chunk_t str, k_encr, k_auth; chunk_t str, k_encr, k_auth;
int i; int i;
@@ -185,12 +175,9 @@ static void derive_keys_reauth(private_simaka_crypto_t *this, chunk_t mk)
this->derived = TRUE; this->derived = TRUE;
} }
/** METHOD(simaka_crypto_t, derive_keys_reauth_msk, chunk_t,
* Implementation of simaka_crypto_t.derive_keys_reauth_msk private_simaka_crypto_t *this, identification_t *id, chunk_t counter,
*/ chunk_t nonce_s, chunk_t mk)
static chunk_t derive_keys_reauth_msk(private_simaka_crypto_t *this,
identification_t *id, chunk_t counter,
chunk_t nonce_s, chunk_t mk)
{ {
char xkey[HASH_SIZE_SHA1]; char xkey[HASH_SIZE_SHA1];
chunk_t str, msk; chunk_t str, msk;
@@ -214,18 +201,14 @@ static chunk_t derive_keys_reauth_msk(private_simaka_crypto_t *this,
return chunk_clone(msk); return chunk_clone(msk);
} }
/** METHOD(simaka_crypto_t, clear_keys, void,
* Implementation of simaka_crypto_t.clear_keys private_simaka_crypto_t *this)
*/
static void clear_keys(private_simaka_crypto_t *this)
{ {
this->derived = FALSE; this->derived = FALSE;
} }
/** METHOD(simaka_crypto_t, destroy, void,
* Implementation of simaka_crypto_t.destroy. private_simaka_crypto_t *this)
*/
static void destroy(private_simaka_crypto_t *this)
{ {
DESTROY_IF(this->rng); DESTROY_IF(this->rng);
DESTROY_IF(this->hasher); DESTROY_IF(this->hasher);
@@ -240,24 +223,26 @@ static void destroy(private_simaka_crypto_t *this)
*/ */
simaka_crypto_t *simaka_crypto_create(eap_type_t type) simaka_crypto_t *simaka_crypto_create(eap_type_t type)
{ {
private_simaka_crypto_t *this = malloc_thing(private_simaka_crypto_t); private_simaka_crypto_t *this;
this->public.get_signer = (signer_t*(*)(simaka_crypto_t*))get_signer; INIT(this,
this->public.get_crypter = (crypter_t*(*)(simaka_crypto_t*))get_crypter; .public = {
this->public.get_rng = (rng_t*(*)(simaka_crypto_t*))get_rng; .get_signer = _get_signer,
this->public.derive_keys_full = (chunk_t(*)(simaka_crypto_t*, identification_t *id, chunk_t data, chunk_t *mk))derive_keys_full; .get_crypter = _get_crypter,
this->public.derive_keys_reauth = (void(*)(simaka_crypto_t*, chunk_t mk))derive_keys_reauth; .get_rng = _get_rng,
this->public.derive_keys_reauth_msk = (chunk_t(*)(simaka_crypto_t*, identification_t *id, chunk_t counter, chunk_t nonce_s, chunk_t mk))derive_keys_reauth_msk; .derive_keys_full = _derive_keys_full,
this->public.clear_keys = (void(*)(simaka_crypto_t*))clear_keys; .derive_keys_reauth = _derive_keys_reauth,
this->public.destroy = (void(*)(simaka_crypto_t*))destroy; .derive_keys_reauth_msk = _derive_keys_reauth_msk,
.clear_keys = _clear_keys,
this->type = type; .destroy = _destroy,
this->derived = FALSE; },
this->rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK); .type = type,
this->hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1); .rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK),
this->prf = lib->crypto->create_prf(lib->crypto, PRF_FIPS_SHA1_160); .hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1),
this->signer = lib->crypto->create_signer(lib->crypto, AUTH_HMAC_SHA1_128); .prf = lib->crypto->create_prf(lib->crypto, PRF_FIPS_SHA1_160),
this->crypter = lib->crypto->create_crypter(lib->crypto, ENCR_AES_CBC, 16); .signer = lib->crypto->create_signer(lib->crypto, AUTH_HMAC_SHA1_128),
.crypter = lib->crypto->create_crypter(lib->crypto, ENCR_AES_CBC, 16),
);
if (!this->rng || !this->hasher || !this->prf || if (!this->rng || !this->hasher || !this->prf ||
!this->signer || !this->crypter) !this->signer || !this->crypter)
{ {
@@ -268,4 +253,3 @@ simaka_crypto_t *simaka_crypto_create(eap_type_t type)
} }
return &this->public; return &this->public;
} }