Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing crypto/ed25519.go #21

Merged
merged 7 commits into from
Feb 23, 2023
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions crypto/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ type (
)

const (
PublicKeyLen = ed25519.PublicKeySize
PrivateKeyLen = ed25519.PrivateKeySize
SignatureLen = ed25519.SignatureSize
PublicKeyCompressedLen = 33
PublicKeyLen = ed25519.PublicKeySize
PrivateKeyLen = ed25519.PrivateKeySize
PrivateKeySeedLen = ed25519.SeedSize
SignatureLen = ed25519.SignatureSize
)

var (
Expand Down Expand Up @@ -51,11 +53,11 @@ func ParseAddress(hrp, saddr string) (PublicKey, error) {
if phrp != hrp {
return EmptyPublicKey, ErrIncorrectHrp
}
if len(paddr) != 33 /* compressed public key size */ {
if len(paddr) != PublicKeyCompressedLen {
return EmptyPublicKey, ErrInvalidPublicKey
}
var p PublicKey
copy(p[:], paddr[:32])
copy(p[:], paddr[:PublicKeyLen])
return p, nil
}

Expand All @@ -74,7 +76,7 @@ func GeneratePrivateKey() (PrivateKey, error) {
// PublicKey returns a PublicKey associated with the Ed25519 PrivateKey p.
// The PublicKey is the last 32 bytes of p.
func (p PrivateKey) PublicKey() PublicKey {
rpk := p[32:] // privateKey == private|public
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put PrivateKeySeedLen here ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

rpk := p[PublicKeyLen:] // privateKey == private|public
var pk PublicKey
copy(pk[:], rpk)
return pk
Expand Down