Skip to content

[ot] hw/opentitan: ot_aes: preserve external state when a new message is started #102

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

Merged
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
20 changes: 12 additions & 8 deletions hw/opentitan/ot_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,24 +420,28 @@ static inline bool ot_aes_key_touch_force_reseed(OtAESRegisters *r)
R_CTRL_AUX_SHADOWED_KEY_TOUCH_FORCES_RESEED_MASK);
}

static void ot_aes_init_keyshare(OtAESState *s)
static void ot_aes_init_keyshare(OtAESState *s, bool randomize)
{
OtAESRegisters *r = s->regs;
OtAESContext *c = s->ctx;

trace_ot_aes_init("keyshare");
ot_aes_randomize(s, r->keyshare, ARRAY_SIZE(r->keyshare));
if (randomize) {
ot_aes_randomize(s, r->keyshare, ARRAY_SIZE(r->keyshare));
}
bitmap_zero(r->keyshare_bm, (int64_t)(PARAM_NUM_REGS_KEY * 2u));
c->key_ready = false;
}

static void ot_aes_init_iv(OtAESState *s)
static void ot_aes_init_iv(OtAESState *s, bool randomize)
{
OtAESRegisters *r = s->regs;
OtAESContext *c = s->ctx;

trace_ot_aes_init("iv");
ot_aes_randomize(s, r->iv, ARRAY_SIZE(r->iv));
if (randomize) {
ot_aes_randomize(s, r->iv, ARRAY_SIZE(r->iv));
}
bitmap_zero(r->iv_bm, PARAM_NUM_REGS_IV);
c->iv_ready = false;
}
Expand Down Expand Up @@ -616,8 +620,8 @@ static void ot_aes_handle_trigger(OtAESState *s)
}

if (r->trigger & R_TRIGGER_KEY_IV_DATA_IN_CLEAR_MASK) {
ot_aes_init_keyshare(s);
ot_aes_init_iv(s);
ot_aes_init_keyshare(s, true);
ot_aes_init_iv(s, true);
ot_aes_init_data(s, false);
r->trigger &= ~R_TRIGGER_KEY_IV_DATA_IN_CLEAR_MASK;
}
Expand Down Expand Up @@ -1176,8 +1180,8 @@ static void ot_aes_write(void *opaque, hwaddr addr, uint64_t val64,
* IV and input data afterwards."
*/
ot_aes_finalize(s, prev_mode);
ot_aes_init_keyshare(s);
ot_aes_init_iv(s);
ot_aes_init_keyshare(s, false);
ot_aes_init_iv(s, false);
ot_aes_load_reseed_rate(s);
break;
case OT_SHADOW_REG_ERROR:
Expand Down
Loading