Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion driver/amcl/fp256bn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 5 additions & 1 deletion driver/common/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion driver/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion math.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading