Change order of complement & filtering

This commit is contained in:
Nico Schottelius 2019-07-15 16:20:51 +02:00
commit 26c27cefa8
3 changed files with 25 additions and 13 deletions

View file

@ -13,16 +13,20 @@ def checksum_scapy(pkt):
if len(pkt) % 2 == 1:
pkt += b"\0"
# P4: ABOVE not needed (always even)
# array: create an array of 16 bit values from the input
# and then sum it up -> this might be sligthly/much higher
# than 16 bit (additions!)
s = sum(array.array("H", pkt))
# P4: summing manually into 32bit
# add the (right shift 16) and the 16 right bits
# basically: assuming 32 bit (?): add the two 16 bit "words"
# together
# This might still exceed 16 bit!
s = (s >> 16) + (s & 0xffff)
# P4:
# right shift 16 -> zero least significant bits,
# and add the upper bits to it