diff options
Diffstat (limited to 'Source/charon/transforms/signers')
-rw-r--r-- | Source/charon/transforms/signers/hmac_signer.c | 74 | ||||
-rw-r--r-- | Source/charon/transforms/signers/hmac_signer.h | 17 | ||||
-rw-r--r-- | Source/charon/transforms/signers/signer.c | 5 | ||||
-rw-r--r-- | Source/charon/transforms/signers/signer.h | 27 |
4 files changed, 38 insertions, 85 deletions
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 */ |