From c813a1fb65b10beee483d7c8c08cfc9205571e73 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Fri, 28 Jul 2023 15:26:42 +0800 Subject: [PATCH] internal/sm2ec: add boundary test --- internal/sm2ec/sm2p256_asm_test.go | 14 ++++++++++++++ sm9/bn256/gfp2_g1_amd64.s | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/sm2ec/sm2p256_asm_test.go b/internal/sm2ec/sm2p256_asm_test.go index 452d879..f467825 100644 --- a/internal/sm2ec/sm2p256_asm_test.go +++ b/internal/sm2ec/sm2p256_asm_test.go @@ -51,6 +51,13 @@ func p256MulTest(t *testing.T, x, y, p, r *big.Int) { } } +func TestP256MulPMinus1(t *testing.T) { + p, _ := new(big.Int).SetString("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16) + r, _ := new(big.Int).SetString("10000000000000000000000000000000000000000000000000000000000000000", 16) + pMinus1 := new(big.Int).Sub(p, big.NewInt(1)) + p256MulTest(t, pMinus1, pMinus1, p, r) +} + func TestFuzzyP256Mul(t *testing.T) { p, _ := new(big.Int).SetString("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16) r, _ := new(big.Int).SetString("10000000000000000000000000000000000000000000000000000000000000000", 16) @@ -95,6 +102,13 @@ func p256SqrTest(t *testing.T, x, p, r *big.Int) { } } +func TestP256SqrPMinus1(t *testing.T) { + p, _ := new(big.Int).SetString("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16) + r, _ := new(big.Int).SetString("10000000000000000000000000000000000000000000000000000000000000000", 16) + pMinus1 := new(big.Int).Sub(p, big.NewInt(1)) + p256SqrTest(t, pMinus1, p, r) +} + func TestFuzzyP256Sqr(t *testing.T) { p, _ := new(big.Int).SetString("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16) r, _ := new(big.Int).SetString("10000000000000000000000000000000000000000000000000000000000000000", 16) diff --git a/sm9/bn256/gfp2_g1_amd64.s b/sm9/bn256/gfp2_g1_amd64.s index d30f4e5..82f4996 100644 --- a/sm9/bn256/gfp2_g1_amd64.s +++ b/sm9/bn256/gfp2_g1_amd64.s @@ -90,7 +90,7 @@ TEXT gfpMulInternal(SB),NOSPLIT,$8 ADDQ mul0, acc4 ADCQ $0, acc5 - // [t3, t2, t1, t0] * acc5 + // [t3, t2, t1, t0] * acc6 MOVQ acc6, mul1 MULXQ t0, mul0, hlp ADDQ mul0, acc2