Skip to content

Commit 44f1fbf

Browse files
authored
Merge branch 'main' into main
2 parents 820e065 + 03a6a6e commit 44f1fbf

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

group/group.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding"
66
"errors"
77
"io"
8+
"math/big"
89
)
910

1011
// Params stores the size in bytes of elements and scalars.
@@ -105,8 +106,12 @@ type Scalar interface {
105106
IsZero() bool
106107
// IsEqual returns true if the receiver is equal to x.
107108
IsEqual(x Scalar) bool
108-
// SetUint64 set the receiver to x, and returns the receiver.
109+
// SetUint64 sets the receiver to x, and returns the receiver.
109110
SetUint64(x uint64) Scalar
111+
// SetBigInt sets the receiver to x, and returns the receiver.
112+
// Warning: operations on big.Int are not constant time. Do not use them
113+
// for cryptography unless you're sure it's safe in your use-case.
114+
SetBigInt(b *big.Int) Scalar
110115
// CMov sets the receiver to x if b=1; the receiver is unmodified if b=0;
111116
// otherwise panics if b is not 0 or 1. In all the cases, it returns the
112117
// receiver.

group/ristretto255.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
_ "crypto/sha512"
66
"fmt"
77
"io"
8+
"math/big"
89

910
r255 "github.com/bwesterb/go-ristretto"
1011
"github.com/cloudflare/circl/expander"
@@ -203,10 +204,11 @@ func (e *ristrettoElement) UnmarshalBinary(data []byte) error {
203204
return e.p.UnmarshalBinary(data)
204205
}
205206

206-
func (s *ristrettoScalar) Group() Group { return Ristretto255 }
207-
func (s *ristrettoScalar) String() string { return conv.BytesLe2Hex(s.s.Bytes()) }
208-
func (s *ristrettoScalar) SetUint64(n uint64) Scalar { s.s.SetUint64(n); return s }
209-
func (s *ristrettoScalar) IsZero() bool { return s.s.IsNonZeroI() == 0 }
207+
func (s *ristrettoScalar) Group() Group { return Ristretto255 }
208+
func (s *ristrettoScalar) String() string { return conv.BytesLe2Hex(s.s.Bytes()) }
209+
func (s *ristrettoScalar) SetUint64(n uint64) Scalar { s.s.SetUint64(n); return s }
210+
func (s *ristrettoScalar) SetBigInt(x *big.Int) Scalar { s.s.SetBigInt(x); return s }
211+
func (s *ristrettoScalar) IsZero() bool { return s.s.IsNonZeroI() == 0 }
210212
func (s *ristrettoScalar) IsEqual(x Scalar) bool {
211213
return s.s.Equals(&x.(*ristrettoScalar).s)
212214
}

group/short.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,10 @@ type wScl struct {
271271
k []byte
272272
}
273273

274-
func (s *wScl) Group() Group { return s.wG }
275-
func (s *wScl) String() string { return fmt.Sprintf("0x%x", s.k) }
276-
func (s *wScl) SetUint64(n uint64) Scalar { s.fromBig(new(big.Int).SetUint64(n)); return s }
274+
func (s *wScl) Group() Group { return s.wG }
275+
func (s *wScl) String() string { return fmt.Sprintf("0x%x", s.k) }
276+
func (s *wScl) SetUint64(n uint64) Scalar { s.fromBig(new(big.Int).SetUint64(n)); return s }
277+
func (s *wScl) SetBigInt(x *big.Int) Scalar { s.fromBig(x); return s }
277278
func (s *wScl) IsZero() bool {
278279
return subtle.ConstantTimeCompare(s.k, make([]byte, (s.wG.c.Params().BitSize+7)/8)) == 1
279280
}

0 commit comments

Comments
 (0)