Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
some clean up in the nist field methods
Browse files Browse the repository at this point in the history
Signed-off-by: bytemare <[email protected]>
  • Loading branch information
bytemare committed Oct 1, 2024
1 parent c695d4a commit b4af5cc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
20 changes: 0 additions & 20 deletions internal/field/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import (
"math/big"
)

var (
zero = big.NewInt(0)
one = big.NewInt(1)
)

// String2Int returns a big.Int representation of the integer s.
func String2Int(s string) big.Int {
if p, _ := new(big.Int).SetString(s, 0); p != nil {
Expand Down Expand Up @@ -63,16 +58,6 @@ func NewField(prime *big.Int) Field {
}
}

// Zero returns the zero big.Int of the finite Field.
func (f Field) Zero() *big.Int {
return zero
}

// One returns one big.Int of the finite Field.
func (f Field) One() *big.Int {
return one
}

// Random sets res to a random big.Int in the Field.
func (f Field) Random(res *big.Int) *big.Int {
tmp, err := rand.Int(rand.Reader, f.order)
Expand All @@ -96,11 +81,6 @@ func (f Field) ByteLen() int {
return f.byteLen
}

// AreEqual returns whether both elements are equal.
func (f Field) AreEqual(f1, f2 *big.Int) bool {
return f.IsZero(f.Sub(&big.Int{}, f1, f2))
}

// IsZero returns whether the big.Int is equivalent to zero.
func (f Field) IsZero(e *big.Int) bool {
return e.Sign() == 0
Expand Down
7 changes: 3 additions & 4 deletions internal/nist/scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func newScalar(f *field.Field) *Scalar {
field: f,
scalar: big.Int{},
}
s.scalar.Set(s.field.Zero())

return s
}
Expand Down Expand Up @@ -64,13 +63,13 @@ func (s *Scalar) Group() byte {

// Zero sets s to 0, and returns it.
func (s *Scalar) Zero() internal.Scalar {
s.scalar.Set(s.field.Zero())
s.scalar.Set(big.NewInt(0))
return s
}

// One sets s to 1, and returns it.
func (s *Scalar) One() internal.Scalar {
s.scalar.Set(s.field.One())
s.scalar.Set(big.NewInt(1))
return s
}

Expand Down Expand Up @@ -182,7 +181,7 @@ func (s *Scalar) LessOrEqual(scalar internal.Scalar) int {

// IsZero returns whether the scalar is 0.
func (s *Scalar) IsZero() bool {
return s.field.AreEqual(&s.scalar, s.field.Zero())
return s.field.IsZero(&s.scalar)
}

// Set sets the receiver to the value of the argument scalar, and returns the receiver.
Expand Down

0 comments on commit b4af5cc

Please sign in to comment.