aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/transforms
diff options
context:
space:
mode:
Diffstat (limited to 'Source/charon/transforms')
-rw-r--r--Source/charon/transforms/crypters/aes_cbc_crypter.c159
-rw-r--r--Source/charon/transforms/crypters/aes_cbc_crypter.h19
-rw-r--r--Source/charon/transforms/crypters/crypter.c1
-rw-r--r--Source/charon/transforms/crypters/crypter.h19
-rw-r--r--Source/charon/transforms/diffie_hellman.c70
-rw-r--r--Source/charon/transforms/diffie_hellman.h19
-rw-r--r--Source/charon/transforms/hashers/hasher.c5
-rw-r--r--Source/charon/transforms/hashers/hasher.h18
-rw-r--r--Source/charon/transforms/hashers/md5_hasher.c40
-rw-r--r--Source/charon/transforms/hashers/md5_hasher.h4
-rw-r--r--Source/charon/transforms/hashers/sha1_hasher.c32
-rw-r--r--Source/charon/transforms/hashers/sha1_hasher.h4
-rw-r--r--Source/charon/transforms/hmac.c49
-rw-r--r--Source/charon/transforms/hmac.h19
-rw-r--r--Source/charon/transforms/prf_plus.c39
-rw-r--r--Source/charon/transforms/prf_plus.h17
-rw-r--r--Source/charon/transforms/prfs/hmac_prf.c27
-rw-r--r--Source/charon/transforms/prfs/hmac_prf.h6
-rw-r--r--Source/charon/transforms/prfs/prf.h19
-rw-r--r--Source/charon/transforms/signers/hmac_signer.c74
-rw-r--r--Source/charon/transforms/signers/hmac_signer.h17
-rw-r--r--Source/charon/transforms/signers/signer.c5
-rw-r--r--Source/charon/transforms/signers/signer.h27
23 files changed, 238 insertions, 451 deletions
diff --git a/Source/charon/transforms/crypters/aes_cbc_crypter.c b/Source/charon/transforms/crypters/aes_cbc_crypter.c
index 1800d2409..97855e7c3 100644
--- a/Source/charon/transforms/crypters/aes_cbc_crypter.c
+++ b/Source/charon/transforms/crypters/aes_cbc_crypter.c
@@ -1474,90 +1474,90 @@ static status_t set_key (private_aes_cbc_crypter_t *this, chunk_t key)
{
u_int32_t *kf, *kt, rci, f = 0;
u_int8_t *in_key = key.ptr;
-
+
if (key.len != this->blocksize)
{
return INVALID_ARG;
}
-
- this->aes_Nrnd = (this->aes_Nkey > (this->aes_Ncol) ? this->aes_Nkey : (this->aes_Ncol)) + 6;
-
- this->aes_e_key[0] = const_word_in(in_key );
- this->aes_e_key[1] = const_word_in(in_key + 4);
- this->aes_e_key[2] = const_word_in(in_key + 8);
- this->aes_e_key[3] = const_word_in(in_key + 12);
-
- kf = this->aes_e_key;
- kt = kf + nc * (this->aes_Nrnd + 1) - this->aes_Nkey;
- rci = 0;
-
- switch(this->aes_Nkey)
+
+ this->aes_Nrnd = (this->aes_Nkey > (this->aes_Ncol) ? this->aes_Nkey : (this->aes_Ncol)) + 6;
+
+ this->aes_e_key[0] = const_word_in(in_key );
+ this->aes_e_key[1] = const_word_in(in_key + 4);
+ this->aes_e_key[2] = const_word_in(in_key + 8);
+ this->aes_e_key[3] = const_word_in(in_key + 12);
+
+ kf = this->aes_e_key;
+ kt = kf + nc * (this->aes_Nrnd + 1) - this->aes_Nkey;
+ rci = 0;
+
+ switch(this->aes_Nkey)
+ {
+ case 4: do
+ { kf[4] = kf[0] ^ ls_box(kf[3],3) ^ rcon_tab[rci++];
+ kf[5] = kf[1] ^ kf[4];
+ kf[6] = kf[2] ^ kf[5];
+ kf[7] = kf[3] ^ kf[6];
+ kf += 4;
+ }
+ while(kf < kt);
+ break;
+
+ case 6: this->aes_e_key[4] = const_word_in(in_key + 16);
+ this->aes_e_key[5] = const_word_in(in_key + 20);
+ do
+ { kf[ 6] = kf[0] ^ ls_box(kf[5],3) ^ rcon_tab[rci++];
+ kf[ 7] = kf[1] ^ kf[ 6];
+ kf[ 8] = kf[2] ^ kf[ 7];
+ kf[ 9] = kf[3] ^ kf[ 8];
+ kf[10] = kf[4] ^ kf[ 9];
+ kf[11] = kf[5] ^ kf[10];
+ kf += 6;
+ }
+ while(kf < kt);
+ break;
+
+ case 8: this->aes_e_key[4] = const_word_in(in_key + 16);
+ this->aes_e_key[5] = const_word_in(in_key + 20);
+ this->aes_e_key[6] = const_word_in(in_key + 24);
+ this->aes_e_key[7] = const_word_in(in_key + 28);
+ do
+ { kf[ 8] = kf[0] ^ ls_box(kf[7],3) ^ rcon_tab[rci++];
+ kf[ 9] = kf[1] ^ kf[ 8];
+ kf[10] = kf[2] ^ kf[ 9];
+ kf[11] = kf[3] ^ kf[10];
+ kf[12] = kf[4] ^ ls_box(kf[11],0);
+ kf[13] = kf[5] ^ kf[12];
+ kf[14] = kf[6] ^ kf[13];
+ kf[15] = kf[7] ^ kf[14];
+ kf += 8;
+ }
+ while (kf < kt);
+ break;
+ }
+
+ if(!f)
{
- case 4: do
- { kf[4] = kf[0] ^ ls_box(kf[3],3) ^ rcon_tab[rci++];
- kf[5] = kf[1] ^ kf[4];
- kf[6] = kf[2] ^ kf[5];
- kf[7] = kf[3] ^ kf[6];
- kf += 4;
- }
- while(kf < kt);
- break;
-
- case 6: this->aes_e_key[4] = const_word_in(in_key + 16);
- this->aes_e_key[5] = const_word_in(in_key + 20);
- do
- { kf[ 6] = kf[0] ^ ls_box(kf[5],3) ^ rcon_tab[rci++];
- kf[ 7] = kf[1] ^ kf[ 6];
- kf[ 8] = kf[2] ^ kf[ 7];
- kf[ 9] = kf[3] ^ kf[ 8];
- kf[10] = kf[4] ^ kf[ 9];
- kf[11] = kf[5] ^ kf[10];
- kf += 6;
- }
- while(kf < kt);
- break;
-
- case 8: this->aes_e_key[4] = const_word_in(in_key + 16);
- this->aes_e_key[5] = const_word_in(in_key + 20);
- this->aes_e_key[6] = const_word_in(in_key + 24);
- this->aes_e_key[7] = const_word_in(in_key + 28);
- do
- { kf[ 8] = kf[0] ^ ls_box(kf[7],3) ^ rcon_tab[rci++];
- kf[ 9] = kf[1] ^ kf[ 8];
- kf[10] = kf[2] ^ kf[ 9];
- kf[11] = kf[3] ^ kf[10];
- kf[12] = kf[4] ^ ls_box(kf[11],0);
- kf[13] = kf[5] ^ kf[12];
- kf[14] = kf[6] ^ kf[13];
- kf[15] = kf[7] ^ kf[14];
- kf += 8;
- }
- while (kf < kt);
- break;
- }
-
- if(!f)
- { u_int32_t i;
-
- kt = this->aes_d_key + nc * this->aes_Nrnd;
- kf = this->aes_e_key;
-
- cpy(kt, kf); kt -= 2 * nc;
-
- for(i = 1; i < this->aes_Nrnd; ++i)
- {
+ u_int32_t i;
+
+ kt = this->aes_d_key + nc * this->aes_Nrnd;
+ kf = this->aes_e_key;
+
+ cpy(kt, kf); kt -= 2 * nc;
+
+ for(i = 1; i < this->aes_Nrnd; ++i)
+ {
#if defined(ONE_TABLE) || defined(FOUR_TABLES)
#if !defined(ONE_IM_TABLE) && !defined(FOUR_IM_TABLES)
- u_int32_t f2, f4, f8, f9;
+ u_int32_t f2, f4, f8, f9;
#endif
- mix(kt, kf);
+ mix(kt, kf);
#else
- cpy(kt, kf);
+ cpy(kt, kf);
#endif
- kt -= 2 * nc;
+ kt -= 2 * nc;
}
-
- cpy(kt, kf);
+ cpy(kt, kf);
}
return SUCCESS;
@@ -1566,10 +1566,9 @@ static status_t set_key (private_aes_cbc_crypter_t *this, chunk_t key)
/**
* Implementation of crypter_t.destroy and aes_cbc_crypter_t.destroy.
*/
-static status_t destroy (private_aes_cbc_crypter_t *this)
+static void destroy (private_aes_cbc_crypter_t *this)
{
allocator_free(this);
- return SUCCESS;
}
/*
@@ -1578,10 +1577,7 @@ static status_t destroy (private_aes_cbc_crypter_t *this)
aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize)
{
private_aes_cbc_crypter_t *this = allocator_alloc_thing(private_aes_cbc_crypter_t);
- if (this == NULL)
- {
- return NULL;
- }
+
#if !defined(FIXED_TABLES)
if(!tab_gen) { gen_tabs(); tab_gen = 1; }
#endif
@@ -1610,10 +1606,7 @@ aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize)
this->public.crypter_interface.decrypt = (status_t (*) (crypter_t *, chunk_t , chunk_t, chunk_t *)) decrypt;
this->public.crypter_interface.get_block_size = (size_t (*) (crypter_t *)) get_block_size;
this->public.crypter_interface.set_key = (status_t (*) (crypter_t *,chunk_t)) set_key;
- this->public.crypter_interface.destroy = (status_t (*) (crypter_t *)) destroy;
-
- /* public functions */
- this->public.destroy = (status_t (*) (aes_cbc_crypter_t *)) destroy;
+ this->public.crypter_interface.destroy = (void (*) (crypter_t *)) destroy;
/* private functions */
this->decrypt_block = decrypt_block;
diff --git a/Source/charon/transforms/crypters/aes_cbc_crypter.h b/Source/charon/transforms/crypters/aes_cbc_crypter.h
index 4a8e935c8..1e5fd1717 100644
--- a/Source/charon/transforms/crypters/aes_cbc_crypter.h
+++ b/Source/charon/transforms/crypters/aes_cbc_crypter.h
@@ -40,26 +40,15 @@ struct aes_cbc_crypter_t {
* crypter_t interface.
*/
crypter_t crypter_interface;
-
- /**
- * @brief Destroys a aes_cbc_crypter_t object.
- *
- * @param this crypter_t object to destroy
- * @return
- * - SUCCESS in any case
- */
- status_t (*destroy) (aes_cbc_crypter_t *this);
};
/**
* @brief Constructor to create aes_cbc_crypter_t objects.
*
- * @param blocksize block size of AES crypter
- * (16, 24 or 32 are supported)
- * Default size is set to 16.
- * @return
- * - aes_cbc_crypter_t if successfully
- * - NULL if out of ressources
+ * @param blocksize block size of AES crypter
+ * (16, 24 or 32 are supported)
+ * Default size is set to 16.
+ * @return aes_cbc_crypter_t if successfully
*/
aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize);
diff --git a/Source/charon/transforms/crypters/crypter.c b/Source/charon/transforms/crypters/crypter.c
index 1a0f859eb..a72e5a554 100644
--- a/Source/charon/transforms/crypters/crypter.c
+++ b/Source/charon/transforms/crypters/crypter.c
@@ -56,7 +56,6 @@ crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm,size_t blo
case ENCR_AES_CBC:
{
return (crypter_t*)aes_cbc_crypter_create(blocksize);
-
}
default:
return NULL;
diff --git a/Source/charon/transforms/crypters/crypter.h b/Source/charon/transforms/crypters/crypter.h
index 878ea5ef4..cd9674775 100644
--- a/Source/charon/transforms/crypters/crypter.h
+++ b/Source/charon/transforms/crypters/crypter.h
@@ -68,8 +68,9 @@ struct crypter_t {
* @param data data to encrypt
* @param iv iv
* @param [out]encrypted pointer where the encrypted bytes will be written
- * @return
- * - SUCCESS in any case
+ * @return
+ * - SUCCESS, or
+ * - INVALID_ARG if data size not a multiple of block size
*/
status_t (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted);
@@ -81,8 +82,9 @@ struct crypter_t {
* @param data data to decrypt
* @param iv iv
* @param [out]encrypted pointer where the decrypted bytes will be written
- * @return
- * - SUCCESS in any case
+ * @return
+ * - SUCCESS, or
+ * - INVALID_ARG if data size not a multiple of block size
*/
status_t (*decrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted);
@@ -100,7 +102,8 @@ struct crypter_t {
* @param this calling crypter
* @param key key to set
* @return
- * - SUCCESS in any case
+ * - SUCCESS, or
+ * - INVALID_ARG if key size != block size
*/
status_t (*set_key) (crypter_t *this, chunk_t key);
@@ -108,10 +111,8 @@ struct crypter_t {
* @brief Destroys a crypter_t object.
*
* @param this crypter_t object to destroy
- * @return
- * - SUCCESS in any case
*/
- status_t (*destroy) (crypter_t *this);
+ void (*destroy) (crypter_t *this);
};
/**
@@ -121,7 +122,7 @@ struct crypter_t {
* @param blocksize block size in bytes
* @return
* - crypter_t if successfully
- * - NULL if out of ressources or crypter not supported
+ * - NULL if crypter not supported
*/
crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm, size_t blocksize);
diff --git a/Source/charon/transforms/diffie_hellman.c b/Source/charon/transforms/diffie_hellman.c
index 1992e5719..2ec37699d 100644
--- a/Source/charon/transforms/diffie_hellman.c
+++ b/Source/charon/transforms/diffie_hellman.c
@@ -438,8 +438,7 @@ struct private_diffie_hellman_t {
};
/**
- * Implements private_diffie_hellman_t's set_modulus function.
- * See #private_diffie_hellman_t.set_modulus for description.
+ * Implements private_diffie_hellman_tset_modulus.
*/
static status_t set_modulus(private_diffie_hellman_t *this)
{
@@ -464,19 +463,16 @@ static status_t set_modulus(private_diffie_hellman_t *this)
}
/**
- * Implements diffie_hellman_t's set_other_public_value function.
- * See #diffie_hellman_t.set_other_public_value for description.
+ * Implementation of diffie_hellman_t.set_other_public_value.
*/
-static status_t set_other_public_value(private_diffie_hellman_t *this,chunk_t public_value)
+static void set_other_public_value(private_diffie_hellman_t *this,chunk_t public_value)
{
this->gmp_helper->chunk_to_mpz(this->gmp_helper,&(this->other_public_value),public_value);
- this->compute_shared_secret(this);
- return SUCCESS;
+ this->compute_shared_secret(this);
}
/**
- * Implements diffie_hellman_t's get_other_public_value function.
- * See #diffie_hellman_t.get_other_public_value for description.
+ * Implements diffie_hellman_t.get_other_public_value.
*/
static status_t get_other_public_value(private_diffie_hellman_t *this,chunk_t *public_value)
{
@@ -484,12 +480,12 @@ static status_t get_other_public_value(private_diffie_hellman_t *this,chunk_t *p
{
return FAILED;
}
- return (this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->other_public_value), public_value,this->modulus_length));
+ this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->other_public_value), public_value,this->modulus_length);
+ return SUCCESS;
}
/**
- * Implements private_diffie_hellman_t's compute_shared_secret function.
- * See #private_diffie_hellman_t.compute_shared_secret for description.
+ * Implements private_diffie_hellman_t.compute_shared_secret.
*/
static void compute_shared_secret (private_diffie_hellman_t *this)
{
@@ -497,14 +493,13 @@ static void compute_shared_secret (private_diffie_hellman_t *this)
mpz_init(this->shared_secret);
/* calculate my public value */
mpz_powm(this->shared_secret,this->other_public_value,this->my_prime,this->modulus);
-
+
this->shared_secret_is_computed = TRUE;
}
/**
- * Implements private_diffie_hellman_t's compute_public_value function.
- * See #private_diffie_hellman_t.compute_public_value for description.
+ * Implements private_diffie_hellman_t.compute_public_value.
*/
static void compute_public_value (private_diffie_hellman_t *this)
{
@@ -521,8 +516,7 @@ static void compute_public_value (private_diffie_hellman_t *this)
}
/**
- * Implements diffie_hellman_t's get_my_public_value function.
- * See #diffie_hellman_t.get_my_public_value for description.
+ * Implements diffie_hellman_t.get_my_public_value.
*/
static status_t get_my_public_value(private_diffie_hellman_t *this,chunk_t *public_value)
{
@@ -530,12 +524,12 @@ static status_t get_my_public_value(private_diffie_hellman_t *this,chunk_t *publ
{
this->compute_public_value(this);
}
- return (this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->my_public_value), public_value,this->modulus_length));
+ this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->my_public_value), public_value,this->modulus_length);
+ return SUCCESS;
}
/**
- * Implements diffie_hellman_t's get_shared_secret function.
- * See #diffie_hellman_t.get_shared_secret for description.
+ * Implements diffie_hellman_t.get_shared_secret.
*/
static status_t get_shared_secret(private_diffie_hellman_t *this,chunk_t *secret)
{
@@ -543,14 +537,14 @@ static status_t get_shared_secret(private_diffie_hellman_t *this,chunk_t *secret
{
return FAILED;
}
- return (this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->shared_secret), secret,this->modulus_length));
+ this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->shared_secret), secret,this->modulus_length);
+ return SUCCESS;
}
/**
- * Implements diffie_hellman_t's destroy function.
- * See #diffie_hellman_t.destroy for description.
+ * Implements diffie_hellman_t.destroy.
*/
-static status_t destroy(private_diffie_hellman_t *this)
+static void destroy(private_diffie_hellman_t *this)
{
this->gmp_helper->destroy(this->gmp_helper);
mpz_clear(this->modulus);
@@ -565,9 +559,7 @@ static status_t destroy(private_diffie_hellman_t *this)
mpz_clear(this->other_public_value);
mpz_clear(this->shared_secret);
}
-
allocator_free(this);
- return SUCCESS;
}
@@ -577,17 +569,13 @@ static status_t destroy(private_diffie_hellman_t *this)
diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number)
{
private_diffie_hellman_t *this = allocator_alloc_thing(private_diffie_hellman_t);
- if ((this == NULL))
- {
- return NULL;
- }
-
+
/* public functions */
this->public.get_shared_secret = (status_t (*)(diffie_hellman_t *, chunk_t *)) get_shared_secret;
- this->public.set_other_public_value = (status_t (*)(diffie_hellman_t *, chunk_t )) set_other_public_value;
+ this->public.set_other_public_value = (void (*)(diffie_hellman_t *, chunk_t )) set_other_public_value;
this->public.get_other_public_value = (status_t (*)(diffie_hellman_t *, chunk_t *)) get_other_public_value;
this->public.get_my_public_value = (status_t (*)(diffie_hellman_t *, chunk_t *)) get_my_public_value;
- this->public.destroy = (status_t (*)(diffie_hellman_t *)) destroy;
+ this->public.destroy = (void (*)(diffie_hellman_t *)) destroy;
/* private functions */
this->set_modulus = set_modulus;
@@ -599,12 +587,6 @@ diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number)
this->gmp_helper = gmp_helper_create();
- if (this->gmp_helper == NULL)
- {
- allocator_free(this);
- return NULL;
- }
-
/* set this->modulus */
if (this->set_modulus(this) != SUCCESS)
{
@@ -612,13 +594,9 @@ diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number)
allocator_free(this);
return NULL;
}
-
- if (this->gmp_helper->init_prime(this->gmp_helper,&(this->my_prime),this->modulus_length) != SUCCESS)
- {
- this->gmp_helper->destroy(this->gmp_helper);
- allocator_free(this);
- return NULL;
- }
+
+ this->gmp_helper->init_prime(this->gmp_helper,&(this->my_prime),this->modulus_length);
+
this->my_public_value_is_computed = FALSE;
this->shared_secret_is_computed = FALSE;
diff --git a/Source/charon/transforms/diffie_hellman.h b/Source/charon/transforms/diffie_hellman.h
index 04cfb98d9..c3ca32524 100644
--- a/Source/charon/transforms/diffie_hellman.h
+++ b/Source/charon/transforms/diffie_hellman.h
@@ -73,7 +73,6 @@ struct diffie_hellman_t {
* @return
* - SUCCESS, or
* - FAILED if not both DH values are set
- * - OUT_OF_RES if out of ressources
*/
status_t (*get_shared_secret) (diffie_hellman_t *this, chunk_t *secret);
@@ -84,11 +83,8 @@ struct diffie_hellman_t {
*
* @param this calling diffie_hellman_t object
* @param public_value public value of partner
- * @return
- * - SUCCESS, or
- * - OUT_OF_RES if out of ressources
*/
- status_t (*set_other_public_value) (diffie_hellman_t *this, chunk_t public_value);
+ void (*set_other_public_value) (diffie_hellman_t *this, chunk_t public_value);
/**
* @brief Gets the public value of partner.
@@ -99,7 +95,6 @@ struct diffie_hellman_t {
* @param[out] public_value public value of partner is stored at this location
* @return
* - SUCCESS, or
- * - OUT_OF_RES if out of ressources
* - FAILED if other public value not set
*/
status_t (*get_other_public_value) (diffie_hellman_t *this, chunk_t *public_value);
@@ -110,10 +105,10 @@ struct diffie_hellman_t {
* @warning chunk gets copied
*
* @param this calling diffie_hellman_t object
- * @param[out] public_value public value of caller is stored at this location
+ * @param[out] public_value public value of caller is stored at this location
* @return
* - SUCCESS, or
- * - OUT_OF_RES if out of ressources
+ * - FAILED if not computed
*/
status_t (*get_my_public_value) (diffie_hellman_t *this, chunk_t *public_value);
@@ -121,10 +116,8 @@ struct diffie_hellman_t {
* @brief Destroys an diffie_hellman_t object.
*
* @param this diffie_hellman_t object to destroy
- * @return
- * - SUCCESS in any case
*/
- status_t (*destroy) (diffie_hellman_t *this);
+ void (*destroy) (diffie_hellman_t *this);
};
/**
@@ -134,8 +127,8 @@ struct diffie_hellman_t {
*
* @param dh_group_number Diffie Hellman group number to use
* @return
- * - diffie_hellman_t if successfully
- * - NULL if out of ressources or dh_group not supported
+ * - diffie_hellman_t object
+ * - NULL if dh group not supported
*
* @ingroup transforms
*/
diff --git a/Source/charon/transforms/hashers/hasher.c b/Source/charon/transforms/hashers/hasher.c
index dfc654e0a..170dfe887 100644
--- a/Source/charon/transforms/hashers/hasher.c
+++ b/Source/charon/transforms/hashers/hasher.c
@@ -54,8 +54,3 @@ hasher_t *hasher_create(hash_algorithm_t hash_algorithm)
return NULL;
}
}
-
-
-
-
-
diff --git a/Source/charon/transforms/hashers/hasher.h b/Source/charon/transforms/hashers/hasher.h
index ed4e0ee8d..eda6fe12f 100644
--- a/Source/charon/transforms/hashers/hasher.h
+++ b/Source/charon/transforms/hashers/hasher.h
@@ -63,10 +63,8 @@ struct hasher_t {
* @param this calling hasher
* @param data data to hash
* @param [out]buffer pointer where the hash will be written
- * @return
- * - SUCCESS in any case
*/
- status_t (*get_hash) (hasher_t *this, chunk_t data, u_int8_t *hash);
+ void (*get_hash) (hasher_t *this, chunk_t data, u_int8_t *hash);
/**
* @brief hash data and allocate space for the hash
@@ -78,11 +76,8 @@ struct hasher_t {
* @param this calling hasher
* @param data chunk with data to hash
* @param [out]hash chunk which will hold allocated hash
- * @return
- * - SUCCESS in any case
- * - OUT_OF_RES if space could not be allocated
*/
- status_t (*allocate_hash) (hasher_t *this, chunk_t data, chunk_t *hash);
+ void (*allocate_hash) (hasher_t *this, chunk_t data, chunk_t *hash);
/**
* @brief Get the block size of this hashing function.
@@ -97,18 +92,15 @@ struct hasher_t {
* computation of a completly new hash.
*
* @param this calling hasher
- * @return - SUCCESS in any case
*/
- status_t (*reset) (hasher_t *this);
+ void (*reset) (hasher_t *this);
/**
* @brief Destroys a hasher object.
*
* @param this hasher_t object to destroy
- * @return
- * SUCCESS in any case
*/
- status_t (*destroy) (hasher_t *this);
+ void (*destroy) (hasher_t *this);
};
/**
@@ -117,7 +109,7 @@ struct hasher_t {
* @param hash_algorithm Algorithm to use for hashing
* @return
* - hasher_t if successfully
- * - NULL if out of ressources
+ * - NULL if algorithm not supported
*
* @ingroup hashers
*/
diff --git a/Source/charon/transforms/hashers/md5_hasher.c b/Source/charon/transforms/hashers/md5_hasher.c
index 36710012c..bdb0b9eb9 100644
--- a/Source/charon/transforms/hashers/md5_hasher.c
+++ b/Source/charon/transforms/hashers/md5_hasher.c
@@ -244,7 +244,7 @@ static void MD5Transform(u_int32_t state[4], u_int8_t block[64])
* operation, processing another message block, and updating the
* context.
*/
-void MD5Update(private_md5_hasher_t *this, u_int8_t *input, size_t inputLen)
+static void MD5Update(private_md5_hasher_t *this, u_int8_t *input, size_t inputLen)
{
u_int32_t i;
size_t index, partLen;
@@ -285,7 +285,7 @@ void MD5Update(private_md5_hasher_t *this, u_int8_t *input, size_t inputLen)
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
* the message digest and zeroizing the context.
*/
-void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
+static void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
{
u_int8_t bits[8];
size_t index, padLen;
@@ -313,7 +313,7 @@ void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
/**
* implementation of hasher_t.get_hash for md5
*/
-static status_t get_hash(private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
+static void get_hash(private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
{
MD5Update(this, chunk.ptr, chunk.len);
if (buffer != NULL)
@@ -321,14 +321,13 @@ static status_t get_hash(private_md5_hasher_t *this, chunk_t chunk, u_int8_t *bu
MD5Final(this, buffer);
this->public.hasher_interface.reset(&(this->public.hasher_interface));
}
- return SUCCESS;
}
/**
* implementation of hasher_t.allocate_hash for md5
*/
-static status_t allocate_hash(private_md5_hasher_t *this, chunk_t chunk, chunk_t *hash)
+static void allocate_hash(private_md5_hasher_t *this, chunk_t chunk, chunk_t *hash)
{
chunk_t allocated_hash;
@@ -337,17 +336,12 @@ static status_t allocate_hash(private_md5_hasher_t *this, chunk_t chunk, chunk_t
{
allocated_hash.ptr = allocator_alloc(BLOCK_SIZE_MD5);
allocated_hash.len = BLOCK_SIZE_MD5;
- if (allocated_hash.ptr == NULL)
- {
- return OUT_OF_RES;
- }
+
MD5Final(this, allocated_hash.ptr);
this->public.hasher_interface.reset(&(this->public.hasher_interface));
*hash = allocated_hash;
}
-
- return SUCCESS;
}
/**
@@ -357,11 +351,11 @@ static size_t get_block_size(private_md5_hasher_t *this)
{
return BLOCK_SIZE_MD5;
}
-
+
/**
* implementation of hasher_t.reset for md5
*/
-static status_t reset(private_md5_hasher_t *this)
+static void reset(private_md5_hasher_t *this)
{
this->state[0] = 0x67452301;
this->state[1] = 0xefcdab89;
@@ -369,34 +363,28 @@ static status_t reset(private_md5_hasher_t *this)
this->state[3] = 0x10325476;
this->count[0] = 0;
this->count[1] = 0;
- return SUCCESS;
}
+
/**
* implementation of hasher_t.destroy for md5
*/
-static status_t destroy(private_md5_hasher_t *this)
+static void destroy(private_md5_hasher_t *this)
{
allocator_free(this);
- return SUCCESS;
}
-
/*
* Described in header
*/
md5_hasher_t *md5_hasher_create()
{
private_md5_hasher_t *this = allocator_alloc_thing(private_md5_hasher_t);
- if (this == NULL)
- {
- return NULL;
- }
-
- this->public.hasher_interface.get_hash = (status_t (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
- this->public.hasher_interface.allocate_hash = (status_t (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
+
+ this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
+ this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
this->public.hasher_interface.get_block_size = (size_t (*) (hasher_t*))get_block_size;
- this->public.hasher_interface.reset = (size_t (*) (hasher_t*))reset;
- this->public.hasher_interface.destroy = (size_t (*) (hasher_t*))destroy;
+ this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
+ this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
/* initialize */
this->public.hasher_interface.reset(&(this->public.hasher_interface));
diff --git a/Source/charon/transforms/hashers/md5_hasher.h b/Source/charon/transforms/hashers/md5_hasher.h
index d2dcb0a9b..f73fdb528 100644
--- a/Source/charon/transforms/hashers/md5_hasher.h
+++ b/Source/charon/transforms/hashers/md5_hasher.h
@@ -45,9 +45,7 @@ struct md5_hasher_t {
/**
* @brief Creates a new md5_hasher_t.
*
- * @return
- * - md5_hasher_t if successfully
- * - NULL if out of ressources
+ * @return md5_hasher_t object
*
* @ingroup hashers
*/
diff --git a/Source/charon/transforms/hashers/sha1_hasher.c b/Source/charon/transforms/hashers/sha1_hasher.c
index 115a6e89a..609571b4c 100644
--- a/Source/charon/transforms/hashers/sha1_hasher.c
+++ b/Source/charon/transforms/hashers/sha1_hasher.c
@@ -74,7 +74,7 @@ struct private_sha1_hasher_t {
/*
* Hash a single 512-bit block. This is the core of the algorithm. *
*/
-void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
+static void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
{
u_int32_t a, b, c, d, e;
typedef union {
@@ -125,7 +125,7 @@ void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
/*
* Run your data through this.
*/
-void SHA1Update(private_sha1_hasher_t* this, u_int8_t *data, u_int32_t len)
+static void SHA1Update(private_sha1_hasher_t* this, u_int8_t *data, u_int32_t len)
{
u_int32_t i;
u_int32_t j;
@@ -158,7 +158,7 @@ void SHA1Update(private_sha1_hasher_t* this, u_int8_t *data, u_int32_t len)
/*
* Add padding and return the message digest.
*/
-void SHA1Final(private_sha1_hasher_t *this, u_int8_t *digest)
+static void SHA1Final(private_sha1_hasher_t *this, u_int8_t *digest)
{
u_int32_t i;
u_int8_t finalcount[8];
@@ -187,7 +187,7 @@ void SHA1Final(private_sha1_hasher_t *this, u_int8_t *digest)
/**
* implementation of hasher_t.get_hash for sha1
*/
-static status_t get_hash(private_sha1_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
+static void get_hash(private_sha1_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
{
SHA1Update(this, chunk.ptr, chunk.len);
if (buffer != NULL)
@@ -195,14 +195,13 @@ static status_t get_hash(private_sha1_hasher_t *this, chunk_t chunk, u_int8_t *b
SHA1Final(this, buffer);
this->public.hasher_interface.reset(&(this->public.hasher_interface));
}
- return SUCCESS;
}
/**
* implementation of hasher_t.allocate_hash for sha1
*/
-static status_t allocate_hash(private_sha1_hasher_t *this, chunk_t chunk, chunk_t *hash)
+static void allocate_hash(private_sha1_hasher_t *this, chunk_t chunk, chunk_t *hash)
{
chunk_t allocated_hash;
@@ -211,17 +210,12 @@ static status_t allocate_hash(private_sha1_hasher_t *this, chunk_t chunk, chunk_
{
allocated_hash.ptr = allocator_alloc(BLOCK_SIZE_SHA1);
allocated_hash.len = BLOCK_SIZE_SHA1;
- if (allocated_hash.ptr == NULL)
- {
- return OUT_OF_RES;
- }
+
SHA1Final(this, allocated_hash.ptr);
this->public.hasher_interface.reset(&(this->public.hasher_interface));
*hash = allocated_hash;
}
-
- return SUCCESS;
}
/**
@@ -235,7 +229,7 @@ static size_t get_block_size(private_sha1_hasher_t *this)
/**
* implementation of hasher_t.reset for sha1
*/
-static status_t reset(private_sha1_hasher_t *this)
+static void reset(private_sha1_hasher_t *this)
{
this->state[0] = 0x67452301;
this->state[1] = 0xEFCDAB89;
@@ -244,15 +238,13 @@ static status_t reset(private_sha1_hasher_t *this)
this->state[4] = 0xC3D2E1F0;
this->count[0] = 0;
this->count[1] = 0;
- return SUCCESS;
}
/**
* implementation of hasher_t.destroy for sha1
*/
-static status_t destroy(private_sha1_hasher_t *this)
+static void destroy(private_sha1_hasher_t *this)
{
allocator_free(this);
- return SUCCESS;
}
@@ -267,11 +259,11 @@ sha1_hasher_t *sha1_hasher_create()
return NULL;
}
- this->public.hasher_interface.get_hash = (status_t (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
- this->public.hasher_interface.allocate_hash = (status_t (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
+ this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
+ this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
this->public.hasher_interface.get_block_size = (size_t (*) (hasher_t*))get_block_size;
- this->public.hasher_interface.reset = (size_t (*) (hasher_t*))reset;
- this->public.hasher_interface.destroy = (size_t (*) (hasher_t*))destroy;
+ this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
+ this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
/* initialize */
this->public.hasher_interface.reset(&(this->public.hasher_interface));
diff --git a/Source/charon/transforms/hashers/sha1_hasher.h b/Source/charon/transforms/hashers/sha1_hasher.h
index ed1780d39..c712e4b40 100644
--- a/Source/charon/transforms/hashers/sha1_hasher.h
+++ b/Source/charon/transforms/hashers/sha1_hasher.h
@@ -45,9 +45,7 @@ struct sha1_hasher_t {
/**
* @brief Creates a new sha1_hasher_t.
*
- * @return
- * - sha1_hasher_t if successfully
- * - NULL if out of ressources
+ * @return sha1_hasher_t object
*
* @ingroup hashers
*/
diff --git a/Source/charon/transforms/hmac.c b/Source/charon/transforms/hmac.c
index 4ecd61e1e..c7847ad23 100644
--- a/Source/charon/transforms/hmac.c
+++ b/Source/charon/transforms/hmac.c
@@ -59,7 +59,7 @@ struct private_hmac_t {
/**
* Implementation of hmac_t.get_mac.
*/
-static status_t get_mac(private_hmac_t *this, chunk_t data, u_int8_t *out)
+static void get_mac(private_hmac_t *this, chunk_t data, u_int8_t *out)
{
/* H(K XOR opad, H(K XOR ipad, text))
*
@@ -92,13 +92,12 @@ static status_t get_mac(private_hmac_t *this, chunk_t data, u_int8_t *out)
/* reinit for next call */
this->h->get_hash(this->h, this->ipaded_key, NULL);
}
- return SUCCESS;
}
/**
* Implementation of hmac_t.allocate_mac.
*/
-static status_t allocate_mac(private_hmac_t *this, chunk_t data, chunk_t *out)
+static void allocate_mac(private_hmac_t *this, chunk_t data, chunk_t *out)
{
/* allocate space and use get_mac */
if (out == NULL)
@@ -110,13 +109,8 @@ static status_t allocate_mac(private_hmac_t *this, chunk_t data, chunk_t *out)
{
out->len = this->h->get_block_size(this->h);
out->ptr = allocator_alloc(out->len);
- if (out->ptr == NULL)
- {
- return OUT_OF_RES;
- }
this->hmac.get_mac(&(this->hmac), data, out->ptr);
}
- return SUCCESS;
}
/**
@@ -130,7 +124,7 @@ static size_t get_block_size(private_hmac_t *this)
/**
* Implementation of hmac_t.set_key.
*/
-static status_t set_key(private_hmac_t *this, chunk_t key)
+static void set_key(private_hmac_t *this, chunk_t key)
{
int i;
u_int8_t buffer[this->b];
@@ -158,20 +152,17 @@ static status_t set_key(private_hmac_t *this, chunk_t key)
/* begin hashing of inner pad */
this->h->reset(this->h);
this->h->get_hash(this->h, this->ipaded_key, NULL);
-
- return SUCCESS;;
}
/**
* Implementation of hmac_t.destroy.
*/
-static status_t destroy(private_hmac_t *this)
+static void destroy(private_hmac_t *this)
{
this->h->destroy(this->h);
allocator_free(this->opaded_key.ptr);
allocator_free(this->ipaded_key.ptr);
allocator_free(this);
- return SUCCESS;
}
/*
@@ -182,16 +173,13 @@ hmac_t *hmac_create(hash_algorithm_t hash_algorithm)
private_hmac_t *this;
this = allocator_alloc_thing(private_hmac_t);
- if (this == NULL)
- {
- return NULL;
- }
+
/* set hmac_t methods */
- this->hmac.get_mac = (size_t (*)(hmac_t *,chunk_t,u_int8_t*))get_mac;
- this->hmac.allocate_mac = (size_t (*)(hmac_t *,chunk_t,chunk_t*))allocate_mac;
+ this->hmac.get_mac = (void (*)(hmac_t *,chunk_t,u_int8_t*))get_mac;
+ this->hmac.allocate_mac = (void (*)(hmac_t *,chunk_t,chunk_t*))allocate_mac;
this->hmac.get_block_size = (size_t (*)(hmac_t *))get_block_size;
- this->hmac.set_key = (status_t (*)(hmac_t *,chunk_t))set_key;
- this->hmac.destroy = (status_t (*)(hmac_t *))destroy;
+ this->hmac.set_key = (void (*)(hmac_t *,chunk_t))set_key;
+ this->hmac.destroy = (void (*)(hmac_t *))destroy;
/* set b, according to hasher */
switch (hash_algorithm)
@@ -207,30 +195,13 @@ hmac_t *hmac_create(hash_algorithm_t hash_algorithm)
/* build the hasher */
this->h = hasher_create(hash_algorithm);
- if (this->h == NULL)
- {
- allocator_free(this);
- return NULL;
- }
/* build ipad and opad */
this->opaded_key.ptr = allocator_alloc(this->b);
this->opaded_key.len = this->b;
- if (this->opaded_key.ptr == NULL)
- {
- this->h->destroy(this->h);
- allocator_free(this);
- return NULL;
- }
+
this->ipaded_key.ptr = allocator_alloc(this->b);
this->ipaded_key.len = this->b;
- if (this->ipaded_key.ptr == NULL)
- {
- this->h->destroy(this->h);
- allocator_free(this->opaded_key.ptr);
- allocator_free(this);
- return NULL;
- }
return &(this->hmac);
}
diff --git a/Source/charon/transforms/hmac.h b/Source/charon/transforms/hmac.h
index 3df69e838..d415acedd 100644
--- a/Source/charon/transforms/hmac.h
+++ b/Source/charon/transforms/hmac.h
@@ -52,10 +52,8 @@ struct hmac_t {
* @param this calling hmac
* @param data chunk of data to authenticate
* @param[out] buffer pointer where the generated bytes will be written
- * @return
- * - SUCCESS in any case
*/
- status_t (*get_mac) (hmac_t *this, chunk_t data, u_int8_t *buffer);
+ void (*get_mac) (hmac_t *this, chunk_t data, u_int8_t *buffer);
/**
* @brief Generates message authentication code and
@@ -69,11 +67,8 @@ struct hmac_t {
* @param this calling hmac
* @param data chunk of data to authenticate
* @param[out] chunk chunk which will hold generated bytes
- * @return
- * - SUCCESS, or
- * - OUT_OF_RES if space could not be allocated
*/
- status_t (*allocate_mac) (hmac_t *this, chunk_t data, chunk_t *chunk);
+ void (*allocate_mac) (hmac_t *this, chunk_t data, chunk_t *chunk);
/**
* @brief Get the block size of this hmac.
@@ -90,19 +85,15 @@ struct hmac_t {
*
* @param this calling hmac
* @param key key to set
- * @return
- * - SUCCESS in any case
*/
- status_t (*set_key) (hmac_t *this, chunk_t key);
+ void (*set_key) (hmac_t *this, chunk_t key);
/**
* @brief Destroys a hmac object.
*
* @param this hmac_t object to destroy
- * @return
- * - SUCCESS in any case
*/
- status_t (*destroy) (hmac_t *this);
+ void (*destroy) (hmac_t *this);
};
/**
@@ -114,7 +105,7 @@ struct hmac_t {
* @param hash_algorithm hash algorithm to use
* @return
* - hmac_t if successfully
- * - NULL if out of ressources or hash not supported
+ * - NULL if hash not supported
*
* @ingroup transforms
*/
diff --git a/Source/charon/transforms/prf_plus.c b/Source/charon/transforms/prf_plus.c
index 64783b129..553a34843 100644
--- a/Source/charon/transforms/prf_plus.c
+++ b/Source/charon/transforms/prf_plus.c
@@ -68,7 +68,7 @@ struct private_prf_plus_t {
/**
* implementation of prf_plus_t.get_bytes
*/
-static status_t get_bytes(private_prf_plus_t *this, size_t length, u_int8_t *buffer)
+static void get_bytes(private_prf_plus_t *this, size_t length, u_int8_t *buffer)
{
chunk_t appending_chunk;
size_t bytes_in_round;
@@ -96,32 +96,26 @@ static status_t get_bytes(private_prf_plus_t *this, size_t length, u_int8_t *buf
this->given_out += bytes_in_round;
total_bytes_written += bytes_in_round;
}
- return SUCCESS;
}
/**
* implementation of prf_plus_t.allocate_bytes
*/
-static status_t allocate_bytes(private_prf_plus_t *this, size_t length, chunk_t *chunk)
+static void allocate_bytes(private_prf_plus_t *this, size_t length, chunk_t *chunk)
{
chunk->ptr = allocator_alloc(length);
chunk->len = length;
- if (chunk->ptr == NULL)
- {
- return OUT_OF_RES;
- }
- return this->public.get_bytes(&(this->public), length, chunk->ptr);
+ this->public.get_bytes(&(this->public), length, chunk->ptr);
}
/**
* implementation of prf_plus_t.destroy
*/
-static status_t destroy(private_prf_plus_t *this)
+static void destroy(private_prf_plus_t *this)
{
allocator_free(this->buffer.ptr);
allocator_free(this->seed.ptr);
allocator_free(this);
- return SUCCESS;
}
/*
@@ -133,14 +127,11 @@ prf_plus_t *prf_plus_create(prf_t *prf, chunk_t seed)
chunk_t appending_chunk;
this = allocator_alloc_thing(private_prf_plus_t);
- if (this == NULL)
- {
- return NULL;
- }
+
/* set public methods */
- this->public.get_bytes = (size_t (*)(prf_plus_t *,size_t,u_int8_t*))get_bytes;
- this->public.allocate_bytes = (size_t (*)(prf_plus_t *,size_t,chunk_t*))allocate_bytes;
- this->public.destroy = (status_t (*)(prf_plus_t *))destroy;
+ this->public.get_bytes = (void (*)(prf_plus_t *,size_t,u_int8_t*))get_bytes;
+ this->public.allocate_bytes = (void (*)(prf_plus_t *,size_t,chunk_t*))allocate_bytes;
+ this->public.destroy = (void (*)(prf_plus_t *))destroy;
/* take over prf */
this->prf = prf;
@@ -148,23 +139,13 @@ prf_plus_t *prf_plus_create(prf_t *prf, chunk_t seed)
/* allocate buffer for prf output */
this->buffer.len = prf->get_block_size(prf);
this->buffer.ptr = allocator_alloc(this->buffer.len);
- if (this->buffer.ptr == NULL)
- {
- allocator_free(this);
- return NULL;
- }
+
this->appending_octet = 0x01;
/* clone seed */
this->seed.ptr = allocator_clone_bytes(seed.ptr, seed.len);
this->seed.len = seed.len;
- if (this->seed.ptr == NULL)
- {
- allocator_free(this->buffer.ptr);
- allocator_free(this);
- return NULL;
- }
-
+
/* do the first run */
appending_chunk.ptr = &(this->appending_octet);
appending_chunk.len = 1;
diff --git a/Source/charon/transforms/prf_plus.h b/Source/charon/transforms/prf_plus.h
index c7396b5fc..812af05aa 100644
--- a/Source/charon/transforms/prf_plus.h
+++ b/Source/charon/transforms/prf_plus.h
@@ -49,10 +49,8 @@ struct prf_plus_t {
* @param this calling prf_plus
* @param length number of bytes to get
* @param[out] buffer pointer where the generated bytes will be written
- * @return
- * - SUCCESS in any case
*/
- status_t (*get_bytes) (prf_plus_t *this, size_t length, u_int8_t *buffer);
+ void (*get_bytes) (prf_plus_t *this, size_t length, u_int8_t *buffer);
/**
* @brief Allocate pseudo random bytes.
@@ -63,20 +61,15 @@ struct prf_plus_t {
* @param this calling prf_plus
* @param length number of bytes to get
* @param[out] chunk chunk which will hold generated bytes
- * @return
- * - SUCCESS in any case
- * - OUT_OF_RES if space could not be allocated
*/
- status_t (*allocate_bytes) (prf_plus_t *this, size_t length, chunk_t *chunk);
+ void (*allocate_bytes) (prf_plus_t *this, size_t length, chunk_t *chunk);
/**
* @brief Destroys a prf_plus_t object.
*
* @param this prf_plus_t object to destroy
- * @return
- * - SUCCESS in any case
*/
- status_t (*destroy) (prf_plus_t *this);
+ void (*destroy) (prf_plus_t *this);
};
/**
@@ -88,9 +81,7 @@ struct prf_plus_t {
*
* @param prf prf object to use
* @param seed input seed for prf
- * @return
- * - prf_plus_t if successfully
- * - NULL if out of ressources
+ * @return created prf_plus_t
*
* @ingroup transforms
*/
diff --git a/Source/charon/transforms/prfs/hmac_prf.c b/Source/charon/transforms/prfs/hmac_prf.c
index 17f60650c..07a3cd854 100644
--- a/Source/charon/transforms/prfs/hmac_prf.c
+++ b/Source/charon/transforms/prfs/hmac_prf.c
@@ -42,17 +42,17 @@ struct private_hmac_prf_t {
/**
* implementation of prf_t.get_bytes
*/
-static status_t get_bytes(private_hmac_prf_t *this, chunk_t seed, u_int8_t *buffer)
+static void get_bytes(private_hmac_prf_t *this, chunk_t seed, u_int8_t *buffer)
{
- return this->hmac->get_mac(this->hmac, seed, buffer);
+ this->hmac->get_mac(this->hmac, seed, buffer);
}
/**
* implementation of prf_t.allocate_bytes
*/
-static status_t allocate_bytes(private_hmac_prf_t *this, chunk_t seed, chunk_t *chunk)
+static void allocate_bytes(private_hmac_prf_t *this, chunk_t seed, chunk_t *chunk)
{
- return this->hmac->allocate_mac(this->hmac, seed, chunk);
+ this->hmac->allocate_mac(this->hmac, seed, chunk);
}
/**
@@ -66,20 +66,18 @@ static size_t get_block_size(private_hmac_prf_t *this)
/**
* implementation of prf_t.set_key
*/
-static status_t set_key(private_hmac_prf_t *this, chunk_t key)
+static void set_key(private_hmac_prf_t *this, chunk_t key)
{
this->hmac->set_key(this->hmac, key);
- return SUCCESS;
}
/**
* implementation of prf_t.destroy
*/
-static status_t destroy(private_hmac_prf_t *this)
+static void destroy(private_hmac_prf_t *this)
{
allocator_free(this);
this->hmac->destroy(this->hmac);
- return SUCCESS;
}
/*
@@ -89,16 +87,11 @@ hmac_prf_t *hmac_prf_create(hash_algorithm_t hash_algorithm)
{
private_hmac_prf_t *this = allocator_alloc_thing(private_hmac_prf_t);
- if (this == NULL)
- {
- return NULL;
- }
-
- this->public.prf_interface.get_bytes = (status_t (*) (prf_t *,chunk_t,u_int8_t*))get_bytes;
- this->public.prf_interface.allocate_bytes = (status_t (*) (prf_t*,chunk_t,chunk_t*))allocate_bytes;
+ this->public.prf_interface.get_bytes = (void (*) (prf_t *,chunk_t,u_int8_t*))get_bytes;
+ this->public.prf_interface.allocate_bytes = (void (*) (prf_t*,chunk_t,chunk_t*))allocate_bytes;
this->public.prf_interface.get_block_size = (size_t (*) (prf_t*))get_block_size;
- this->public.prf_interface.set_key = (status_t (*) (prf_t *,chunk_t))set_key;
- this->public.prf_interface.destroy = (status_t (*) (prf_t *))destroy;
+ this->public.prf_interface.set_key = (void (*) (prf_t *,chunk_t))set_key;
+ this->public.prf_interface.destroy = (void (*) (prf_t *))destroy;
this->hmac = hmac_create(hash_algorithm);
if (this->hmac == NULL)
diff --git a/Source/charon/transforms/prfs/hmac_prf.h b/Source/charon/transforms/prfs/hmac_prf.h
index d1b741d04..70605ff0e 100644
--- a/Source/charon/transforms/prfs/hmac_prf.h
+++ b/Source/charon/transforms/prfs/hmac_prf.h
@@ -49,10 +49,10 @@ struct hmac_prf_t {
/**
* @brief Creates a new hmac_prf_t object
*
- * @param hash_algorithm hmac's hash algorithm
+ * @param hash_algorithm hmac's hash algorithm
* @return
- * - hmac_prf_t if successfully
- * - NULL if out of ressources
+ * - hmac_prf_t if successfully
+ * - NULL if hash not supported
*
* @ingroup prfs
*/
diff --git a/Source/charon/transforms/prfs/prf.h b/Source/charon/transforms/prfs/prf.h
index 9a79c6047..470556dc8 100644
--- a/Source/charon/transforms/prfs/prf.h
+++ b/Source/charon/transforms/prfs/prf.h
@@ -59,10 +59,8 @@ struct prf_t {
* @param this calling prf
* @param seed a chunk containing the seed for the next bytes
* @param[out] buffer pointer where the generated bytes will be written
- * @return
- * - SUCCESS in any case
*/
- status_t (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
+ void (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
/**
* @brief generates pseudo random bytes and allocate space for them.
@@ -70,11 +68,8 @@ struct prf_t {
* @param this calling prf
* @param seed a chunk containing the seed for the next bytes
* @param[out] chunk chunk which will hold generated bytes
- * @return
- * - SUCCESS in any case
- * - OUT_OF_RES if space could not be allocated
*/
- status_t (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
+ void (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
/**
* @brief get the block size of this prf.
@@ -89,19 +84,15 @@ struct prf_t {
*
* @param this calling prf
* @param key key to set
- * @return
- * - SUCCESS in any case
*/
- status_t (*set_key) (prf_t *this, chunk_t key);
+ void (*set_key) (prf_t *this, chunk_t key);
/**
* @brief Destroys a prf object..
*
* @param this prf_t object to destroy
- * @return
- * - SUCCESS in any case
*/
- status_t (*destroy) (prf_t *this);
+ void (*destroy) (prf_t *this);
};
/**
@@ -110,7 +101,7 @@ struct prf_t {
* @param pseudo_random_function Algorithm to use
* @return
* - prf_t if successfully
- * - NULL if out of ressources or prf not supported
+ * - NULL if prf not supported
*
* @ingroup prfs
*/
diff --git a/Source/charon/transforms/signers/hmac_signer.c b/Source/charon/transforms/signers/hmac_signer.c
index c548bfb15..e6aeeae47 100644
--- a/Source/charon/transforms/signers/hmac_signer.c
+++ b/Source/charon/transforms/signers/hmac_signer.c
@@ -48,66 +48,42 @@ struct private_hmac_signer_t {
};
-static status_t get_signature (private_hmac_signer_t *this, chunk_t data, u_int8_t *buffer)
+static void get_signature (private_hmac_signer_t *this, chunk_t data, u_int8_t *buffer)
{
u_int8_t full_mac[this->hmac_prf->get_block_size(this->hmac_prf)];
- status_t status;
- status = this->hmac_prf->get_bytes(this->hmac_prf,data,full_mac);
- if (status != SUCCESS)
- {
- return status;
- }
+ this->hmac_prf->get_bytes(this->hmac_prf,data,full_mac);
/* copy mac aka signature :-) */
memcpy(buffer,full_mac,BLOCK_SIZE);
-
- return SUCCESS;
}
-static status_t allocate_signature (private_hmac_signer_t *this, chunk_t data, chunk_t *chunk)
+static void allocate_signature (private_hmac_signer_t *this, chunk_t data, chunk_t *chunk)
{
chunk_t signature;
- status_t status;
u_int8_t full_mac[this->hmac_prf->get_block_size(this->hmac_prf)];
- status = this->hmac_prf->get_bytes(this->hmac_prf,data,full_mac);
- if (status != SUCCESS)
- {
- return status;
- }
-
+ this->hmac_prf->get_bytes(this->hmac_prf,data,full_mac);
+
signature.ptr = allocator_alloc(BLOCK_SIZE);
- if (signature.ptr == NULL)
- {
- return OUT_OF_RES;
- }
signature.len = BLOCK_SIZE;
/* copy mac aka signature :-) */
memcpy(signature.ptr,full_mac,BLOCK_SIZE);
*chunk = signature;
-
- return SUCCESS;
-
}
-static status_t verify_signature (private_hmac_signer_t *this, chunk_t data, chunk_t signature, bool *valid)
+static void verify_signature (private_hmac_signer_t *this, chunk_t data, chunk_t signature, bool *valid)
{
- status_t status;
u_int8_t full_mac[this->hmac_prf->get_block_size(this->hmac_prf)];
- status = this->hmac_prf->get_bytes(this->hmac_prf,data,full_mac);
- if (status != SUCCESS)
- {
- return status;
- }
+ this->hmac_prf->get_bytes(this->hmac_prf,data,full_mac);
if (signature.len != BLOCK_SIZE)
{
- /* signature must have BLOCK_SIZE length */
- return INVALID_ARG;
+ *valid = FALSE;
+ return;
}
/* compare mac aka signature :-) */
@@ -119,8 +95,6 @@ static status_t verify_signature (private_hmac_signer_t *this, chunk_t data, chu
{
*valid = FALSE;
}
-
- return SUCCESS;
}
static size_t get_block_size (private_hmac_signer_t *this)
@@ -128,9 +102,9 @@ static size_t get_block_size (private_hmac_signer_t *this)
return BLOCK_SIZE;
}
-static status_t set_key (private_hmac_signer_t *this, chunk_t key)
+static void set_key (private_hmac_signer_t *this, chunk_t key)
{
- return (this->hmac_prf->set_key(this->hmac_prf,key));
+ this->hmac_prf->set_key(this->hmac_prf,key);
}
/**
@@ -150,35 +124,23 @@ static status_t destroy(private_hmac_signer_t *this)
hmac_signer_t *hmac_signer_create(hash_algorithm_t hash_algoritm)
{
private_hmac_signer_t *this = allocator_alloc_thing(private_hmac_signer_t);
- if (this == NULL)
- {
- return NULL;
- }
-
+
this->hmac_prf = (prf_t *) hmac_prf_create(hash_algoritm);
if (this->hmac_prf == NULL)
{
- /* hmac prf could not be created !!! */
- allocator_free(this);
- return NULL;
- }
-
- if (this->hmac_prf->get_block_size(this->hmac_prf) < BLOCK_SIZE)
- {
- /* hmac prf with given algorithm has to small block size */
+ /* algorithm not supported */
allocator_free(this);
return NULL;
-
}
/* interface functions */
- this->public.signer_interface.get_signature = (status_t (*) (signer_t*, chunk_t, u_int8_t*))get_signature;
- this->public.signer_interface.allocate_signature = (status_t (*) (signer_t*, chunk_t, chunk_t*))allocate_signature;
- this->public.signer_interface.verify_signature = (status_t (*) (signer_t*, chunk_t, chunk_t,bool *))verify_signature;
+ this->public.signer_interface.get_signature = (void (*) (signer_t*, chunk_t, u_int8_t*))get_signature;
+ this->public.signer_interface.allocate_signature = (void (*) (signer_t*, chunk_t, chunk_t*))allocate_signature;
+ this->public.signer_interface.verify_signature = (void (*) (signer_t*, chunk_t, chunk_t,bool *))verify_signature;
this->public.signer_interface.get_block_size = (size_t (*) (signer_t*))get_block_size;
- this->public.signer_interface.set_key = (size_t (*) (signer_t*,chunk_t))set_key;
- this->public.signer_interface.destroy = (status_t (*) (signer_t*))destroy;
+ this->public.signer_interface.set_key = (void (*) (signer_t*,chunk_t))set_key;
+ this->public.signer_interface.destroy = (void (*) (signer_t*))destroy;
return &(this->public);
}
diff --git a/Source/charon/transforms/signers/hmac_signer.h b/Source/charon/transforms/signers/hmac_signer.h
index 129a1ee39..3504b5311 100644
--- a/Source/charon/transforms/signers/hmac_signer.h
+++ b/Source/charon/transforms/signers/hmac_signer.h
@@ -20,8 +20,8 @@
* for more details.
*/
-#ifndef _HMAC_SIGNER_H_
-#define _HMAC_SIGNER_H_
+#ifndef HMAC_SIGNER_H_
+#define HMAC_SIGNER_H_
#include <transforms/signers/signer.h>
#include <transforms/hashers/hasher.h>
@@ -30,7 +30,7 @@ typedef struct hmac_signer_t hmac_signer_t;
/**
* @brief Implementation of hmac_signer_t interface using the
- * HMAC algorithm in combination with eather MD5 or SHA1.
+ * HMAC algorithm in combination with either MD5 or SHA1.
*
* @ingroup signers
*/
@@ -45,15 +45,14 @@ struct hmac_signer_t {
/**
* @brief Creates a new hmac_signer_t.
*
- * @param hash_algorithm Hash algorithm to use with signer
- *
- * @return
- * - hmac_signer_t if successfully
- * - NULL if out of ressources
+ * @param hash_algorithm Hash algorithm to use with signer
+ * @return
+ * - hmac_signer_t
+ * - NULL if hash not supported
*
* @ingroup signers
*/
hmac_signer_t *hmac_signer_create(hash_algorithm_t hash_algoritm);
-#endif //_HMAC_SIGNER_H_
+#endif /*HMAC_SIGNER_H_*/
diff --git a/Source/charon/transforms/signers/signer.c b/Source/charon/transforms/signers/signer.c
index 98c639f6c..4d6d3e837 100644
--- a/Source/charon/transforms/signers/signer.c
+++ b/Source/charon/transforms/signers/signer.c
@@ -37,6 +37,10 @@ mapping_t integrity_algorithm_m[] = {
{MAPPING_END, NULL}
};
+
+/*
+ * see header
+ */
signer_t *signer_create(integrity_algorithm_t integrity_algorithm)
{
switch(integrity_algorithm)
@@ -49,7 +53,6 @@ signer_t *signer_create(integrity_algorithm_t integrity_algorithm)
{
return ((signer_t *) hmac_signer_create(HASH_MD5));
}
-
default:
return NULL;
}
diff --git a/Source/charon/transforms/signers/signer.h b/Source/charon/transforms/signers/signer.h
index 5eb4c1875..eb6a68a93 100644
--- a/Source/charon/transforms/signers/signer.h
+++ b/Source/charon/transforms/signers/signer.h
@@ -61,10 +61,8 @@ struct signer_t {
* @param this calling signer
* @param data a chunk containing the data to sign
* @param[out] buffer pointer where the signature will be written
- * @return
- * - SUCCESS in any case
*/
- status_t (*get_signature) (signer_t *this, chunk_t data, u_int8_t *buffer);
+ void (*get_signature) (signer_t *this, chunk_t data, u_int8_t *buffer);
/**
* @brief Generate a signature and allocate space for it.
@@ -72,11 +70,8 @@ struct signer_t {
* @param this calling signer
* @param data a chunk containing the data to sign
* @param[out] chunk chunk which will hold the allocated signature
- * @return
- * - SUCCESS in any case
- * - OUT_OF_RES if space could not be allocated
*/
- status_t (*allocate_signature) (signer_t *this, chunk_t data, chunk_t *chunk);
+ void (*allocate_signature) (signer_t *this, chunk_t data, chunk_t *chunk);
/**
* @brief Verify a signature.
@@ -85,10 +80,8 @@ struct signer_t {
* @param data a chunk containing the data to verify
* @param signature a chunk containing the signature
* @param[out] vaild set to TRUE, if signature is valid, to FALSE otherwise
- * @return
- * - SUCCESS in any case
*/
- status_t (*verify_signature) (signer_t *this, chunk_t data, chunk_t signature, bool *valid);
+ void (*verify_signature) (signer_t *this, chunk_t data, chunk_t signature, bool *valid);
/**
* @brief Get the block size of this signature algorithm.
@@ -103,19 +96,15 @@ struct signer_t {
*
* @param this calling signer
* @param key key to set
- * @return
- * - SUCCESS in any case
*/
- status_t (*set_key) (signer_t *this, chunk_t key);
+ void (*set_key) (signer_t *this, chunk_t key);
/**
* @brief Destroys a signer object.
*
- * @param this signer_t object to destroy
- * @return
- * - SUCCESS in any case
+ * @param this signer_t object to destroy
*/
- status_t (*destroy) (signer_t *this);
+ void (*destroy) (signer_t *this);
};
/**
@@ -123,8 +112,8 @@ struct signer_t {
*
* @param integrity_algorithm Algorithm to use for signing and verifying.
* @return
- * - signer_t if successfully
- * - NULL if out of ressources or signer not supported
+ * - signer_t if successfully,
+ * - NULL if signer not supported
*
* @ingroup signers
*/