From d923faef772ac59bd3690002baf98aa87f0a2ab5 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Wed, 11 May 2022 12:29:36 +0800 Subject: [PATCH] Update SM9 test --- include/gmssl/sm9.h | 6 +++++- src/sm9_alg.c | 24 ------------------------ tests/sm9test.c | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/include/gmssl/sm9.h b/include/gmssl/sm9.h index 40a860a9..9604c574 100644 --- a/include/gmssl/sm9.h +++ b/include/gmssl/sm9.h @@ -75,6 +75,11 @@ typedef struct { sm9_fp2_t Z; } sm9_twist_point_t; + +// FIXME: 公开的参数值应该是序列化之后的 +extern const sm9_bn_t SM9_P; +extern const sm9_bn_t SM9_N; +extern const sm9_point_t *SM9_P1; extern const sm9_twist_point_t *SM9_P2; extern const sm9_twist_point_t *SM9_Ppubs; @@ -271,7 +276,6 @@ void sm9_final_exponent_hard_part(sm9_fp12_t r, const sm9_fp12_t f); void sm9_final_exponent(sm9_fp12_t r, const sm9_fp12_t f); void sm9_pairing(sm9_fp12_t r, const sm9_twist_point_t *Q, const sm9_point_t *P); -void sm9_pairing_test(); /* old API diff --git a/src/sm9_alg.c b/src/sm9_alg.c index efdb4c5d..46ff9a8a 100644 --- a/src/sm9_alg.c +++ b/src/sm9_alg.c @@ -1925,27 +1925,3 @@ void sm9_pairing(sm9_fp12_t r, const sm9_twist_point_t *Q, const sm9_point_t *P) sm9_final_exponent(r, r); } -void sm9_pairing_test() -{ - sm9_fp12_t r; - sm9_fp12_init(r); - - const char *sm9_g_hex[] = { - "aab9f06a4eeba4323a7833db202e4e35639d93fa3305af73f0f071d7d284fcfb\n", - "84b87422330d7936eaba1109fa5a7a7181ee16f2438b0aeb2f38fd5f7554e57a\n", - "4c744e69c4a2e1c8ed72f796d151a17ce2325b943260fc460b9f73cb57c9014b\n", - "b3129a75d31d17194675a1bc56947920898fbf390a5bf5d931ce6cbb3340f66d\n", - "93634f44fa13af76169f3cc8fbea880adaff8475d5fd28a75deb83c44362b439\n", - "1604a3fcfa9783e667ce9fcb1062c2a5c6685c316dda62de0548baa6ba30038b\n", - "5a1ae172102efd95df7338dbc577c66d8d6c15e0a0158c7507228efb078f42a6\n", - "67e0e0c2eed7a6993dce28fe9aa2ef56834307860839677f96685f2b44d0911f\n", - "a01f2c8bee81769609462c69c96aa923fd863e209d3ce26dd889b55e2e3873db\n", - "38bffe40a22d529a0c66124b2c308dac9229912656f62b4facfced408e02380f\n", - "28b3404a61908f5d6198815c99af1990c8af38655930058c28c21bb539ce0000\n", - "4e378fb5561cd0668f906b731ac58fee25738edf09cadc7a29c0abc0177aea6d\n", - }; - - sm9_pairing(r, SM9_Ppubs, SM9_P1); - //printf("test pairing: %d\n", sm9_fp12_equ(&r, sm9_fp12_from_hex(g))); -} - diff --git a/tests/sm9test.c b/tests/sm9test.c index 5cade8a4..9fe91b72 100644 --- a/tests/sm9test.c +++ b/tests/sm9test.c @@ -301,14 +301,38 @@ err: return -1; } +int test_sm9_pairing() +{ + sm9_fp12_t r; + sm9_fp12_init(r); + const char *sm9_g_hex[] = { + "aab9f06a4eeba4323a7833db202e4e35639d93fa3305af73f0f071d7d284fcfb\n", + "84b87422330d7936eaba1109fa5a7a7181ee16f2438b0aeb2f38fd5f7554e57a\n", + "4c744e69c4a2e1c8ed72f796d151a17ce2325b943260fc460b9f73cb57c9014b\n", + "b3129a75d31d17194675a1bc56947920898fbf390a5bf5d931ce6cbb3340f66d\n", + "93634f44fa13af76169f3cc8fbea880adaff8475d5fd28a75deb83c44362b439\n", + "1604a3fcfa9783e667ce9fcb1062c2a5c6685c316dda62de0548baa6ba30038b\n", + "5a1ae172102efd95df7338dbc577c66d8d6c15e0a0158c7507228efb078f42a6\n", + "67e0e0c2eed7a6993dce28fe9aa2ef56834307860839677f96685f2b44d0911f\n", + "a01f2c8bee81769609462c69c96aa923fd863e209d3ce26dd889b55e2e3873db\n", + "38bffe40a22d529a0c66124b2c308dac9229912656f62b4facfced408e02380f\n", + "28b3404a61908f5d6198815c99af1990c8af38655930058c28c21bb539ce0000\n", + "4e378fb5561cd0668f906b731ac58fee25738edf09cadc7a29c0abc0177aea6d\n", + }; + sm9_pairing(r, SM9_Ppubs, SM9_P1); // FIXME: check + + //printf("test pairing: %d\n", sm9_fp12_equ(&r, sm9_fp12_from_hex(g))); + return 1; +} int main(void) { if (test_sm9_fp() != 1) goto err; if (test_sm9_fp2() != 1) goto err; if (test_sm9_fp4() != 1) goto err; if (test_sm9_fp12() != 1) goto err; + if (test_sm9_pairing() != 1) goto err; printf("%s all tests passed\n", __FILE__); return 0;