aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/transforms/hashers
diff options
context:
space:
mode:
authorJan Hutter <jhutter@hsr.ch>2005-12-06 15:37:56 +0000
committerJan Hutter <jhutter@hsr.ch>2005-12-06 15:37:56 +0000
commit6f36717843c71a46c5cfb8d4d4f9b74d0585de1f (patch)
treeffa1345c68767e8660a6bf917eeef9d5ce15b947 /Source/charon/transforms/hashers
parent62abe4a37dade51bc122e97d566ec7b728648638 (diff)
downloadstrongswan-6f36717843c71a46c5cfb8d4d4f9b74d0585de1f.tar.bz2
strongswan-6f36717843c71a46c5cfb8d4d4f9b74d0585de1f.tar.xz
- code cleaned up
Diffstat (limited to 'Source/charon/transforms/hashers')
-rw-r--r--Source/charon/transforms/hashers/hasher.c6
-rw-r--r--Source/charon/transforms/hashers/hasher.h56
-rw-r--r--Source/charon/transforms/hashers/md5_hasher.c18
-rw-r--r--Source/charon/transforms/hashers/md5_hasher.h4
-rw-r--r--Source/charon/transforms/hashers/sha1_hasher.c22
-rw-r--r--Source/charon/transforms/hashers/sha1_hasher.h4
6 files changed, 63 insertions, 47 deletions
diff --git a/Source/charon/transforms/hashers/hasher.c b/Source/charon/transforms/hashers/hasher.c
index 0b86eef37..71811c16a 100644
--- a/Source/charon/transforms/hashers/hasher.c
+++ b/Source/charon/transforms/hashers/hasher.c
@@ -1,7 +1,7 @@
/**
* @file hasher.c
*
- * @brief Generic constructor for hasher_t
+ * @brief Generic constructor for hasher_t.
*
*/
@@ -27,7 +27,7 @@
#include <transforms/hashers/md5_hasher.h>
/**
- * mappings for hash_algorithm_t
+ * String mappings for hash_algorithm_t.
*/
mapping_t hash_algorithm_m[] = {
{HASH_MD2,"HASH_MD2"},
@@ -40,7 +40,7 @@ mapping_t hash_algorithm_m[] = {
};
/*
- * Described in header
+ * Described in header.
*/
hasher_t *hasher_create(hash_algorithm_t hash_algorithm)
{
diff --git a/Source/charon/transforms/hashers/hasher.h b/Source/charon/transforms/hashers/hasher.h
index e207b30f1..00ea0a724 100644
--- a/Source/charon/transforms/hashers/hasher.h
+++ b/Source/charon/transforms/hashers/hasher.h
@@ -1,7 +1,7 @@
/**
* @file hasher.h
*
- * @brief Interface for hasher_t.
+ * @brief Interface hasher_t.
*
*/
@@ -26,22 +26,36 @@
#include <types.h>
+
typedef enum hash_algorithm_t hash_algorithm_t;
/**
* @brief Algorithms to use for hashing.
+ *
+ * Currently only the following algorithms are implemented and therefore supported:
+ * - HASH_MD5
+ * - HASH_SHA1
+ *
+ * @ingroup hashers
+ *
*/
enum hash_algorithm_t {
HASH_MD2,
- HASH_MD5, /* supported */
- HASH_SHA1, /* supported */
+ /**
+ * Implemented in class md5_hasher_t.
+ */
+ HASH_MD5,
+ /**
+ * Implemented in class sha1_hasher_t.
+ */
+ HASH_SHA1,
HASH_SHA256,
HASH_SHA384,
HASH_SHA512,
};
/**
- * string mappings for hash_algorithm_t
+ * String mappings for hash_algorithm_t.
*/
extern mapping_t hash_algorithm_m[];
@@ -52,37 +66,43 @@ typedef struct hasher_t hasher_t;
* @brief Generic interface for all hash functions.
*
* @b Constructors:
- * - hasher_create()
+ * - hasher_create()
+ * - md5_hasher_create()
+ * - sha1_hasher_create()
+ *
+ * @see
+ * - md5_hasher_t
+ * - sha1_hasher_t
*
- * @see md5_hasher_t, sha1_hasher_t
+ * @todo Implement more hash algorithms
*
* @ingroup hashers
*/
struct hasher_t {
/**
- * @brief hash data and write it in the buffer
+ * @brief Hash data and write it in the buffer.
*
* If the parameter hash is NULL, no result is written back
* an more data can be appended to already hashed data.
- * If not, the result is written back and the hasher is reset.
+ * If not, the result is written back and the hasher is reseted.
*
* @warning: the hash output parameter must hold at least
* hash_t.get_block_size bytes.
*
- * @param this calling hasher
+ * @param this calling object
* @param data data to hash
- * @param [out]buffer pointer where the hash will be written
+ * @param [out]hash pointer where the hash will be written
*/
void (*get_hash) (hasher_t *this, chunk_t data, u_int8_t *hash);
/**
- * @brief hash data and allocate space for the hash
+ * @brief Hash data and allocate space for the hash.
*
* If the parameter hash is NULL, no result is written back
* an more data can be appended to already hashed data.
- * If not, the result is written back and the hasher is reset.
+ * If not, the result is written back and the hasher is reseted.
*
- * @param this calling hasher
+ * @param this calling object
* @param data chunk with data to hash
* @param [out]hash chunk which will hold allocated hash
*/
@@ -91,23 +111,23 @@ struct hasher_t {
/**
* @brief Get the block size of this hashing function.
*
- * @param this calling hasher
+ * @param this calling object
* @return block size in bytes
*/
size_t (*get_block_size) (hasher_t *this);
/**
* @brief Resets the hashers state, which allows
- * computation of a completly new hash.
+ * computation of a completely new hash.
*
- * @param this calling hasher
+ * @param this calling object
*/
void (*reset) (hasher_t *this);
/**
* @brief Destroys a hasher object.
*
- * @param this hasher_t object to destroy
+ * @param this calling object
*/
void (*destroy) (hasher_t *this);
};
@@ -117,7 +137,7 @@ struct hasher_t {
*
* @param hash_algorithm Algorithm to use for hashing
* @return
- * - hasher_t if successfully
+ * - hasher_t object
* - 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 bdb0b9eb9..cd883d92c 100644
--- a/Source/charon/transforms/hashers/md5_hasher.c
+++ b/Source/charon/transforms/hashers/md5_hasher.c
@@ -100,16 +100,16 @@ Rotation is separate from addition to prevent recomputation.
typedef struct private_md5_hasher_t private_md5_hasher_t;
/**
- * private data structure with hasing context
+ * Private data structure with hasing context.
*/
struct private_md5_hasher_t {
/**
- * public interface for this hasher
+ * Public interface for this hasher.
*/
md5_hasher_t public;
/*
- * state of the hasher
+ * State of the hasher.
*/
u_int32_t state[5];
u_int32_t count[2];
@@ -311,7 +311,7 @@ static void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
/**
- * implementation of hasher_t.get_hash for md5
+ * Implementation of hasher_t.get_hash.
*/
static void get_hash(private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
{
@@ -325,7 +325,7 @@ static void get_hash(private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer
/**
- * implementation of hasher_t.allocate_hash for md5
+ * Implementation of hasher_t.allocate_hash.
*/
static void allocate_hash(private_md5_hasher_t *this, chunk_t chunk, chunk_t *hash)
{
@@ -345,7 +345,7 @@ static void allocate_hash(private_md5_hasher_t *this, chunk_t chunk, chunk_t *ha
}
/**
- * implementation of hasher_t.get_block_size for md5
+ * Implementation of hasher_t.get_block_size.
*/
static size_t get_block_size(private_md5_hasher_t *this)
{
@@ -353,7 +353,7 @@ static size_t get_block_size(private_md5_hasher_t *this)
}
/**
- * implementation of hasher_t.reset for md5
+ * Implementation of hasher_t.reset.
*/
static void reset(private_md5_hasher_t *this)
{
@@ -366,7 +366,7 @@ static void reset(private_md5_hasher_t *this)
}
/**
- * implementation of hasher_t.destroy for md5
+ * Implementation of hasher_t.destroy.
*/
static void destroy(private_md5_hasher_t *this)
{
@@ -374,7 +374,7 @@ static void destroy(private_md5_hasher_t *this)
}
/*
- * Described in header
+ * Described in header.
*/
md5_hasher_t *md5_hasher_create()
{
diff --git a/Source/charon/transforms/hashers/md5_hasher.h b/Source/charon/transforms/hashers/md5_hasher.h
index 9a4b53e15..b32acc062 100644
--- a/Source/charon/transforms/hashers/md5_hasher.h
+++ b/Source/charon/transforms/hashers/md5_hasher.h
@@ -33,7 +33,7 @@ typedef struct md5_hasher_t md5_hasher_t;
* MD5 algorithm.
*
* @b Constructors:
- * - hasher_create() using HASH_MD5
+ * - hasher_create() using HASH_MD5 as algorithm
* - md5_hasher_create()
*
* @see hasher_t
@@ -43,7 +43,7 @@ typedef struct md5_hasher_t md5_hasher_t;
struct md5_hasher_t {
/**
- * generic hasher_t interface for this hasher
+ * Generic hasher_t interface for this hasher.
*/
hasher_t hasher_interface;
};
diff --git a/Source/charon/transforms/hashers/sha1_hasher.c b/Source/charon/transforms/hashers/sha1_hasher.c
index 609571b4c..2fa659f74 100644
--- a/Source/charon/transforms/hashers/sha1_hasher.c
+++ b/Source/charon/transforms/hashers/sha1_hasher.c
@@ -55,16 +55,16 @@
typedef struct private_sha1_hasher_t private_sha1_hasher_t;
/**
- * private data structure with hasing context
+ * Private data structure with hasing context.
*/
struct private_sha1_hasher_t {
/**
- * public interface for this hasher
+ * Public interface for this hasher.
*/
sha1_hasher_t public;
/*
- * state of the hasher
+ * State of the hasher.
*/
u_int32_t state[5];
u_int32_t count[2];
@@ -185,7 +185,7 @@ static void SHA1Final(private_sha1_hasher_t *this, u_int8_t *digest)
/**
- * implementation of hasher_t.get_hash for sha1
+ * Implementation of hasher_t.get_hash.
*/
static void get_hash(private_sha1_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
{
@@ -199,7 +199,7 @@ static void get_hash(private_sha1_hasher_t *this, chunk_t chunk, u_int8_t *buffe
/**
- * implementation of hasher_t.allocate_hash for sha1
+ * Implementation of hasher_t.allocate_hash.
*/
static void allocate_hash(private_sha1_hasher_t *this, chunk_t chunk, chunk_t *hash)
{
@@ -219,7 +219,7 @@ static void allocate_hash(private_sha1_hasher_t *this, chunk_t chunk, chunk_t *h
}
/**
- * implementation of hasher_t.get_block_size for sha1
+ * Implementation of hasher_t.get_block_size.
*/
static size_t get_block_size(private_sha1_hasher_t *this)
{
@@ -227,7 +227,7 @@ static size_t get_block_size(private_sha1_hasher_t *this)
}
/**
- * implementation of hasher_t.reset for sha1
+ * Implementation of hasher_t.reset.
*/
static void reset(private_sha1_hasher_t *this)
{
@@ -240,7 +240,7 @@ static void reset(private_sha1_hasher_t *this)
this->count[1] = 0;
}
/**
- * implementation of hasher_t.destroy for sha1
+ * Implementation of hasher_t.destroy.
*/
static void destroy(private_sha1_hasher_t *this)
{
@@ -249,15 +249,11 @@ static void destroy(private_sha1_hasher_t *this)
/*
- * Described in header
+ * Described in header.
*/
sha1_hasher_t *sha1_hasher_create()
{
private_sha1_hasher_t *this = allocator_alloc_thing(private_sha1_hasher_t);
- if (this == NULL)
- {
- return NULL;
- }
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;
diff --git a/Source/charon/transforms/hashers/sha1_hasher.h b/Source/charon/transforms/hashers/sha1_hasher.h
index d5c0c3230..43ad0ae20 100644
--- a/Source/charon/transforms/hashers/sha1_hasher.h
+++ b/Source/charon/transforms/hashers/sha1_hasher.h
@@ -33,7 +33,7 @@ typedef struct sha1_hasher_t sha1_hasher_t;
* SHA1 algorithm.
*
* @b Constructors:
- * - hasher_create() using HASH_SHA1
+ * - hasher_create() using HASH_SHA1 as algorithm
* - sha1_hasher_create()
*
* @see hasher_t
@@ -43,7 +43,7 @@ typedef struct sha1_hasher_t sha1_hasher_t;
struct sha1_hasher_t {
/**
- * generic hasher_t interface for this hasher
+ * Generic hasher_t interface for this hasher.
*/
hasher_t hasher_interface;
};