*/
#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
* @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 -----------------------------------------------*/