Skip to content

Commit

Permalink
Revert prev change and add error flow in test, update sva to check fo…
Browse files Browse the repository at this point in the history
…r regular sha as well
  • Loading branch information
Kiran Upadhyayula committed Mar 18, 2024
1 parent 959a880 commit fd37d25
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/integration/asserts/caliptra_top_sva.sv
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,9 @@ module caliptra_top_sva
// SVA for LMS WNTZ accelerator
wntz_mode: assert property (
@(posedge `SVA_RDC_CLK)
`SHA256_PATH.wntz_mode |-> (`SHA256_PATH.init_reg) & (!`SHA256_PATH.next_reg)
`SHA256_PATH.init_reg |-> !`SHA256_PATH.next_reg
)
else $display("SVA ERROR: WNTZ mode is not valid without INIT!");
else $display("SVA ERROR: SHA256 operation is not valid with INIT and NEXT asserted in the same cycle!");

// Bus IDLE on Firmware Update Reset
fw_upd_rst_doe_idle: assert property (@(posedge `SVA_RDC_CLK) `CPTRA_FW_UPD_RST_WINDOW |-> !`DOE_REG_PATH.s_cpuif_req)
Expand Down
54 changes: 48 additions & 6 deletions src/integration/test_suites/libs/sha256/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ void wait_for_sha256_intr(uint32_t notif, uint32_t error){
__asm__ volatile ("nop"); // Sleep loop as "nop"
}
};
//printf("Received SHA256 error intr with status = %d\n", cptra_intr_rcv.sha256_error);
printf("Received SHA256 notif intr with status = %d\n", cptra_intr_rcv.sha256_notif);
if (error)
printf("Received SHA256 err intr with status = %d\n", cptra_intr_rcv.sha256_error);
else
printf("Received SHA256 notif intr with status = %d\n", cptra_intr_rcv.sha256_notif);
cptra_intr_rcv.sha256_notif &= ~notif;
cptra_intr_rcv.sha256_error &= ~error;
}
Expand All @@ -40,7 +42,7 @@ void sha256_zeroize(){
lsu_write_32(CLP_SHA256_REG_SHA256_CTRL, (1 << SHA256_REG_SHA256_CTRL_ZEROIZE_LOW) & SHA256_REG_SHA256_CTRL_ZEROIZE_MASK);
}

void sha256_flow(sha256_io block, uint8_t mode, uint8_t wntz_mode, uint8_t wntz_w, uint8_t wntz_n, sha256_io digest, uint32_t notif, uint32_t error){
void sha256_flow(sha256_io block, uint8_t mode, uint8_t wntz_mode, uint8_t wntz_w, uint8_t wntz_n, sha256_io digest){
volatile uint32_t * reg_ptr;
uint8_t offset;
uint8_t fail_cmd = 0x1;
Expand All @@ -65,7 +67,7 @@ void sha256_flow(sha256_io block, uint8_t mode, uint8_t wntz_mode, uint8_t wntz_
((wntz_n << SHA256_REG_SHA256_CTRL_WNTZ_N_MODE_LOW) & SHA256_REG_SHA256_CTRL_WNTZ_N_MODE_MASK));

// wait for SHA to be valid
wait_for_sha256_intr(notif, error);
wait_for_sha256_intr(SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
reg_ptr = (uint32_t *) CLP_SHA256_REG_SHA256_DIGEST_0;
printf("Load DIGEST data from SHA256\n");
offset = 0;
Expand All @@ -84,7 +86,47 @@ void sha256_flow(sha256_io block, uint8_t mode, uint8_t wntz_mode, uint8_t wntz_

}

void sha256_flow_wntz_rand(uint8_t mode, uint32_t notif, uint32_t error) {
void sha256_error_flow(sha256_io block, uint8_t mode, uint8_t next, uint8_t wntz_mode, uint8_t wntz_w, uint8_t wntz_n, sha256_io digest, uint32_t error) {
volatile uint32_t * reg_ptr;
uint8_t offset;
uint8_t fail_cmd = 0x1;
uint32_t sha256_digest [8];

// wait for SHA to be ready
while((lsu_read_32(CLP_SHA256_REG_SHA256_STATUS) & SHA256_REG_SHA256_STATUS_READY_MASK) == 0);

// Write SHA256 block
reg_ptr = (uint32_t*) CLP_SHA256_REG_SHA256_BLOCK_0;
offset = 0;
while (reg_ptr <= (uint32_t*) CLP_SHA256_REG_SHA256_BLOCK_15) {
*reg_ptr++ = block.data[offset++];
}

// init and next triggers error1 bit. Check to make sure correct error arg is given
if (next & (error == SHA256_REG_INTR_BLOCK_RF_ERROR_INTERNAL_INTR_R_ERROR0_STS_MASK)) {
printf("Error1 is expected when init and next are asserted at the same time. Check args given to sha256_error_flow()\n");
printf("%c", fail_cmd);
}
else if (~next & (error == SHA256_REG_INTR_BLOCK_RF_ERROR_INTERNAL_INTR_R_ERROR1_STS_MASK)) {
printf("Error0 is expected for invalid wntz_mode or w. Check args given to sha256_error_flow()\n");
printf("%c", fail_cmd);
}

// Enable SHA256 core
VPRINTF(LOW, "Enable SHA256\n");
lsu_write_32(CLP_SHA256_REG_SHA256_CTRL, SHA256_REG_SHA256_CTRL_INIT_MASK |
((next << SHA256_REG_SHA256_CTRL_NEXT_LOW) & SHA256_REG_SHA256_CTRL_NEXT_MASK) |
((mode << SHA256_REG_SHA256_CTRL_MODE_LOW) & SHA256_REG_SHA256_CTRL_MODE_MASK) |
((wntz_mode << SHA256_REG_SHA256_CTRL_WNTZ_MODE_LOW) & SHA256_REG_SHA256_CTRL_WNTZ_MODE_MASK) |
((wntz_w << SHA256_REG_SHA256_CTRL_WNTZ_W_LOW) & SHA256_REG_SHA256_CTRL_WNTZ_W_MASK) |
((wntz_n << SHA256_REG_SHA256_CTRL_WNTZ_N_MODE_LOW) & SHA256_REG_SHA256_CTRL_WNTZ_N_MODE_MASK));

// wait for SHA to trig error
wait_for_sha256_intr(0, error);

}

void sha256_flow_wntz_rand(uint8_t mode) {
// wait for SHA to be ready
while((lsu_read_32(CLP_SHA256_REG_SHA256_STATUS) & SHA256_REG_SHA256_STATUS_READY_MASK) == 0);

Expand All @@ -97,5 +139,5 @@ void sha256_flow_wntz_rand(uint8_t mode, uint32_t notif, uint32_t error) {
// ((wntz_n << SHA256_REG_SHA256_CTRL_WNTZ_N_MODE_LOW) & SHA256_REG_SHA256_CTRL_WNTZ_N_MODE_MASK));

// wait for SHA to be valid
wait_for_sha256_intr(notif, error);
wait_for_sha256_intr(SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
}
5 changes: 3 additions & 2 deletions src/integration/test_suites/libs/sha256/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ typedef struct {
}sha256_io;

void sha256_zeroize();
void sha256_flow(sha256_io block, uint8_t mode, uint8_t wntz_mode, uint8_t wntz_w, uint8_t wntz_n, sha256_io digest, uint32_t notif, uint32_t error);
void sha256_flow_wntz_rand(uint8_t mode, uint32_t notif, uint32_t error);
void sha256_flow(sha256_io block, uint8_t mode, uint8_t wntz_mode, uint8_t wntz_w, uint8_t wntz_n, sha256_io digest);
void sha256_error_flow(sha256_io block, uint8_t mode, uint8_t next, uint8_t wntz_mode, uint8_t wntz_w, uint8_t wntz_n, sha256_io digest, uint32_t error);
void sha256_flow_wntz_rand(uint8_t mode);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void main() {
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_digest[i];

sha256_flow(sha256_block, SHA256_MODE_SHA_256, 0, 0, 0, sha256_digest, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow(sha256_block, SHA256_MODE_SHA_256, 0, 0, 0, sha256_digest);
sha256_zeroize();

// Write 0xff to STDOUT for TB to terminate test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,28 +201,28 @@ void main() {
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w1_256[i];

sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 1, 1, sha256_digest, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 1, 1, sha256_digest);
sha256_zeroize();

sha256_digest.data_size = 8;
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w2_256[i];

sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 2, 1, sha256_digest, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 2, 1, sha256_digest);
sha256_zeroize();

sha256_digest.data_size = 8;
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w4_256[i];

sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 4, 1, sha256_digest, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 4, 1, sha256_digest);
sha256_zeroize();

sha256_digest.data_size = 8;
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w8_256[i];

sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 8, 1, sha256_digest, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 8, 1, sha256_digest);
sha256_zeroize();

//--------------------------------------------------------------------
Expand All @@ -231,30 +231,65 @@ void main() {
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w1_192[i];

sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 1, 0, sha256_digest, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 1, 0, sha256_digest);
sha256_zeroize();

// sha256_digest.data_size = 8;
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w2_192[i];

sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 2, 0, sha256_digest, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 2, 0, sha256_digest);
sha256_zeroize();

sha256_digest.data_size = 8;
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w4_192[i];

sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 4, 0, sha256_digest, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 4, 0, sha256_digest);
sha256_zeroize();

sha256_digest.data_size = 8;
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w8_192[i];

sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 8, 0, sha256_digest, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 8, 0, sha256_digest);
sha256_zeroize();

//WNTZ errors

//Invalid w
sha256_digest.data_size = 8;
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w8_192[i];
// sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 3, 0, sha256_digest);
sha256_error_flow(sha256_block, SHA256_MODE_SHA_256, 0, 1, 3, 0, sha256_digest, SHA256_REG_INTR_BLOCK_RF_ERROR_INTERNAL_INTR_R_ERROR0_STS_MASK);
sha256_zeroize();

//Invalid mode
sha256_digest.data_size = 8;
for (int i = 0; i < sha256_digest.data_size; i++)
sha256_digest.data[i] = expected_wntz_digest_w8_192[i];
// sha256_flow(sha256_block, SHA256_MODE_SHA_224, 1, 8, 0, sha256_digest);
sha256_error_flow(sha256_block, SHA256_MODE_SHA_224, 0, 1, 8, 0, sha256_digest, SHA256_REG_INTR_BLOCK_RF_ERROR_INTERNAL_INTR_R_ERROR0_STS_MASK);
sha256_zeroize();

//SVA in place to check init and next in same cycle
// //Invalid wntz op (init and next in same cycle)
// sha256_digest.data_size = 8;
// for (int i = 0; i < sha256_digest.data_size; i++)
// sha256_digest.data[i] = expected_wntz_digest_w8_192[i];
// // sha256_flow(sha256_block, SHA256_MODE_SHA_256, 1, 8, 0, sha256_digest);
// sha256_error_flow(sha256_block, SHA256_MODE_SHA_256, 1, 1, 4, 0, sha256_digest, SHA256_REG_INTR_BLOCK_RF_ERROR_INTERNAL_INTR_R_ERROR1_STS_MASK);
// sha256_zeroize();

// //Invalid regular sha op (init and next in same cycle)
// sha256_digest.data_size = 8;
// for (int i = 0; i < sha256_digest.data_size; i++)
// sha256_digest.data[i] = expected_wntz_digest_w8_192[i];
// // sha256_flow(sha256_block, SHA256_MODE_SHA_256, 0, 8, 0, sha256_digest);
// sha256_error_flow(sha256_block, SHA256_MODE_SHA_256, 1, 0, 0, 0, sha256_digest, SHA256_REG_INTR_BLOCK_RF_ERROR_INTERNAL_INTR_R_ERROR1_STS_MASK);
// sha256_zeroize();

// Write 0xff to STDOUT for TB to terminate test.
SEND_STDOUT_CTRL( 0xff);
while(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void main() {
// sha256_io sha256_digest;

SEND_STDOUT_CTRL(0xdd); //Forces random block, w and n
sha256_flow_wntz_rand(SHA256_MODE_SHA_256, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_flow_wntz_rand(SHA256_MODE_SHA_256);
sha256_zeroize();

// Write 0xff to STDOUT for TB to terminate test.
Expand Down

0 comments on commit fd37d25

Please sign in to comment.