Ejemplo n.º 1
0
void
netpgpv_RMD160Final(u_char digest[20], NETPGPV_RMD160_CTX *ctx)
{
	int i;
	u_char size[8];
	uint32_t padlen;

	PUT_64BIT_LE(size, ctx->count);

	/*
	 * pad to 64 byte blocks, at least one byte from PADDING plus 8 bytes
	 * for the size
	 */
	padlen = (uint32_t)(64 - ((ctx->count/8) % 64));
	if (padlen < 1 + 8)
		padlen += 64;
	netpgpv_RMD160Update(ctx, PADDING, padlen - 8);		/* padlen - 8 <= 64 */
	netpgpv_RMD160Update(ctx, size, 8);

	if (digest != NULL)
		for (i = 0; i < 5; i++)
			PUT_32BIT_LE(digest + i*4, ctx->state[i]);

	memset(ctx, 0, sizeof (*ctx));
}
Ejemplo n.º 2
0
int
digest_update(digest_t *hash, const uint8_t *data, size_t length)
{
    if (hash == NULL || data == NULL) {
        return 0;
    }
    switch(hash->alg) {
    case MD5_HASH_ALG:
        netpgpv_MD5Update(hash->ctx, data, (unsigned)length);
        return 1;
    case SHA1_HASH_ALG:
        netpgpv_SHA1Update(hash->ctx, data, (unsigned)length);
        return 1;
    case RIPEMD_HASH_ALG:
        netpgpv_RMD160Update(hash->ctx, data, (unsigned)length);
        return 1;
    case SHA256_HASH_ALG:
        netpgpv_SHA256_Update(hash->ctx, data, length);
        return 1;
    case SHA512_HASH_ALG:
        netpgpv_SHA512_Update(hash->ctx, data, length);
        return 1;
    default:
        printf("hash_any: bad algorithm\n");
        return 0;
    }
}