check arm64 mul

This commit is contained in:
Sun Yimin 2022-06-14 12:13:27 +08:00 committed by GitHub
parent 4c532200a9
commit dcb4dadd47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,6 +58,7 @@ func Test_gfpBasicOperations(t *testing.T) {
expectedSub := fromBigInt(bigFromHex("67b381821c52a5624f3304a8149be8461e3bc07adcb872c38aa65051ba53ba97")) expectedSub := fromBigInt(bigFromHex("67b381821c52a5624f3304a8149be8461e3bc07adcb872c38aa65051ba53ba97"))
expectedNeg := fromBigInt(bigFromHex("7f1d8aad70909be90358f1d02240062433cc3a0248ded72febb879ec33ce6f22")) expectedNeg := fromBigInt(bigFromHex("7f1d8aad70909be90358f1d02240062433cc3a0248ded72febb879ec33ce6f22"))
expectedMul := fromBigInt(bigFromHex("3d08bbad376584e4f74bd31f78f716372b96ba8c3f939c12b8d54e79b6489e76")) expectedMul := fromBigInt(bigFromHex("3d08bbad376584e4f74bd31f78f716372b96ba8c3f939c12b8d54e79b6489e76"))
expectedMul2 := fromBigInt(bigFromHex("1df94a9e05a559ff38e0ab50cece734dc058d33738ceacaa15986a67cbff1ef6"))
ret := &gfP{} ret := &gfP{}
gfpAdd(ret, x, y) gfpAdd(ret, x, y)
@ -79,6 +80,11 @@ func Test_gfpBasicOperations(t *testing.T) {
if *expectedMul != *ret { if *expectedMul != *ret {
t.Errorf("mul not same") t.Errorf("mul not same")
} }
gfpMul(ret, ret, ret)
if *expectedMul2 != *ret {
t.Errorf("mul not same")
}
} }
func TestGfpExp(t *testing.T) { func TestGfpExp(t *testing.T) {
@ -98,6 +104,13 @@ func TestGfpExp(t *testing.T) {
t.Errorf("exp not same, got %v, expected %v\n", ret, hex.EncodeToString(ret2.Bytes())) t.Errorf("exp not same, got %v, expected %v\n", ret, hex.EncodeToString(ret2.Bytes()))
} }
ret1 := &gfP{}
ret1.exp2(x, bigFromHex("b640000002a3a6f1d603ab4ff58ec74521f2934b1a7aeedbe56f9b27e351457b"))
montDecode(ret1, ret1)
if hex.EncodeToString(ret2.Bytes()) != ret1.String() {
t.Errorf("exp not same, got %v, expected %v\n", ret1, hex.EncodeToString(ret2.Bytes()))
}
xInv := new(big.Int).ModInverse(xI, p) xInv := new(big.Int).ModInverse(xI, p)
if hex.EncodeToString(ret2.Bytes()) != hex.EncodeToString(xInv.Bytes()) { if hex.EncodeToString(ret2.Bytes()) != hex.EncodeToString(xInv.Bytes()) {
t.Errorf("exp not same, got %v, expected %v\n", hex.EncodeToString(ret2.Bytes()), hex.EncodeToString(xInv.Bytes())) t.Errorf("exp not same, got %v, expected %v\n", hex.EncodeToString(ret2.Bytes()), hex.EncodeToString(xInv.Bytes()))