Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The trouble with computers is that they do what you tell them, not what you want. -- D. Cohen


devel / comp.arch.fpga / Re: Embedding a Checksum in an Image File

SubjectAuthor
* Embedding a Checksum in an Image Filegnuarm.del...@gmail.com
+- Re: Embedding a Checksum in an Image FileDavid Brown
`- Re: Embedding a Checksum in an Image FileMichael Schwingen

1
Embedding a Checksum in an Image File

<39425618-bfce-491f-9418-c3b2f7514ef5n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=414&group=comp.arch.fpga#414

  copy link   Newsgroups: comp.arch.fpga
X-Received: by 2002:ad4:4e14:0:b0:5ef:4151:49c4 with SMTP id dl20-20020ad44e14000000b005ef415149c4mr123771qvb.6.1681956629429;
Wed, 19 Apr 2023 19:10:29 -0700 (PDT)
X-Received: by 2002:a81:4315:0:b0:545:4133:fc40 with SMTP id
q21-20020a814315000000b005454133fc40mr3000694ywa.9.1681956629078; Wed, 19 Apr
2023 19:10:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch.fpga
Date: Wed, 19 Apr 2023 19:10:28 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=198.245.101.90; posting-account=I-_H_woAAAA9zzro6crtEpUAyIvzd19b
NNTP-Posting-Host: 198.245.101.90
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <39425618-bfce-491f-9418-c3b2f7514ef5n@googlegroups.com>
Subject: Embedding a Checksum in an Image File
From: gnuarm.deletethisbit@gmail.com (gnuarm.del...@gmail.com)
Injection-Date: Thu, 20 Apr 2023 02:10:29 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3078
 by: gnuarm.del...@gmail. - Thu, 20 Apr 2023 02:10 UTC

This is a bit of the chicken and egg thing. If you want a embed the code checksum in a code module to report the checksum, is there a way of doing this? It's a bit like being your own grandfather, I think.

I'm not thinking anything too fancy, like a CRC, but rather a simple modulo N addition, maybe N being 2^16.

I keep thinking of using a placeholder, but that doesn't seem to work out in any useful way. Even if you try to anticipate the impact of adding the checksum, that only gives you a different checksum, that you then need to anticipate further... ad infinitum.

I'm not thinking of coding any special checksum generator that excludes the checksum data. That would be too messy. Just use the existing tools to checksum the file.

I keep thinking there is a different way of looking at this to achieve the result I want...

Maybe I can prove it is impossible. Assume the file checksums to X when the checksum data is zero. The goal would then be to include the checksum data value Y in the file, that would change X to Y. Given the properties of the module N checksum, this would appear to be impossible for the general case, unless... Add another data value, called, checksum normalizer. This data value checksums with the original checksum to give the result zero. Then, when these two values are added to the file, the resulting checksum does not change.

This might be inordinately hard for a CRC, but a simple checksum would not be an issue, I think. At least, this could work in software, where data can be included in an image file as itself. In a device like an FPGA, it might not be included in the bit stream file so directly... but that might depend on where in the device it is inserted. Memory might have data that is stored as itself. I'll need to look into that.

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209

Re: Embedding a Checksum in an Image File

<u1rj40$kpej$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=415&group=comp.arch.fpga#415

  copy link   Newsgroups: comp.arch.fpga
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch.fpga
Subject: Re: Embedding a Checksum in an Image File
Date: Thu, 20 Apr 2023 16:44:16 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <u1rj40$kpej$1@dont-email.me>
References: <39425618-bfce-491f-9418-c3b2f7514ef5n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 Apr 2023 14:44:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="32ed44ad5f461f1f317cfb44e64d0860";
logging-data="681427"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18uqbR4NnkEMN8nE4ItLOE0pRvj1QrFNeA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:kIthjcnCUVMm71wb22eiWudgLxI=
In-Reply-To: <39425618-bfce-491f-9418-c3b2f7514ef5n@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Thu, 20 Apr 2023 14:44 UTC

On 20/04/2023 04:10, gnuarm.del...@gmail.com wrote:
> This is a bit of the chicken and egg thing. If you want a embed the
> code checksum in a code module to report the checksum, is there a way
> of doing this? It's a bit like being your own grandfather, I think.
>
> I'm not thinking anything too fancy, like a CRC, but rather a simple
> modulo N addition, maybe N being 2^16.
>
> I keep thinking of using a placeholder, but that doesn't seem to work
> out in any useful way. Even if you try to anticipate the impact of
> adding the checksum, that only gives you a different checksum, that
> you then need to anticipate further... ad infinitum.
>
> I'm not thinking of coding any special checksum generator that
> excludes the checksum data. That would be too messy. Just use the
> existing tools to checksum the file.
>
> I keep thinking there is a different way of looking at this to
> achieve the result I want...
>
> Maybe I can prove it is impossible. Assume the file checksums to X
> when the checksum data is zero. The goal would then be to include
> the checksum data value Y in the file, that would change X to Y.
> Given the properties of the module N checksum, this would appear to
> be impossible for the general case, unless... Add another data
> value, called, checksum normalizer. This data value checksums with
> the original checksum to give the result zero. Then, when these two
> values are added to the file, the resulting checksum does not
> change.
>
> This might be inordinately hard for a CRC, but a simple checksum
> would not be an issue, I think. At least, this could work in
> software, where data can be included in an image file as itself. In
> a device like an FPGA, it might not be included in the bit stream
> file so directly... but that might depend on where in the device it
> is inserted. Memory might have data that is stored as itself. I'll
> need to look into that.
>

I am not sure what your intended use-case is here. But it is very
common to add a checksum of some sort to binary image files after
generating them. This is done post-link. You have a struct in your
read-only data that you link at a known fixed point in the binary. Your
post-link patcher can read this struct (for example, to get the program
version number that is then used to rename the final image file). It
can modify the struct (such as inserting the length of the image). Then
it calculates a CRC and appends it to the end of the image.

Re: Embedding a Checksum in an Image File

<slrnu435uj.e86u.news-1513678000@a-tuin.ms.intern>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=418&group=comp.arch.fpga#418

  copy link   Newsgroups: comp.arch.fpga
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: news-1513678000@discworld.dascon.de (Michael Schwingen)
Newsgroups: comp.arch.fpga
Subject: Re: Embedding a Checksum in an Image File
Date: 20 Apr 2023 19:51:47 GMT
Lines: 31
Message-ID: <slrnu435uj.e86u.news-1513678000@a-tuin.ms.intern>
References: <39425618-bfce-491f-9418-c3b2f7514ef5n@googlegroups.com>
X-Trace: individual.net vdqjinXvFg9pWErCEMLbBw3sQPvVwWkcH4yHbA8HUurnFX8qrl
Cancel-Lock: sha1:M3+ZYZVBStQis2QRnBJ97QOQ0us=
User-Agent: slrn/1.0.3 (Linux)
 by: Michael Schwingen - Thu, 20 Apr 2023 19:51 UTC

On 2023-04-20, gnuarm.del...@gmail.com <gnuarm.deletethisbit@gmail.com> wrote:
>
> Maybe I can prove it is impossible. Assume the file checksums to X when
> the checksum data is zero. The goal would then be to include the checksum
> data value Y in the file, that would change X to Y. Given the properties
> of the module N checksum, this would appear to be impossible for the
> general case, unless... Add another data value, called, checksum
> normalizer. This data value checksums with the original checksum to give
> the result zero. Then, when these two values are added to the file, the
> resulting checksum does not change.

- write the patch area with zero
- checksum the file
- write the negative of the checksum to the patch area
- make the software check that the sum is zero

However, that is only easy with a sum, not with a CRC or hash. It is common
to have the CRC/hash at the beginning or end of the image and exclude that
area from being summed/hashed to avoid the problem you describe.

LPC8xx is one CPU which needs a checksum in the vector table to even start
the flashed program:

https://github.com/nPipen/lpcpatchelf

https://stackoverflow.com/questions/24150030/storing-crc-into-an-axf-elf-file

cu
Michael
--
Some people have no respect of age unless it is bottled.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor