Skip to content

Commit

Permalink
fixbug: Encode point incorrectly in Ed25519
Browse files Browse the repository at this point in the history
When the first byte of public key is zero, the EncodePoint will
get a wrong output. In this case, we add a prefix 0 in the front
of encoded public key manually.

Signed-off-by: NoelBright <noel.n.bright@gmail.com>
  • Loading branch information
NoelBright authored and gdmmx committed Apr 25, 2019
1 parent 8185c44 commit ed50f28
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crypto/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ func DecodePoint(encodeData []byte) (*PubKey, error) {
func (e *PubKey) EncodePoint(isCommpressed bool) ([]byte, error) {
if AlgChoice == Ed25519 {
encodedData := make([]byte, COMPRESSEDLEN)
copy(encodedData[1:], e.X.Bytes())
xBytes := e.X.Bytes()
copy(encodedData[COMPRESSEDLEN-len(xBytes):COMPRESSEDLEN], xBytes)
encodedData[0] = 0x04
return encodedData, nil
} else {
Expand Down

0 comments on commit ed50f28

Please sign in to comment.