diff --git a/driver/amcl/fp256bn.go b/driver/amcl/fp256bn.go index 2337573..4926635 100644 --- a/driver/amcl/fp256bn.go +++ b/driver/amcl/fp256bn.go @@ -235,7 +235,7 @@ func (b *fp256bnG1) String() string { } func (e *fp256bnG1) Neg() { - res := e.Mul(NewFp256bn().NewZrFromInt(-1)) + res := e.Mul(NewFp256bn().NewZrFromInt64(-1)) e.ECP = res.(*fp256bnG1).ECP } diff --git a/driver/common/curve.go b/driver/common/curve.go index 79cd10e..cb65333 100644 --- a/driver/common/curve.go +++ b/driver/common/curve.go @@ -61,10 +61,14 @@ func (c *CurveBase) NewZrFromBytes(b []byte) driver.Zr { return res } -func (c *CurveBase) NewZrFromInt(i int64) driver.Zr { +func (c *CurveBase) NewZrFromInt64(i int64) driver.Zr { return &BaseZr{Int: *big.NewInt(i), Modulus: c.Modulus} } +func (c *CurveBase) NewZrFromUint64(i uint64) driver.Zr { + return &BaseZr{Int: *new(big.Int).SetUint64(i), Modulus: c.Modulus} +} + func (c *CurveBase) NewRandomZr(rng io.Reader) driver.Zr { bi, err := rand.Int(rng, &c.Modulus) if err != nil { diff --git a/driver/math.go b/driver/math.go index 152c840..a7ccff5 100644 --- a/driver/math.go +++ b/driver/math.go @@ -29,7 +29,8 @@ type Curve interface { NewG1() G1 NewG2() G2 NewZrFromBytes(b []byte) Zr - NewZrFromInt(i int64) Zr + NewZrFromInt64(i int64) Zr + NewZrFromUint64(i uint64) Zr NewG1FromBytes(b []byte) G1 NewG1FromCompressed(b []byte) G1 NewG2FromBytes(b []byte) G2 diff --git a/math.go b/math.go index 71ee8a0..d69cbfa 100644 --- a/math.go +++ b/math.go @@ -480,7 +480,11 @@ func (c *Curve) NewGtFromBytes(b []byte) (p *Gt, err error) { } func (c *Curve) NewZrFromInt(i int64) *Zr { - return &Zr{zr: c.c.NewZrFromInt(i), curveID: c.curveID} + return &Zr{zr: c.c.NewZrFromInt64(i), curveID: c.curveID} +} + +func (c *Curve) NewZrFromUint64(i uint64) *Zr { + return &Zr{zr: c.c.NewZrFromUint64(i), curveID: c.curveID} } func (c *Curve) NewG2() *G2 { diff --git a/math_test.go b/math_test.go index a6993b3..530e61f 100644 --- a/math_test.go +++ b/math_test.go @@ -124,6 +124,11 @@ func runZrTest(t *testing.T, c *Curve) { rng, err := c.Rand() assert.NoError(t, err) + maxint64 := c.NewZrFromInt(math.MaxInt64) + maxuint64 := c.NewZrFromUint64(math.MaxUint64) + assert.Equal(t, fmt.Sprintf("%x", math.MaxInt64), maxint64.String()) + assert.Equal(t, fmt.Sprintf("%x", uint64(math.MaxUint64)), maxuint64.String()) + // serialising and deserialising negative numbers rr := c.NewRandomZr(rng) rr1 := rr.Copy()