- if (iv)
- /* IV load, convert size */
- LOAD(p, (uintptr_t)iv, CONTEXT1, iv_off, ivlen, IMMED | COPY);
- else
- /* IV is present first before the actual message */
- SEQLOAD(p, CONTEXT1, iv_off, ivlen, 0);
+ /* IV is present first before the actual message */
+ SEQLOAD(p, CONTEXT1, iv_off, ivlen, 0);
+
+ /* If IV len is less than 16 bytes, set 'counter' as 1 */
+ if (cipherdata->algmode == OP_ALG_AAI_CTR && ivlen < 16) {
+ counter = 1;
+ if (!swap)
+ counter = swab32(1);
+
+ LOAD(p, counter, CONTEXT1, (iv_off + ivlen), 16 - ivlen, IMMED);
+ }