fix test cases

This commit is contained in:
Sun Yimin 2024-08-23 15:25:42 +08:00 committed by GitHub
parent eea60eea91
commit 223d593817
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -47,7 +47,7 @@ func testP256FromMont(v *big.Int, t *testing.T) {
res := new(p256Element)
p256FromMont(res, val)
if toBigInt(res).Cmp(v) != 0 {
t.Fatalf("p256FromMont failed for %v", v)
t.Fatalf("p256FromMont failed for %x", v.Bytes())
}
}
@ -61,12 +61,12 @@ func TestP256FromMont(t *testing.T) {
}
}
func testP256OrderReduce(v *big.Int, t *testing.T) {
func testP256OrderReduce(v, expected *big.Int, t *testing.T) {
val := new(p256OrdElement)
montFromBig((*[4]uint64)(val), v)
fromBig((*[4]uint64)(val), v)
p256OrdReduce(val)
if ordElmToBigInt(val).Cmp(v) != 0 {
t.Fatalf("p256OrdReduce failed for %v", v)
if ordElmToBigInt(val).Cmp(expected) != 0 {
t.Fatalf("p256OrdReduce failed for %x", v.Bytes())
}
}
@ -75,8 +75,10 @@ func TestP256OrderReduce(t *testing.T) {
p, _ := new(big.Int).SetString("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", 16)
for i := 0; i < 20; i++ {
bigVal := big.NewInt(int64(i))
testP256OrderReduce(bigVal, t)
testP256OrderReduce(bigVal, bigVal, t)
bigVal = new(big.Int).Sub(p, big.NewInt(int64(i)))
testP256OrderReduce(bigVal, t)
testP256OrderReduce(bigVal, bigVal, t)
bigVal = new(big.Int).Add(p, big.NewInt(int64(i)))
testP256OrderReduce(bigVal, big.NewInt(int64(i)), t)
}
}