1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-12 07:27:57 +00:00
freebsd-ports/security/digest/files/patch-triger.c
Martin Wilke 8ee0d2721f - Add a patch for output the correct checksum for the null string.
PR:		112553
Submitted by:	Ighighi<ighighi@gmail.com>
Obtained from:	pkgsrc
2007-05-29 14:54:04 +00:00

63 lines
1.5 KiB
C

--- tiger.c.orig Tue May 8 06:31:30 2007
+++ tiger.c Tue May 8 08:07:57 2007
@@ -646,12 +646,16 @@
TIGER_COMPRESS_MACRO(((const uint64_t *) str), ((uint64_t *) state));
}
+static uint64_t init_state[3] = {
+ 0x0123456789ABCDEFLL, 0xFEDCBA9876543210LL, 0xF096A5B4C3B2E187LL
+};
+
void
TIGERInit(tiger_context_t *tp)
{
- tp->ctx[0] = 0x0123456789ABCDEFLL;
- tp->ctx[1] = 0xFEDCBA9876543210LL;
- tp->ctx[2] = 0xF096A5B4C3B2E187LL;
+ tp->ctx[0] = init_state[0];
+ tp->ctx[1] = init_state[1];
+ tp->ctx[2] = init_state[2];
}
void
@@ -708,10 +712,27 @@
tiger_compress(((uint64_t *) temp), tp->ctx);
}
+#define PUT_64BIT_BE(cp, value) do { \
+ (cp)[0] = (value) >> 56; \
+ (cp)[1] = (value) >> 48; \
+ (cp)[2] = (value) >> 40; \
+ (cp)[3] = (value) >> 32; \
+ (cp)[4] = (value) >> 24; \
+ (cp)[5] = (value) >> 16; \
+ (cp)[6] = (value) >> 8; \
+ (cp)[7] = (value); } while (0)
+
void
TIGERFinal(uint8_t *digest, tiger_context_t *tp)
{
- /* nothing to do - included for compatibility with SHA* interface */
+ int i;
+
+ if (tp->ctx[0] == init_state[0] && tp->ctx[1] == init_state[1] &&
+ tp->ctx[2] == init_state[2])
+ TIGERUpdate(tp, "", 0);
+
+ for (i = 0; i < 3; i++)
+ PUT_64BIT_BE(digest + i * 8, tp->ctx[i]);
}
static void
@@ -734,6 +755,9 @@
if (buf == NULL && (buf = malloc(41)) == NULL) {
return NULL;
}
+ if (tp->ctx[0] == init_state[0] && tp->ctx[1] == init_state[1] &&
+ tp->ctx[2] == init_state[2])
+ TIGERUpdate(tp, "", 0);
for (i = 0; i < 3; ++i)
print_uint64(buf + i * 16, tp->ctx[i]);