X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/1da1ed6a5815deef6c33d74f1eb3c856793df3e5..1519ef6617fd7351bd40026b9eeb47c7f7f42234:/symm/salsa20-core.h diff --git a/symm/salsa20-core.h b/symm/salsa20-core.h index b27f2220..e64e7331 100644 --- a/symm/salsa20-core.h +++ b/symm/salsa20-core.h @@ -164,8 +164,8 @@ */ #define SALSA20_PREPBUF(ctx, a) do { \ int _i; \ - for (_i = 0; _i < 16; _i++) STORE32_L((ctx)->buf + 4*_i, (a)[_i]); \ - (ctx)->bufi = 0; \ + for (_i = 0; _i < 16; _i++) STORE32_L((ctx)->b + 4*_i, (a)[_i]); \ + (ctx)->off = 0; \ } while (0) /* Write at most @n@ bytes of buffered output from the context @ctx@ to the @@ -174,12 +174,13 @@ * @n@ is decreased appropriately. */ #define SALSA20_OUTBUF(ctx, d, s, n) do { \ - size_t _n = (n), _left = SALSA20_OUTSZ - (ctx)->bufi; \ - if (_n > _left) _n = _left; \ - (n) -= _n; \ - if (!(d)) (ctx)->bufi += _n; \ - else if (s) while (_n--) *(d)++ = (ctx)->buf[(ctx)->bufi++] ^ *(s)++; \ - else while (_n--) *(d)++ = (ctx)->buf[(ctx)->bufi++]; \ + const octet *_p = (ctx)->b + (ctx)->off; \ + size_t _n = (n); \ + \ + (ctx)->off += _n; \ + if (!(d)) /* nothing to do */; \ + else if (!(s)) { memcpy((d), _p, _n); (d) += _n; } \ + else while (_n--) *(d)++ = *(s)++ ^ *_p++; \ } while (0) /*----- Variants and naming -----------------------------------------------*/