I'm trying to generate a self-signed certificate for ed25519 keys using openSSL, using the following command:
openssl req -new -newkey ed25519 -noenc -config root.cnf -section root_req -out RootCA.csr -keyout RootCA.key -passout file:password.txt -batch
These are the relevant config sections (I doubt they matter here):
[root_req]
default_bits = 256
encrypt_key = no
default_md = sha256
utf8 = yes
string_mask = utf8only
prompt = no
distinguished_name = root_dn
req_extensions = root_ext
[root_ext]
basicConstraints = critical,CA:true
keyUsage = critical,keyCertSign
subjectKeyIdentifier = hash
This generates a request with the public key:
BFDC8F370A5B5CA66E5FA55A6CFBC6D10963B2D6EFFCB86C006E08F64A0654D8
And the resulting signed cert agrees:
Subject Public Key Info:
Public Key Algorithm: ED25519
ED25519 Public-Key:
pub:
bf:dc:8f:37:0a:5b:5c:a6:6e:5f:a5:5a:6c:fb:c6:
d1:09:63:b2:d6:ef:fc:b8:6c:00:6e:08:f6:4a:06:
54:d8
The req command also generates a RootCA.key file:
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIJkwKy4DxV2Ve6o4xkvtkDIbU1vcKGSjKrGL7W8RxxWd
-----END PRIVATE KEY-----
I decode that to 48 bytes, first 16 being the algorithm marker 302e020100300506032b657004220420, and the private key being:
99302B2E03C55D957BAA38C64BED90321B535BDC2864A32AB18BED6F11C7159D
I then try to verify the keys using NaCl.net, which also implements ed25519, and here the trouble start.
Curve25519XSalsa20Poly1305.Encrypt and .TryDecrypt fails when using this key set.
Furthermore, when using Curve25519.ScalarMultiplicationBase to reconstruct the public key from the private key, they don't match. NaCl.net claims the public key associated with above private key 99302B... should instead be:
5089A9E4FBFF67D9419713FC0267C1540091E0126607BF903F4996E03EC79F29
And this key pair works, they succesfully sign a signature.
So... why do the keys output by openSSL not seem like they match? Have I screwed up somewhere in request generation, or is there some formatting difference between openSSL and NaCl.net that's tricking me?