示例#1
0
文件: md5.c 项目: davies/moosefs
void md5_final (uint8_t digest[16],md5ctx *ctx) {
	uint8_t bits[8];
	uint32_t indx,padleng;

	md5_encode(bits,ctx->count,2);
	indx = (uint32_t)((ctx->count[0]>>3)&0x3f);
	padleng = (indx<56)?(56-indx):(120-indx);
	md5_update (ctx,padding,padleng);
	md5_update(ctx,bits,8);
	md5_encode(digest,ctx->state,4);
	memset((char*)ctx,0,sizeof(md5ctx));
}
示例#2
0
/**
 @brief	md5 finalisation. Ends an md5 message-digest operation, writing the
		message digest and zeroing the context.
*/
void md5_final(uint8_t digest[16], md5_ctx *context)
{
	uint8_t  bits[8];
	uint32_t index, padLen;

	// Save number of bits
	md5_encode(bits, context->count, 8);

	// Pad out to 56 mod 64.
	index  = (uint32_t)((context->count[0] >> 3) & 0x3f);
	padLen = (index < 56) ? (56 - index) : (120 - index);
	md5_update(context, padding, padLen);

	// Append length (before padding)
	md5_update(context, bits, 8);
	// Store state in digest
	md5_encode(digest, context->state, 16);

	// Zero sensitive information.
	memset((void*)context,0,sizeof(*context));
}