Skip to content

Commit

Permalink
[aes,dv] Add coverage bins and crosses for AES-GCM
Browse files Browse the repository at this point in the history
This commit adds coverage bins and crosses for different
AAD and TEXT lengths. The bins cover multiple blocks
and partial block lengths as well as cipher operations (enc,dec).

Signed-off-by: Pascal Nasahl <[email protected]>
  • Loading branch information
nasahlpa committed Feb 16, 2025
1 parent 3c3203e commit 0a453db
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
78 changes: 77 additions & 1 deletion hw/ip/aes/dv/cov/aes_cov_if.sv
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,69 @@ interface aes_cov_if
}
endgroup // aes_reg_interleave_cg

covergroup aes_gcm_len_cg with function sample(
int aad_blocks,
int aad_last_block_len,
int text_blocks,
int text_last_block_len,
bit [aes_pkg::AES_OP_WIDTH-1:0] aes_op
);
option.per_instance = 1;
option.name = "aes_gcm_len_cg";

cp_operation: coverpoint aes_op
{
bins enc = {AES_ENC};
bins dec = {AES_DEC};
}

cp_aad_blocks: coverpoint aad_blocks
{
bins aad_blocks_0 = {0};
bins aad_blocks_l[2] = {[1:2]};
bins aad_blocks_h = {[3:$]};
}

cp_aad_last_block_len: coverpoint aad_last_block_len
{
// If aad_blocks > 0, then aad_last_block_len = 0 means a full 16-byte
// block. Value between 1-15 indicate that the last block is a partial
// block.
bins aad_last_block_len_l[2] = {[0:1]};
bins aad_last_block_len_m[2] = {[2:13]};
bins aad_last_block_len_h[2] = {[14:15]};
}

cp_text_blocks: coverpoint text_blocks
{
bins text_blocks_0 = {0};
bins text_blocks_l[2] = {[1:2]};
bins text_blocks_h = {[3:$]};
}

cp_text_last_block_len: coverpoint text_last_block_len
{
// If text_blocks > 0, then text_last_block_len = 0 means a full 16-byte
// block. Value between 1-15 indicate that the last block is a partial
// block.
bins text_last_block_len_l[2] = {[0:1]};
bins text_last_block_len_m[2] = {[2:13]};
bins text_last_block_len_h[2] = {[14:15]};
}

// Cross coverage points
// Ignore zero block in cross coverage.
cr_op_aad_block_len: cross cp_operation, cp_aad_blocks, cp_aad_last_block_len
{
ignore_bins zero_blocks = binsof(cp_aad_blocks) intersect {0};
}

cr_op_text_block_len: cross cp_operation, cp_text_blocks, cp_text_last_block_len
{
ignore_bins zero_blocks = binsof(cp_text_blocks) intersect {0};
}

endgroup // aes_gcm_aad_len_cg

///////////////////////////////////
// Instantiation Macros //
Expand All @@ -296,7 +359,7 @@ interface aes_cov_if
`DV_FCOV_INSTANTIATE_CG(aes_iv_interleave_cg, en_full_cov)
`DV_FCOV_INSTANTIATE_CG(aes_key_interleave_cg, en_full_cov)
`DV_FCOV_INSTANTIATE_CG(aes_reg_interleave_cg, en_full_cov)

`DV_FCOV_INSTANTIATE_CG(aes_gcm_len_cg, en_full_cov)

///////////////////////////////////
// Sample functions //
Expand Down Expand Up @@ -356,4 +419,17 @@ interface aes_cov_if
aes_key_interleave_cg_inst.sample(key, idle_i);
aes_reg_interleave_cg_inst.sample(1);
endfunction

function automatic void cg_gcm_len_sample(
int aad_blocks,
int aad_last_block_len,
int text_blocks,
int text_last_block_len,
bit [aes_pkg::AES_OP_WIDTH-1:0] aes_op);
aes_gcm_len_cg_inst.sample(aad_blocks,
aad_last_block_len,
text_blocks,
text_last_block_len,
aes_op);
endfunction
endinterface
12 changes: 12 additions & 0 deletions hw/ip/aes/dv/env/aes_scoreboard.sv
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,18 @@ class aes_scoreboard extends cip_base_scoreboard #(
$sformatf("\n\t ----| MESSAGE #%0d MATCHED %s |-----",
cfg.good_cnt, msg.aes_mode.name()), UVM_MEDIUM)
cfg.good_cnt++;

if (input_item.mode == AES_GCM) begin
// As the message and tag matched the predicted output, sample AAD &
// message length as well as the mode of operation.
int msg_blocks = msg.message_length / 16;
int msg_last_block_len_bytes = msg_blocks % 16;
int aad_blocks = msg.aad_length / 16;
int aad_last_block_len_bytes = aad_blocks % 16;
cov_if.cg_gcm_len_sample(aad_blocks, aad_last_block_len_bytes, msg_blocks,
msg_last_block_len_bytes, msg.aes_operation);
end

end else begin
if (msg.aes_mode == AES_NONE) begin
`uvm_info(`gfn,
Expand Down

0 comments on commit 0a453db

Please sign in to comment.