(hash.c) Some cleanups/documentation

This commit is contained in:
twinaphex 2015-01-15 02:04:14 +01:00
parent 89917218b1
commit 67c95b1b61
2 changed files with 21 additions and 12 deletions

23
hash.c
View File

@ -155,6 +155,14 @@ static void sha256_subhash(struct sha256_ctx *p, uint32_t *t)
store32be(t++, p->h[i]);
}
/**
* sha256_hash:
* @out : Output.
* @in : Input.
* @size : Size of @out.
*
* Hashes SHA256 and outputs a human readable string.
**/
void sha256_hash(char *out, const uint8_t *in, size_t size)
{
unsigned i;
@ -399,23 +407,18 @@ static void SHA1PadMessage(SHA1Context *context)
* block, process it, and then continue padding into a second
* block.
*/
context->Message_Block[context->Message_Block_Index++] = 0x80;
if (context->Message_Block_Index > 55)
{
context->Message_Block[context->Message_Block_Index++] = 0x80;
while(context->Message_Block_Index < 64)
context->Message_Block[context->Message_Block_Index++] = 0;
SHA1ProcessMessageBlock(context);
}
while(context->Message_Block_Index < 56)
context->Message_Block[context->Message_Block_Index++] = 0;
}
else
{
context->Message_Block[context->Message_Block_Index++] = 0x80;
while(context->Message_Block_Index < 56)
context->Message_Block[context->Message_Block_Index++] = 0;
}
while(context->Message_Block_Index < 56)
context->Message_Block[context->Message_Block_Index++] = 0;
/* Store the message length as the last 8 octets */
context->Message_Block[56] = (context->Length_High >> 24) & 0xFF;

10
hash.h
View File

@ -48,8 +48,14 @@
#include "config.h"
#endif
/* Hashes sha256 and outputs a human readable string
* for comparing with the cheat XML values. */
/**
* sha256_hash:
* @out : Output.
* @in : Input.
* @size : Size of @out.
*
* Hashes SHA256 and outputs a human readable string.
**/
void sha256_hash(char *out, const uint8_t *in, size_t size);
#ifdef HAVE_ZLIB