Skip to content

Commit

Permalink
Remove hardcoding in generic wait function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiran Upadhyayula committed Mar 15, 2024
1 parent ef36b45 commit 2bb4c48
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
15 changes: 8 additions & 7 deletions src/integration/test_suites/libs/sha256/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

extern volatile caliptra_intr_received_s cptra_intr_rcv;

void wait_for_sha256_intr(){
void wait_for_sha256_intr(uint32_t notif, uint32_t error){
printf("SHA256 flow in progress...\n");
while((cptra_intr_rcv.sha256_error == 0) & (cptra_intr_rcv.sha256_notif == 0)){
while(((cptra_intr_rcv.sha256_error & error) != error) || ((cptra_intr_rcv.sha256_notif & notif) != notif)){
__asm__ volatile ("wfi"); // "Wait for interrupt"
// Sleep during SHA256 operation to allow ISR to execute and show idle time in sims
for (uint16_t slp = 0; slp < 100; slp++) {
Expand All @@ -31,15 +31,16 @@ void wait_for_sha256_intr(){
};
//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);
cptra_intr_rcv.sha256_notif &= ~SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK;
cptra_intr_rcv.sha256_notif &= ~notif;
cptra_intr_rcv.sha256_error &= ~error;
}

void sha256_zeroize(){
printf("SHA256 zeroize flow.\n");
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){
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){
volatile uint32_t * reg_ptr;
uint8_t offset;
uint8_t fail_cmd = 0x1;
Expand All @@ -64,7 +65,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();
wait_for_sha256_intr(notif, error);
reg_ptr = (uint32_t *) CLP_SHA256_REG_SHA256_DIGEST_0;
printf("Load DIGEST data from SHA256\n");
offset = 0;
Expand All @@ -83,7 +84,7 @@ void sha256_flow(sha256_io block, uint8_t mode, uint8_t wntz_mode, uint8_t wntz_

}

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

Expand All @@ -96,5 +97,5 @@ void sha256_flow_wntz_rand(uint8_t mode) {
// ((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();
wait_for_sha256_intr(notif, error);
}
4 changes: 2 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,7 @@ 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);
void sha256_flow_wntz_rand(uint8_t mode);
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);

#endif
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_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_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_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_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_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_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_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_zeroize();

//--------------------------------------------------------------------
Expand All @@ -231,28 +231,28 @@ 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_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_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_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_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_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_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_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_zeroize();

// Write 0xff to STDOUT for TB to terminate test.
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_flow_wntz_rand(SHA256_MODE_SHA_256, SHA256_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK, 0);
sha256_zeroize();

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

0 comments on commit 2bb4c48

Please sign in to comment.