From 9c5f05dfd4bd757ecdbeabe4bcd60caaf45a5789 Mon Sep 17 00:00:00 2001 From: "Pavel V. Shatov (Meister)" Date: Tue, 17 Apr 2018 14:43:53 +0300 Subject: Additional test cases. --- ecdh_fpga_model.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'ecdh_fpga_model.cpp') diff --git a/ecdh_fpga_model.cpp b/ecdh_fpga_model.cpp index 730292e..8d2be88 100644 --- a/ecdh_fpga_model.cpp +++ b/ecdh_fpga_model.cpp @@ -64,7 +64,7 @@ bool compare_fpga_buffers (FPGA_BUFFER *ax, FPGA_BUFFER *ay, FPGA_BUFFER *bx, int main() //------------------------------------------------------------------------------ { - bool ok_a, ok_b; // flags + bool ok_a, ok_b, ok_g; // flags // // initialize buffers @@ -116,9 +116,10 @@ int main() // // abuse point multiplier // + ok_g = abuse_point_multiplier(&ecdsa_g_x, &ecdsa_g_y); ok_a = abuse_point_multiplier(&ecdh_qa_x, &ecdh_qa_y); ok_b = abuse_point_multiplier(&ecdh_qb_x, &ecdh_qb_y); - if (!ok_a || !ok_b) return EXIT_FAILURE; + if (!ok_g || !ok_a || !ok_b) return EXIT_FAILURE; // @@ -172,13 +173,24 @@ bool abuse_point_multiplier(FPGA_BUFFER *qx, FPGA_BUFFER *qy) { bool ok; // flag - // obtain quantity n + 2 - FPGA_BUFFER two, n2; - fpga_modular_add(&ecdsa_one, &ecdsa_one, &two); // n1 = n + 1 - fpga_modular_add(&ecdsa_n, &two, &n2); // n2 = n1 + 1 = n + 2 + // obtain quantity n + 1, n + 2 + FPGA_BUFFER two, n1, n2; + fpga_modular_add(&ecdsa_one, &ecdsa_one, &two); // n1 = n + 1 + fpga_modular_add(&ecdsa_n, &ecdsa_one, &n1); // n1 = n + 1 + fpga_modular_add(&n1, &ecdsa_one, &n2); // n2 = n1 + 1 = n + 2 printf("Trying to abuse point multiplier...\n\n"); + // make sure, that (n + 1) * Q = Q + FPGA_BUFFER qn1_x, qn1_y; + fpga_curve_scalar_multiply(qx, qy, &n1, &qn1_x, &qn1_y); + ok = compare_fpga_buffers(qx, qy, &qn1_x, &qn1_y); + if (! ok) + { printf("\n ERROR\n\n"); + return false; + } + else printf("\n OK\n\n"); + // we first calculate 2 * Q FPGA_BUFFER q2a_x, q2a_y; fpga_curve_scalar_multiply(qx, qy, &two, &q2a_x, &q2a_y); -- cgit v1.2.3