From ed50f2813980ec890cbc6981cd04f86019b686b0 Mon Sep 17 00:00:00 2001 From: NoelBright Date: Tue, 23 Apr 2019 16:34:53 +0800 Subject: [PATCH] fixbug: Encode point incorrectly in Ed25519 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 --- crypto/encode.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crypto/encode.go b/crypto/encode.go index 3b9d38528..c346e307a 100644 --- a/crypto/encode.go +++ b/crypto/encode.go @@ -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 {