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

Commit

Permalink
Merge pull request #21 from bytemare/groups-add-order
Browse files Browse the repository at this point in the history
Add Order() to groups, returning the order
  • Loading branch information
bytemare authored Oct 2, 2022
2 parents 07b3159 + 83b908c commit 33e2059
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Group interface {
EncodeToGroup(input, dst []byte) Element
ScalarLength() uint
ElementLength() uint
Order() string
}
```

Expand All @@ -67,8 +68,6 @@ type Scalar interface {
Decode(in []byte) error
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
encoding.TextMarshaler
encoding.TextUnmarshaler
}
```

Expand All @@ -91,8 +90,6 @@ type Element interface {
Decode(data []byte) error
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
encoding.TextMarshaler
encoding.TextUnmarshaler
}
```

Expand Down
5 changes: 5 additions & 0 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (g Group) ElementLength() uint {
return g.get().ElementLength()
}

// Order returns the order of the canonical group of scalars.
func (g Group) Order() string {
return g.get().Order()
}

func (g Group) initGroup(get func() internal.Group) {
groups[g-1] = get()
}
Expand Down
3 changes: 3 additions & 0 deletions internal/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ type Group interface {

// ElementLength returns the byte size of an encoded element.
ElementLength() uint

// Order returns the order of the canonical group of scalars.
Order() string
}
5 changes: 5 additions & 0 deletions internal/nist/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ func (g Group[P]) ElementLength() uint {
return uint(1 + byteLen)
}

// Order returns the order of the canonical group of scalars.
func (g Group[P]) Order() string {
return g.scalarField.prime.String()
}

var (
initOnceP256 sync.Once
initOnceP384 sync.Once
Expand Down
11 changes: 11 additions & 0 deletions internal/ristretto/ristretto.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const (

// H2C represents the hash-to-curve string identifier.
H2C = "ristretto255_XMD:SHA-512_R255MAP_RO_"

// orderPrime represents curve25519's subgroup prime-order
// = 2^252 + 27742317777372353535851937790883648493
// = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed
// cofactor h = 8.
orderPrime = "7237005577332262213973186563042994240857116359379907606001950938285454250989"
)

// Group represents the Ristretto255 group. It exposes a prime-order group API with hash-to-curve operations.
Expand Down Expand Up @@ -83,3 +89,8 @@ func (g Group) ScalarLength() uint {
func (g Group) ElementLength() uint {
return canonicalEncodingLength
}

// Order returns the order of the canonical group of scalars.
func (g Group) Order() string {
return orderPrime
}

0 comments on commit 33e2059

Please sign in to comment.