From d16d1a541233ab2c950ec1b534a447636aaf44c1 Mon Sep 17 00:00:00 2001 From: "Pavel V. Shatov (Meister)" Date: Thu, 10 Aug 2017 15:58:05 +0300 Subject: Generate additional quantities required for testing of CRT in hardware. --- test/format_test_vectors.py | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'test/format_test_vectors.py') diff --git a/test/format_test_vectors.py b/test/format_test_vectors.py index c56fe18..f9e4ba8 100644 --- a/test/format_test_vectors.py +++ b/test/format_test_vectors.py @@ -194,13 +194,17 @@ def calc_montgomery_n_coeff(k, n): # # format one test vector # -def format_verilog_include(f, key, n, m, d, s): +def format_verilog_include(f, key, n, m, d, s, p, q, dp, dq, mp, mq): # calculate factor to bring message into Montgomery domain factor = calc_montgomery_factor(int(key), n) + factor_p = calc_montgomery_factor(int(key)//2, p); + factor_q = calc_montgomery_factor(int(key)//2, q); - # calculate helper coefficient for Montgomery multiplication + # calculate helper coefficients for Montgomery multiplication n_coeff = calc_montgomery_n_coeff(int(key), n) + p_coeff = calc_montgomery_n_coeff(int(key)//2, p) + q_coeff = calc_montgomery_n_coeff(int(key)//2, q) # calculate the extra coefficient Montgomery multiplication brings in coeff = modinv(1 << int(key), n) @@ -209,14 +213,25 @@ def format_verilog_include(f, key, n, m, d, s): m_factor = (m * factor * coeff) % n # write all numbers - format_verilog_concatenation(f, m, "localparam [" + str(int(key)-1) + ":0] M_" + str(key) + " =\n") - format_verilog_concatenation(f, n, "localparam [" + str(int(key)-1) + ":0] N_" + str(key) + " =\n") - format_verilog_concatenation(f, n_coeff, "localparam [" + str(int(key)-1) + ":0] N_COEFF_" + str(key) + " =\n") - format_verilog_concatenation(f, factor, "localparam [" + str(int(key)-1) + ":0] FACTOR_" + str(key) + " =\n") - format_verilog_concatenation(f, coeff, "localparam [" + str(int(key)-1) + ":0] COEFF_" + str(key) + " =\n") - format_verilog_concatenation(f, m_factor, "localparam [" + str(int(key)-1) + ":0] M_FACTOR_" + str(key) + " =\n") - format_verilog_concatenation(f, d, "localparam [" + str(int(key)-1) + ":0] D_" + str(key) + " =\n") - format_verilog_concatenation(f, s, "localparam [" + str(int(key)-1) + ":0] S_" + str(key) + " =\n") + format_verilog_concatenation(f, m, "localparam [" + str(int(key)-1) + ":0] M_" + key + " =\n") + format_verilog_concatenation(f, n, "localparam [" + str(int(key)-1) + ":0] N_" + key + " =\n") + format_verilog_concatenation(f, n_coeff, "localparam [" + str(int(key)-1) + ":0] N_COEFF_" + key + " =\n") + format_verilog_concatenation(f, factor, "localparam [" + str(int(key)-1) + ":0] FACTOR_" + key + " =\n") + format_verilog_concatenation(f, coeff, "localparam [" + str(int(key)-1) + ":0] COEFF_" + key + " =\n") + format_verilog_concatenation(f, m_factor, "localparam [" + str(int(key)-1) + ":0] M_FACTOR_" + key + " =\n") + format_verilog_concatenation(f, d, "localparam [" + str(int(key)-1) + ":0] D_" + key + " =\n") + format_verilog_concatenation(f, s, "localparam [" + str(int(key)-1) + ":0] S_" + key + " =\n") + + format_verilog_concatenation(f, p, "localparam [" + str(int(key)//2-1) + ":0] P_" + str(int(key)//2) + " =\n") + format_verilog_concatenation(f, q, "localparam [" + str(int(key)//2-1) + ":0] Q_" + str(int(key)//2) + " =\n") + format_verilog_concatenation(f, p_coeff, "localparam [" + str(int(key)//2-1) + ":0] P_COEFF_" + str(int(key)//2) + " =\n") + format_verilog_concatenation(f, q_coeff, "localparam [" + str(int(key)//2-1) + ":0] Q_COEFF_" + str(int(key)//2) + " =\n") + format_verilog_concatenation(f, factor_p, "localparam [" + str(int(key)//2-1) + ":0] FACTOR_P_" + str(int(key)//2) + " =\n") + format_verilog_concatenation(f, factor_q, "localparam [" + str(int(key)//2-1) + ":0] FACTOR_Q_" + str(int(key)//2) + " =\n") + format_verilog_concatenation(f, dp, "localparam [" + str(int(key)//2-1) + ":0] DP_" + str(int(key)//2) + " =\n") + format_verilog_concatenation(f, dq, "localparam [" + str(int(key)//2-1) + ":0] DQ_" + str(int(key)//2) + " =\n") + format_verilog_concatenation(f, mp, "localparam [" + str(int(key)//2-1) + ":0] MP_" + str(int(key)//2) + " =\n") + format_verilog_concatenation(f, mq, "localparam [" + str(int(key)//2-1) + ":0] MQ_" + str(int(key)//2) + " =\n") # @@ -359,7 +374,7 @@ if __name__ == "__main__": # format numbers and write to file format_c_header(file_h, key, modulus, message, secret, signature, prime1, prime2, exponent1, exponent2, message1, message2) - format_verilog_include(file_v, key, modulus, message, secret, signature) + format_verilog_include(file_v, key, modulus, message, secret, signature, prime1, prime2, exponent1, exponent2, message1, message2) # done -- cgit v1.2.3