@@ -8,23 +8,20 @@ import (
88 "crypto/cipher"
99 "encoding/hex"
1010 "errors"
11- "github.com/cronokirby/saferith "
11+ "go.dedis.ch/kyber/v4 "
1212 "go.dedis.ch/kyber/v4/compatible"
1313 "go.dedis.ch/kyber/v4/compatible/compatible_mod"
14- "io"
15- "math/big"
16-
17- "go.dedis.ch/kyber/v4"
1814 "go.dedis.ch/kyber/v4/group/internal/marshalling"
1915 "go.dedis.ch/kyber/v4/util/random"
16+ "io"
2017)
2118
2219var Cap = 64
2320var marshalScalarID = [8 ]byte {'m' , 'o' , 'd' , '.' , 'i' , 'n' , 't' , ' ' }
2421
2522// Int is a generic implementation of finite field arithmetic
2623// on integer finite fields with a given constant modulus,
27- // built using Go's built-in big.Int or with the saferith package,
24+ // built using Go's built-in big.Int or with the filosottile/bigmod package,
2825// depending on whether the constantTime build tag is chosen.
2926// Int satisfies the kyber.Scalar interface,
3027// and hence serves as a basic implementation of kyber.Scalar,
@@ -66,17 +63,18 @@ func (i *Int) SetString(n, d string, base int) (*Int, bool) {
6663 return i , true
6764}
6865
69- // Jacobi computes the Jacobi symbol of (a/M), which indicates whether a is
70- // zero (0), a positive square in M (1), or a non-square in M (-1).
71- func (i * Int ) Jacobi (as kyber.Scalar ) kyber.Scalar {
72- ai := as .(* Int ) //nolint:errcheck // Design pattern to emulate generics
73- i .M = ai .M
74- i .V .SetUint (uint (big .Jacobi (& ai .V , i .M )))
75- return i
76- }
66+ // Not used in constant time
67+ //// Jacobi computes the Jacobi symbol of (a/M), which indicates whether a is
68+ //// zero (0), a positive square in M (1), or a non-square in M (-1).
69+ //func (i *Int) Jacobi(as kyber.Scalar) kyber.Scalar {
70+ // ai := as.(*Int) //nolint:errcheck // Design pattern to emulate generics
71+ // i.M = ai.M
72+ // i.V.SetUint(uint(big.Jacobi(&ai.V, i.M)))
73+ // return i
74+ //}
7775
7876// NewInt creaters a new Int with a given compatible.Int and a compatible.Int modulus.
79- func NewInt (v * saferith. Nat , m * compatible_mod.Mod ) * Int {
77+ func NewInt (v * compatible. Int , m * compatible_mod.Mod ) * Int {
8078 return new (Int ).Init (v , m )
8179}
8280
@@ -182,13 +180,13 @@ func (i *Int) Clone() kyber.Scalar {
182180
183181// Zero set the Int to the value 0. The modulus must already be initialized.
184182func (i * Int ) Zero () kyber.Scalar {
185- i .V .SetUint64 (0 )
183+ i .V .SetUint (0 )
186184 return i
187185}
188186
189187// One sets the Int to the value 1. The modulus must already be initialized.
190188func (i * Int ) One () kyber.Scalar {
191- i .V .SetUint64 (1 )
189+ i .V .SetUint (1 )
192190 return i
193191}
194192
@@ -295,28 +293,25 @@ func (i *Int) Exp(a kyber.Scalar, e *compatible.Int) kyber.Scalar {
295293 return i
296294}
297295
298- // Sqrt computes some square root of a mod M of one exists.
299- // Assumes the modulus M is an odd prime.
300- // Returns true on success, false if input a is not a square.
301- func (i * Int ) Sqrt (as kyber.Scalar ) bool {
302- ai := as .(* Int ) //nolint:errcheck // Design pattern to emulate generics
303- out := i .V .ModSqrt (ai .V , ai .M )
304- i .M = ai .M
305- return out != nil
306- }
296+ //not used in constant time
297+ //// Sqrt computes some square root of a mod M of one exists.
298+ //// Assumes the modulus M is an odd prime.
299+ //// Returns true on success, false if input a is not a square.
300+ //func (i *Int) Sqrt(as kyber.Scalar) bool {
301+ // ai := as.(*Int) //nolint:errcheck // Design pattern to emulate generics
302+ // out := i.V.ModSqrt(ai.V, ai.M)
303+ // i.M = ai.M
304+ // return out != nil
305+ //}
307306
308307// Pick a [pseudo-]random integer, modulo M,
309308// using bits from the given stream cipher.
310309func (i * Int ) Pick (rand cipher.Stream ) kyber.Scalar {
311- moduleInt := & saferith.Int {}
312- moduleInt .SetNat (i .M .Nat ())
313-
314- compInt := & compatible.Int {
315- moduleInt ,
316- }
310+ moduleInt := i .M .Nat ()
311+ moduleCompatible := compatible .SetFromNat (moduleInt )
317312
318313 i .V .Set (
319- random .Int (compInt , rand ),
314+ random .Int (moduleCompatible , rand ),
320315 )
321316 return i
322317}
@@ -328,8 +323,8 @@ func (i *Int) ByteOrder() kyber.ByteOrder {
328323
329324// GroupOrder returns the order of the underlying group
330325// todo change to compatible_mod.Mod
331- func (i * Int ) GroupOrder () * big. Int {
332- return big . NewInt ( 0 ). Set ( i .M . Modulus )
326+ func (i * Int ) GroupOrder () * compatible_mod. Mod {
327+ return i .M
333328}
334329
335330// MarshalSize returns the length in bytes of encoded integers with modulus M.
0 commit comments