Skip to content

Commit

Permalink
replace ed25519 Library
Browse files Browse the repository at this point in the history
  • Loading branch information
cychuang0924 committed Nov 27, 2024
1 parent 12b7a0e commit d16dc72
Show file tree
Hide file tree
Showing 29 changed files with 27 additions and 5,098 deletions.
26 changes: 16 additions & 10 deletions crypto/elliptic/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ package elliptic

import (
"crypto/elliptic"
"crypto/sha512"
"math/big"

ED25519 "github.com/getamis/alice/crypto/elliptic/ed25519prue"
ED25519 "filippo.io/edwards25519"

"github.com/decred/dcrd/dcrec/edwards"
edwards "github.com/decred/dcrd/dcrec/edwards/v2"
)

var (
Expand Down Expand Up @@ -54,15 +55,20 @@ func (ed *ed25519) Slip10SeedList() []byte {
return []byte("ed25519 seed")
}

func (ed *ed25519) CompressedPublicKey(secret *big.Int, method string) ([]byte, error) {
func (ed *ed25519) CompressedPublicKey(secret *big.Int, method string) []byte {
if method == BIP32ED25519 {
pubKey, err := ED25519.PubKeyCompression(secret.Bytes())
if err != nil {
return nil, err
}
return pubKey, nil
return pubKeyRFC8032Compression(secret.Bytes()[:32])
} else {
privateKey := ED25519.NewKeyFromSeed(secret.Bytes()[:32])
return privateKey[32:], nil
sha512 := sha512.New()
sha512.Write(secret.Bytes()[:32])
h := sha512.Sum(nil)
return pubKeyRFC8032Compression(h[:32])
}
}

func pubKeyRFC8032Compression(secret []byte) []byte {
s := ED25519.NewScalar()
s, _ = s.SetBytesWithClamping(secret)
v := ED25519.NewGeneratorPoint().ScalarMult(s, ED25519.NewGeneratorPoint())
return v.Bytes()
}
3 changes: 1 addition & 2 deletions crypto/elliptic/ed25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ var _ = Describe("ed25519", func() {
// Test vectors : https://asecuritysite.com/ecc/eddsa4
DescribeTable("Compressed PubKey", func(secrethex string, expected string, method string) {
secret, _ := new(big.Int).SetString(secrethex, 16)
pubKey, err := Ed25519().CompressedPublicKey(secret, method)
Expect(err).Should(BeNil())
pubKey := Ed25519().CompressedPublicKey(secret, method)
Expect(hex.EncodeToString(pubKey) == expected).Should(BeTrue())
},
Entry("case1:", "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a", ""),
Expand Down
149 changes: 0 additions & 149 deletions crypto/elliptic/ed25519prue/byte/byteorder.go

This file was deleted.

Loading

0 comments on commit d16dc72

Please sign in to comment.