merged EAP framework from branch into trunk

includes a lot of other modifications
This commit is contained in:
Martin Willi
2007-02-12 15:56:47 +00:00
parent 6fda18d99d
commit f27f6296e6
64 changed files with 8538 additions and 481 deletions
+15 -1
View File
@@ -122,10 +122,24 @@ struct hasher_t {
*/
void (*reset) (hasher_t *this);
/**
* @brief Get the state of the hasher.
*
* A hasher stores internal state information. This state may be
* manipulated to include a "seed" into the hashing operation. It used by
* some exotic protocols (such as AKA).
* The data pointed by chunk may be manipulated, but not replaced nor freed.
* This is more a hack than a feature. The hasher's state may be byte
* order dependant; use with care.
*
* @param this calling object
*/
chunk_t (*get_state) (hasher_t *this);
/**
* @brief Destroys a hasher object.
*
* @param this calling object
* @param this calling object
*/
void (*destroy) (hasher_t *this);
};
@@ -363,6 +363,19 @@ static void reset(private_md5_hasher_t *this)
this->count[1] = 0;
}
/**
* Implementation of hasher_t.get_state
*/
static chunk_t get_state(private_md5_hasher_t *this)
{
chunk_t chunk;
chunk.ptr = (u_char*)&this->state[0];
chunk.len = sizeof(this->state);
return chunk;
}
/**
* Implementation of hasher_t.destroy.
*/
@@ -382,6 +395,7 @@ md5_hasher_t *md5_hasher_create(void)
this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
this->public.hasher_interface.get_hash_size = (size_t (*) (hasher_t*))get_hash_size;
this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
this->public.hasher_interface.get_state = (chunk_t (*) (hasher_t*))get_state;
this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
/* initialize */
+16 -1
View File
@@ -223,7 +223,7 @@ static size_t get_hash_size(private_sha1_hasher_t *this)
{
return HASH_SIZE_SHA1;
}
/**
* Implementation of hasher_t.reset.
*/
@@ -237,6 +237,20 @@ static void reset(private_sha1_hasher_t *this)
this->count[0] = 0;
this->count[1] = 0;
}
/**
* Implementation of hasher_t.get_state
*/
static chunk_t get_state(private_sha1_hasher_t *this)
{
chunk_t chunk;
chunk.ptr = (u_char*)&this->state[0];
chunk.len = sizeof(this->state);
return chunk;
}
/**
* Implementation of hasher_t.destroy.
*/
@@ -256,6 +270,7 @@ sha1_hasher_t *sha1_hasher_create(void)
this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
this->public.hasher_interface.get_hash_size = (size_t (*) (hasher_t*))get_hash_size;
this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
this->public.hasher_interface.get_state = (chunk_t (*) (hasher_t*))get_state;
this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
/* initialize */
@@ -586,6 +586,38 @@ static void reset512(private_sha512_hasher_t *ctx)
ctx->sha_bufCnt = 0;
}
/**
* Implementation of hasher_t.get_state for SHA256
*/
static chunk_t get_state256(private_sha256_hasher_t *ctx)
{
chunk_t chunk;
chunk.ptr = (u_char*)&ctx->sha_H[0];
chunk.len = HASH_SIZE_SHA256;
return chunk;
}
/**
* Implementation of hasher_t.get_state for SHA384
*/
static chunk_t get_state384(private_sha512_hasher_t *ctx)
{
chunk_t chunk;
chunk.ptr = (u_char*)&ctx->sha_H[0];
chunk.len = HASH_SIZE_SHA384;
return chunk;
}
/**
* Implementation of hasher_t.get_state for SHA512
*/
static chunk_t get_state512(private_sha512_hasher_t *ctx)
{
chunk_t chunk;
chunk.ptr = (u_char*)&ctx->sha_H[0];
chunk.len = HASH_SIZE_SHA512;
return chunk;
}
/**
* Implementation of hasher_t.destroy.
*/
@@ -606,6 +638,7 @@ sha2_hasher_t *sha2_hasher_create(hash_algorithm_t algorithm)
case HASH_SHA256:
this = (sha2_hasher_t*)malloc_thing(private_sha256_hasher_t);
this->hasher_interface.reset = (void(*)(hasher_t*))reset256;
this->hasher_interface.get_state = (chunk_t(*)(hasher_t*))get_state256;
this->hasher_interface.get_hash_size = (size_t(*)(hasher_t*))get_hash_size256;
this->hasher_interface.get_hash = (void(*)(hasher_t*,chunk_t,u_int8_t*))get_hash256;
this->hasher_interface.allocate_hash = (void(*)(hasher_t*,chunk_t,chunk_t*))allocate_hash256;
@@ -614,6 +647,7 @@ sha2_hasher_t *sha2_hasher_create(hash_algorithm_t algorithm)
/* uses SHA512 data structure */
this = (sha2_hasher_t*)malloc_thing(private_sha512_hasher_t);
this->hasher_interface.reset = (void(*)(hasher_t*))reset384;
this->hasher_interface.get_state = (chunk_t(*)(hasher_t*))get_state384;
this->hasher_interface.get_hash_size = (size_t(*)(hasher_t*))get_hash_size384;
this->hasher_interface.get_hash = (void(*)(hasher_t*,chunk_t,u_int8_t*))get_hash384;
this->hasher_interface.allocate_hash = (void(*)(hasher_t*,chunk_t,chunk_t*))allocate_hash384;
@@ -621,6 +655,7 @@ sha2_hasher_t *sha2_hasher_create(hash_algorithm_t algorithm)
case HASH_SHA512:
this = (sha2_hasher_t*)malloc_thing(private_sha512_hasher_t);
this->hasher_interface.reset = (void(*)(hasher_t*))reset512;
this->hasher_interface.get_state = (chunk_t(*)(hasher_t*))get_state512;
this->hasher_interface.get_hash_size = (size_t(*)(hasher_t*))get_hash_size512;
this->hasher_interface.get_hash = (void(*)(hasher_t*,chunk_t,u_int8_t*))get_hash512;
this->hasher_interface.allocate_hash = (void(*)(hasher_t*,chunk_t,chunk_t*))allocate_hash512;