X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/0f00dc4c8eb47e67bc0f148c2dd109f73a451e0a..6a024d24d97cb5d42c0091571735475b849f59f4:/symm/whirlpool.c diff --git a/symm/whirlpool.c b/symm/whirlpool.c index 4543287e..f22a366a 100644 --- a/symm/whirlpool.c +++ b/symm/whirlpool.c @@ -33,7 +33,6 @@ #include "ghash-def.h" #include "hash.h" #include "whirlpool.h" -#include "whirlpool-tab.h" #if defined(HAVE_UINT64) # define USE64 @@ -41,12 +40,12 @@ /*----- Static variables --------------------------------------------------*/ -static const kludge64 C[10] = WHIRLPOOL_C; +extern const kludge64 whirlpool_c[10]; #ifdef USE64 -static const kludge64 T[8][256] = WHIRLPOOL_T; +extern const kludge64 whirlpool_t[8][256]; #else -static const uint32 U[4][256] = WHIRLPOOL_U, V[4][256] = WHIRLPOOL_V; +extern const uint32 whirlpool_u[4][256], whirlpool_v[4][256]; #endif /*----- Main code ---------------------------------------------------------*/ @@ -69,7 +68,7 @@ static const uint32 U[4][256] = WHIRLPOOL_U, V[4][256] = WHIRLPOOL_V; (LO64(x) >> ((j) * 8)) : \ (HI64(x) >> ((j) * 8 - 32))) -#define TT(v, i, j) T[j][BYTE(v[OFFSET(i, j)], j)] +#define TT(v, i, j) whirlpool_t[j][BYTE(v[OFFSET(i, j)], j)] #define XROW(vv, v, i) do { \ XOR64(vv[i], vv[i], TT(v, i, 1)); \ @@ -96,10 +95,10 @@ static const uint32 U[4][256] = WHIRLPOOL_U, V[4][256] = WHIRLPOOL_V; #define BYTE(x, j) U8((x) >> (((j) & 3) * 8)) -#define UUL(v, i, j) U[j & 3][BYTE(v[OFFSET(i, j)].lo, j)] -#define VVL(v, i, j) V[j & 3][BYTE(v[OFFSET(i, j)].lo, j)] -#define UUH(v, i, j) U[j & 3][BYTE(v[OFFSET(i, j)].hi, j)] -#define VVH(v, i, j) V[j & 3][BYTE(v[OFFSET(i, j)].hi, j)] +#define UUL(v, i, j) whirlpool_u[j & 3][BYTE(v[OFFSET(i, j)].lo, j)] +#define VVL(v, i, j) whirlpool_v[j & 3][BYTE(v[OFFSET(i, j)].lo, j)] +#define UUH(v, i, j) whirlpool_u[j & 3][BYTE(v[OFFSET(i, j)].hi, j)] +#define VVH(v, i, j) whirlpool_v[j & 3][BYTE(v[OFFSET(i, j)].hi, j)] #define XROW(vv, v, i) do { \ vv[i].lo ^= UUL(v, i, 1); vv[i].hi ^= VVL(v, i, 1); \ @@ -138,7 +137,7 @@ static const uint32 U[4][256] = WHIRLPOOL_U, V[4][256] = WHIRLPOOL_V; void whirlpool_compress(whirlpool_ctx *ctx, const void *sbuf) { kludge64 m[8], k[8], kk[8], v[8], vv[8]; - const kludge64 *c = C; + const kludge64 *c = whirlpool_c; const octet *s = sbuf; int i; @@ -207,7 +206,7 @@ void whirlpool_set(whirlpool_ctx *ctx, const void *buf, unsigned long count) } ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @whirlpool_hash@, @whirlpool256_hash@ --- * @@ -295,10 +294,31 @@ unsigned long whirlpool_state(whirlpool_ctx *ctx, void *state) /* --- Generic interface --- */ -GHASH_DEF(WHIRLPOOL, whirlpool) +#define HASHES(_) \ + _(WHIRLPOOL, whirlpool) \ + _(WHIRLPOOL256, whirlpool256) -/* --- Test code --- */ +HASHES(GHASH_DEF) -HASH_TEST(WHIRLPOOL, whirlpool) +/*----- Test rig ----------------------------------------------------------*/ + +#ifdef TEST_RIG + +#include + +HASHES(HASH_VERIFY) + +static const test_chunk defs[] = { + HASHES(HASH_TESTDEFS) + { 0, 0, { 0 } } +}; + +int main(int argc, char *argv[]) +{ + test_run(argc, argv, defs, SRCDIR "/t/whirlpool"); + return (0); +} + +#endif /*----- That's all, folks -------------------------------------------------*/