forked from lowRISC/opentitan
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tlul,shim] Expand
pre_dv
to handle arbitrary test cases
This commit generalizes the `pre_dv` testbench to arbitrary test cases and adds an array of tests covering both AES-GCM and its modes of operation. The process of adding/modify tests is now streamlined reducing the feedback loop. Signed-off-by: Andrea Caforio <[email protected]> Co-authored-by: Pirmin Vogel <[email protected]>
- Loading branch information
1 parent
d592957
commit e683124
Showing
11 changed files
with
5,305 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
hw/ip/aes/pre_dv/aes_tlul_shim_tb/data/gcm_k128_a0_d0.svh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// AES-GCM-128 Test Case #1 | ||
// https://csrc.nist.rip/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf | ||
|
||
// Preamble: | ||
`define AD_LENGTH 0 | ||
`define DATA_LENGTH 0 | ||
`define NUM_REQUESTS 42 | ||
|
||
`define REQUESTS shim_request_t requests[`NUM_REQUESTS] = '{ \ | ||
c_dpi_load('{ \ | ||
operation: AES_ENC, \ | ||
mode: AES_GCM, \ | ||
key_length: AES_128, \ | ||
key: 256'h0000000000000000000000000000000000000000000000000000000000000000, \ | ||
iv: 128'h0000000000000000000000000000000000, \ | ||
data: '0, \ | ||
ad: '0, \ | ||
tag: '0 \ | ||
}), \ | ||
\ | ||
/* Check AES core is idle before writing the control registers */ \ | ||
read_request(AES_STATUS_OFFSET, 32'(1'b1) << AES_STATUS_IDLE_OFFSET), \ | ||
\ | ||
/* Config AES core, config GCM in `INIT` mode */ \ | ||
write_request( \ | ||
AES_CTRL_SHADOWED_OFFSET, \ | ||
32'(0) << AES_CTRL_MANUAL_OPERATION_OFFSET | \ | ||
32'(PER_1) << AES_CTRL_PRNG_RESEED_RATE_OFFSET | \ | ||
32'(0) << AES_CTRL_SIDELOAD_OFFSET | \ | ||
32'(AES_128) << AES_CTRL_KEY_LEN_OFFSET | \ | ||
32'(AES_GCM) << AES_CTRL_MODE_OFFSET | \ | ||
32'(AES_ENC) << AES_CTRL_OPERATION_OFFSET \ | ||
), \ | ||
write_request( \ | ||
AES_CTRL_SHADOWED_OFFSET, \ | ||
32'(0) << AES_CTRL_MANUAL_OPERATION_OFFSET | \ | ||
32'(PER_1) << AES_CTRL_PRNG_RESEED_RATE_OFFSET | \ | ||
32'(0) << AES_CTRL_SIDELOAD_OFFSET | \ | ||
32'(AES_128) << AES_CTRL_KEY_LEN_OFFSET | \ | ||
32'(AES_GCM) << AES_CTRL_MODE_OFFSET | \ | ||
32'(AES_ENC) << AES_CTRL_OPERATION_OFFSET \ | ||
), \ | ||
write_request( \ | ||
AES_CTRL_GCM_SHADOWED_OFFSET, \ | ||
32'(16) << AES_CTRL_GCM_NUM_VALID_BYTES_OFFSET | \ | ||
32'(GCM_INIT) << AES_CTRL_GCM_PHASE_OFFSET \ | ||
), \ | ||
write_request( \ | ||
AES_CTRL_GCM_SHADOWED_OFFSET, \ | ||
32'(16) << AES_CTRL_GCM_NUM_VALID_BYTES_OFFSET | \ | ||
32'(GCM_INIT) << AES_CTRL_GCM_PHASE_OFFSET \ | ||
), \ | ||
read_request(AES_STATUS_OFFSET, 32'(1'b1) << AES_STATUS_IDLE_OFFSET), \ | ||
\ | ||
/* Write key registers */ \ | ||
write_request(AES_KEY_SHARE0_0_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE0_1_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE0_2_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE0_3_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE0_4_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE0_5_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE0_6_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE0_7_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE1_0_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE1_1_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE1_2_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE1_3_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE1_4_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE1_5_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE1_6_OFFSET, 32'h00000000), \ | ||
write_request(AES_KEY_SHARE1_7_OFFSET, 32'h00000000), \ | ||
read_request(AES_STATUS_OFFSET, 32'(1'b1) << AES_STATUS_IDLE_OFFSET), \ | ||
\ | ||
/* Write IV registers */ \ | ||
write_request(AES_IV_0_OFFSET, 32'h00000000), \ | ||
write_request(AES_IV_1_OFFSET, 32'h00000000), \ | ||
write_request(AES_IV_2_OFFSET, 32'h00000000), \ | ||
write_request(AES_IV_3_OFFSET, 32'h00000000), \ | ||
read_request(AES_STATUS_OFFSET, 32'(1'b1) << AES_STATUS_IDLE_OFFSET), \ | ||
\ | ||
/* Config GCM in `TAG` mode and write len(ad) || len(pt) to trigger tag computation */ \ | ||
write_request( \ | ||
AES_CTRL_GCM_SHADOWED_OFFSET, \ | ||
32'(16) << AES_CTRL_GCM_NUM_VALID_BYTES_OFFSET | \ | ||
32'(GCM_TAG) << AES_CTRL_GCM_PHASE_OFFSET \ | ||
), \ | ||
write_request( \ | ||
AES_CTRL_GCM_SHADOWED_OFFSET, \ | ||
32'(16) << AES_CTRL_GCM_NUM_VALID_BYTES_OFFSET | \ | ||
32'(GCM_TAG) << AES_CTRL_GCM_PHASE_OFFSET \ | ||
), \ | ||
write_request(AES_DATA_IN_0_OFFSET, 32'h00000000), \ | ||
write_request(AES_DATA_IN_1_OFFSET, 32'h00000000), \ | ||
write_request(AES_DATA_IN_2_OFFSET, 32'h00000000), \ | ||
write_request(AES_DATA_IN_3_OFFSET, 32'h00000000), \ | ||
read_request(AES_STATUS_OFFSET, 32'(1'b1) << AES_STATUS_OUTPUT_VALID_OFFSET), \ | ||
\ | ||
/* Read back the authentication tag */ \ | ||
read_request(AES_DATA_OUT_0_OFFSET), \ | ||
read_request(AES_DATA_OUT_1_OFFSET), \ | ||
read_request(AES_DATA_OUT_2_OFFSET), \ | ||
read_request(AES_DATA_OUT_3_OFFSET), \ | ||
\ | ||
/* Read Caliptra-specific register */ \ | ||
read_caliptra(CALIPTRA_NAME_0_OFFSET), \ | ||
read_caliptra(CALIPTRA_VERSION_0_OFFSET) \ | ||
}; |
Oops, something went wrong.