diff options
Diffstat (limited to 'Source/charon/transforms/hashers')
-rw-r--r-- | Source/charon/transforms/hashers/hasher.c | 5 | ||||
-rw-r--r-- | Source/charon/transforms/hashers/hasher.h | 18 | ||||
-rw-r--r-- | Source/charon/transforms/hashers/md5_hasher.c | 40 | ||||
-rw-r--r-- | Source/charon/transforms/hashers/md5_hasher.h | 4 | ||||
-rw-r--r-- | Source/charon/transforms/hashers/sha1_hasher.c | 32 | ||||
-rw-r--r-- | Source/charon/transforms/hashers/sha1_hasher.h | 4 |
6 files changed, 33 insertions, 70 deletions
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 */ |