File tree 3 files changed +16
-8
lines changed
3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 5
5
"encoding"
6
6
"errors"
7
7
"io"
8
+ "math/big"
8
9
)
9
10
10
11
// Params stores the size in bytes of elements and scalars.
@@ -105,8 +106,12 @@ type Scalar interface {
105
106
IsZero () bool
106
107
// IsEqual returns true if the receiver is equal to x.
107
108
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.
109
110
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
110
115
// CMov sets the receiver to x if b=1; the receiver is unmodified if b=0;
111
116
// otherwise panics if b is not 0 or 1. In all the cases, it returns the
112
117
// receiver.
Original file line number Diff line number Diff line change 5
5
_ "crypto/sha512"
6
6
"fmt"
7
7
"io"
8
+ "math/big"
8
9
9
10
r255 "github.com/bwesterb/go-ristretto"
10
11
"github.com/cloudflare/circl/expander"
@@ -203,10 +204,11 @@ func (e *ristrettoElement) UnmarshalBinary(data []byte) error {
203
204
return e .p .UnmarshalBinary (data )
204
205
}
205
206
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 }
210
212
func (s * ristrettoScalar ) IsEqual (x Scalar ) bool {
211
213
return s .s .Equals (& x .(* ristrettoScalar ).s )
212
214
}
Original file line number Diff line number Diff line change @@ -271,9 +271,10 @@ type wScl struct {
271
271
k []byte
272
272
}
273
273
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 }
277
278
func (s * wScl ) IsZero () bool {
278
279
return subtle .ConstantTimeCompare (s .k , make ([]byte , (s .wG .c .Params ().BitSize + 7 )/ 8 )) == 1
279
280
}
You can’t perform that action at this time.
0 commit comments