diff --git a/src/ecc/config/compile.yml b/src/ecc/config/compile.yml index afc86d44f..369d1ed2c 100755 --- a/src/ecc/config/compile.yml +++ b/src/ecc/config/compile.yml @@ -59,6 +59,20 @@ targets: - $COMPILE_ROOT/tb/ecc_top_tb.sv tops: [ecc_top_tb] --- +provides: [ecc_montgomerymultiplier_tb] +schema_version: 2.4.0 +requires: + - ecc_top +targets: + tb: + directories: + - $COMPILE_ROOT/tb + files: + - $COMPILE_ROOT/tb/ecc_montgomerymultiplier_tb.sv + tops: [ecc_montgomerymultiplier_tb] + sim: + pre_exec: 'echo "[PRE-EXEC] Copying Mont multiplication test vector to $PWD" && cp $COMPILE_ROOT/tb/test_vectors/mm_test_vectors*.hex .' +--- provides: [ecc_coverage] schema_version: 2.4.0 requires: diff --git a/src/ecc/config/ecc_montgomerymultiplier_tb.vf b/src/ecc/config/ecc_montgomerymultiplier_tb.vf new file mode 100644 index 000000000..6c4652734 --- /dev/null +++ b/src/ecc/config/ecc_montgomerymultiplier_tb.vf @@ -0,0 +1,80 @@ ++incdir+${CALIPTRA_ROOT}/src/integration/rtl ++incdir+${CALIPTRA_ROOT}/src/libs/rtl ++incdir+${CALIPTRA_ROOT}/src/keyvault/rtl ++incdir+${CALIPTRA_ROOT}/src/pcrvault/rtl ++incdir+${CALIPTRA_ROOT}/src/ecc/tb ++incdir+${CALIPTRA_ROOT}/src/sha512/rtl ++incdir+${CALIPTRA_ROOT}/src/sha512_masked/rtl ++incdir+${CALIPTRA_ROOT}/src/hmac/rtl ++incdir+${CALIPTRA_ROOT}/src/hmac_drbg/rtl ++incdir+${CALIPTRA_ROOT}/src/ecc/rtl +${CALIPTRA_ROOT}/src/integration/rtl/config_defines.svh +${CALIPTRA_ROOT}/src/integration/rtl/caliptra_reg_defines.svh +${CALIPTRA_ROOT}/src/libs/rtl/caliptra_sva.svh +${CALIPTRA_ROOT}/src/libs/rtl/caliptra_macros.svh +${CALIPTRA_ROOT}/src/libs/rtl/caliptra_sram.sv +${CALIPTRA_ROOT}/src/libs/rtl/ahb_defines_pkg.sv +${CALIPTRA_ROOT}/src/libs/rtl/caliptra_ahb_srom.sv +${CALIPTRA_ROOT}/src/libs/rtl/apb_slv_sif.sv +${CALIPTRA_ROOT}/src/libs/rtl/ahb_slv_sif.sv +${CALIPTRA_ROOT}/src/libs/rtl/caliptra_icg.sv +${CALIPTRA_ROOT}/src/libs/rtl/clk_gate.sv +${CALIPTRA_ROOT}/src/keyvault/rtl/kv_defines_pkg.sv +${CALIPTRA_ROOT}/src/keyvault/rtl/kv_macros.svh +${CALIPTRA_ROOT}/src/pcrvault/rtl/pv_defines_pkg.sv +${CALIPTRA_ROOT}/src/pcrvault/rtl/pv_macros.svh +${CALIPTRA_ROOT}/src/pcrvault/rtl/pv_gen_hash.sv +${CALIPTRA_ROOT}/src/ecc/tb/ecc_montgomerymultiplier_tb.sv +${CALIPTRA_ROOT}/src/libs/rtl/ahb_to_reg_adapter.sv +${CALIPTRA_ROOT}/src/keyvault/rtl/kv_reg_pkg.sv +${CALIPTRA_ROOT}/src/keyvault/rtl/kv_reg.sv +${CALIPTRA_ROOT}/src/keyvault/rtl/kv.sv +${CALIPTRA_ROOT}/src/keyvault/rtl/kv_fsm.sv +${CALIPTRA_ROOT}/src/keyvault/rtl/kv_read_client.sv +${CALIPTRA_ROOT}/src/keyvault/rtl/kv_write_client.sv +${CALIPTRA_ROOT}/src/pcrvault/rtl/pv_reg_pkg.sv +${CALIPTRA_ROOT}/src/pcrvault/rtl/pv_reg.sv +${CALIPTRA_ROOT}/src/pcrvault/rtl/pv.sv +${CALIPTRA_ROOT}/src/sha512/rtl/sha512_reg_pkg.sv +${CALIPTRA_ROOT}/src/sha512/rtl/sha512_params_pkg.sv +${CALIPTRA_ROOT}/src/sha512/rtl/sha512_ctrl.sv +${CALIPTRA_ROOT}/src/sha512/rtl/sha512.sv +${CALIPTRA_ROOT}/src/sha512/rtl/sha512_core.v +${CALIPTRA_ROOT}/src/sha512/rtl/sha512_h_constants.v +${CALIPTRA_ROOT}/src/sha512/rtl/sha512_k_constants.v +${CALIPTRA_ROOT}/src/sha512/rtl/sha512_w_mem.v +${CALIPTRA_ROOT}/src/sha512/rtl/sha512_reg.sv +${CALIPTRA_ROOT}/src/sha512_masked/rtl/sha512_masked_defines_pkg.sv +${CALIPTRA_ROOT}/src/sha512_masked/rtl/sha512_masked_core.sv +${CALIPTRA_ROOT}/src/sha512_masked/rtl/sha512_masked_lfsr.sv +${CALIPTRA_ROOT}/src/hmac/rtl/hmac_param_pkg.sv +${CALIPTRA_ROOT}/src/hmac/rtl/hmac_reg_pkg.sv +${CALIPTRA_ROOT}/src/hmac/rtl/hmac_ctrl.sv +${CALIPTRA_ROOT}/src/hmac/rtl/hmac.sv +${CALIPTRA_ROOT}/src/hmac/rtl/hmac_core.v +${CALIPTRA_ROOT}/src/hmac/rtl/hmac_reg.sv +${CALIPTRA_ROOT}/src/hmac_drbg/rtl/hmac_drbg.sv +${CALIPTRA_ROOT}/src/hmac_drbg/rtl/hmac_drbg_lfsr.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_reg_pkg.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_defines_pkg.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_params_pkg.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_dsa_uop_pkg.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_pm_uop_pkg.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_top.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_reg.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_dsa_ctrl.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_dsa_sequencer.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_scalar_blinding.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_hmac_drbg_interface.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_arith_unit.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_pm_ctrl.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_pm_sequencer.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_ram_tdp_file.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_fau.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_montgomerymultiplier.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_pe_first.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_pe.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_pe_final.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_mult_dsp.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_add_sub_mod_alter.sv +${CALIPTRA_ROOT}/src/ecc/rtl/ecc_adder.sv \ No newline at end of file diff --git a/src/ecc/coverage/ecc_top_cov_if.sv b/src/ecc/coverage/ecc_top_cov_if.sv index 369e8e06d..ec86e056b 100644 --- a/src/ecc/coverage/ecc_top_cov_if.sv +++ b/src/ecc/coverage/ecc_top_cov_if.sv @@ -53,7 +53,8 @@ interface ecc_top_cov_if logic add_res_greater_than_prime; logic add_res_greater_than_384_bit; - logic PE_UNITS; + logic mult_ready; + logic mult_last_reduction; logic mult_final_subtraction; assign mod_p_q = ecc_top.ecc_dsa_ctrl_i.ecc_arith_unit_i.mod_p_q; @@ -66,17 +67,9 @@ interface ecc_top_cov_if assign add_res_greater_than_prime = ((add_cout0 == 1'b0) & (add_res0 >= ecc_top.ecc_dsa_ctrl_i.ecc_arith_unit_i.ecc_fau_i.prime_i)); assign add_res_greater_than_384_bit = (add_cout0 == 1'b1); - assign PE_UNITS = ecc_top.ecc_dsa_ctrl_i.ecc_arith_unit_i.ecc_fau_i.i_MULTIPLIER.PE_UNITS; - always_ff @(posedge clk) begin - if (!reset_n) begin - mult_final_subtraction <= '0; - end - else if (ecc_top.ecc_dsa_ctrl_i.ecc_arith_unit_i.ecc_fau_i.i_MULTIPLIER.ready_o) begin - mult_final_subtraction <= ecc_top.ecc_dsa_ctrl_i.ecc_arith_unit_i.ecc_fau_i.i_MULTIPLIER.sub_b_o[2*(PE_UNITS+1)]; - end - end - - + assign mult_ready = ecc_top.ecc_dsa_ctrl_i.ecc_arith_unit_i.ecc_fau_i.i_MULTIPLIER.ready_o; + assign mult_last_reduction = ecc_top.ecc_dsa_ctrl_i.ecc_arith_unit_i.ecc_fau_i.i_MULTIPLIER.last_reduction; + assign mult_final_subtraction = mult_ready & mult_last_reduction; assign ecc_cmd = ecc_top.ecc_dsa_ctrl_i.cmd_reg; assign pcr_sign_mode = ecc_top.ecc_dsa_ctrl_i.pcr_sign_mode; diff --git a/src/ecc/rtl/ecc_montgomerymultiplier.sv b/src/ecc/rtl/ecc_montgomerymultiplier.sv index df0fb79a2..db767af83 100644 --- a/src/ecc/rtl/ecc_montgomerymultiplier.sv +++ b/src/ecc/rtl/ecc_montgomerymultiplier.sv @@ -100,6 +100,7 @@ module ecc_montgomerymultiplier #( logic [RADIX-1 : 0] last_s_reg; logic [FULL_REG_SIZE-1:0] p_internal; logic [FULL_REG_SIZE-1:0] p_subtracted_internal; + logic last_reduction; //---------------------------------------------------------------- // Processing elements (PEs) @@ -291,8 +292,15 @@ module ecc_montgomerymultiplier #( always_comb sub_b_i[t1] = 1; else always_comb sub_b_i[t1] = sub_b_o[t1 - 1]; - - always_comb sub_b_o[t1] = sub_res[t1][RADIX]; + + always_ff @(posedge clk or negedge reset_n) begin + if (~reset_n) + sub_b_o[t1] <= '0; + else if (zeroize) + sub_b_o[t1] <= '0; + else + sub_b_o[t1] <= sub_res[t1][RADIX]; + end end endgenerate @@ -337,7 +345,8 @@ module ecc_montgomerymultiplier #( end endgenerate - assign p_o = (sub_b_o[2*(PE_UNITS+1)])? p_subtracted_internal[REG_SIZE-1:0] : p_internal[REG_SIZE-1:0]; + always_comb last_reduction = (sub_b_o[2*(PE_UNITS+1)]); + assign p_o = (last_reduction)? p_subtracted_internal[REG_SIZE-1:0] : p_internal[REG_SIZE-1:0]; // Determines when results are ready based on S_NUM always_ff @(posedge clk or negedge reset_n) begin diff --git a/src/ecc/rtl/ecc_pm_ctrl.sv b/src/ecc/rtl/ecc_pm_ctrl.sv index 4d53778ec..0593c5f65 100644 --- a/src/ecc/rtl/ecc_pm_ctrl.sv +++ b/src/ecc/rtl/ecc_pm_ctrl.sv @@ -65,7 +65,7 @@ module ecc_pm_ctrl //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- - localparam [7 : 0] MULT_DELAY = 8'd38; //39 -1; + localparam [7 : 0] MULT_DELAY = 8'd39; //40 -1; localparam [7 : 0] ADD_DELAY = 8'd1; // 2 -1; localparam [9 : 0] Secp384_SCA_MONT_COUNT = REG_SIZE[9 : 0] + RND_SIZE[9 : 0]; diff --git a/src/ecc/tb/ecc_montgomerymultiplier_tb.sv b/src/ecc/tb/ecc_montgomerymultiplier_tb.sv index eb11056c5..5fef6665d 100644 --- a/src/ecc/tb/ecc_montgomerymultiplier_tb.sv +++ b/src/ecc/tb/ecc_montgomerymultiplier_tb.sv @@ -22,9 +22,9 @@ //====================================================================== module ecc_montgomerymultiplier_tb #( - parameter OPERAND_WIDTH = 384, - parameter WORD_WIDTH = 32, - parameter TEST_VECTOR_NUM = 102 + parameter OPERAND_WIDTH = 16, + parameter WORD_WIDTH = 4, + parameter TEST_VECTOR_NUM = 5 ) (); @@ -91,6 +91,7 @@ module ecc_montgomerymultiplier_tb #( mm_dut ( .clk (clk_tb), .reset_n (reset_n_tb), + .zeroize (1'b0), .start_i (start_i_tb), .opa_i (opa_i_tb), @@ -317,7 +318,8 @@ module ecc_montgomerymultiplier_tb #( $display(" -= Testbench for mm started =-"); $display(" ==============================\n"); - fname = $sformatf("/home/mojtabab/workspace_aha_poc/ws1/Caliptra/src/ecc/tb/test_vectors/mm_test_vectors_%0d_key_%0d_word_%0d.hex", TEST_VECTOR_NUM, OPERAND_WIDTH, WORD_WIDTH); + fname = $sformatf("mm_test_vectors_%0d_key_%0d_word_%0d.hex", TEST_VECTOR_NUM, OPERAND_WIDTH, WORD_WIDTH); + read_test_vectors(fname); init_sim(); diff --git a/src/ecc/tb/test_vectors/mm_test_vectors_5_key_16_word_4.hex b/src/ecc/tb/test_vectors/mm_test_vectors_5_key_16_word_4.hex new file mode 100644 index 000000000..56ea6deda --- /dev/null +++ b/src/ecc/tb/test_vectors/mm_test_vectors_5_key_16_word_4.hex @@ -0,0 +1,30 @@ +0013 +0d79 +fffb +0d +0000 +0 +0015 +00ff +fff1 +0f +b00c +1 +0026 +e509 +fffb +0d +0000 +2 +c15f +5445 +fff1 +0f +0006 +3 +bfff +2fff +fff1 +0f +002f +4 \ No newline at end of file