X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/aa1082f28ddd05f3b946ca1a9c6bfaa17d18aca5..79ba130cb5776f994f6a3f0f87159d8cbc5ff129:/hash.h diff --git a/hash.h b/hash.h index 5d43bfb..5b7f0c3 100644 --- a/hash.h +++ b/hash.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: hash.h,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: hash.h,v 1.2 1999/12/10 23:16:40 mdw Exp $ * * Generic handling for message digest functions * @@ -30,13 +30,16 @@ /*----- Revision history --------------------------------------------------* * * $Log: hash.h,v $ + * Revision 1.2 1999/12/10 23:16:40 mdw + * Split mode macros into interface and implementation. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * */ -#ifndef HASH_H -#define HASH_H +#ifndef CATACOMB_HASH_H +#define CATACOMB_HASH_H #ifdef __cplusplus extern "C" { @@ -70,9 +73,19 @@ size_t _bsz = (isz); \ const octet *_bbuf = (octet *)(ibuf); \ \ - /* --- Add on the size done so far --- */ \ - \ - _bctx->count += _bsz; \ + /* --- Add on the size done so far --- * \ + * \ + * Messy, because trapping overflow is difficult when you don't know \ + * how many bits you've actually got. \ + */ \ + \ + { \ + uint32 _l = U32(_bsz), _h = (_bsz >> 16) >> 16; \ + _bctx->nh += _h; \ + _bctx->nl += _l; \ + if (_bctx->nl < _l || _bctx->nl & ~MASK32) \ + _bctx->nh++; \ + } \ \ /* --- Handle very small contributions --- */ \ \ @@ -144,8 +157,9 @@ #define HASH_MD5STRENGTH(PRE, pre, ictx) do { \ pre##_ctx *_mctx = (ictx); \ HASH_PAD(PRE, pre, _mctx, 0x80u, 0, 8); \ - STORE32_L(_mctx->buf + PRE##_BUFSZ - 8, _mctx->count << 3); \ - STORE32_L(_mctx->buf + PRE##_BUFSZ - 4, _mctx->count >> 29); \ + STORE32_L(_mctx->buf + PRE##_BUFSZ - 8, _mctx->nl << 3); \ + STORE32_L(_mctx->buf + PRE##_BUFSZ - 4, \ + (_mctx->nl >> 29) | (_mctx->nh << 3)); \ pre##_compress(_mctx, _mctx->buf); \ } while (0)