From d8b4348736af02414491230c7a6134ebfb09c802 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Thu, 20 Oct 2022 17:52:26 +0800 Subject: [PATCH] Update sm2_lib.c --- src/sm2_lib.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/sm2_lib.c b/src/sm2_lib.c index 8557d466..ea9d54d3 100644 --- a/src/sm2_lib.c +++ b/src/sm2_lib.c @@ -146,6 +146,23 @@ int sm2_do_verify(const SM2_KEY *key, const uint8_t dgst[32], const SM2_SIGNATUR return 1; } +// verify the xR of R = s * G + (s + r) * P +// so (-r, -s) is also a valid SM2 signature +int sm2_signature_conjugate(const SM2_SIGNATURE *sig, SM2_SIGNATURE *new_sig) +{ + SM2_Fn r; + SM2_Fn s; + + sm2_bn_from_bytes(r, sig->r); + sm2_bn_from_bytes(s, sig->s); + sm2_fn_neg(r, r); + sm2_fn_neg(s, s); + sm2_bn_to_bytes(r, new_sig->r); + sm2_bn_to_bytes(s, new_sig->s); + + return 1; +} + int sm2_signature_to_der(const SM2_SIGNATURE *sig, uint8_t **out, size_t *outlen) { size_t len = 0;