Skip to content

Commit fb7953c

Browse files
[ot] hw/opentitan: ot_otp_eg: perform partition descrambling in DAI
Unscramble DAI reads from secret partitions, which are scrambled with a scrambling key (configured per-partition as a netlist constant) via a simple Present block cipher. Co-authored-by: Alex Jones <[email protected]> Signed-off-by: Luís Marques <[email protected]> Signed-off-by: Alex Jones <[email protected]>
1 parent 8a4ea03 commit fb7953c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

hw/opentitan/ot_otp_eg.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,7 @@ static void ot_otp_eg_dai_read(OtOTPEgState *s)
17171717
bool is_digest = ot_otp_eg_is_part_digest_offset(partition, address);
17181718
bool is_readable = ot_otp_eg_is_readable(s, partition);
17191719
bool is_wide = ot_otp_eg_is_wide_granule(partition, address);
1720+
bool is_secret = OtOTPPartDescs[partition].secret;
17201721

17211722
/* "in all partitions, the digest itself is ALWAYS readable." */
17221723
if (!is_digest && !is_readable) {
@@ -1770,6 +1771,18 @@ static void ot_otp_eg_dai_read(OtOTPEgState *s)
17701771
}
17711772
}
17721773

1774+
if (is_secret) {
1775+
const uint8_t *scrambling_key = s->otp_scramble_keys[partition];
1776+
g_assert(scrambling_key);
1777+
uint64_t data = ((uint64_t)data_hi << 32u) | data_lo;
1778+
OtPresentState *ps = ot_present_new();
1779+
ot_present_init(ps, scrambling_key);
1780+
ot_present_decrypt(ps, data, &data);
1781+
ot_present_free(ps);
1782+
data_lo = data;
1783+
data_hi = (data >> 32u);
1784+
}
1785+
17731786
s->regs[R_DIRECT_ACCESS_RDATA_0] = data_lo;
17741787
s->regs[R_DIRECT_ACCESS_RDATA_1] = data_hi;
17751788

0 commit comments

Comments
 (0)