From d9f69be3472ae0f3081e2652ef0b90cea5913955 Mon Sep 17 00:00:00 2001 From: Mahmoud Almontasser Date: Thu, 18 Jul 2024 11:24:24 +0200 Subject: [PATCH 1/2] fix checksum calculation code When summing the higher two bytes with the lower two bytes, that results sometimes to an overflow, meaning the result is bigger than 0xffff (16 bit). This way we keep folding the upper bytes until we end up with a 16 bit checksum --- protocol.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/protocol.md b/protocol.md index 0752bc6..1980181 100644 --- a/protocol.md +++ b/protocol.md @@ -337,8 +337,9 @@ while j>16) +# Fold carry bits into the lower 16 bits +while (chk_32b &0xffff0000) != 0: + chk_32b = (chk_32b & 0xffff) + (chk_32b >> 16) # calculate ones complement to get final checksum (in big endian) chk_16b = chk_32b ^ 0xFFFF From 3306926ef600e08530a57d4e89532db4748c850b Mon Sep 17 00:00:00 2001 From: Mahmoud Almontasser Date: Thu, 18 Jul 2024 11:26:12 +0200 Subject: [PATCH 2/2] fix type --- protocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol.md b/protocol.md index 1980181..3007185 100644 --- a/protocol.md +++ b/protocol.md @@ -338,7 +338,7 @@ while j> 16) # calculate ones complement to get final checksum (in big endian)