- /* --- Main encryption loop --- */ \
- \
- { \
- uint32 iv[PRE##_BLKSZ / 4]; \
- BLKC_LOAD(PRE, iv, ctx->iv); \
- \
- for (;;) { \
- pre##_eblk(&ctx->ctx, iv, iv); \
- if (sz < PRE##_BLKSZ) \
- break; \
- if (d) { \
- if (!s) \
- BLKC_STORE(PRE, d, iv); \
- else { \
- uint32 x[PRE##_BLKSZ / 4]; \
- BLKC_LOAD(PRE, x, s); \
- BLKC_XSTORE(PRE, d, iv, x); \
- s += PRE##_BLKSZ; \
- } \
- d += PRE##_BLKSZ; \
- } \
- sz -= PRE##_BLKSZ; \
- } \
- \
- BLKC_STORE(PRE, ctx->iv, iv); \
- off = 0; \
+ /* If the buffer is all used, then reset it ready for next time. */ \
+ ctx->off -= plan.from_rsvr; \
+ \
+ /* Handle multiple whole blocks. */ \
+ if (!d) while (plan.from_input) { \
+ pre##_eblk(&ctx->ctx, t, t); \
+ plan.from_input -= PRE##_BLKSZ; \
+ } else if (!s) while (plan.from_input) { \
+ pre##_eblk(&ctx->ctx, t, t); \
+ BLKC_STORE(PRE, d, t); d += PRE##_BLKSZ; \
+ plan.from_input -= PRE##_BLKSZ; \
+ } else while (plan.from_input) { \
+ pre##_eblk(&ctx->ctx, t, t); \
+ BLKC_LOAD(PRE, u, s); s += PRE##_BLKSZ; \
+ BLKC_XSTORE(PRE, d, t, u); d += PRE##_BLKSZ; \
+ plan.from_input -= PRE##_BLKSZ; \