From 361c3d6c87f3d2be7d204fdc6a83ca0373bcc928 Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Wed, 18 Dec 2024 16:37:19 +0000 Subject: [PATCH] [ot] hw/opentitan: ot_otbn: compute checksum over LE values. The checksum computation is currently being computed over big-endian order 48-bit values {imem, addr, value}, but the CRC32 checksum of an OTBN application is actually computed over the values in little-endian order. Replace the existing BE logic with little endian so that the computed checksum is correct. --- hw/opentitan/ot_otbn.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hw/opentitan/ot_otbn.c b/hw/opentitan/ot_otbn.c index f383d6297258..afcb297ba47c 100644 --- a/hw/opentitan/ot_otbn.c +++ b/hw/opentitan/ot_otbn.c @@ -523,10 +523,9 @@ static void ot_otbn_update_checksum(OtOTBNState *s, bool doi, uint32_t addr, { uint8_t buf[6]; - /* BE or LE? */ - stw_be_p(&buf[0], addr >> 2U); - buf[0] |= doi ? 0x80u : 0x00u; - stl_be_p(&buf[2], value); + stw_le_p(&buf[4], addr >> 2U); + buf[5] |= doi ? 0x80u : 0x00u; + stl_le_p(&buf[0], value); s->load_checksum = crc32(s->load_checksum, buf, sizeof(buf)); }