- unsigned off = ctx->off; \
- uint32 t[PRE##_BLKSZ/4], u[PRE##_BLKSZ/4]; \
- octet y; \
- \
- /* --- Empty blocks are trivial --- */ \
- \
- if (!sz) return; \
- \
- /* --- If I can deal with the block from my buffer, do that --- */ \
- \
- if (sz < PRE##_BLKSZ - off) goto small; \
- \
- /* --- Finish off what's left in my buffer --- */ \
- \
- if (!d) sz -= PRE##_BLKSZ - off; \
- else while (off < PRE##_BLKSZ) \
- { y = s ? *s++ : 0; *d++ = ctx->b[off++] ^ y; sz--; } \
- \
- /* --- Main encryption loop --- */ \
- \
- for (;;) { \
- pre##_eblk(&ctx->ctx, ctx->c, t); \
- BLKC_STEP(PRE, ctx->c); \
- if (sz < PRE##_BLKSZ) break; \
- if (!d) /* do nothing */; \
- else if (!s) { BLKC_STORE(PRE, d, t); d += PRE##_BLKSZ; } \
- else { \
- BLKC_LOAD(PRE, u, s); s += PRE##_BLKSZ; \
- BLKC_XSTORE(PRE, d, t, u); d += PRE##_BLKSZ; \
+ uint32 t[PRE##_BLKSZ/4]; \
+ \
+ /* Construct a plan and prepare to follow through. */ \
+ rsvr_mkplan(&plan, &pre##_counterpolicy, ctx->off, sz); \
+ \
+ /* Initial portion, fulfilled from the buffer. If the chunk is small \
+ * enough, then this will be the only portion. If the buffer is \
+ * currently empty, then we must prepare it. \
+ */ \
+ if (plan.head) { \
+ if (!ctx->off) { \
+ pre##_eblk(&ctx->ctx, ctx->c, t); BLKC_STEP(PRE, ctx->c); \
+ BLKC_STORE(PRE, ctx->b, t); \