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 1 commit
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
8 changes: 3 additions & 5 deletions crypto/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func ParseAddress(hrp, saddr string) (PublicKey, error) {
if phrp != hrp {
return EmptyPublicKey, ErrIncorrectHrp
}
if len(paddr) != 33 /* compressed public key size */ {
const CompressedPublicKeySize = 33
rafael-abuawad marked this conversation as resolved.
Show resolved Hide resolved
if len(paddr) != CompressedPublicKeySize {
return EmptyPublicKey, ErrInvalidPublicKey
}
var p PublicKey
Expand All @@ -74,10 +75,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!

var pk PublicKey
copy(pk[:], rpk)
return pk
return PublicKey(p[32:])
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice...not sure why I didn't do this in the first place.

You should use PublicKeyLen here instead of 32. I also think you should keep the commend that explains why we go 32 in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Thank you!

}

// ToHex converts a PrivateKey to a hex string.
Expand Down