X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/1aaccf40b93719fd3df7cc89e023b9bb48b358b6..8f2287ef5c05d496fcb9b012629af007fe56f897:/symm/poly1305.c diff --git a/symm/poly1305.c b/symm/poly1305.c index 942aa384..c4a88a84 100644 --- a/symm/poly1305.c +++ b/symm/poly1305.c @@ -33,6 +33,7 @@ #include #include "poly1305.h" +#include "rsvr.h" /*----- Global variables --------------------------------------------------*/ @@ -183,7 +184,7 @@ static void mul_r(const poly1305_ctx *ctx, felt z, const felt x) #endif -/*----- Low-level implementation for 32/64-bit targets --------------------*/ +/*----- Low-level implementation for 16/32-bit targets --------------------*/ #ifndef POLY1305_IMPL # define POLY1305_IMPL 11 @@ -536,28 +537,15 @@ static void update_full(poly1305_ctx *ctx, const octet *p) ctx->count++; } +static const rsvr_policy pol = { 0, 16, 16 }; + void poly1305_hash(poly1305_ctx *ctx, const void *p, size_t sz) { - const octet *pp = p; - size_t n; - - if (ctx->nbuf) { - if (sz < 16 - ctx->nbuf) { - memcpy(ctx->buf + ctx->nbuf, p, sz); - ctx->nbuf += sz; - return; - } - n = 16 - ctx->nbuf; - memcpy(ctx->buf + ctx->nbuf, pp, n); - update_full(ctx, ctx->buf); - pp += n; sz -= n; - } - while (sz >= 16) { - update_full(ctx, pp); - pp += 16; sz -= 16; - } - if (sz) memcpy(ctx->buf, pp, sz); - ctx->nbuf = sz; + rsvr_state st; + const octet *q = p; + + rsvr_setup(&st, &pol, &ctx->buf, &ctx->nbuf, p, sz); + RSVR_DO(&st) while ((q = RSVR_NEXT(&st, 16)) != 0) update_full(ctx, q); } /* --- @poly1305_flush@ --- *