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

[ot] hw/opentitan: ot_aes fix initialization/reset bug #5

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
19 changes: 13 additions & 6 deletions hw/opentitan/ot_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ typedef struct OtAESContext {
uint64_t iv[OT_AES_IV_SIZE / sizeof(uint64_t)];
uint8_t src[OT_AES_DATA_SIZE];
uint8_t dst[OT_AES_DATA_SIZE];
bool key_ready;
bool iv_ready;
bool di_full;
bool do_full;
int aes_cipher;
bool key_ready; /* Key has been fully loaded */
bool iv_ready; /* IV has been fully loaded */
bool di_full; /* Input DATA FIFO fully filled */
bool do_full; /* Output DATA FIFO not empty */
int aes_cipher; /* AES context for tomcrypt */
} OtAESContext;

typedef struct OtAESEDN {
Expand Down Expand Up @@ -581,15 +581,21 @@ static inline bool ot_aes_can_process(const OtAESState *s)
/* auto mode */
if (c->do_full) {
/* cannot schedule a round if output FIFO has not been emptied */
xtrace_ot_aes_debug("DO full");
return false;
}
} else {
if (!(r->trigger & R_TRIGGER_START_MASK)) {
/* cannot execute in manual mode w/o an explicit trigger */
xtrace_ot_aes_debug("manual not triggered");
return false;
}
}

if (!c->di_full) {
xtrace_ot_aes_debug("DI not filled");
}

/* TODO: not sure if this also applies in manual mode */
return c->di_full;
}
Expand Down Expand Up @@ -1227,6 +1233,7 @@ static void ot_aes_reset(DeviceState *dev)

s->prng = ot_prng_allocate();

memset(s->ctx, 0, sizeof(*s->ctx));
memset(r, 0, sizeof(*r));

ot_shadow_reg_init(&r->ctrl, 0x1181u);
Expand Down Expand Up @@ -1254,7 +1261,7 @@ static void ot_aes_init(Object *obj)
sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio);

s->regs = g_new0(OtAESRegisters, 1u);
s->ctx = g_new(OtAESContext, 1u);
s->ctx = g_new0(OtAESContext, 1u);

s->ctx->aes_cipher =
register_cipher(&aes_desc); /* aes_desc is defined in libtomcrypt */
Expand Down