From d6d1c8dae59c43cedc537765cc1ee3f8dfe8bad2 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 24 Sep 2023 09:07:51 +0200 Subject: [PATCH] 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. --- fletcher16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fletcher16.c b/fletcher16.c index 9d7ccef..1778d28 100644 --- a/fletcher16.c +++ b/fletcher16.c @@ -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;