diff --git a/include/gmssl/sm2_z256.h b/include/gmssl/sm2_z256.h index f69eab6a1..738197a55 100644 --- a/include/gmssl/sm2_z256.h +++ b/include/gmssl/sm2_z256.h @@ -21,7 +21,7 @@ extern "C" { #endif -typedef uint64_t SM2_Z256[4]; +typedef uint64_t sm2_z256_t[4]; int sm2_z256_rand_range(uint64_t r[4], const uint64_t range[4]); void sm2_z256_copy(uint64_t r[4], const uint64_t a[4]); diff --git a/src/sm2_sign.c b/src/sm2_sign.c index 973d97d6c..e9fc55803 100644 --- a/src/sm2_sign.c +++ b/src/sm2_sign.c @@ -24,14 +24,14 @@ int sm2_do_sign(const SM2_KEY *key, const uint8_t dgst[32], SM2_SIGNATURE *sig) { SM2_Z256_POINT _P, *P = &_P; - SM2_Z256 d; - SM2_Z256 d_inv; - SM2_Z256 e; - SM2_Z256 k; - SM2_Z256 x; - SM2_Z256 t; - SM2_Z256 r; - SM2_Z256 s; + sm2_z256_t d; + sm2_z256_t d_inv; + sm2_z256_t e; + sm2_z256_t k; + sm2_z256_t x; + sm2_z256_t t; + sm2_z256_t r; + sm2_z256_t s; const uint64_t *one = sm2_z256_one(); const uint64_t *order = sm2_z256_order(); @@ -170,11 +170,11 @@ int sm2_do_sign_fast_ex(const uint64_t d[4], const uint64_t k[4], const uint64_t int sm2_do_sign_fast(const uint64_t d[4], const uint8_t dgst[32], SM2_SIGNATURE *sig) { SM2_Z256_POINT R; - SM2_Z256 e; - SM2_Z256 k; - SM2_Z256 x1; - SM2_Z256 r; - SM2_Z256 s; + sm2_z256_t e; + sm2_z256_t k; + sm2_z256_t x1; + sm2_z256_t r; + sm2_z256_t s; const uint64_t *order = sm2_z256_order(); @@ -224,11 +224,11 @@ int sm2_do_sign_fast(const uint64_t d[4], const uint8_t dgst[32], SM2_SIGNATURE int sm2_do_verify_fast(const SM2_Z256_POINT *P, const uint8_t dgst[32], const SM2_SIGNATURE *sig) { SM2_Z256_POINT R; - SM2_Z256 r; - SM2_Z256 s; - SM2_Z256 e; - SM2_Z256 x; - SM2_Z256 t; + sm2_z256_t r; + sm2_z256_t s; + sm2_z256_t e; + sm2_z256_t x; + sm2_z256_t t; const uint64_t *order = sm2_z256_order(); @@ -289,11 +289,11 @@ int sm2_do_verify(const SM2_KEY *key, const uint8_t dgst[32], const SM2_SIGNATUR { SM2_Z256_POINT _P, *P = &_P; SM2_Z256_POINT _R, *R = &_R; - SM2_Z256 r; - SM2_Z256 s; - SM2_Z256 e; - SM2_Z256 x; - SM2_Z256 t; + sm2_z256_t r; + sm2_z256_t s; + sm2_z256_t e; + sm2_z256_t x; + sm2_z256_t t; const uint64_t *order = sm2_z256_order(); @@ -403,7 +403,7 @@ int sm2_do_encrypt_pre_compute(uint64_t k[4], uint8_t C1[64]) // 其中k是要参与计算的,但是 (x1, y1) 不参与计算,输出为 bytes 就可以了 int sm2_do_encrypt(const SM2_KEY *key, const uint8_t *in, size_t inlen, SM2_CIPHERTEXT *out) { - SM2_Z256 k; + sm2_z256_t k; SM2_Z256_POINT _P, *P = &_P; SM2_Z256_POINT _C1, *C1 = &_C1; SM2_Z256_POINT _kP, *kP = &_kP; @@ -467,7 +467,7 @@ int sm2_do_encrypt(const SM2_KEY *key, const uint8_t *in, size_t inlen, SM2_CIPH int sm2_do_encrypt_fixlen(const SM2_KEY *key, const uint8_t *in, size_t inlen, int point_size, SM2_CIPHERTEXT *out) { unsigned int trys = 200; - SM2_Z256 k; + sm2_z256_t k; SM2_Z256_POINT _P, *P = &_P; SM2_Z256_POINT _C1, *C1 = &_C1; SM2_Z256_POINT _kP, *kP = &_kP; @@ -555,7 +555,7 @@ int sm2_do_encrypt_fixlen(const SM2_KEY *key, const uint8_t *in, size_t inlen, i int sm2_do_decrypt(const SM2_KEY *key, const SM2_CIPHERTEXT *in, uint8_t *out, size_t *outlen) { int ret = -1; - SM2_Z256 d; + sm2_z256_t d; SM2_Z256_POINT _C1, *C1 = &_C1; uint8_t x2y2[64]; SM3_CTX sm3_ctx; diff --git a/tests/sm2_signtest.c b/tests/sm2_signtest.c index 5a2005ea4..8b25223a6 100644 --- a/tests/sm2_signtest.c +++ b/tests/sm2_signtest.c @@ -102,30 +102,22 @@ static int test_sm2_do_sign(void) return 1; } -#define SM2_U256 SM2_Z256 -#define sm2_u256_one sm2_z256_one -#define sm2_u256_is_zero sm2_z256_is_zero -#define sm2_u256_from_bytes sm2_z256_from_bytes -#define sm2_u256_modn_add sm2_z256_modn_add -#define sm2_u256_modn_inv sm2_z256_modn_inv - - static int test_sm2_do_sign_fast(void) { SM2_KEY sm2_key; - SM2_U256 d; + sm2_z256_t d; uint8_t dgst[32]; SM2_SIGNATURE sig; size_t i; // d' = (d + 1)^-1 (mod n) - const uint64_t *one = sm2_u256_one(); + const uint64_t *one = sm2_z256_one(); do { sm2_key_generate(&sm2_key); - sm2_u256_from_bytes(d, sm2_key.private_key); - sm2_u256_modn_add(d, d, one); - sm2_u256_modn_inv(d, d); - } while (sm2_u256_is_zero(d)); + sm2_z256_from_bytes(d, sm2_key.private_key); + sm2_z256_modn_add(d, d, one); + sm2_z256_modn_inv(d, d); + } while (sm2_z256_is_zero(d)); for (i = 0; i < TEST_COUNT; i++) { if (sm2_do_sign_fast(d, dgst, &sig) != 1) {