mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-24 17:41:28 +00:00
Output real private key in x25519 command (#1747)
This commit is contained in:
parent
c04c333afc
commit
4a0b45d1ff
|
@ -4,7 +4,6 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/main/commands/base"
|
"github.com/xtls/xray-core/main/commands/base"
|
||||||
"golang.org/x/crypto/curve25519"
|
"golang.org/x/crypto/curve25519"
|
||||||
|
@ -44,17 +43,26 @@ func executeX25519(cmd *base.Command, args []string) {
|
||||||
goto out
|
goto out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if privateKey == nil {
|
if privateKey == nil {
|
||||||
privateKey = make([]byte, curve25519.ScalarSize)
|
privateKey = make([]byte, curve25519.ScalarSize)
|
||||||
if _, err = io.ReadFull(rand.Reader, privateKey); err != nil {
|
if _, err = rand.Read(privateKey); err != nil {
|
||||||
output = err.Error()
|
output = err.Error()
|
||||||
goto out
|
goto out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modify random bytes using algorithm described at:
|
||||||
|
// https://cr.yp.to/ecdh.html.
|
||||||
|
privateKey[0] &= 248
|
||||||
|
privateKey[31] &= 127
|
||||||
|
privateKey[31] |= 64
|
||||||
|
|
||||||
if publicKey, err = curve25519.X25519(privateKey, curve25519.Basepoint); err != nil {
|
if publicKey, err = curve25519.X25519(privateKey, curve25519.Basepoint); err != nil {
|
||||||
output = err.Error()
|
output = err.Error()
|
||||||
goto out
|
goto out
|
||||||
}
|
}
|
||||||
|
|
||||||
output = fmt.Sprintf("Private key: %v\nPublic key: %v",
|
output = fmt.Sprintf("Private key: %v\nPublic key: %v",
|
||||||
base64.RawURLEncoding.EncodeToString(privateKey),
|
base64.RawURLEncoding.EncodeToString(privateKey),
|
||||||
base64.RawURLEncoding.EncodeToString(publicKey))
|
base64.RawURLEncoding.EncodeToString(publicKey))
|
||||||
|
|
Loading…
Reference in a new issue