Пример #1
0
int SHA1Result(SHA1Context *context) {
	if (context->Corrupted)
		return 0;
	if (!context->Computed) {
		SHA1PadMessage(context);
		context->Computed = 1;
	}
	return 1;
}
Пример #2
0
Файл: sha1.c Проект: ireader/sdk
/*
* SHA1Finalize
*
* Description:
*	This helper function finishes off the digest calculations.
*
* Parameters:
*	context: [in/out]
*		The SHA context to update.
*	Pad_Byte: [in]
*		The last byte to add to the message block before the 0-padding
*		and length. This will contain the last bits of the message
*		followed by another single bit. If the message was an
*		exact multiple of 8-bits long, Pad_Byte will be 0x80.
*
* Returns:
*	sha Error Code.
*
*/
static void SHA1Finalize(SHA1Context *context, uint8_t Pad_Byte)
{
	int i;
	SHA1PadMessage(context, Pad_Byte);
	/* message may be sensitive, clear it out */
	for (i = 0; i < SHA1_Message_Block_Size; ++i)
		context->Message_Block[i] = 0;
	context->Length_High = 0; /* and clear length */
	context->Length_Low = 0;
	context->Computed = 1;
}
Пример #3
0
/*
 *  SHA1Result
 *
 *  Description:
 *      This function will return the 160-bit message digest into the
 *      Message_Digest array within the sha1_ctx provided
 *
 *  Parameters:
 *      context: [in/out]
 *          The context to use to calculate the SHA-1 hash.
 *
 *  Returns:
 *      1 if successful, 0 if it failed.
 *
 *  Comments:
 *
 */
int sha1_end(sha1_ctx *ctx) {

    if (ctx->Corrupted) {
        return 0;
    }

    if (!ctx->Computed) {
        SHA1PadMessage(ctx);
        ctx->Computed = 1;
    }

    return 1;
}
Пример #4
0
/*
 *  SHA1Result
 *
 *  Description:
 *      This function will return the 160-bit message digest into the
 *      Message_Digest array  provided by the caller.
 *      NOTE: The first octet of hash is stored in the 0th element,
 *            the last octet of hash in the 19th element.
 *
 *  Parameters:
 *      context: [in/out]
 *          The context to use to calculate the SHA-1 hash.
 *      Message_Digest: [out]
 *          Where the digest is returned.
 *
 *  Returns:
 *      sha Error Code.
 *
 */
void SHA1Result(SHA1Context *context, PCHAR Message_Digest)
{
    UCHAR i;
	PCHAR p;

    SHA1PadMessage(context);
/*
    for(i=0; i<64; ++i)
    {
        context->Message_Block[i] = 0;
    }
*/
    /* message may be sensitive, clear it out */
	memset(context->Message_Block, 0, 64);
    context->Length_Low = 0;    /* and clear length */

	p = Message_Digest;
    for(i = 0; i < (SHA1HashSize/4); i ++)
    {
//        Message_Digest[i] = (UCHAR)(context->Intermediate_Hash[i>>2] >> 8 * ( 3 - ( i & 0x03 ) ));
		ULONG2PCHAR(context->Intermediate_Hash[i], p);
		p += 4;
    }
}