{"id":11,"date":"2006-04-18T23:48:57","date_gmt":"2006-04-19T07:48:57","guid":{"rendered":"http:\/\/www.tranzoa.net\/~alex\/blog\/?p=11"},"modified":"2006-04-18T23:48:59","modified_gmt":"2006-04-19T07:48:59","slug":"crc-checksums-again","status":"publish","type":"post","link":"https:\/\/www.tranzoa.net\/~alex\/blog\/?p=11","title":{"rendered":"CRC \/ Checksums Again"},"content":{"rendered":"<p>Shudda noted that the method of doing additive checksums by look-up table values makes for some pretty dumb, fast code able to compute things like 256 bit checksums. Just concatenate 16 16-bit checksums, each computed using a different set of tables. Or whatever.<\/p>\n<p>Also thinking about computing a rolling checksum or incremental checksum:<\/p>\n<p>I gather the standard method of distinguishing the difference between, for instance, &#8220;xy&#8221; and &#8220;yx&#8221; (which a normal checksum considers equal) is to sum the sum in a separate super-sum. &#8230; The final checksum is a combination of the sum and super-sum. The super-sum effectively indexes the position of each byte by shifting the byte&#8217;s value up in the super-sum as a function of how far back the byte is in the data stream. Pulling the byte&#8217;s effect out of the super-sum is easy: subtract the byte&#8217;s value times the length of the rolling data block. Let&#8217;s presume the byte-value multiple is precomputed.<\/p>\n<p>Off hand, I don&#8217;t see anything wrong with wrapping the sums something like this (Warning: vanilla C carry bit kludge ahead.):<\/p>\n<pre>\r\nbyte           b\r\nuint32         sum_of_sums, sum\r\n\r\nsum         += table[b]\r\nsum          = (sum         >> 16) + (sum         & 0xffff)\r\nsum_of_sums +=  sum\r\nsum_of_sums  = (sum_of_sums >> 16) + (sum_of_sums & 0xffff)\r\n<\/pre>\n<p>Yes, in this 16-bit example if you have more than 64k bytes of data you could have a problem, but you&#8217;d have a problem if the overflow goes to the bit bucket. And, anyway, you&#8217;d probably want to use 31 bits or 32 bits in a real application, giving you a 2-4 gig of data without overflow. Etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Shudda noted that the method of doing additive checksums by look-up table values makes for some pretty dumb, fast code able to compute things like 256 bit checksums. Just concatenate 16 16-bit checksums, each computed using a different set of &hellip; <a href=\"https:\/\/www.tranzoa.net\/~alex\/blog\/?p=11\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-11","post","type-post","status-publish","format-standard","hentry","category-programing"],"_links":{"self":[{"href":"https:\/\/www.tranzoa.net\/~alex\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tranzoa.net\/~alex\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tranzoa.net\/~alex\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tranzoa.net\/~alex\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tranzoa.net\/~alex\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11"}],"version-history":[{"count":0,"href":"https:\/\/www.tranzoa.net\/~alex\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tranzoa.net\/~alex\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tranzoa.net\/~alex\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tranzoa.net\/~alex\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}