Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rom_ctrl scrambling logic #90

Open
wants to merge 2 commits into
base: dev/ot-earlgrey-1.0.0-updates
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions hw/opentitan/ot_rom_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static const char *REG_NAMES[REGS_COUNT] = {

#define OT_ROM_CTRL_NUM_ADDR_SUBST_PERM_ROUNDS 2u
#define OT_ROM_CTRL_NUM_DATA_SUBST_PERM_ROUNDS 2u
#define OT_ROM_CTRL_NUM_PRINCE_HALF_ROUNDS 2u
#define OT_ROM_CTRL_NUM_PRINCE_HALF_ROUNDS 3u

#define OT_ROM_CTRL_DATA_BITS (sizeof(uint32_t) * 8u)
#define OT_ROM_CTRL_ECC_BITS 7u
Expand All @@ -121,10 +121,6 @@ static const char *REG_NAMES[REGS_COUNT] = {
static const uint8_t SBOX4[16u] = {
12u, 5u, 6u, 11u, 9u, 0u, 10u, 13u, 3u, 14u, 15u, 8u, 4u, 7u, 1u, 2u
};

static const uint8_t SBOX4_INV[16u] = {
5u, 14u, 15u, 8u, 12u, 1u, 2u, 13u, 11u, 4u, 6u, 3u, 0u, 7u, 9u, 10u
};
/* clang-format on */

static const OtKMACAppCfg KMAC_APP_CFG =
Expand Down Expand Up @@ -281,36 +277,12 @@ static uint64_t ot_rom_ctrl_subst_perm_enc(uint64_t in, uint64_t key,
return state;
}

static uint64_t ot_rom_ctrl_subst_perm_dec(uint64_t in, uint64_t key,
unsigned width, unsigned num_rounds)
{
uint64_t state = in;

for (unsigned ix = 0; ix < num_rounds; ix++) {
state ^= key;
state = ot_rom_ctrl_perm(state, width, true);
state = ot_rom_ctrl_flip(state, width);
state = ot_rom_ctrl_sbox(state, width, SBOX4_INV);
}

state ^= key;

return state;
}

static unsigned ot_rom_ctrl_addr_sp_enc(const OtRomCtrlState *s, unsigned addr)
{
return ot_rom_ctrl_subst_perm_enc(addr, s->addr_nonce, s->addr_width,
OT_ROM_CTRL_NUM_ADDR_SUBST_PERM_ROUNDS);
}

static uint64_t ot_rom_ctrl_data_sp_dec(const OtRomCtrlState *s, uint64_t in)
{
(void)s;
return ot_rom_ctrl_subst_perm_dec(in, 0, OT_ROM_CTRL_WORD_BITS,
OT_ROM_CTRL_NUM_DATA_SUBST_PERM_ROUNDS);
}

static uint64_t
ot_rom_ctrl_get_keystream(const OtRomCtrlState *s, unsigned addr)
{
Expand Down Expand Up @@ -438,8 +410,7 @@ static uint64_t
ot_rom_ctrl_unscramble_word(const OtRomCtrlState *s, unsigned addr, uint64_t in)
{
uint64_t keystream = ot_rom_ctrl_get_keystream(s, addr);
uint64_t sp = ot_rom_ctrl_data_sp_dec(s, in);
return keystream ^ sp;
return keystream ^ in;
}

static uint32_t ot_rom_ctrl_verify_ecc_39_32_u32(
Expand Down
Loading