Skip to content

Commit

Permalink
Adds a method to retrieve the group.
Browse files Browse the repository at this point in the history
  • Loading branch information
armfazh committed Jul 29, 2022
1 parent 033f07b commit c8971c0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Group interface {

// Element represents an abstract element of a prime-order group.
type Element interface {
Group() Group
Set(Element) Element
Copy() Element
IsIdentity() bool
Expand All @@ -47,6 +48,7 @@ type Element interface {

// Scalar represents an integer scalar.
type Scalar interface {
Group() Group
Set(Scalar) Scalar
Copy() Scalar
IsEqual(Scalar) bool
Expand Down
3 changes: 3 additions & 0 deletions group/ristretto255.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func (g ristrettoGroup) HashToScalar(msg, dst []byte) Scalar {
return s
}

func (e *ristrettoElement) Group() Group { return Ristretto255 }

func (e *ristrettoElement) IsIdentity() bool {
var zero r255.Point
zero.SetZero()
Expand Down Expand Up @@ -181,6 +183,7 @@ func (e *ristrettoElement) UnmarshalBinary(data []byte) error {
return e.p.UnmarshalBinary(data)
}

func (s *ristrettoScalar) Group() Group { return Ristretto255 }
func (s *ristrettoScalar) String() string { return fmt.Sprintf("0x%x", s.s.Bytes()) }
func (s *ristrettoScalar) SetUint64(n uint64) { s.s.SetUint64(n) }

Expand Down
2 changes: 2 additions & 0 deletions group/short.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type wElt struct {
x, y *big.Int
}

func (e *wElt) Group() Group { return e.wG }
func (e *wElt) String() string { return fmt.Sprintf("x: 0x%v\ny: 0x%v", e.x.Text(16), e.y.Text(16)) }
func (e *wElt) IsIdentity() bool { return e.x.Sign() == 0 && e.y.Sign() == 0 }
func (e *wElt) IsEqual(o Element) bool {
Expand Down Expand Up @@ -219,6 +220,7 @@ type wScl struct {
k []byte
}

func (s *wScl) Group() Group { return s.wG }
func (s *wScl) String() string { return fmt.Sprintf("0x%x", s.k) }
func (s *wScl) SetUint64(n uint64) { s.fromBig(new(big.Int).SetUint64(n)) }
func (s *wScl) IsEqual(a Scalar) bool {
Expand Down

0 comments on commit c8971c0

Please sign in to comment.