X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/0fee61eb2ff1807c5f32a34499ef2753b6fcd9a5..bd6d65e32b835551677456bf286d09ced6859882:/symm/hash.h diff --git a/symm/hash.h b/symm/hash.h index 420277d2..5b2e7fb8 100644 --- a/symm/hash.h +++ b/symm/hash.h @@ -38,6 +38,10 @@ #include +#ifndef CATACOMB_RSVR_H +# include "rsvr.h" +#endif + /*----- Macros ------------------------------------------------------------*/ /* --- @HASH_BUFFER@ --- * @@ -58,9 +62,10 @@ #define HASH_BUFFER(PRE, pre, ictx, ibuf, isz) do { \ pre##_ctx *_bctx = (ictx); \ size_t _bsz = (isz); \ - const octet *_bbuf = (octet *)(ibuf); \ - size_t _s; \ + const octet *_bbuf = (octet *)(ibuf), *_p; \ + static const rsvr_policy _pol = { 0, PRE##_BUFSZ, PRE##_BUFSZ }; \ uint32 _l, _h; \ + rsvr_state _st; \ \ /* --- Add on the size done so far --- * \ * \ @@ -72,33 +77,11 @@ _bctx->nl += _l; if (_bctx->nl < _l || _bctx->nl & ~(uint32)MASK32) _h++; \ _bctx->nh += _h; \ \ - /* --- Handle very small contributions --- */ \ - \ - if (_bctx->off + _bsz < PRE##_BUFSZ) \ - { memcpy(_bctx->buf + _bctx->off, _bbuf, _bsz); _bctx->off += _bsz; } \ - else { \ - \ - /* --- Handle an initial partial buffer --- */ \ - \ - if (_bctx->off) { \ - _s = PRE##_BUFSZ - _bctx->off; \ - memcpy(_bctx->buf + _bctx->off, _bbuf, _s); \ - pre##_compress(_bctx, _bctx->buf); \ - _bsz -= _s; _bbuf += _s; \ - } \ + /* --- Accumulate the input data --- */ \ \ - /* --- Do whole buffers while we can --- */ \ - \ - while (_bsz >= PRE##_BUFSZ) { \ - pre##_compress(_bctx, _bbuf); \ - _bsz -= PRE##_BUFSZ; _bbuf += PRE##_BUFSZ; \ - } \ - \ - /* --- And wrap up at the end --- */ \ - \ - if (_bsz) memcpy(_bctx->buf, _bbuf, _bsz); \ - _bctx->off = _bsz; \ - } \ + rsvr_setup(&_st, &_pol, _bctx->buf, &_bctx->off, _bbuf, _bsz); \ + RSVR_DO(&_st) while ((_p = RSVR_NEXT(&_st, PRE##_BUFSZ)) != 0) \ + pre##_compress(_bctx, _p); \ } while (0) /* --- @HASH_PAD@ --- * @@ -155,6 +138,7 @@ #ifdef TEST_RIG +#include #include #include @@ -195,7 +179,7 @@ static int vrf_##pre(dstr *v, const test_type *msgty) \ sz -= i; \ } \ pre##_done(&ctx, d.buf); \ - if (memcmp(d.buf, v[1].buf, PRE##_HASHSZ) != 0) { \ + if (MEMCMP(d.buf, !=, v[1].buf, PRE##_HASHSZ)) { \ printf("\nfail:\n\tstep = %i\n\tinput = ", *ip); \ msgty->dump(&v[0], stdout); \ printf("\n\texpected = "); \ @@ -239,7 +223,7 @@ static int vrf_##pre##_rep(dstr *v) \ while (n--) pre##_hash(&ctx, p, len); \ pre##_done(&ctx, d.buf); \ \ - if (memcmp(d.buf, v[2].buf, PRE##_HASHSZ) != 0) { \ + if (MEMCMP(d.buf, !=, v[2].buf, PRE##_HASHSZ)) { \ printf("\nfail:\n\tinput = `%s'\n\treps = `%i'\n\texpected = ", \ v[0].buf, *(int *)v[1].buf); \ type_hex.dump(&v[2], stdout); \