diff options
author | Martin Willi <martin@strongswan.org> | 2005-11-21 18:07:10 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2005-11-21 18:07:10 +0000 |
commit | 3e13b35a498a9ad5d2accf855475781c8643589b (patch) | |
tree | d92a7036057097028b5b8342f2560fd926217eb3 /Source/charon/transforms | |
parent | 3e075ba1ed5b9cfd93089198e9727473df753f4f (diff) | |
download | strongswan-3e13b35a498a9ad5d2accf855475781c8643589b.tar.bz2 strongswan-3e13b35a498a9ad5d2accf855475781c8643589b.tar.xz |
- doc
- reseting when result fetched
Diffstat (limited to 'Source/charon/transforms')
-rw-r--r-- | Source/charon/transforms/hashers/hasher_sha1.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Source/charon/transforms/hashers/hasher_sha1.c b/Source/charon/transforms/hashers/hasher_sha1.c index 1349a4135..8dfc35870 100644 --- a/Source/charon/transforms/hashers/hasher_sha1.c +++ b/Source/charon/transforms/hashers/hasher_sha1.c @@ -31,7 +31,9 @@ #define BLOCK_SIZE_SHA1 20 - +/* + * ugly macro stuff + */ #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) #if BYTE_ORDER == LITTLE_ENDIAN @@ -50,6 +52,10 @@ #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); + +/** + * private data structure with hasing context + */ typedef struct private_hasher_sha1_s private_hasher_sha1_t; struct private_hasher_sha1_s { @@ -58,13 +64,17 @@ struct private_hasher_sha1_s { */ hasher_sha1_t public; - + /* + * state of the hasher + */ u_int32_t state[5]; u_int32_t count[2]; u_int8_t buffer[64]; }; -/* Hash a single 512-bit block. This is the core of the algorithm. */ +/* + * 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]) { u_int32_t a, b, c, d, e; @@ -113,7 +123,9 @@ void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64]) memset(block, '\0', sizeof(block)); } -/* Run your data through this. */ +/* + * Run your data through this. + */ void SHA1Update(private_hasher_sha1_t* this, u_int8_t *data, u_int32_t len) { u_int32_t i; @@ -182,6 +194,7 @@ static status_t get_hash(private_hasher_sha1_t *this, chunk_t chunk, u_int8_t *b if (buffer != NULL) { SHA1Final(this, buffer); + this->public.hasher_interface.reset(&(this->public.hasher_interface)); } return SUCCESS; } @@ -204,6 +217,7 @@ static status_t allocate_hash(private_hasher_sha1_t *this, chunk_t chunk, chunk_ if (hash != NULL) { SHA1Final(this, allocated_hash.ptr); + this->public.hasher_interface.reset(&(this->public.hasher_interface)); } *hash = allocated_hash; |