mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 12:16:20 +08:00
try again
This commit is contained in:
parent
4f2585ddbc
commit
4c532200a9
@ -82,30 +82,42 @@ func Test_gfpBasicOperations(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGfpExp(t *testing.T) {
|
||||
xI := bigFromHex("85AEF3D078640C98597B6027B441A01FF1DD2C190F5E93C454806C11D8806141")
|
||||
xI := bigFromHex("9093a2b979e6186f43a9b28d41ba644d533377f2ede8c66b19774bf4a9c7a596")
|
||||
x := fromBigInt(xI)
|
||||
ret := &gfP{}
|
||||
ret, ret3 := &gfP{}, &gfP{}
|
||||
ret.exp(x, pMinus2)
|
||||
|
||||
ret1 := &gfP{}
|
||||
ret1.exp2(x, bigFromHex("b640000002a3a6f1d603ab4ff58ec74521f2934b1a7aeedbe56f9b27e351457b"))
|
||||
if ret1.String() == ret.String() {
|
||||
t.Errorf("exp not same")
|
||||
gfpMul(ret3, x, ret)
|
||||
if *ret3 != *one {
|
||||
t.Errorf("got %v, expected %v\n", ret3, one)
|
||||
}
|
||||
montDecode(ret, ret)
|
||||
|
||||
ret2 := new(big.Int).Exp(xI, bigFromHex("b640000002a3a6f1d603ab4ff58ec74521f2934b1a7aeedbe56f9b27e351457b"), p)
|
||||
if hex.EncodeToString(ret2.Bytes()) == ret.String() {
|
||||
t.Errorf("exp not same")
|
||||
if hex.EncodeToString(ret2.Bytes()) != ret.String() {
|
||||
t.Errorf("exp not same, got %v, expected %v\n", ret, hex.EncodeToString(ret2.Bytes()))
|
||||
}
|
||||
|
||||
xInv := new(big.Int).ModInverse(xI, p)
|
||||
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()))
|
||||
}
|
||||
|
||||
x2 := new(big.Int).Mul(xI, xInv)
|
||||
x2.Mod(x2, p)
|
||||
if big.NewInt(1).Cmp(x2) != 0 {
|
||||
t.Errorf("not same")
|
||||
}
|
||||
|
||||
xInvGfp := fromBigInt(xInv)
|
||||
gfpMul(ret, x, xInvGfp)
|
||||
if *ret != *one {
|
||||
t.Errorf("got %v, expected %v", ret, one)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGfpInvert(t *testing.T) {
|
||||
x := fromBigInt(bigFromHex("9093a2b979e6186f43a9b28d41ba644d533377f2ede8c66b19774bf4a9c7a596"))
|
||||
x := fromBigInt(bigFromHex("85AEF3D078640C98597B6027B441A01FF1DD2C190F5E93C454806C11D8806141"))
|
||||
xInv := &gfP{}
|
||||
xInv.Invert(x)
|
||||
y := &gfP{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user