Skip to content

Commit

Permalink
re-enabled mldsa smoke tests (#672)
Browse files Browse the repository at this point in the history
* MLDSA sva, keygen randomization in tb, abr submod update

* re-enabled mldsa smoke tests

* updated vf files

* updated vf file

* disabled sva valid/ready flag for mldsa

* MICROSOFT AUTOMATED PIPELINE: Stamp 'mojtaba-mldsa-smoketest' with updated timestamp and hash after successful run

* updated submodule

* Add failure inject smoke test

* Add rand keygen test

* Add tests to regression

* Add random seed

* fixed typo

* updated linker to use all of DCCM, preload data sections to DCCM, move data vectors from stack to global namespace (data)

* MICROSOFT AUTOMATED PIPELINE: Stamp 'mojtaba-mldsa-smoketest' with updated timestamp and hash after successful run

* Update inject logic, fix indent

* MICROSOFT AUTOMATED PIPELINE: Stamp 'mojtaba-mldsa-smoketest' with updated timestamp and hash after successful run

---------

Co-authored-by: Kiran Upadhyayula <[email protected]>
  • Loading branch information
mojtaba-bisheh and upadhyayulakiran authored Dec 23, 2024
1 parent bf69cd3 commit de9d9c8
Show file tree
Hide file tree
Showing 22 changed files with 1,166 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1cad8694bd690a699ed8a95772494825b142b6cb12db11fa682a9c71e0865c474b066e6f3c1abe35ce52b03edbac73c1
c8e06113e37e54e9876411db9113dde467573ddcdfa04c21e4aabed77398465566c22fc6db80017342843e5b55280e45
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1734735334
1734986966
10 changes: 5 additions & 5 deletions src/integration/asserts/caliptra_top_sva.sv
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,11 @@ module caliptra_top_sva
)
else $display("SVA ERROR: ECC VALID flag mismatch!");

MLDSA_valid_flag: assert property (
@(posedge `SVA_RDC_CLK)
`MLDSA_PATH.mldsa_valid_reg |-> `MLDSA_PATH.mldsa_ready
)
else $display("SVA ERROR: MLDSA VALID flag mismatch!");
// MLDSA_valid_flag: assert property (
// @(posedge `SVA_RDC_CLK)
// `MLDSA_PATH.mldsa_valid_reg |-> `MLDSA_PATH.mldsa_ready
// )
// else $display("SVA ERROR: MLDSA VALID flag mismatch!");

//SVA for SHA512 restore
sha512_restore_cmd: assert property (
Expand Down
3 changes: 3 additions & 0 deletions src/integration/config/caliptra_top_tb.vf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
+incdir+${CALIPTRA_ROOT}/src/soc_ifc/coverage
+incdir+${CALIPTRA_ROOT}/src/pcrvault/coverage
+incdir+${CALIPTRA_ROOT}/src/keyvault/coverage
+incdir+${CALIPTRA_ROOT}/submodules/adams-bridge/src/mldsa_top/coverage
+incdir+${CALIPTRA_ROOT}/src/integration/tb
+incdir+${CALIPTRA_ROOT}/src/integration/coverage
+incdir+${CALIPTRA_ROOT}/src/riscv_core/veer_el2/rtl/include
Expand Down Expand Up @@ -148,6 +149,8 @@ ${CALIPTRA_ROOT}/src/pcrvault/coverage/pcrvault_cov_bind.sv
${CALIPTRA_ROOT}/src/keyvault/coverage/keyvault_cov_if.sv
${CALIPTRA_ROOT}/src/keyvault/coverage/keyvault_cov_props.sv
${CALIPTRA_ROOT}/src/keyvault/coverage/keyvault_cov_bind.sv
${CALIPTRA_ROOT}/submodules/adams-bridge/src/mldsa_top/coverage/mldsa_top_cov_if.sv
${CALIPTRA_ROOT}/submodules/adams-bridge/src/mldsa_top/coverage/mldsa_top_cov_bind.sv
${CALIPTRA_ROOT}/src/integration/tb/caliptra_top_tb_pkg.sv
${CALIPTRA_ROOT}/src/integration/tb/caliptra_veer_sram_export.sv
${CALIPTRA_ROOT}/src/integration/tb/caliptra_top_tb_services.sv
Expand Down
3 changes: 3 additions & 0 deletions src/integration/config/caliptra_top_tb_pkg.vf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
+incdir+${CALIPTRA_ROOT}/src/soc_ifc/coverage
+incdir+${CALIPTRA_ROOT}/src/pcrvault/coverage
+incdir+${CALIPTRA_ROOT}/src/keyvault/coverage
+incdir+${CALIPTRA_ROOT}/submodules/adams-bridge/src/mldsa_top/coverage
+incdir+${CALIPTRA_ROOT}/src/integration/tb
+incdir+${CALIPTRA_ROOT}/src/integration/coverage
+incdir+${CALIPTRA_ROOT}/src/riscv_core/veer_el2/rtl/include
Expand Down Expand Up @@ -148,6 +149,8 @@ ${CALIPTRA_ROOT}/src/pcrvault/coverage/pcrvault_cov_bind.sv
${CALIPTRA_ROOT}/src/keyvault/coverage/keyvault_cov_if.sv
${CALIPTRA_ROOT}/src/keyvault/coverage/keyvault_cov_props.sv
${CALIPTRA_ROOT}/src/keyvault/coverage/keyvault_cov_bind.sv
${CALIPTRA_ROOT}/submodules/adams-bridge/src/mldsa_top/coverage/mldsa_top_cov_if.sv
${CALIPTRA_ROOT}/submodules/adams-bridge/src/mldsa_top/coverage/mldsa_top_cov_bind.sv
${CALIPTRA_ROOT}/src/integration/tb/caliptra_top_tb_pkg.sv
${CALIPTRA_ROOT}/src/integration/tb/caliptra_veer_sram_export.sv
${CALIPTRA_ROOT}/src/integration/tb/caliptra_top_tb_services.sv
Expand Down
3 changes: 3 additions & 0 deletions src/integration/config/caliptra_top_trng_tb.vf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
+incdir+${CALIPTRA_ROOT}/src/soc_ifc/coverage
+incdir+${CALIPTRA_ROOT}/src/pcrvault/coverage
+incdir+${CALIPTRA_ROOT}/src/keyvault/coverage
+incdir+${CALIPTRA_ROOT}/submodules/adams-bridge/src/mldsa_top/coverage
+incdir+${CALIPTRA_ROOT}/src/integration/tb
+incdir+${CALIPTRA_ROOT}/src/integration/coverage
+incdir+${CALIPTRA_ROOT}/src/riscv_core/veer_el2/rtl/include
Expand Down Expand Up @@ -148,6 +149,8 @@ ${CALIPTRA_ROOT}/src/pcrvault/coverage/pcrvault_cov_bind.sv
${CALIPTRA_ROOT}/src/keyvault/coverage/keyvault_cov_if.sv
${CALIPTRA_ROOT}/src/keyvault/coverage/keyvault_cov_props.sv
${CALIPTRA_ROOT}/src/keyvault/coverage/keyvault_cov_bind.sv
${CALIPTRA_ROOT}/submodules/adams-bridge/src/mldsa_top/coverage/mldsa_top_cov_if.sv
${CALIPTRA_ROOT}/submodules/adams-bridge/src/mldsa_top/coverage/mldsa_top_cov_bind.sv
${CALIPTRA_ROOT}/src/integration/tb/caliptra_top_tb_pkg.sv
${CALIPTRA_ROOT}/src/integration/tb/caliptra_veer_sram_export.sv
${CALIPTRA_ROOT}/src/integration/tb/caliptra_top_tb_services.sv
Expand Down
2 changes: 1 addition & 1 deletion src/integration/config/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ requires:
- soc_ifc_coverage
- pcrvault_cov
- keyvault_cov
#- mldsa_coverage //TODO: Add after updating submodule
- mldsa_coverage
targets:
dpi_compile:
directories:
Expand Down
5 changes: 3 additions & 2 deletions src/integration/stimulus/L0_regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ contents:
- ../test_suites/c_intr_handler/c_intr_handler.yml
- ../test_suites/smoke_test_ecc/smoke_test_ecc.yml
- ../test_suites/smoke_test_hmac/smoke_test_hmac.yml
#- ../test_suites/smoke_test_mldsa/smoke_test_mldsa.yml //TODO: Add after updating submodule
- ../test_suites/smoke_test_mldsa/smoke_test_mldsa.yml
- ../test_suites/smoke_test_aes/smoke_test_aes.yml
- ../test_suites/smoke_test_mldsa_edge/smoke_test_mldsa_edge.yml
- ../test_suites/smoke_test_kv/smoke_test_kv.yml
- ../test_suites/smoke_test_sram_ecc/smoke_test_sram_ecc.yml
- ../test_suites/smoke_test_ras/smoke_test_ras.yml
Expand All @@ -42,7 +43,7 @@ contents:
#- ../test_suites/smoke_test_kv_sha512_flow/smoke_test_kv_sha512_flow.yml Removed SHA KV functionality
- ../test_suites/smoke_test_kv_crypto_flow/smoke_test_kv_crypto_flow.yml
- ../test_suites/smoke_test_kv_cg/smoke_test_kv_cg.yml
#- ../test_suites/smoke_test_kv_mldsa/smoke_test_kv_mldsa.yml //TODO: Add after updating submodule
- ../test_suites/smoke_test_kv_mldsa/smoke_test_kv_mldsa.yml
- ../test_suites/pv_hash_and_sign/pv_hash_and_sign.yml
- ../test_suites/smoke_test_pcr_signing/smoke_test_pcr_signing.yml
- ../test_suites/smoke_test_fw_kv_backtoback_hmac/smoke_test_fw_kv_backtoback_hmac.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ contents:
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_ecc/smoke_test_ecc.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_hmac/smoke_test_hmac.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_hmac_errortrigger/smoke_test_hmac_errortrigger.yml
# - ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_mldsa_rand/smoke_test_mldsa_rand.yml //TODO: Add after updating submodule
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_mldsa_rand/smoke_test_mldsa_rand.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_mldsa_rand/smoke_test_mldsa_keygen_rand.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_kv/smoke_test_kv.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_sram_ecc/smoke_test_sram_ecc.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_ras/smoke_test_ras.yml
Expand All @@ -44,7 +45,7 @@ contents:
# - ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_kv_sha512_flow/smoke_test_kv_sha512_flow.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_kv_crypto_flow/smoke_test_kv_crypto_flow.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_kv_cg/smoke_test_kv_cg.yml
#- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_kv_mldsa/smoke_test_kv_mldsa.yml //TODO: Add after updating submodule
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_kv_mldsa/smoke_test_kv_mldsa.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/pv_hash_and_sign/pv_hash_and_sign.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_pcr_signing/smoke_test_pcr_signing.yml
- ${CALIPTRA_ROOT}/src/integration/test_suites/smoke_test_fw_kv_backtoback_hmac/smoke_test_fw_kv_backtoback_hmac.yml
Expand Down
52 changes: 51 additions & 1 deletion src/integration/tb/caliptra_top_tb_services.sv
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ module caliptra_top_tb_services
// 8'ha8 - Inject zero as HMAC_KEY to kv_key register
// 8'ha9: 8'haf - Inject HMAC512_KEY to kv_key register
// 8'hc0: 8'hc7 - Inject MLDSA_SEED to kv_key register
// 8'hd7 - Inject normcheck failure during mldsa signing
// 8'hd8 - Inject makehint failure during mldsa signing
// 8'hd9 - Perform mldsa keygen
// 8'hda - Perform mldsa signing
Expand Down Expand Up @@ -598,6 +599,48 @@ module caliptra_top_tb_services
end

//MLDSA
logic inject_makehint_failure, inject_normcheck_failure;
logic reset_mldsa_failure;
logic [1:0] normcheck_mode_random;

always_ff @(negedge clk or negedge cptra_rst_b) begin
if (!cptra_rst_b) begin
inject_makehint_failure <= 1'b0;
inject_normcheck_failure <= 1'b0;
reset_mldsa_failure <= 1'b0;
normcheck_mode_random <= 'h0;
end
else if (((WriteData[7:0] == 8'hd8) && mailbox_write) /*&& !caliptra_top_dut.mldsa.mldsa_ctrl_inst.clear_signature_valid*/) begin
inject_makehint_failure <= 1'b1;
end
else if (((WriteData[7:0] == 8'hd7) && mailbox_write) /*&& (!caliptra_top_dut.mldsa.mldsa_ctrl_inst.clear_signature_valid || !caliptra_top_dut.mldsa.mldsa_ctrl_inst.clear_verify_valid)*/) begin
inject_normcheck_failure <= 1'b1;
if (caliptra_top_dut.mldsa.mldsa_ctrl_inst.verifying_process)
normcheck_mode_random <= 'h0;
else
normcheck_mode_random <= $urandom_range(0,2);
end
else if ((caliptra_top_dut.mldsa.mldsa_ctrl_inst.clear_signature_valid))
reset_mldsa_failure <= 1'b1;
else if (((caliptra_top_dut.mldsa.mldsa_ctrl_inst.sec_prog_cntr == 'h1A) && reset_mldsa_failure) || caliptra_top_dut.mldsa.mldsa_ctrl_inst.clear_verify_valid) begin //clear flags if end of signing loop or verify failed
reset_mldsa_failure <= 1'b0;
inject_makehint_failure <= 1'b0;
inject_normcheck_failure <= 1'b0;
end
end

always_ff @(negedge clk) begin
if (inject_makehint_failure & caliptra_top_dut.mldsa.makehint_inst.hintgen_enable)
force caliptra_top_dut.mldsa.makehint_inst.hintsum = 'd80; //> OMEGA => makehint fails
else
release caliptra_top_dut.mldsa.makehint_inst.hintsum;

if (inject_normcheck_failure & caliptra_top_dut.mldsa.norm_check_inst.norm_check_ctrl_inst.check_enable & (caliptra_top_dut.mldsa.norm_check_inst.mode == normcheck_mode_random))
force caliptra_top_dut.mldsa.norm_check_inst.invalid = 'b1;
else
release caliptra_top_dut.mldsa.norm_check_inst.invalid;
end

logic mldsa_keygen, mldsa_signing, mldsa_verify, mldsa_keygen_signing;

always @(negedge clk or negedge cptra_rst_b) begin
Expand Down Expand Up @@ -632,6 +675,13 @@ module caliptra_top_tb_services
mldsa_verify <= 'b0;
mldsa_keygen_signing <= 'b1;
end
else if((WriteData[7:0] == 8'hdc) && mailbox_write) begin
mldsa_keygen <= 'b0;
mldsa_signing <= 'b0;
mldsa_verify <= 'b0;
mldsa_keygen_signing <= 'b1;
$display("In keygen+sign branch\n");
end
end

genvar mldsa_dword;
Expand Down Expand Up @@ -1953,7 +2003,7 @@ sha512_ctrl_cov_bind i_sha512_ctrl_cov_bind();
sha256_ctrl_cov_bind i_sha256_ctrl_cov_bind();
hmac_ctrl_cov_bind i_hmac_ctrl_cov_bind();
ecc_top_cov_bind i_ecc_top_cov_bind();
// mldsa_top_cov_bind i_mldsa_top_cov_bind(); //TODO: Add after updating submodule
mldsa_top_cov_bind i_mldsa_top_cov_bind();
keyvault_cov_bind i_keyvault_cov_bind();
pcrvault_cov_bind i_pcrvault_cov_bind();
`endif
Expand Down
2 changes: 1 addition & 1 deletion src/integration/test_suites/libs/mldsa/mldsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void mldsa_keygen_signing_flow(mldsa_io seed, uint32_t msg[MLDSA87_MSG_SIZE], ui
// Enable MLDSA KEYGEN + SIGNING core
printf("\nMLDSA KEYGEN + SIGNING\n");
lsu_write_32(CLP_MLDSA_REG_MLDSA_CTRL, MLDSA_CMD_KEYGEN_SIGN);

// wait for MLDSA SIGNING process to be done
wait_for_mldsa_intr();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ SECTIONS {
* when copying to DCCM */
/* Only upper half of DCCM is used for ROM image */
_data_lma_start = ALIGN(4);
_data_vma_start = 0x50010000;
.data _data_vma_start : AT(_data_lma_start) { *(.*data) *(.*data.*) *(.rodata*) *(.srodata*) ; . = ALIGN(4);} =0x0000,
_data_vma_start = 0x50000000;
.data _data_vma_start : AT(_data_lma_start) { *(.*data.*) ; . = ALIGN(4);} =0x0000,
_data_lma_end = _data_lma_start + SIZEOF(.data);
_data_vma_end = _data_vma_start + SIZEOF(.data);

Expand All @@ -48,7 +48,7 @@ SECTIONS {
. = _bss_vma_end;
_dccm_lma_start = _bss_vma_end; /* ----\___ SAME */
_dccm_vma_start = _bss_vma_end; /* ----/ */
.dccm _dccm_vma_start : AT(_dccm_lma_start) { *(.dccm*) . = ALIGN(4); } =0x0000,
.dccm _dccm_vma_start : AT(_dccm_lma_start) { *(.dccm*) *(.*data) *(.rodata*) *(.srodata*) . = ALIGN(4); } =0x0000,
iccm_code0_start = .;

/* ICCM as VMA */
Expand Down
120 changes: 120 additions & 0 deletions src/integration/test_suites/smoke_test_mldsa_edge/caliptra_isr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ---------------------------------------------------------------------
// File: caliptra_isr.h
// Description:
// Provides function declarations for use by external test files, so
// that the ISR functionality may behave like a library.
// TODO:
// This header file includes inline function definitions for event and
// test specific interrupt service behavior, so it should be copied and
// modified for each test.
// ---------------------------------------------------------------------

#ifndef CALIPTRA_ISR_H
#define CALIPTRA_ISR_H

#define EN_ISR_PRINTS 1

#include "caliptra_defines.h"
#include <stdint.h>
#include "printf.h"

/* --------------- symbols/typedefs --------------- */
typedef struct {
uint32_t doe_error;
uint32_t doe_notif;
uint32_t ecc_error;
uint32_t ecc_notif;
uint32_t hmac_error;
uint32_t hmac_notif;
uint32_t kv_error;
uint32_t kv_notif;
uint32_t sha512_error;
uint32_t sha512_notif;
uint32_t sha256_error;
uint32_t sha256_notif;
uint32_t soc_ifc_error;
uint32_t soc_ifc_notif;
uint32_t sha512_acc_error;
uint32_t sha512_acc_notif;
uint32_t mldsa_error;
uint32_t mldsa_notif;
uint32_t axi_dma_error;
uint32_t axi_dma_notif;
} caliptra_intr_received_s; //TODO: add mldsa intr
extern volatile caliptra_intr_received_s cptra_intr_rcv;

//////////////////////////////////////////////////////////////////////////////
// Function Declarations
//

// Performs all the CSR setup to configure and enable vectored external interrupts
void init_interrupts(void);

// These inline functions are used to insert event-specific functionality into the
// otherwise generic ISR that gets laid down by the parameterized macro "nonstd_veer_isr"
inline void service_doe_error_intr() {return;}
inline void service_doe_notif_intr() {return;
}

inline void service_ecc_error_intr() {return;}
inline void service_ecc_notif_intr() {return;
}

inline void service_hmac_error_intr() {return;}
inline void service_hmac_notif_intr() {return;
}

inline void service_kv_error_intr() {return;}
inline void service_kv_notif_intr() {return;}
inline void service_sha512_error_intr() {return;}
inline void service_sha512_notif_intr() {return;
}

inline void service_sha256_error_intr() {return;}
inline void service_sha256_notif_intr() {return;
}


inline void service_soc_ifc_error_intr() {return;
}

inline void service_soc_ifc_notif_intr () {return;
}

inline void service_sha512_acc_error_intr() {return;}
inline void service_sha512_acc_notif_intr() {return;
}

inline void service_mldsa_error_intr() {return;}
inline void service_mldsa_notif_intr() {
uint32_t * reg = (uint32_t *) (CLP_MLDSA_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R);
uint32_t sts = *reg;
/* Write 1 to Clear the pending interrupt */
if (sts & MLDSA_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK) {
*reg = MLDSA_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK;
cptra_intr_rcv.mldsa_notif |= MLDSA_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_DONE_STS_MASK;
}
if (sts == 0) {
VPRINTF(ERROR,"bad mldsa_notif_intr sts:%x\n", sts);
SEND_STDOUT_CTRL(0x1);
while(1);
}
}
inline void service_axi_dma_error_intr() {return;}
inline void service_axi_dma_notif_intr() {return;}

#endif //CALIPTRA_ISR_H
Loading

0 comments on commit de9d9c8

Please sign in to comment.