From b4af5cc942127847a811e4649a165f8a4ef7b9ce Mon Sep 17 00:00:00 2001 From: bytemare <3641580+bytemare@users.noreply.github.com> Date: Tue, 1 Oct 2024 18:10:01 +0200 Subject: [PATCH] some clean up in the nist field methods Signed-off-by: bytemare <3641580+bytemare@users.noreply.github.com> --- internal/field/field.go | 20 -------------------- internal/nist/scalar.go | 7 +++---- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/internal/field/field.go b/internal/field/field.go index 978c013..74f596e 100644 --- a/internal/field/field.go +++ b/internal/field/field.go @@ -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 { @@ -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) @@ -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 diff --git a/internal/nist/scalar.go b/internal/nist/scalar.go index 7d71697..dc536a4 100644 --- a/internal/nist/scalar.go +++ b/internal/nist/scalar.go @@ -30,7 +30,6 @@ func newScalar(f *field.Field) *Scalar { field: f, scalar: big.Int{}, } - s.scalar.Set(s.field.Zero()) return s } @@ -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 } @@ -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.