mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-07-01 02:03:37 +08:00
Update SM9 to/from_hex API
This commit is contained in:
@@ -109,7 +109,7 @@ int sm9_z256_fp4_rand(sm9_z256_fp4_t r);
|
||||
void sm9_z256_fp4_copy(sm9_z256_fp4_t r, const sm9_z256_fp4_t a);
|
||||
void sm9_z256_fp4_to_bytes(const sm9_z256_fp4_t a, uint8_t buf[128]);
|
||||
int sm9_z256_fp4_from_bytes(sm9_z256_fp4_t r, const uint8_t buf[128]);
|
||||
int sm9_z256_fp4_from_hex(sm9_z256_fp4_t r, const char hex[65 * 4]);
|
||||
int sm9_z256_fp4_from_hex(sm9_z256_fp4_t r, const char hex[259]);
|
||||
void sm9_z256_fp4_to_hex(const sm9_z256_fp4_t a, char hex[259]);
|
||||
void sm9_z256_fp4_add(sm9_z256_fp4_t r, const sm9_z256_fp4_t a, const sm9_z256_fp4_t b);
|
||||
void sm9_z256_fp4_dbl(sm9_z256_fp4_t r, const sm9_z256_fp4_t a);
|
||||
@@ -136,10 +136,10 @@ void sm9_z256_fp12_set_one(sm9_z256_fp12_t r);
|
||||
void sm9_z256_fp12_set_zero(sm9_z256_fp12_t r);
|
||||
void sm9_z256_fp12_copy(sm9_z256_fp12_t r, const sm9_z256_fp12_t a);
|
||||
int sm9_z256_fp12_rand(sm9_z256_fp12_t r);
|
||||
int sm9_z256_fp12_from_hex(sm9_z256_fp12_t r, const char hex[65 * 12 - 1]);
|
||||
void sm9_z256_fp12_to_hex(const sm9_z256_fp12_t a, char hex[65 * 12 - 1]);
|
||||
void sm9_z256_fp12_to_bytes(const sm9_z256_fp12_t a, uint8_t buf[32 * 12]);
|
||||
int sm9_z256_fp12_from_bytes(sm9_z256_fp12_t r, const uint8_t buf[32 * 12]);
|
||||
int sm9_z256_fp12_from_hex(sm9_z256_fp12_t r, const char hex[779]); // 779 = 64*12 + 11
|
||||
void sm9_z256_fp12_to_hex(const sm9_z256_fp12_t a, char hex[779]);
|
||||
void sm9_z256_fp12_to_bytes(const sm9_z256_fp12_t a, uint8_t buf[384]);
|
||||
int sm9_z256_fp12_from_bytes(sm9_z256_fp12_t r, const uint8_t buf[384]);
|
||||
|
||||
void sm9_z256_fp12_print(const char *prefix, const sm9_z256_fp12_t a);
|
||||
void sm9_z256_fp12_set(sm9_z256_fp12_t r, const sm9_z256_fp4_t a0, const sm9_z256_fp4_t a1, const sm9_z256_fp4_t a2);
|
||||
@@ -169,7 +169,7 @@ typedef struct {
|
||||
|
||||
const SM9_Z256_POINT *sm9_z256_generator(void);
|
||||
|
||||
int sm9_z256_point_from_hex(SM9_Z256_POINT *R, const char hex[65 * 2]);
|
||||
int sm9_z256_point_from_hex(SM9_Z256_POINT *R, const char hex[129]);
|
||||
int sm9_z256_point_is_at_infinity(const SM9_Z256_POINT *P);
|
||||
void sm9_z256_point_set_infinity(SM9_Z256_POINT *R);
|
||||
void sm9_z256_point_get_xy(const SM9_Z256_POINT *P, sm9_z256_t x, sm9_z256_t y);
|
||||
@@ -208,7 +208,7 @@ int sm9_z256_twist_point_to_uncompressed_octets(const SM9_Z256_TWIST_POINT *P, u
|
||||
int sm9_z256_twist_point_from_uncompressed_octets(SM9_Z256_TWIST_POINT *P, const uint8_t octets[129]);
|
||||
|
||||
int sm9_z256_twist_point_print(FILE *fp, int fmt, int ind, const char *label, const SM9_Z256_TWIST_POINT *P);
|
||||
void sm9_z256_twist_point_from_hex(SM9_Z256_TWIST_POINT *R, const char hex[65 * 4]);
|
||||
void sm9_z256_twist_point_from_hex(SM9_Z256_TWIST_POINT *R, const char hex[259]); // 259 = 64 * 4 + 3
|
||||
int sm9_z256_twist_point_is_at_infinity(const SM9_Z256_TWIST_POINT *P);
|
||||
void sm9_z256_twist_point_set_infinity(SM9_Z256_TWIST_POINT *R);
|
||||
void sm9_z256_twist_point_get_xy(const SM9_Z256_TWIST_POINT *P, sm9_z256_fp2_t x, sm9_z256_fp2_t y);
|
||||
|
||||
157
src/sm9_z256.c
157
src/sm9_z256.c
@@ -767,12 +767,14 @@ void sm9_z256_fp2_copy(sm9_z256_fp2_t r, const sm9_z256_fp2_t a)
|
||||
|
||||
int sm9_z256_fp2_rand(sm9_z256_fp2_t r)
|
||||
{
|
||||
if (sm9_z256_rand_range(r[0], SM9_Z256_P) != 1) {
|
||||
error_print();
|
||||
int ret;
|
||||
|
||||
if ((ret = sm9_z256_rand_range(r[0], SM9_Z256_P)) != 1) {
|
||||
if (ret) error_print();
|
||||
return -1;
|
||||
}
|
||||
if (sm9_z256_rand_range(r[1], SM9_Z256_P) != 1) {
|
||||
error_print();
|
||||
if ((ret = sm9_z256_rand_range(r[1], SM9_Z256_P)) != 1) {
|
||||
if (ret) error_print();
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
@@ -796,19 +798,19 @@ int sm9_z256_fp2_from_bytes(sm9_z256_fp2_t r, const uint8_t buf[64])
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
sm9_z256_modp_to_mont(r[1], r[1]);
|
||||
|
||||
sm9_z256_from_bytes(r[0], buf + 32);
|
||||
if (sm9_z256_cmp(r[0], SM9_Z256_P) >= 0) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
|
||||
sm9_z256_modp_to_mont(r[1], r[1]);
|
||||
sm9_z256_modp_to_mont(r[0], r[0]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sm9_z256_fp2_from_hex(sm9_z256_fp2_t r, const char hex[129])
|
||||
int sm9_z256_fp2_from_hex(sm9_z256_fp2_t r, const char hex[64 * 2 + 1])
|
||||
{
|
||||
if (sm9_z256_from_hex(r[1], hex) != 1) {
|
||||
error_print();
|
||||
@@ -820,12 +822,10 @@ int sm9_z256_fp2_from_hex(sm9_z256_fp2_t r, const char hex[129])
|
||||
}
|
||||
sm9_z256_modp_to_mont(r[1], r[1]);
|
||||
|
||||
/*
|
||||
if (hex[64] != SM9_Z256_HEX_SEP) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
if (sm9_z256_from_hex(r[0], hex + 65) != 1) {
|
||||
error_print();
|
||||
@@ -840,7 +840,7 @@ int sm9_z256_fp2_from_hex(sm9_z256_fp2_t r, const char hex[129])
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sm9_z256_fp2_to_hex(const sm9_z256_fp2_t a, char hex[129])
|
||||
void sm9_z256_fp2_to_hex(const sm9_z256_fp2_t a, char hex[64 * 2 + 1])
|
||||
{
|
||||
sm9_z256_t z;
|
||||
|
||||
@@ -1079,10 +1079,14 @@ int sm9_z256_fp4_equ(const sm9_z256_fp4_t a, const sm9_z256_fp4_t b)
|
||||
|
||||
int sm9_z256_fp4_rand(sm9_z256_fp4_t r)
|
||||
{
|
||||
if (sm9_z256_fp2_rand(r[1]) != 1
|
||||
|| sm9_z256_fp2_rand(r[0]) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
int ret;
|
||||
if ((ret = sm9_z256_fp2_rand(r[1])) != 1) {
|
||||
if (ret) error_print();
|
||||
return ret;
|
||||
}
|
||||
if ((ret = sm9_z256_fp2_rand(r[0])) != 1) {
|
||||
if (ret) error_print();
|
||||
return ret;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -1112,18 +1116,24 @@ int sm9_z256_fp4_from_bytes(sm9_z256_fp4_t r, const uint8_t buf[128])
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sm9_z256_fp4_from_hex(sm9_z256_fp4_t r, const char hex[65 * 4])
|
||||
int sm9_z256_fp4_from_hex(sm9_z256_fp4_t r, const char hex[64 * 4 + 3])
|
||||
{
|
||||
if (sm9_z256_fp2_from_hex(r[1], hex) != 1
|
||||
|| hex[129] != SM9_Z256_HEX_SEP
|
||||
|| sm9_z256_fp2_from_hex(r[0], hex + 130) != 1) {
|
||||
if (sm9_z256_fp2_from_hex(r[1], hex) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (hex[129] != SM9_Z256_HEX_SEP) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (sm9_z256_fp2_from_hex(r[0], hex + 130) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sm9_z256_fp4_to_hex(const sm9_z256_fp4_t a, char hex[259])
|
||||
void sm9_z256_fp4_to_hex(const sm9_z256_fp4_t a, char hex[64 * 4 + 3])
|
||||
{
|
||||
sm9_z256_fp2_to_hex(a[1], hex);
|
||||
hex[129] = SM9_Z256_HEX_SEP;
|
||||
@@ -1160,9 +1170,10 @@ void sm9_z256_fp4_haf(sm9_z256_fp4_t r, const sm9_z256_fp4_t a)
|
||||
sm9_z256_fp2_haf(r[1], a[1]);
|
||||
}
|
||||
|
||||
// (a0 + a1*v) * v = a0 * v + a1 * v^2 = a1 * u + a0 * v
|
||||
void sm9_z256_fp4_a_mul_v(sm9_z256_fp4_t r, sm9_z256_fp4_t a)
|
||||
{
|
||||
sm9_z256_fp2_t r0;
|
||||
sm9_z256_fp2_t r0; // incase r is a
|
||||
|
||||
sm9_z256_fp2_a_mul_u(r0, a[1]);
|
||||
|
||||
@@ -1284,6 +1295,7 @@ void sm9_z256_fp4_inv(sm9_z256_fp4_t r, const sm9_z256_fp4_t a)
|
||||
sm9_z256_fp2_copy(r[1], r1);
|
||||
}
|
||||
|
||||
|
||||
void sm9_z256_fp12_copy(sm9_z256_fp12_t r, const sm9_z256_fp12_t a)
|
||||
{
|
||||
sm9_z256_fp4_copy(r[0], a[0]);
|
||||
@@ -1293,10 +1305,18 @@ void sm9_z256_fp12_copy(sm9_z256_fp12_t r, const sm9_z256_fp12_t a)
|
||||
|
||||
int sm9_z256_fp12_rand(sm9_z256_fp12_t r)
|
||||
{
|
||||
if (sm9_z256_fp4_rand(r[0]) != 1
|
||||
|| sm9_z256_fp4_rand(r[1]) != 1
|
||||
|| sm9_z256_fp4_rand(r[2]) != 1) {
|
||||
error_print();
|
||||
int ret;
|
||||
|
||||
if ((ret = sm9_z256_fp4_rand(r[0])) != 1) {
|
||||
if (ret) error_print();
|
||||
return -1;
|
||||
}
|
||||
if ((ret = sm9_z256_fp4_rand(r[1])) != 1) {
|
||||
if (ret) error_print();
|
||||
return -1;
|
||||
}
|
||||
if ((ret = sm9_z256_fp4_rand(r[2])) != 1) {
|
||||
if (ret) error_print();
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
@@ -1316,7 +1336,7 @@ void sm9_z256_fp12_set_one(sm9_z256_fp12_t r)
|
||||
sm9_z256_fp4_copy(r[2], SM9_Z256_FP4_ZERO);
|
||||
}
|
||||
|
||||
int sm9_z256_fp12_from_hex(sm9_z256_fp12_t r, const char hex[65 * 12 - 1])
|
||||
int sm9_z256_fp12_from_hex(sm9_z256_fp12_t r, const char hex[64 * 12 + 11])
|
||||
{
|
||||
if (sm9_z256_fp4_from_hex(r[2], hex) != 1
|
||||
|| hex[65 * 4 - 1] != SM9_Z256_HEX_SEP
|
||||
@@ -1329,7 +1349,7 @@ int sm9_z256_fp12_from_hex(sm9_z256_fp12_t r, const char hex[65 * 12 - 1])
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sm9_z256_fp12_to_hex(const sm9_z256_fp12_t a, char hex[65 * 12 - 1])
|
||||
void sm9_z256_fp12_to_hex(const sm9_z256_fp12_t a, char hex[64 * 12 + 11])
|
||||
{
|
||||
sm9_z256_fp4_to_hex(a[2], hex);
|
||||
hex[65 * 4 - 1] = SM9_Z256_HEX_SEP;
|
||||
@@ -1345,7 +1365,7 @@ void sm9_z256_fp12_to_bytes(const sm9_z256_fp12_t a, uint8_t buf[32 * 12])
|
||||
sm9_z256_fp4_to_bytes(a[0], buf + 32 * 8);
|
||||
}
|
||||
|
||||
int sm9_z256_fp12_from_bytes(sm9_z256_fp12_t r, const uint8_t buf[128 * 3])
|
||||
int sm9_z256_fp12_from_bytes(sm9_z256_fp12_t r, const uint8_t buf[32 * 12])
|
||||
{
|
||||
if (sm9_z256_fp4_from_bytes(r[2], buf) != 1) {
|
||||
error_print();
|
||||
@@ -1740,7 +1760,7 @@ void sm9_z256_fp12_frobenius6(sm9_z256_fp12_t r, const sm9_z256_fp12_t x)
|
||||
sm9_z256_fp4_copy(r[2], c);
|
||||
}
|
||||
|
||||
int sm9_z256_point_from_hex(SM9_Z256_POINT *R, const char hex[65 * 2])
|
||||
int sm9_z256_point_from_hex(SM9_Z256_POINT *R, const char hex[64 * 2 + 1])
|
||||
{
|
||||
if (sm9_z256_from_hex(R->X, hex) != 1) {
|
||||
error_print();
|
||||
@@ -1752,7 +1772,10 @@ int sm9_z256_point_from_hex(SM9_Z256_POINT *R, const char hex[65 * 2])
|
||||
}
|
||||
sm9_z256_modp_to_mont(R->X, R->X);
|
||||
|
||||
// 检查分隔符
|
||||
if (hex[64] != SM9_Z256_HEX_SEP) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sm9_z256_from_hex(R->Y, hex + 65) != 1) {
|
||||
error_print();
|
||||
@@ -1952,9 +1975,9 @@ void sm9_z256_point_neg(SM9_Z256_POINT *R, const SM9_Z256_POINT *P)
|
||||
|
||||
void sm9_z256_point_sub(SM9_Z256_POINT *R, const SM9_Z256_POINT *P, const SM9_Z256_POINT *Q)
|
||||
{
|
||||
SM9_Z256_POINT _T, *T = &_T;
|
||||
sm9_z256_point_neg(T, Q);
|
||||
sm9_z256_point_add(R, P, T);
|
||||
SM9_Z256_POINT T;
|
||||
sm9_z256_point_neg(&T, Q);
|
||||
sm9_z256_point_add(R, P, &T);
|
||||
}
|
||||
|
||||
void sm9_z256_point_dbl_x5(SM9_Z256_POINT *R, const SM9_Z256_POINT *A)
|
||||
@@ -2028,16 +2051,16 @@ void sm9_z256_point_copy_affine(SM9_Z256_POINT *R, const SM9_Z256_AFFINE_POINT *
|
||||
|
||||
void sm9_z256_point_add_affine(SM9_Z256_POINT *R, const SM9_Z256_POINT *P, const SM9_Z256_AFFINE_POINT *Q)
|
||||
{
|
||||
SM9_Z256_POINT _S, *S = &_S;
|
||||
sm9_z256_point_copy_affine(S, Q);
|
||||
sm9_z256_point_add(R, P, S);
|
||||
SM9_Z256_POINT T;
|
||||
sm9_z256_point_copy_affine(&T, Q);
|
||||
sm9_z256_point_add(R, P, &T);
|
||||
}
|
||||
|
||||
void sm9_z256_point_sub_affine(SM9_Z256_POINT *R, const SM9_Z256_POINT *P, const SM9_Z256_AFFINE_POINT *Q)
|
||||
{
|
||||
SM9_Z256_POINT _S, *S = &_S;
|
||||
sm9_z256_point_copy_affine(S, Q);
|
||||
sm9_z256_point_sub(R, P, S);
|
||||
SM9_Z256_POINT T;
|
||||
sm9_z256_point_copy_affine(&T, Q);
|
||||
sm9_z256_point_sub(R, P, &T);
|
||||
}
|
||||
|
||||
extern const uint64_t sm9_z256_pre_comp[37][64 * 4 * 2];
|
||||
@@ -2088,7 +2111,7 @@ int sm9_z256_twist_point_print(FILE *fp, int fmt, int ind, const char *label, co
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sm9_z256_twist_point_from_hex(SM9_Z256_TWIST_POINT *R, const char hex[65 * 4])
|
||||
void sm9_z256_twist_point_from_hex(SM9_Z256_TWIST_POINT *R, const char hex[64 * 4 + 3])
|
||||
{
|
||||
sm9_z256_fp2_from_hex(R->X, hex);
|
||||
sm9_z256_fp2_from_hex(R->Y, hex + 65 * 2);
|
||||
@@ -2541,9 +2564,9 @@ void sm9_z256_pairing(sm9_z256_fp12_t r, const SM9_Z256_TWIST_POINT *Q, const SM
|
||||
{
|
||||
const char *abits = "00100000000000000000000000000000000000010000101100020200101000020";
|
||||
|
||||
SM9_Z256_TWIST_POINT _T, *T = &_T;
|
||||
SM9_Z256_TWIST_POINT _Q1, *Q1 = &_Q1;
|
||||
SM9_Z256_TWIST_POINT _Q2, *Q2 = &_Q2;
|
||||
SM9_Z256_TWIST_POINT T;
|
||||
SM9_Z256_TWIST_POINT Q1;
|
||||
SM9_Z256_TWIST_POINT Q2;
|
||||
|
||||
sm9_z256_fp12_t f_num;
|
||||
sm9_z256_fp12_t f_den;
|
||||
@@ -2551,7 +2574,7 @@ void sm9_z256_pairing(sm9_z256_fp12_t r, const SM9_Z256_TWIST_POINT *Q, const SM
|
||||
sm9_z256_fp12_t g_den;
|
||||
int i;
|
||||
|
||||
*T = *Q;
|
||||
T = *Q;
|
||||
|
||||
sm9_z256_fp12_set_one(f_num);
|
||||
sm9_z256_fp12_set_one(f_den);
|
||||
@@ -2559,38 +2582,38 @@ void sm9_z256_pairing(sm9_z256_fp12_t r, const SM9_Z256_TWIST_POINT *Q, const SM
|
||||
for (i = 0; i < strlen(abits); i++) {
|
||||
sm9_z256_fp12_sqr(f_num, f_num);
|
||||
sm9_z256_fp12_sqr(f_den, f_den);
|
||||
sm9_z256_eval_g_tangent(g_num, g_den, T, P);
|
||||
sm9_z256_eval_g_tangent(g_num, g_den, &T, P);
|
||||
sm9_z256_fp12_mul(f_num, f_num, g_num);
|
||||
sm9_z256_fp12_mul(f_den, f_den, g_den);
|
||||
|
||||
sm9_z256_twist_point_dbl(T, T);
|
||||
sm9_z256_twist_point_dbl(&T, &T);
|
||||
|
||||
if (abits[i] == '1') {
|
||||
sm9_z256_eval_g_line(g_num, g_den, T, Q, P);
|
||||
sm9_z256_eval_g_line(g_num, g_den, &T, Q, P);
|
||||
sm9_z256_fp12_mul(f_num, f_num, g_num);
|
||||
sm9_z256_fp12_mul(f_den, f_den, g_den);
|
||||
sm9_z256_twist_point_add_full(T, T, Q);
|
||||
sm9_z256_twist_point_add_full(&T, &T, Q);
|
||||
} else if (abits[i] == '2') {
|
||||
sm9_z256_twist_point_neg(Q1, Q);
|
||||
sm9_z256_eval_g_line(g_num, g_den, T, Q1, P);
|
||||
sm9_z256_twist_point_neg(&Q1, Q);
|
||||
sm9_z256_eval_g_line(g_num, g_den, &T, &Q1, P);
|
||||
sm9_z256_fp12_mul(f_num, f_num, g_num);
|
||||
sm9_z256_fp12_mul(f_den, f_den, g_den);
|
||||
sm9_z256_twist_point_add_full(T, T, Q1);
|
||||
sm9_z256_twist_point_add_full(&T, &T, &Q1);
|
||||
}
|
||||
}
|
||||
|
||||
sm9_z256_twist_point_pi1(Q1, Q);
|
||||
sm9_z256_twist_point_neg_pi2(Q2, Q);
|
||||
sm9_z256_twist_point_pi1(&Q1, Q);
|
||||
sm9_z256_twist_point_neg_pi2(&Q2, Q);
|
||||
|
||||
sm9_z256_eval_g_line(g_num, g_den, T, Q1, P);
|
||||
sm9_z256_eval_g_line(g_num, g_den, &T, &Q1, P);
|
||||
sm9_z256_fp12_mul(f_num, f_num, g_num);
|
||||
sm9_z256_fp12_mul(f_den, f_den, g_den);
|
||||
sm9_z256_twist_point_add_full(T, T, Q1);
|
||||
sm9_z256_twist_point_add_full(&T, &T, &Q1);
|
||||
|
||||
sm9_z256_eval_g_line(g_num, g_den, T, Q2, P);
|
||||
sm9_z256_eval_g_line(g_num, g_den, &T, &Q2, P);
|
||||
sm9_z256_fp12_mul(f_num, f_num, g_num);
|
||||
sm9_z256_fp12_mul(f_den, f_den, g_den);
|
||||
sm9_z256_twist_point_add_full(T, T, Q2);
|
||||
sm9_z256_twist_point_add_full(&T, &T, &Q2);
|
||||
|
||||
sm9_z256_fp12_inv(f_den, f_den);
|
||||
sm9_z256_fp12_mul(r, f_num, f_den);
|
||||
@@ -2825,10 +2848,24 @@ int sm9_z256_twist_point_to_uncompressed_octets(const SM9_Z256_TWIST_POINT *P, u
|
||||
|
||||
int sm9_z256_twist_point_from_uncompressed_octets(SM9_Z256_TWIST_POINT *P, const uint8_t octets[129])
|
||||
{
|
||||
assert(octets[0] == 0x04);
|
||||
sm9_z256_fp2_from_bytes(P->X, octets + 1);
|
||||
sm9_z256_fp2_from_bytes(P->Y, octets + 32 * 2 + 1);
|
||||
if (octets[0] != 0x04) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sm9_z256_fp2_from_bytes(P->X, octets + 1) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (sm9_z256_fp2_from_bytes(P->Y, octets + 32 * 2 + 1) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
sm9_z256_fp2_set_one(P->Z);
|
||||
if (!sm9_z256_twist_point_is_on_curve(P)) return -1;
|
||||
|
||||
if (!sm9_z256_twist_point_is_on_curve(P)) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -115,20 +115,20 @@ err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define hex_iv2 "123456789abcdef00fedcba987654321123456789abcdef00fedcba987654321-a39654024e243d806e492768664a2b72d632457dd14f49a9f1fdd299c9bb073c"
|
||||
#define hex_fp2_add "0074a3145c65ac547541612178e584a902248740e70606dcaaafe2bcbd2f6a21-1b6ac9eb2c47b62cf61608b26c3c7e20674a48c4c509ac130bbaf6d47d32c07c"
|
||||
#define hex_fp2_dbl "2ea136125d08b824cd741a4c597dcdda0e6d52df468f917b0adb8ed709d7d72c-995e51aa30d8d45ae85f34da84c0589f6dece1e633b92146debbdc23afe20a11"
|
||||
#define hex_fp2_tri "45f1d11b8b8d1437342e2772863cb4c715a3fc4ee9d75a38904956428ec3c2c2-8aed7a7f47f36b0f718cf99fcc59214c93ea0933c0583a7c5b61fca1962a6c5b"
|
||||
#define hex_fp2_sub "2e2c92fe00a30bd05832b92ae09849310c48cb9e5f898a9e602bac1a4ca86d0b-7df387bf04911e2df2492c281883da7f06a299216eaf7533d300e54f32af4995"
|
||||
#define hex_fp2_neg "9eef64f6d41f4adf6f499e29c8cfe0581abbe9db7733261e6001d3bc5e6559e7-0e70d72ae8e5694b76d23b3ab8673752da02d8b27360e6ca8359df8219b79db6"
|
||||
#define hex_fp2_mul "192eb5c3350a03e4baf23dd035b8804af8d5189c710adda53edd9cc0633f2d67-27fe3a559abcc3e1b1fc3f1eb35b4bd5e465f0ef2bcb9997b36e3548637456b6"
|
||||
#define hex_fp2_mul_u "27fe3a559abcc3e1b1fc3f1eb35b4bd5e465f0ef2bcb9997b36e3548637456b6-83e29479988f9f28601f2faf8a1dc6af304862123865339167b461a71cd2eaaf"
|
||||
#define hex_fp2_mul_fp "546e5945201b73c6ae44053114761efe351d5884c737301cfc7d2376d349a616-3c2f6327ef1c5aa1d06e8cebc4100f0758c04476f40e8a0facb0a0bf09a9dd42"
|
||||
#define hex_fp2_sqr "8896d4306fb19d0e4a0e09899240e35cafed70bebb3ad56cf7b07964fefdfb93-16bd622a907d7a92e475ed336e8ebca2cc1e38dd2ae69aaf2a96208eba0ee06e"
|
||||
#define hex_fp2_sqr_u "16bd622a907d7a92e475ed336e8ebca2cc1e38dd2ae69aaf2a96208eba0ee06e-5b52579f25e413c717eb438cc69bc7d0e40a4518be8032dddb7e4385c8a693d4"
|
||||
#define hex_fp2_inv "93ceda7dddd537eb9307a06313598e650a568d931d16ab98ca0a7483c3b502e2-6face8b958e2bdc0771fd9d700f2703f881ef0d13509f16937f0a0c344647175"
|
||||
#define hex_fp2_div "ad68ff7c507f2d4e1cc6cd973c6b821906b9f5937a04fdedc84af1f75f97d00b-8a84a35da11d401c8dca50a572ce7a8c99e7117c45d251f57a2418613dab16bb"
|
||||
#define hex_fp2_haf "0ba84d8497422e09335d0693165f7376839b54b7d1a3e45ec2b6e3b5c275f5cb-af07946a8e30f24c1a9a8db2995b2b9bb4f126f1e0ca7b76a3c2ab66d67576a2"
|
||||
#define hex_iv2 "123456789abcdef00fedcba987654321123456789abcdef00fedcba987654321\na39654024e243d806e492768664a2b72d632457dd14f49a9f1fdd299c9bb073c"
|
||||
#define hex_fp2_add "0074a3145c65ac547541612178e584a902248740e70606dcaaafe2bcbd2f6a21\n1b6ac9eb2c47b62cf61608b26c3c7e20674a48c4c509ac130bbaf6d47d32c07c"
|
||||
#define hex_fp2_dbl "2ea136125d08b824cd741a4c597dcdda0e6d52df468f917b0adb8ed709d7d72c\n995e51aa30d8d45ae85f34da84c0589f6dece1e633b92146debbdc23afe20a11"
|
||||
#define hex_fp2_tri "45f1d11b8b8d1437342e2772863cb4c715a3fc4ee9d75a38904956428ec3c2c2\n8aed7a7f47f36b0f718cf99fcc59214c93ea0933c0583a7c5b61fca1962a6c5b"
|
||||
#define hex_fp2_sub "2e2c92fe00a30bd05832b92ae09849310c48cb9e5f898a9e602bac1a4ca86d0b\n7df387bf04911e2df2492c281883da7f06a299216eaf7533d300e54f32af4995"
|
||||
#define hex_fp2_neg "9eef64f6d41f4adf6f499e29c8cfe0581abbe9db7733261e6001d3bc5e6559e7\n0e70d72ae8e5694b76d23b3ab8673752da02d8b27360e6ca8359df8219b79db6"
|
||||
#define hex_fp2_mul "192eb5c3350a03e4baf23dd035b8804af8d5189c710adda53edd9cc0633f2d67\n27fe3a559abcc3e1b1fc3f1eb35b4bd5e465f0ef2bcb9997b36e3548637456b6"
|
||||
#define hex_fp2_mul_u "27fe3a559abcc3e1b1fc3f1eb35b4bd5e465f0ef2bcb9997b36e3548637456b6\n83e29479988f9f28601f2faf8a1dc6af304862123865339167b461a71cd2eaaf"
|
||||
#define hex_fp2_mul_fp "546e5945201b73c6ae44053114761efe351d5884c737301cfc7d2376d349a616\n3c2f6327ef1c5aa1d06e8cebc4100f0758c04476f40e8a0facb0a0bf09a9dd42"
|
||||
#define hex_fp2_sqr "8896d4306fb19d0e4a0e09899240e35cafed70bebb3ad56cf7b07964fefdfb93\n16bd622a907d7a92e475ed336e8ebca2cc1e38dd2ae69aaf2a96208eba0ee06e"
|
||||
#define hex_fp2_sqr_u "16bd622a907d7a92e475ed336e8ebca2cc1e38dd2ae69aaf2a96208eba0ee06e\n5b52579f25e413c717eb438cc69bc7d0e40a4518be8032dddb7e4385c8a693d4"
|
||||
#define hex_fp2_inv "93ceda7dddd537eb9307a06313598e650a568d931d16ab98ca0a7483c3b502e2\n6face8b958e2bdc0771fd9d700f2703f881ef0d13509f16937f0a0c344647175"
|
||||
#define hex_fp2_div "ad68ff7c507f2d4e1cc6cd973c6b821906b9f5937a04fdedc84af1f75f97d00b\n8a84a35da11d401c8dca50a572ce7a8c99e7117c45d251f57a2418613dab16bb"
|
||||
#define hex_fp2_haf "0ba84d8497422e09335d0693165f7376839b54b7d1a3e45ec2b6e3b5c275f5cb\naf07946a8e30f24c1a9a8db2995b2b9bb4f126f1e0ca7b76a3c2ab66d67576a2"
|
||||
|
||||
int test_sm9_z256_fp2() {
|
||||
const SM9_Z256_TWIST_POINT _P2 = {
|
||||
@@ -362,14 +362,36 @@ err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define hex_point1 "917be49d159184fba140f4dfc5d653464e94f718fe195b226b3f715829e6e768-288578d9505d462867a50acee40ee143b896e72505be10e8ce4c6b0c945b642b"
|
||||
#define hex_point2 "593417680f252445fd0522383e23c77a54b11fe222de4a886eabc26e16bffa3c-38e8fc9a8b60f5ba0c6c411f721c117044435a833757d8fee65828511b8b245d"
|
||||
#define hex_point_dbl "268def7968f1e8c51635e277425403df88355fb2ecf16f7920f112eb2a7e50c9-5c596b534bbaa85c1d3aecf436e61ff1bfd9f70856f0309c2a63d8248205d84e"
|
||||
#define hex_point_add "056610cb69f8d5659ea94e4a67bbf3b93fb0bd449672d7ca2525ec3b68c894d1-88f3f99ce78ed3ffe6ca1cface5242570cb5d053f16a8e0baae10414babd86a7"
|
||||
#define hex_point_neg "917be49d159184fba140f4dfc5d653464e94f718fe195b226b3f715829e6e768-8dba8726b24660c96e5ea081117fe601695bac2614bcddf31723301b4ef5e152"
|
||||
#define hex_point_sub "29e4a54cad98da9939b95f677784bff3b1dd9334c83d93e351e0f8f7c4ce2dc5-4473eba3b8ff990b8456c41ec0727b76cb2b0f960495b144949f70bf95643b82"
|
||||
#define hex_point_mul "997fcff625adbae62566f684f9e89181713f972c5a9cd9ce6764636761ba87d1-8142a28d1bd109501452a649e2d68f012e265460e0c7d3da743fb036eb23b03b"
|
||||
#define hex_point_mul_g "7cf689748f3714490d7a19eae0e7bfad0e0182498b7bcd8a6998dfd00f59be51-4e2e98d190e9d775e0caa943196bfb066d9c30818b2d768fb5299e7135830a6f"
|
||||
#define hex_point1 \
|
||||
"917be49d159184fba140f4dfc5d653464e94f718fe195b226b3f715829e6e768\n" \
|
||||
"288578d9505d462867a50acee40ee143b896e72505be10e8ce4c6b0c945b642b"
|
||||
|
||||
#define hex_point2 \
|
||||
"593417680f252445fd0522383e23c77a54b11fe222de4a886eabc26e16bffa3c\n" \
|
||||
"38e8fc9a8b60f5ba0c6c411f721c117044435a833757d8fee65828511b8b245d"
|
||||
|
||||
#define hex_point_dbl \
|
||||
"268def7968f1e8c51635e277425403df88355fb2ecf16f7920f112eb2a7e50c9\n" \
|
||||
"5c596b534bbaa85c1d3aecf436e61ff1bfd9f70856f0309c2a63d8248205d84e"
|
||||
|
||||
#define hex_point_add \
|
||||
"056610cb69f8d5659ea94e4a67bbf3b93fb0bd449672d7ca2525ec3b68c894d1\n" \
|
||||
"88f3f99ce78ed3ffe6ca1cface5242570cb5d053f16a8e0baae10414babd86a7"
|
||||
|
||||
#define hex_point_neg \
|
||||
"917be49d159184fba140f4dfc5d653464e94f718fe195b226b3f715829e6e768\n" \
|
||||
"8dba8726b24660c96e5ea081117fe601695bac2614bcddf31723301b4ef5e152"
|
||||
|
||||
#define hex_point_sub \
|
||||
"29e4a54cad98da9939b95f677784bff3b1dd9334c83d93e351e0f8f7c4ce2dc5\n" \
|
||||
"4473eba3b8ff990b8456c41ec0727b76cb2b0f960495b144949f70bf95643b82"
|
||||
#define hex_point_mul \
|
||||
"997fcff625adbae62566f684f9e89181713f972c5a9cd9ce6764636761ba87d1\n" \
|
||||
"8142a28d1bd109501452a649e2d68f012e265460e0c7d3da743fb036eb23b03b"
|
||||
|
||||
#define hex_point_mul_g \
|
||||
"7cf689748f3714490d7a19eae0e7bfad0e0182498b7bcd8a6998dfd00f59be51\n" \
|
||||
"4e2e98d190e9d775e0caa943196bfb066d9c30818b2d768fb5299e7135830a6f"
|
||||
|
||||
int test_sm9_z256_point() {
|
||||
SM9_Z256_POINT p;
|
||||
|
||||
Reference in New Issue
Block a user