Fix Fletcher-16 for small lengths

For Fletcher-32, the conditional subtract approach works for lengths up
to 514 bytes, but for Fletcher-16 it only works up to 2 bytes due to
FLETCHER16_MODULE being much smaller than FLETCHER32_MODULE.
This commit is contained in:
JosJuice
2023-09-24 09:07:51 +02:00
committed by Natalia Portillo
parent d325d82cf1
commit d6d1c8dae5

View File

@@ -91,7 +91,7 @@ AARU_EXPORT int AARU_CALL fletcher16_update(fletcher16_ctx *ctx, const uint8_t *
sum1 += *data++;
sum2 += sum1;
}
if(sum1 >= FLETCHER16_MODULE) sum1 -= FLETCHER16_MODULE;
sum1 %= FLETCHER16_MODULE;
sum2 %= FLETCHER16_MODULE; /* only added so many FLETCHER16_MODULE's */
ctx->sum1 = sum1 & 0xFF;
ctx->sum2 = sum2 & 0xFF;