Skip to content

Commit d7ec969

Browse files
committed
Add SetUint64 to Group.Scalar.
1 parent 0518755 commit d7ec969

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

group/group.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Element interface {
4545
// Scalar represents an integer scalar.
4646
type Scalar interface {
4747
IsEqual(Scalar) bool
48+
SetUint64(uint64)
4849
Add(Scalar, Scalar) Scalar
4950
Sub(Scalar, Scalar) Scalar
5051
Mul(Scalar, Scalar) Scalar

group/ristretto255.go

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto"
55
_ "crypto/sha512" // to link libraries
66
"io"
7+
"math/big"
78

89
r255 "github.com/bwesterb/go-ristretto"
910
)
@@ -145,6 +146,8 @@ func (e *ristrettoElement) UnmarshalBinary(data []byte) error {
145146
return e.p.UnmarshalBinary(data)
146147
}
147148

149+
func (s *ristrettoScalar) SetUint64(n uint64) { s.s.SetBigInt(new(big.Int).SetUint64(n)) }
150+
148151
func (s *ristrettoScalar) IsEqual(x Scalar) bool {
149152
return s.s.Equals(&x.(*ristrettoScalar).s)
150153
}

group/short.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ type wScl struct {
195195
k []byte
196196
}
197197

198-
func (s *wScl) String() string { return fmt.Sprintf("0x%x", s.k) }
198+
func (s *wScl) String() string { return fmt.Sprintf("0x%x", s.k) }
199+
func (s *wScl) SetUint64(n uint64) { s.fromBig(new(big.Int).SetUint64(n)) }
199200
func (s *wScl) IsEqual(a Scalar) bool {
200201
aa := s.cvtScl(a)
201202
return subtle.ConstantTimeCompare(s.k, aa.k) == 1

0 commit comments

Comments
 (0)