Skip to content

Commit

Permalink
crypto/tss/eddsa: fix some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
cychuang0924 authored and markya0616 committed Nov 22, 2023
1 parent ad72db6 commit b78a9b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
19 changes: 8 additions & 11 deletions crypto/tss/eddsa/frost/signer/round_1.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ const (
)

var (
bit254 = new(big.Int).Lsh(big.NewInt(1), 253)
big0 = big.NewInt(0)
big1 = big.NewInt(1)
big0 = big.NewInt(0)
big1 = big.NewInt(1)

//ErrExceedMaxRetry is returned if we retried over times
ErrExceedMaxRetry = errors.New("exceed max retries")
Expand Down Expand Up @@ -260,9 +259,6 @@ func (p *round1) Finalize(logger log.Logger) (types.Handler, error) {
p.r = R
// Compute own zi = di+ ei*li + c bi xi
selfNode := p.nodes[p.peerManager.SelfID()]
if err != nil {
return nil, err
}
share := new(big.Int).Set(p.share)
p.d, p.e, share, err = computeDEShareTaproot(p.d, p.e, share, R, p.pubKey)
if err != nil {
Expand Down Expand Up @@ -376,14 +372,15 @@ func SHAPoints(pubKey, R *ecpointgrouplaw.ECPoint, message []byte) (*big.Int, er
return nil, ErrNotSupportCurve
}

func ecpointEncoding(pt *ecpointgrouplaw.ECPoint) (*[32]byte, error) {
func ecpointEncoding(pt *ecpointgrouplaw.ECPoint) ([32]byte, error) {
curveType := pt.GetCurve()
nullSlice := [32]byte{}
if pt.IsIdentity() {
return nil, ErrTrivialPoint
return nullSlice, ErrTrivialPoint
}
switch curveType {
case elliptic.Secp256k1():
return (*[32]byte)(utils.Bytes32(pt.GetX())), nil
return ([32]byte)(utils.Bytes32(pt.GetX())), nil
case elliptic.Ed25519():
var result, X, Y [32]byte
var x, y edwards25519.FieldElement
Expand All @@ -407,9 +404,9 @@ func ecpointEncoding(pt *ecpointgrouplaw.ECPoint) (*[32]byte, error) {
edwards25519.FeFromBytes(&y, &Y)
edwards25519.FeToBytes(&result, &y)
result[31] ^= edwards25519.FeIsNegative(&x) << 7
return &result, nil
return result, nil
}
return nil, ErrNotSupportCurve
return nullSlice, ErrNotSupportCurve
}

// Get xi,Di,Ei,.......
Expand Down
6 changes: 3 additions & 3 deletions crypto/tss/eddsa/frost/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func Verify(pubKey, R *ecpointgrouplaw.ECPoint, message []byte, s *big.Int) bool
curveP := curveType.Params().P
curveN := curveType.Params().N
// Let P = lift_x(int(pk))
Px, Py, err := lift_x(pubKey.GetX(), curveType)
Px, Py, err := liftX(pubKey.GetX(), curveType)
if err != nil {
return false
}
Expand Down Expand Up @@ -251,14 +251,14 @@ func Verify(pubKey, R *ecpointgrouplaw.ECPoint, message []byte, s *big.Int) bool
edwardPubKey := edwards.NewPublicKey(edwards.Edwards(), pubKey.GetX(), pubKey.GetY())
test1, err := ecpointEncoding(R)
Expect(err).Should(BeNil())
test2 := *test1
test2 := test1
r := new(big.Int).SetBytes(utils.ReverseByte(test2[:]))
return edwards.Verify(edwardPubKey, message, r, s)
}
return false
}

func lift_x(x *big.Int, curve elliptic.Curve) (*big.Int, *big.Int, error) {
func liftX(x *big.Int, curve elliptic.Curve) (*big.Int, *big.Int, error) {
curveP := curve.Params().P
if x.Cmp(big0) == -1 || x.Cmp(curveP) == 1 {
return nil, nil, ErrNotSupportCurve
Expand Down
7 changes: 5 additions & 2 deletions crypto/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,11 @@ func ExtendHashOutput(salt, message []byte, outputByteLength int) []byte {
}

func Pad(x []byte, n int) []byte {
pad := make([]byte, n-len(x))
return append(pad, x...)
if n-len(x) >= 0 {
pad := make([]byte, n-len(x))
return append(pad, x...)
}
return x[0:n]
}

func Bytes32(x *big.Int) []byte {
Expand Down

0 comments on commit b78a9b3

Please sign in to comment.