ARM ASM ChaCha20: Fix calc of left over bytes

This commit is contained in:
Sean Parkinson
2020-09-30 15:44:30 +10:00
parent 66ed9b1522
commit f76165a3fa
2 changed files with 4 additions and 4 deletions

View File

@ -2839,10 +2839,10 @@ static void wc_Chacha_encrypt_bytes(ChaCha* ctx, const byte* m, byte* c,
}
if (bytes > 0) {
wc_Chacha_encrypt_64(ctx->X, m, c, bytes, (byte*)ctx->over);
if (bytes > 64)
if (bytes > CHACHA_CHUNK_BYTES)
ctx->X[CHACHA_IV_BYTES] = PLUSONE(ctx->X[CHACHA_IV_BYTES]);
else
ctx->left = CHACHA_CHUNK_BYTES - bytes;
ctx->left = CHACHA_CHUNK_BYTES - (bytes & (CHACHA_CHUNK_BYTES - 1));
ctx->left &= CHACHA_CHUNK_BYTES - 1;
ctx->X[CHACHA_IV_BYTES] = PLUSONE(ctx->X[CHACHA_IV_BYTES]);
}
}

View File

@ -4857,7 +4857,7 @@ static int chacha_test(void)
}
/* Streaming test */
for (i = 1; i <= (int)CHACHA_CHUNK_BYTES; i++) {
for (i = 1; i <= (int)CHACHA_CHUNK_BYTES + 1; i++) {
int j, rem;
ret = wc_Chacha_SetKey(&enc, keys[0], keySz);