예제 #1
0
void CCHashInstance::finish(unsigned char *digest)
{
	if (mTruncate == 0) {
	 	CCDigestFinal(mDigest, digest);
	} else {
		unsigned char fullDigest[CCDigestOutputSize(mDigest)];
		CCDigestFinal(mDigest, fullDigest);
		memcpy(digest, fullDigest, mTruncate);
	}
}
예제 #2
0
char *
Digest_End(CCDigestRef ctx, char *buf)
{
	static const char hex[] = "0123456789abcdef";
	uint8_t digest[32]; // SHA256 is the biggest
	size_t i, length;

	(void)osx_assumes_zero(CCDigestFinal(ctx, digest));
	length = CCDigestOutputSize(ctx);
	osx_assert(length <= sizeof(digest));
	for (i = 0; i < length; i++) {
		buf[i+i] = hex[digest[i] >> 4];
		buf[i+i+1] = hex[digest[i] & 0x0f];
	}
	buf[i+i] = '\0';
	return buf;
}