Skip to content

Commit d16dc72

Browse files
committed
replace ed25519 Library
1 parent 12b7a0e commit d16dc72

29 files changed

+27
-5098
lines changed

crypto/elliptic/ed25519.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ package elliptic
1616

1717
import (
1818
"crypto/elliptic"
19+
"crypto/sha512"
1920
"math/big"
2021

21-
ED25519 "github.com/getamis/alice/crypto/elliptic/ed25519prue"
22+
ED25519 "filippo.io/edwards25519"
2223

23-
"github.com/decred/dcrd/dcrec/edwards"
24+
edwards "github.com/decred/dcrd/dcrec/edwards/v2"
2425
)
2526

2627
var (
@@ -54,15 +55,20 @@ func (ed *ed25519) Slip10SeedList() []byte {
5455
return []byte("ed25519 seed")
5556
}
5657

57-
func (ed *ed25519) CompressedPublicKey(secret *big.Int, method string) ([]byte, error) {
58+
func (ed *ed25519) CompressedPublicKey(secret *big.Int, method string) []byte {
5859
if method == BIP32ED25519 {
59-
pubKey, err := ED25519.PubKeyCompression(secret.Bytes())
60-
if err != nil {
61-
return nil, err
62-
}
63-
return pubKey, nil
60+
return pubKeyRFC8032Compression(secret.Bytes()[:32])
6461
} else {
65-
privateKey := ED25519.NewKeyFromSeed(secret.Bytes()[:32])
66-
return privateKey[32:], nil
62+
sha512 := sha512.New()
63+
sha512.Write(secret.Bytes()[:32])
64+
h := sha512.Sum(nil)
65+
return pubKeyRFC8032Compression(h[:32])
6766
}
6867
}
68+
69+
func pubKeyRFC8032Compression(secret []byte) []byte {
70+
s := ED25519.NewScalar()
71+
s, _ = s.SetBytesWithClamping(secret)
72+
v := ED25519.NewGeneratorPoint().ScalarMult(s, ED25519.NewGeneratorPoint())
73+
return v.Bytes()
74+
}

crypto/elliptic/ed25519_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ var _ = Describe("ed25519", func() {
3636
// Test vectors : https://asecuritysite.com/ecc/eddsa4
3737
DescribeTable("Compressed PubKey", func(secrethex string, expected string, method string) {
3838
secret, _ := new(big.Int).SetString(secrethex, 16)
39-
pubKey, err := Ed25519().CompressedPublicKey(secret, method)
40-
Expect(err).Should(BeNil())
39+
pubKey := Ed25519().CompressedPublicKey(secret, method)
4140
Expect(hex.EncodeToString(pubKey) == expected).Should(BeTrue())
4241
},
4342
Entry("case1:", "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a", ""),

crypto/elliptic/ed25519prue/byte/byteorder.go

Lines changed: 0 additions & 149 deletions
This file was deleted.

0 commit comments

Comments
 (0)