From 75bac76b901d2ba48aae427924a1242e857b9875 Mon Sep 17 00:00:00 2001 From: libo Date: Mon, 2 Feb 2026 16:29:47 +0800 Subject: [PATCH] fix(sm2): fix compressed point output writing y instead of x In sm2_z256_point_to_compressed_octets(), the compressed point format should be: [1-byte flag] + [32-byte x-coordinate] The flag indicates y's parity (0x02=even, 0x03=odd), but the actual coordinate stored should be x (since y can be recovered from x using the curve equation). The original code incorrectly wrote y-coordinate instead of x-coordinate. --- src/sm2_z256.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sm2_z256.c b/src/sm2_z256.c index e6ff43f9..0ff023aa 100644 --- a/src/sm2_z256.c +++ b/src/sm2_z256.c @@ -1865,7 +1865,7 @@ int sm2_z256_point_to_compressed_octets(const SM2_Z256_POINT *P, uint8_t out[33] } else { out[0] = SM2_point_compressed_y_even; } - sm2_z256_to_bytes(y, out + 1); + sm2_z256_to_bytes(x, out + 1); return 1; }