Skip to content

Commit

Permalink
[ot] hw/opentitan: replace assert() with g_assert()
Browse files Browse the repository at this point in the history
Signed-off-by: Emmanuel Blot <[email protected]>
  • Loading branch information
rivos-eblot committed Aug 30, 2023
1 parent 60d0e9d commit b40b830
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 78 deletions.
4 changes: 2 additions & 2 deletions hw/opentitan/ot_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,8 @@ static void ot_aes_reset(DeviceState *dev)

timer_del(s->retard_timer);

assert(e->device);
assert(e->ep != UINT8_MAX);
g_assert(e->device);
g_assert(e->ep != UINT8_MAX);

s->prng = ot_prng_allocate();

Expand Down
2 changes: 1 addition & 1 deletion hw/opentitan/ot_aon_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ static void ot_aon_timer_reset(DeviceState *dev)
{
OtAonTimerState *s = OT_AON_TIMER(dev);

assert(s->pclk > 0);
g_assert(s->pclk > 0);

timer_del(s->wkup_timer);
timer_del(s->wdog_timer);
Expand Down
2 changes: 1 addition & 1 deletion hw/opentitan/ot_clkmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static void ot_clkmgr_clock_hint(void *opaque, int irq, int level)

unsigned clock = (unsigned)irq;

assert(clock < OT_CLKMGR_HINT_COUNT);
g_assert(clock < OT_CLKMGR_HINT_COUNT);

trace_ot_clkmgr_clock_hint(CLOCK_NAME(clock), clock, (bool)level);

Expand Down
50 changes: 25 additions & 25 deletions hw/opentitan/ot_csrng.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,17 @@ qemu_irq ot_csnrg_connect_hw_app(OtCSRNGState *s, unsigned app_id,
qemu_irq req_sts, ot_csrng_genbit_filler_fn fn,
void *opaque)
{
assert(app_id < OT_CSRNG_HW_APP_MAX);
assert(req_sts);
assert(fn);
g_assert(app_id < OT_CSRNG_HW_APP_MAX);
g_assert(req_sts);
g_assert(fn);

OtCSRNGInstance *inst = &s->instances[app_id];
/* if connection is invoked many times, there is no reason for changes */
if (inst->hw.filler) {
assert(inst->hw.filler == fn);
g_assert(inst->hw.filler == fn);
}
if (inst->hw.req_sts) {
assert(inst->hw.req_sts == req_sts);
g_assert(inst->hw.req_sts == req_sts);
}
inst->hw.filler = fn;
inst->hw.opaque = opaque;
Expand All @@ -399,15 +399,15 @@ qemu_irq ot_csnrg_connect_hw_app(OtCSRNGState *s, unsigned app_id,
int ot_csrng_push_command(OtCSRNGState *s, unsigned app_id,
const uint32_t *command)
{
assert(app_id < OT_CSRNG_HW_APP_MAX);
g_assert(app_id < OT_CSRNG_HW_APP_MAX);

if (s->state == CSRNG_ERROR) {
return -1;
}

OtCSRNGInstance *inst = &s->instances[app_id];
assert(inst->hw.filler);
assert(inst->hw.req_sts);
g_assert(inst->hw.filler);
g_assert(inst->hw.req_sts);

ot_fifo32_reset(&inst->cmd_fifo);
uint32_t acmd = FIELD_EX32(command[0], OT_CSNRG_CMD, ACMD);
Expand Down Expand Up @@ -553,7 +553,7 @@ static OtCSRNDCmdResult ot_csrng_drng_instanciate(
int res;
res = ecb_start(inst->parent->aes_cipher, key, (int)sizeof(key), 0,
&drng->ecb);
assert(res == CRYPT_OK);
g_assert(res == CRYPT_OK);

memcpy(drng->key, key, OT_CSRNG_AES_KEY_SIZE);
drng->instantiated = true;
Expand Down Expand Up @@ -602,7 +602,7 @@ static int ot_csrng_drng_update(OtCSRNGInstance *inst)

res = ecb_encrypt(drng->v_counter, ptmp, OT_CSRNG_AES_BLOCK_SIZE,
&drng->ecb);
assert(res == CRYPT_OK);
g_assert(res == CRYPT_OK);
ptmp += OT_CSRNG_AES_BLOCK_SIZE;
}

Expand All @@ -613,12 +613,12 @@ static int ot_csrng_drng_update(OtCSRNGInstance *inst)
ot_csrng_drng_clear_material(inst);

res = ecb_done(&drng->ecb);
assert(res == CRYPT_OK);
g_assert(res == CRYPT_OK);

ptmp = (uint8_t *)tmp;
res = ecb_start(inst->parent->aes_cipher, ptmp, (int)OT_CSRNG_AES_KEY_SIZE,
0, &drng->ecb);
assert(res == CRYPT_OK);
g_assert(res == CRYPT_OK);

memcpy(drng->key, ptmp, OT_CSRNG_AES_KEY_SIZE);
memcpy(drng->v_counter, &ptmp[OT_CSRNG_AES_KEY_SIZE],
Expand All @@ -636,7 +636,7 @@ static OtCSRNDCmdResult ot_csrng_drng_reseed(
OtCSRNGInstance *inst, OtEntropySrcState *entropy_src, bool flag0)
{
OtCSRNGDrng *drng = &inst->drng;
assert(drng->instantiated);
g_assert(drng->instantiated);

if (!flag0) {
if (!inst->parent->es_available) {
Expand Down Expand Up @@ -693,7 +693,7 @@ static void ot_csrng_drng_generate(OtCSRNGInstance *inst, uint32_t *out,

res = ecb_encrypt(drng->v_counter, (uint8_t *)out, OT_CSRNG_AES_BLOCK_SIZE,
&drng->ecb);
assert(res == CRYPT_OK);
g_assert(res == CRYPT_OK);

xtrace_ot_csrng_show_buffer(ot_csrng_get_slot(inst), "out", out,
OT_CSRNG_AES_BLOCK_SIZE);
Expand All @@ -713,7 +713,7 @@ static void ot_csrng_drng_generate(OtCSRNGInstance *inst, uint32_t *out,
static unsigned ot_csrng_get_slot(OtCSRNGInstance *inst)
{
unsigned slot = (unsigned)(uintptr_t)(inst - &inst->parent->instances[0]);
assert(slot <= SW_INSTANCE_ID);
g_assert(slot <= SW_INSTANCE_ID);
return slot;
}

Expand Down Expand Up @@ -1001,7 +1001,7 @@ ot_csrng_handle_instantiate(OtCSRNGState *s, unsigned slot)
const uint32_t *buffer =
ot_fifo32_peek_buf(&inst->cmd_fifo, ot_fifo32_num_used(&inst->cmd_fifo),
&num);
assert(num - 1u == clen);
g_assert(num - 1u == clen);
buffer += 1u;

if (clen) {
Expand Down Expand Up @@ -1055,7 +1055,7 @@ static int ot_csrng_handle_generate(OtCSRNGState *s, unsigned slot)
const uint32_t *buffer =
ot_fifo32_peek_buf(&inst->cmd_fifo,
ot_fifo32_num_used(&inst->cmd_fifo), &num);
assert(num - 1u == clen);
g_assert(num - 1u == clen);
buffer += 1u;
xtrace_ot_csrng_show_buffer(ot_csrng_get_slot(inst), "mat", buffer,
clen * sizeof(uint32_t));
Expand All @@ -1065,7 +1065,7 @@ static int ot_csrng_handle_generate(OtCSRNGState *s, unsigned slot)
trace_ot_csrng_generate(ot_csrng_get_slot(inst), packet_count);

OtCSRNGDrng *drng = &inst->drng;
assert(drng->instantiated);
g_assert(drng->instantiated);

if (ot_csrng_drng_remaining_count(inst)) {
xtrace_ot_csrng_info("remaining packets to generate",
Expand Down Expand Up @@ -1100,7 +1100,7 @@ static OtCSRNDCmdResult ot_csrng_handle_reseed(OtCSRNGState *s, unsigned slot)
const uint32_t *buffer =
ot_fifo32_peek_buf(&inst->cmd_fifo,
ot_fifo32_num_used(&inst->cmd_fifo), &num);
assert(num - 1u == clen);
g_assert(num - 1u == clen);
buffer += 1u;

xtrace_ot_csrng_show_buffer(ot_csrng_get_slot(inst), "mat", buffer,
Expand Down Expand Up @@ -1134,7 +1134,7 @@ static OtCSRNDCmdResult ot_csrng_handle_update(OtCSRNGState *s, unsigned slot)
const uint32_t *buffer =
ot_fifo32_peek_buf(&inst->cmd_fifo,
ot_fifo32_num_used(&inst->cmd_fifo), &num);
assert(num - 1u == clen);
g_assert(num - 1u == clen);
buffer += 1u;

xtrace_ot_csrng_show_buffer(ot_csrng_get_slot(inst), "mat", buffer,
Expand All @@ -1154,7 +1154,7 @@ static void ot_csrng_hwapp_ready_irq(void *opaque, int n, int level)
OtCSRNGState *s = opaque;

unsigned slot = (unsigned)n;
assert(slot < OT_CSRNG_HW_APP_MAX);
g_assert(slot < OT_CSRNG_HW_APP_MAX);
bool ready = (bool)level;

OtCSRNGInstance *inst = &s->instances[slot];
Expand Down Expand Up @@ -1267,7 +1267,7 @@ static int ot_csrng_handle_command(OtCSRNGState *s, unsigned slot)
case OT_CSRNG_CMD_RESEED:
break;
case OT_CSRNG_CMD_GENERATE:
assert(slot == SW_INSTANCE_ID || inst->hw.filler);
g_assert(slot == SW_INSTANCE_ID || inst->hw.filler);
break;
case OT_CSRNG_CMD_UPDATE:
case OT_CSRNG_CMD_UNINSTANTIATE:
Expand Down Expand Up @@ -1743,8 +1743,8 @@ static void ot_csrng_reset(DeviceState *dev)
{
OtCSRNGState *s = OT_CSRNG(dev);

assert(s->entropy_src);
assert(s->otp_ctrl);
g_assert(s->entropy_src);
g_assert(s->otp_ctrl);

timer_del(s->cmd_scheduler);

Expand All @@ -1764,7 +1764,7 @@ static void ot_csrng_reset(DeviceState *dev)

for (unsigned ix = 0; ix < OT_CSRNG_HW_APP_MAX + 1u; ix++) {
OtCSRNGInstance *inst = &s->instances[ix];
assert(inst->parent);
g_assert(inst->parent);
ot_fifo32_reset(&inst->cmd_fifo);
if (ix == SW_INSTANCE_ID) {
ot_fifo32_reset(&inst->sw.bits_fifo);
Expand Down
24 changes: 12 additions & 12 deletions hw/opentitan/ot_edn.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ static void ot_edn_csrng_ack_irq(void *opaque, int n, int level);
void ot_edn_connect_endpoint(OtEDNState *s, unsigned ep_id,
ot_edn_push_entropy_fn fn, void *opaque)
{
assert(ep_id < ENDPOINT_COUNT_MAX);
assert(fn);
g_assert(ep_id < ENDPOINT_COUNT_MAX);
g_assert(fn);

OtEDNEndPoint *ep = &s->endpoints[ep_id];
if (ep->fn) {
assert(ep->fn == fn);
g_assert(ep->fn == fn);
} else {
trace_ot_edn_connect_endpoint(s->rng.appid, ep_id);
}
Expand All @@ -314,7 +314,7 @@ int ot_edn_request_entropy(OtEDNState *s, unsigned ep_id)
{
trace_ot_edn_request_entropy(s->rng.appid, ep_id);

assert(ep_id < ENDPOINT_COUNT_MAX);
g_assert(ep_id < ENDPOINT_COUNT_MAX);
OtEDNEndPoint *ep = &s->endpoints[ep_id];
if (!ep->fn) {
xtrace_ot_edn_error(s->rng.appid,
Expand Down Expand Up @@ -499,7 +499,7 @@ static int ot_edn_push_csrng_request(OtEDNState *s)
req_sts = qdev_get_gpio_in_named(DEVICE(s), TYPE_OT_EDN "-req_sts", 0);
c->genbits_ready = ot_csnrg_connect_hw_app(c->device, c->appid, req_sts,
&ot_edn_fill_bits, s);
assert(c->genbits_ready);
g_assert(c->genbits_ready);
}
int res = ot_csrng_push_command(c->device, c->appid, c->buffer);
if (res) {
Expand Down Expand Up @@ -577,7 +577,7 @@ static void ot_edn_try_auto_instantiate(OtEDNState *s)

uint32_t num = length;
const uint32_t *cmd = ot_fifo32_pop_buf(&c->sw_cmd_fifo, num, &num);
assert(num == length);
g_assert(num == length);
memcpy(c->buffer, cmd, length * sizeof(uint32_t));

if (ot_edn_push_csrng_request(s)) {
Expand Down Expand Up @@ -618,7 +618,7 @@ static void ot_edn_send_reseed_cmd(OtEDNState *s)

uint32_t num = length;
const uint32_t *cmd = ot_fifo32_peek_buf(&c->cmd_reseed_fifo, num, &num);
assert(num == length);
g_assert(num == length);
memcpy(c->buffer, cmd, length * sizeof(uint32_t));

if (ot_edn_push_csrng_request(s)) {
Expand Down Expand Up @@ -657,7 +657,7 @@ static void ot_edn_send_generate_cmd(OtEDNState *s)

uint32_t num = length;
const uint32_t *cmd = ot_fifo32_peek_buf(&c->cmd_gen_fifo, num, &num);
assert(num == length);
g_assert(num == length);
memcpy(c->buffer, cmd, length * sizeof(uint32_t));
c->rem_packet_count = FIELD_EX32(c->buffer[0], OT_CSNRG_CMD, GLEN);
xtrace_ot_edn_dinfo(c->appid, "Generate cmd w/ packets",
Expand Down Expand Up @@ -711,7 +711,7 @@ static void ot_edn_try_sw_request(OtEDNState *s)
return;
}

assert(s->state == EDN_SW_PORT_MODE);
g_assert(s->state == EDN_SW_PORT_MODE);

uint32_t num = length;
const uint32_t *cmd = ot_fifo32_peek_buf(&c->sw_cmd_fifo, num, &num);
Expand Down Expand Up @@ -744,7 +744,7 @@ static void ot_edn_handle_disable(OtEDNState *s)
{
OtEDNCSRNG *c = &s->rng;

assert(ot_edn_get_last_csrng_command(s) != OT_CSRNG_CMD_UNINSTANTIATE);
g_assert(ot_edn_get_last_csrng_command(s) != OT_CSRNG_CMD_UNINSTANTIATE);

c->no_fips = false;
c->rem_packet_count = 0;
Expand Down Expand Up @@ -1284,8 +1284,8 @@ static void ot_edn_reset(DeviceState *dev)
ot_fifo32_reset(&c->cmd_reseed_fifo);

/* check that properties have been initialized */
assert(c->device);
assert(c->appid < OT_CSRNG_HW_APP_MAX);
g_assert(c->device);
g_assert(c->appid < OT_CSRNG_HW_APP_MAX);
}

static void ot_edn_init(Object *obj)
Expand Down
22 changes: 11 additions & 11 deletions hw/opentitan/ot_entropy_src.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ int ot_entropy_src_get_random(OtEntropySrcState *s, int genid,
uint32_t *randu32 = (uint32_t *)random;
size_t pos = 0;
while (pos < ES_WORD_COUNT) {
assert(!ot_fifo32_is_empty(&s->final_fifo));
g_assert(!ot_fifo32_is_empty(&s->final_fifo));
randu32[pos++] = ot_fifo32_pop(&s->final_fifo);
}

Expand Down Expand Up @@ -802,10 +802,10 @@ ot_entropy_src_push_entropy_to_conditioner(OtEntropySrcState *s, uint32_t word)
if (s->cond_word == 0) {
res = sha3_384_init(&s->sha3_state);
ot_entropy_src_change_state(s, ENTROPY_SRC_SHA3_PREP);
assert(res == CRYPT_OK);
g_assert(res == CRYPT_OK);
}

assert(!ot_fifo32_is_full(&s->precon_fifo));
g_assert(!ot_fifo32_is_full(&s->precon_fifo));

ot_fifo32_push(&s->precon_fifo, word);

Expand All @@ -818,11 +818,11 @@ ot_entropy_src_push_entropy_to_conditioner(OtEntropySrcState *s, uint32_t word)
uint32_t size;
const uint32_t *buf;
buf = ot_fifo32_peek_buf(&s->precon_fifo, s->precon_fifo.num, &size);
assert(size == s->precon_fifo.num);
g_assert(size == s->precon_fifo.num);
xtrace_ot_entropy_src_show_buffer("sha3 in", buf, size * sizeof(uint32_t));
res = sha3_process(&s->sha3_state, (const uint8_t *)buf,
size * sizeof(uint32_t));
assert(res == CRYPT_OK);
g_assert(res == CRYPT_OK);
s->cond_word += size;
ot_fifo32_reset(&s->precon_fifo);

Expand All @@ -840,7 +840,7 @@ static void ot_entropy_src_perform_hash(OtEntropySrcState *s)
uint32_t hash[OT_ENTROPY_SRC_WORD_COUNT];
int res;
res = sha3_done(&s->sha3_state, (uint8_t *)hash);
assert(res == CRYPT_OK);
g_assert(res == CRYPT_OK);
s->cond_word = 0;

xtrace_ot_entropy_src_show_buffer("sha3 md", hash,
Expand All @@ -850,7 +850,7 @@ static void ot_entropy_src_perform_hash(OtEntropySrcState *s)
ot_entropy_src_change_state(s, ENTROPY_SRC_SHA3_MSGDONE);

for (unsigned ix = 0; ix < OT_ENTROPY_SRC_WORD_COUNT; ix++) {
assert(!ot_fifo32_is_full(&s->final_fifo));
g_assert(!ot_fifo32_is_full(&s->final_fifo));
ot_fifo32_push(&s->final_fifo, hash[ix]);
}
s->packet_count += 1u;
Expand All @@ -864,7 +864,7 @@ static void ot_entropy_src_perform_hash(OtEntropySrcState *s)
static bool
ot_entropy_src_push_bypass_entropy(OtEntropySrcState *s, uint32_t word)
{
assert(!ot_fifo32_is_full(&s->bypass_fifo));
g_assert(!ot_fifo32_is_full(&s->bypass_fifo));

ot_fifo32_push(&s->bypass_fifo, word);
if (!ot_fifo32_is_full(&s->bypass_fifo)) {
Expand All @@ -874,7 +874,7 @@ ot_entropy_src_push_bypass_entropy(OtEntropySrcState *s, uint32_t word)

/* bypass conditioner full/ready, empty it into the final FIFO */
while (!ot_fifo32_is_empty(&s->bypass_fifo)) {
assert(!ot_fifo32_is_full(&s->final_fifo));
g_assert(!ot_fifo32_is_full(&s->final_fifo));
ot_fifo32_push(&s->final_fifo, ot_fifo32_pop(&s->bypass_fifo));
}
s->packet_count += 1u;
Expand Down Expand Up @@ -1529,8 +1529,8 @@ static void ot_entropy_src_reset(DeviceState *dev)
{
OtEntropySrcState *s = OT_ENTROPY_SRC(dev);

assert(s->ast);
assert(s->otp_ctrl);
g_assert(s->ast);
g_assert(s->otp_ctrl);

timer_del(s->scheduler);

Expand Down
Loading

0 comments on commit b40b830

Please sign in to comment.