Christopher Duckworth
Christopher Duckworth

Reputation: 19

Checksum is part of checked data, how to calculate?

I have an eprom where the checksum is the 16bit sum of the entire eprom. The problem is that correcting the checksum changes the checked data since the checksum resides within the checked data. Is there an algorithm that I can apply to generate the checksum that will account for this conundrum?

I tried calculating the checksum with the original value in place. The sum 16 calculator provides a new checksum but once you change the checksum to the new value, it is no longer valid. I tried zeroing out the checksum but the same thing happens. I tried computing it a bunch of times in a row to see if it would home in on a value that checks itself correctly, also with no joy. You end up chasing your tail, the new value is not valid once you update it. I'd figure there has to be a formula or bit flipping trick but I can't wrap my head around it. It's too vague a concept to get anything useful from google. Can someone enlighten me?

Upvotes: 0

Views: 44

Answers (2)

Christopher Duckworth
Christopher Duckworth

Reputation: 19

Thanks for the reply. It gave me the hints I needed to solve my problem. I could not change how the checksum works, I'm trying to modify an existing system. What I ended up noticing is that the word following the checksum is its complement. If I replace the checksum and its complement with any two words that sum to FFFF (IE. FFFF 0000, or 7F7F 8080) and then calculate the checksum, the resulting value and its complement wouldn't change the calculated checksum when substituted back in.

Upvotes: 1

ipodtouch0218
ipodtouch0218

Reputation: 3346

Short answer: No. (65535/65536ths of the time, anyway...)

A recursive checksum like this would only be valid if the sum of the data happens to already equal zero- otherwise you'd just end up changing the result when writing it back into the ROM. An example "proof" of this (not mathematically rigorous) would be

  1. SUM(data) + Checksum = Checksum
  2. SUM(data) + Checksum - Checksum = Checksum - Checksum
  3. SUM(data) = 0

If you're allowed to change the way you generate (and interpret) the checksum, you can make the checksum into the complement of the data's sum, where SUM(data) + Checksum = 0; and assume success if the total ROM sums to zero.

Upvotes: 2

Related Questions