Date: Fri, 11 Nov 2022 18:36:46 GMT From: John Baldwin <jhb@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 44c1914ee672 - stable/13 - powerpc_nvram: Fix a bug in the adler32 checksum. Message-ID: <202211111836.2ABIak9a004031@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=44c1914ee672487fe19363647f787958f2e3bebb commit 44c1914ee672487fe19363647f787958f2e3bebb Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2022-10-03 23:10:41 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2022-11-11 18:18:53 +0000 powerpc_nvram: Fix a bug in the adler32 checksum. The Adler32 digest consists of two 16-bit words whose values are calculated modulo 65521 (largest prime < 2^16). To avoid two division instructions per byte, this version copies an optimization found in zlib which defers the modulus until close to the point that the intermediate sums can overflow 2^32. (zlib uses NMAX == 5552 for this, this version uses 5000) The bug is that in the deferred modulus case, the modulus was only applied to the high word (and twice at that) but not to the low word. The fix is to apply it to both words. Reviewed by: jhibbits Reported by: Miod Vallat <miod@openbsd.org> Differential Revision: https://reviews.freebsd.org/D36798 (cherry picked from commit e0df0dce71d86796195502b923243bb6bacdcdc2) --- sys/dev/powermac_nvram/powermac_nvram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/dev/powermac_nvram/powermac_nvram.c b/sys/dev/powermac_nvram/powermac_nvram.c index 7c6c4d2bc8a1..bce511463d38 100644 --- a/sys/dev/powermac_nvram/powermac_nvram.c +++ b/sys/dev/powermac_nvram/powermac_nvram.c @@ -362,7 +362,7 @@ adler_checksum(uint8_t *data, int len) high = 0; for (i = 0; i < len; i++) { if ((i % 5000) == 0) { - high %= 65521UL; + low %= 65521UL; high %= 65521UL; } low += data[i];
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202211111836.2ABIak9a004031>