Skip to content

Conversation

@pamaury
Copy link
Contributor

@pamaury pamaury commented Nov 19, 2025

Backport #25969

I had to change a little bit how the annotate/serde is handle on the Sha256Digest because it wasn't supported as-is by the serde-annotate used on master. Following @nbdd0121 advice, I move the #[annotate(format = "hexstr")] to the user and added back the #[serde(with = "serde_bytes")] to the field inside Sha256Digest.

@pamaury pamaury marked this pull request as ready for review November 19, 2025 16:49
@pamaury pamaury requested review from a team and cfrantz as code owners November 19, 2025 16:49
@pamaury pamaury requested review from AlexJones0, engdoreis, jwnrt and nbdd0121 and removed request for a team November 19, 2025 16:49
@pamaury pamaury force-pushed the backport_25969 branch 2 times, most recently from 607c1cf to 4d53336 Compare November 20, 2025 09:07
Opentitanlib was computing the SHA256 hash and storing it in a fixed-sized
bigint.  This led to various problems dealing with the endianness of the
resulting digest, including emitting digest in "little-endian" order.
A SHA256 digest _is not_ an integer; it is a sequence of bytes.

1. Eliminate the bigint representation of the SHA256 digest.  Give the
   digest struct serialization, display and parsing traits to eliminate
   the need for dealing with conversions for those ues cases.  Add
   `to_vec` and `to_vec_rev` to produce the raw bytes when needed.
2. Add a `--spx-hash-reversal-bug` switch to opentitantool spx commands
   for cases where firmware erroneously uses a reversed digest.
3. Eliminate the copious digest reversals present in hsmtool.  Add a
   `Sha256HashReversed` input format for cases where
   firmware erroneously uses a reversed digest.
4. Fix the signing rules to use the reversed format only for keys
   tied to a firmware implementation with the reversal bug.

Signed-off-by: Chris Frantz <[email protected]>
(cherry picked from commit 51e6a41)
1. Add tests that check that signatures generated with opentitantool can
   be verified by hsmtool.
2. Add tests that check that signatures generated with hsmtool can
   be verified by opentitantool.
3. Verify the correctness of the manifest digest calculcated by
   opentitantool.

Signed-off-by: Chris Frantz <[email protected]>
(cherry picked from commit 12467bb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants