Skip to content

Commit

Permalink
internal/sm2ec: add boundary test
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Jul 28, 2023
1 parent ca474a6 commit c813a1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions internal/sm2ec/sm2p256_asm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sm9/bn256/gfp2_g1_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c813a1f

Please sign in to comment.