Skip to content

Commit 7443b28

Browse files
AlexJones0luismarques
authored andcommitted
[ot] hw/opentitan: ot_otp_dj: 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. Signed-off-by: Alex Jones <[email protected]>
1 parent fb7953c commit 7443b28

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

hw/opentitan/ot_otp_dj.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,7 @@ static void ot_otp_dj_dai_read(OtOTPDjState *s)
18891889
bool is_zer = ot_otp_dj_is_part_zer_offset(partition, address);
18901890
bool is_readable = ot_otp_dj_is_readable(s, partition);
18911891
bool is_wide = ot_otp_dj_is_wide_granule(partition, address);
1892+
bool is_secret = OtOTPPartDescs[partition].secret;
18921893

18931894
/* "in all partitions, the digest itself is ALWAYS readable." */
18941895
if (!is_digest && !is_zer && !is_readable) {
@@ -1945,6 +1946,18 @@ static void ot_otp_dj_dai_read(OtOTPDjState *s)
19451946
}
19461947
}
19471948

1949+
if (is_secret) {
1950+
const uint8_t *scrambling_key = s->otp_scramble_keys[partition];
1951+
g_assert(scrambling_key);
1952+
uint64_t data = ((uint64_t)data_hi << 32u) | data_lo;
1953+
OtPresentState *ps = ot_present_new();
1954+
ot_present_init(ps, scrambling_key);
1955+
ot_present_decrypt(ps, data, &data);
1956+
ot_present_free(ps);
1957+
data_lo = data;
1958+
data_hi = (data >> 32u);
1959+
}
1960+
19481961
s->regs[R_DIRECT_ACCESS_RDATA_0] = data_lo;
19491962
s->regs[R_DIRECT_ACCESS_RDATA_1] = data_hi;
19501963

0 commit comments

Comments
 (0)