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

added restore feature for SHA512 #612

Merged
merged 9 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4c8faff2f6d91d6196096aae143f7d81fc0b7dc5f38742cbe5398f2ecf7abd11327d51d29c1f95540503721dad790fd3
6c8e7c3d77cadcbbf3b13e4f0f6853df60f57395826819dfbfda73a1a14f4533e5ca20c786cbb1b2535b771c4ebfa2b4
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1730225605
1730243083
14 changes: 7 additions & 7 deletions src/integration/asserts/caliptra_top_sva.sv
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,6 @@ module caliptra_top_sva

generate
for(genvar dword = 0; dword < KV_NUM_DWORDS; dword++) begin
//sha512 block read
kv_sha512_block_r_flow: assert property (
@(posedge `SVA_RDC_CLK)
$rose(`SHA512_PATH.kv_src_done & ~`SHA512_PATH.pcr_hash_extend_ip) && (dword < (`KEYVAULT_PATH.kv_reg1.hwif_out.KEY_CTRL[`SHA512_PATH.kv_read.read_entry].last_dword.value + 1)) |-> (`KEYVAULT_PATH.kv_reg1.hwif_out.KEY_ENTRY[`SHA512_PATH.kv_read.read_entry][dword].data.value == `SHA512_PATH.block_reg[dword])
)
else $display("SVA ERROR: SHA384 block mismatch!, 0x%04x, 0x%04x", `KEYVAULT_PATH.kv_reg1.hwif_out.KEY_ENTRY[`SHA512_PATH.kv_read.read_entry][dword].data.value, `SHA512_PATH.block_reg[dword]);

//sha512 digest write
if (dword < SHA512_DIG_NUM_DWORDS) begin
kv_sha512_digest_w_flow: assert property (
Expand Down Expand Up @@ -553,6 +546,13 @@ module caliptra_top_sva
)
else $display("SVA ERROR: ECC VALID flag mismatch!");

//SVA for SHA512 restore
sha512_restore_cmd: assert property (
@(posedge `SVA_RDC_CLK)
`SHA512_PATH.restore_reg |-> (`SHA512_PATH.next_reg && !`SHA512_PATH.init_reg)
)
else $display("SVA ERROR: SHA512 restore is not valid!");

//SVA for modular operations
ecc_opa_input: assert property (
@(posedge `SVA_RDC_CLK)
Expand Down
2 changes: 2 additions & 0 deletions src/integration/rtl/caliptra_reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -3967,6 +3967,8 @@
#define SHA512_REG_SHA512_CTRL_ZEROIZE_MASK (0x10)
#define SHA512_REG_SHA512_CTRL_LAST_LOW (5)
#define SHA512_REG_SHA512_CTRL_LAST_MASK (0x20)
#define SHA512_REG_SHA512_CTRL_RESTORE_LOW (6)
#define SHA512_REG_SHA512_CTRL_RESTORE_MASK (0x40)
#define CLP_SHA512_REG_SHA512_STATUS (0x10020018)
#define SHA512_REG_SHA512_STATUS (0x18)
#define SHA512_REG_SHA512_STATUS_READY_LOW (0)
Expand Down
2 changes: 2 additions & 0 deletions src/integration/rtl/caliptra_reg_defines.svh
Original file line number Diff line number Diff line change
Expand Up @@ -3967,6 +3967,8 @@
`define SHA512_REG_SHA512_CTRL_ZEROIZE_MASK (32'h10)
`define SHA512_REG_SHA512_CTRL_LAST_LOW (5)
`define SHA512_REG_SHA512_CTRL_LAST_MASK (32'h20)
`define SHA512_REG_SHA512_CTRL_RESTORE_LOW (6)
`define SHA512_REG_SHA512_CTRL_RESTORE_MASK (32'h40)
`define CLP_SHA512_REG_SHA512_STATUS (32'h10020018)
`define SHA512_REG_SHA512_STATUS (32'h18)
`define SHA512_REG_SHA512_STATUS_READY_LOW (0)
Expand Down
7 changes: 3 additions & 4 deletions src/integration/rtl/caliptra_top.sv
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,6 @@ sha512_ctrl #(
.hresp_o (responder_inst[`CALIPTRA_SLAVE_SEL_SHA512].hresp),
.hreadyout_o (responder_inst[`CALIPTRA_SLAVE_SEL_SHA512].hreadyout),
.hrdata_o (responder_inst[`CALIPTRA_SLAVE_SEL_SHA512].hrdata),
.kv_read (kv_read[2]),
.kv_write (kv_write[1]),
.kv_rd_resp (kv_rd_resp[2]),
.kv_wr_resp (kv_wr_resp[1]),
.pv_read (pv_read),
.pv_write (pv_write),
.pv_rd_resp (pv_rd_resp),
Expand All @@ -813,6 +809,9 @@ sha512_ctrl #(
.debugUnlock_or_scan_mode_switch(debug_lock_or_scan_mode_switch)
);

always_comb kv_read[2] = '0;
always_comb kv_write[1] = '0;

sha256_ctrl #(
.AHB_DATA_WIDTH (`CALIPTRA_AHB_HDATA_SIZE),
.AHB_ADDR_WIDTH (`CALIPTRA_SLAVE_ADDR_WIDTH(`CALIPTRA_SLAVE_SEL_SHA256))
Expand Down
1 change: 1 addition & 0 deletions src/integration/stimulus/L0_regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contents:
- ../test_suites/smoke_test_mbox_byte_read/smoke_test_mbox_byte_read.yml
- ../test_suites/smoke_test_mbox_cg/smoke_test_mbox_cg.yml
- ../test_suites/smoke_test_sha512/smoke_test_sha512.yml
- ../test_suites/smoke_test_sha512_restore/smoke_test_sha512_restore.yml
- ../test_suites/smoke_test_sha256/smoke_test_sha256.yml
- ../test_suites/smoke_test_sha256_wntz/smoke_test_sha256_wntz.yml
- ../test_suites/smoke_test_sha256_wntz_rand/smoke_test_sha256_wntz_rand.yml
Expand Down
50 changes: 50 additions & 0 deletions src/integration/test_suites/libs/sha512/sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,54 @@ void sha512_flow(sha512_io block, uint8_t mode, sha512_io digest){
offset++;
}

}

void sha512_restore_flow(sha512_io block, uint8_t mode, sha512_io restore_digest, sha512_io digest){
volatile uint32_t * reg_ptr;
uint8_t offset;
uint8_t fail_cmd = 0x1;
uint32_t sha512_digest [16];

// wait for SHA to be ready
while((lsu_read_32(CLP_SHA512_REG_SHA512_STATUS) & SHA512_REG_SHA512_STATUS_READY_MASK) == 0);

// Write SHA512 block
reg_ptr = (uint32_t*) CLP_SHA512_REG_SHA512_BLOCK_0;
offset = 0;
while (reg_ptr <= (uint32_t*) CLP_SHA512_REG_SHA512_BLOCK_31) {
*reg_ptr++ = block.data[offset++];
}

// Write SHA512 restore DIGEST
reg_ptr = (uint32_t*) CLP_SHA512_REG_SHA512_DIGEST_0;
offset = 0;
while (reg_ptr <= (uint32_t*) CLP_SHA512_REG_SHA512_DIGEST_15) {
*reg_ptr++ = restore_digest.data[offset++];
}

// Enable SHA512 core
VPRINTF(LOW, "Enable SHA512\n");
lsu_write_32(CLP_SHA512_REG_SHA512_CTRL, SHA512_REG_SHA512_CTRL_NEXT_MASK |
SHA512_REG_SHA512_CTRL_RESTORE_MASK |
(mode << SHA512_REG_SHA512_CTRL_MODE_LOW) & SHA512_REG_SHA512_CTRL_MODE_MASK);

// wait for SHA to be valid
wait_for_sha512_intr();

reg_ptr = (uint32_t *) CLP_SHA512_REG_SHA512_DIGEST_0;
printf("Load DIGEST data from SHA512\n");
offset = 0;
while (reg_ptr <= (uint32_t*) CLP_SHA512_REG_SHA512_DIGEST_15) {
sha512_digest[offset] = *reg_ptr;
if (sha512_digest[offset] != digest.data[offset]) {
printf("At offset [%d], sha_digest data mismatch!\n", offset);
printf("Actual data: 0x%x\n", sha512_digest[offset]);
printf("Expected data: 0x%x\n", digest.data[offset]);
printf("%c", fail_cmd);
while(1);
}
reg_ptr++;
offset++;
}

}
1 change: 1 addition & 0 deletions src/integration/test_suites/libs/sha512/sha512.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void sha_next_last(enum sha512_mode_e mode);
void sha384_kvflow(uint8_t sha_kv_id, uint8_t store_to_kv, uint8_t digest_kv_id, uint32_t expected_digest[12]);
void sha512_zeroize();
void sha512_flow(sha512_io block, uint8_t mode, sha512_io digest);
void sha512_restore_flow(sha512_io block, uint8_t mode, sha512_io restore_digest, sha512_io digest);

//polls until sha512 is ready to be used
inline void sha512_poll_ready() {
Expand Down
Loading
Loading