Skip to content

crypto/ed25519: not generating valid private key (invalid format) #69418

Description

@the-hotmann

Go version

go version go1.23.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2769731916=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I generated two ed25519 private keys:

  1. with ssh-keygen
  2. with crypto/ed25519

1:

ssh-keygen -a 5000 -b 521  -t ed25519 -E sha512 -C "name@domain (a=5000 b=521  t=ed25519 E=sha512)"

2: (like this)

https://gist.github.com/rorycl/d300f3ab942fd79e6cc1f37db0c6260f

Then I converted BOTH to RFC4716 with:

ssh-keygen -ef "path/to/key"

and stored it in the correct path for proftpd.

What did you see happen?

Logging in with the key from ssh-keygen was possible via FileZilla
Logging in with the golang generated key was not possible. It complains about the private key file not containing a private key!

To rule out FileZillas fault (which worked with the ssh-keaygen based key) I used the windows cmd:

ssh -i "path/to/key" user@ip

and got back:

Load key "C:\\Users\\user\\ssh\\key_test\\skel_id_ed25519": invalid format

So it seems like golangs library crypto/ed25519 is generating invalid keys.

Here btw the key (no worries I dont use it):

-----BEGIN OPENSSH PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEICD5FPTasx5/JS4aVWhVZ2agE9j6x71anKKxfEH3avNd
-----END OPENSSH PRIVATE KEY-----

It is very small and definitely smaller as the ssh-keygen based ones, which I was able to set to 521 bits.

Any help would be appreciated! :)

What did you expect to see?

  1. the golang generated key to work aswell
  2. https://github.com/golang/go/blob/master/src/crypto/ed25519/ed25519.go#L30-L39 beeing configuratable.
    as I want to adjust the keysizes to my needs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions