-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
utils.go
39 lines (34 loc) · 1 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package dkgsignkey
import (
"math/big"
"github.com/pkg/errors"
"go.dedis.ch/kyber/v3"
)
// scalarFromBig creates a kyber.Scalar belonging to the edwards25519
// kyber suite from a big integer. This is useful for testing.
func scalarFromBig(i *big.Int) kyber.Scalar {
scalar := suite.Scalar()
// big.Int.Bytes() returns a byte slice in big-endian order,
// need to reverse the slice before we SetBytes since
// SetBytes interprets it in little-endian order.
b := i.Bytes()
reverseSliceInPlace(b)
return scalar.SetBytes(b)
}
func keyFromScalar(k kyber.Scalar) (Key, error) {
publicKey := suite.Point().Base().Mul(k, nil)
publicKeyBytes, err := publicKey.MarshalBinary()
if err != nil {
return Key{}, errors.Wrap(err, "kyber point MarshalBinary")
}
return Key{
privateKey: k,
PublicKey: publicKey,
publicKeyBytes: publicKeyBytes,
}, nil
}
func reverseSliceInPlace[T any](elems []T) {
for i := 0; i < len(elems)/2; i++ {
elems[i], elems[len(elems)-i-1] = elems[len(elems)-i-1], elems[i]
}
}