From 90c022c803ff378df63a5dc583925d2b817ced1a Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Sun, 19 Feb 2023 08:24:17 +0800 Subject: [PATCH] Add sm2_point_ functions --- include/gmssl/sm2.h | 5 ++++- src/sm2_alg.c | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/gmssl/sm2.h b/include/gmssl/sm2.h index 44888758..1d39fde0 100644 --- a/include/gmssl/sm2.h +++ b/include/gmssl/sm2.h @@ -164,13 +164,16 @@ typedef struct { uint8_t y[32]; } SM2_POINT; +#define sm2_point_init(P) memset((P),0,sizeof(SM2_POINT)) +#define sm2_point_set_infinity(P) sm2_point_init(P) +int sm2_point_from_octets(SM2_POINT *P, const uint8_t *in, size_t inlen); void sm2_point_to_compressed_octets(const SM2_POINT *P, uint8_t out[33]); void sm2_point_to_uncompressed_octets(const SM2_POINT *P, uint8_t out[65]); -int sm2_point_from_octets(SM2_POINT *P, const uint8_t *in, size_t inlen); int sm2_point_from_x(SM2_POINT *P, const uint8_t x[32], int y); int sm2_point_from_xy(SM2_POINT *P, const uint8_t x[32], const uint8_t y[32]); int sm2_point_is_on_curve(const SM2_POINT *P); +int sm2_point_is_at_infinity(const SM2_POINT *P); int sm2_point_add(SM2_POINT *R, const SM2_POINT *P, const SM2_POINT *Q); int sm2_point_sub(SM2_POINT *R, const SM2_POINT *P, const SM2_POINT *Q); int sm2_point_neg(SM2_POINT *R, const SM2_POINT *P); diff --git a/src/sm2_alg.c b/src/sm2_alg.c index 8364a8ab..1865eaf4 100644 --- a/src/sm2_alg.c +++ b/src/sm2_alg.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1088,6 +1089,11 @@ int sm2_point_is_on_curve(const SM2_POINT *P) return sm2_jacobian_point_is_on_curve(&T); } +int sm2_point_is_at_infinity(const SM2_POINT *P) +{ + return mem_is_zero((uint8_t *)P, sizeof(SM2_POINT)); +} + int sm2_point_from_x(SM2_POINT *P, const uint8_t x[32], int y) { SM2_BN _x, _y, _g, _z;