Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group: adds a method to retrieve the group. #354

Merged
merged 1 commit into from
Jul 29, 2022
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: 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