size_t pos = 0;
while (pos < length)
{
- EncryptBlock(d + pos, s + pos, ctx);
+ if (pos + 8 < length)
+ EncryptBlock(d + pos, s + pos, ctx);
+ else
+ {
+ // Short string, use 0-padded buffer.
+ char buf[8];
+ memset(buf, 0, sizeof(buf));
+ memcpy(buf, s + pos, length - pos);
+ EncryptBlock(d + pos, buf, ctx);
+ }
pos += 8;
}
}