Commit 219f0d2
committed
Ed25519 support in the OpenSSL compatibility layer
wolfCrypt has full Ed25519 (keygen, sign/verify, ASN.1 import/export) and
the TLS 1.3 stack already authenticates with Ed25519 certificates, but the
OpenSSL-compatibility surface was missing the dispatch for several common
operations, so an application driving Ed25519 purely through the OpenSSL
API (EVP_PKEY_keygen, i2d_PUBKEY, X509_sign of an in-memory self-signed
cert, X509_verify, then loading it into an SSL_CTX) could not use it. Fill
those gaps, each mirroring the adjacent RSA/ECC/X25519 case:
- EVP_PKEY_keygen (wolfcrypt/src/evp.c): generate an Ed25519 key and cache
the PKCS#8 PrivateKeyInfo DER, like the EC/RSA cases; if the DER cannot be
cached the freshly generated key is freed so a failed keygen never leaves
a partial key behind.
- wolfSSL_i2d_PublicKey / i2d_PUBKEY (wolfcrypt/src/evp_pk.c): encode an
Ed25519 SubjectPublicKeyInfo. i2d_PublicKey intentionally emits the full
SPKI here (rather than the bare key) because i2d_PUBKEY aliases it and the
PEM_write_PUBKEY / d2i_PUBKEY round-trip relies on it.
- pkcs8_encode (src/pk.c): return the already-PKCS#8 cached DER for Ed25519
(as the DH case does) after checking it is present, so
i2d_PKCS8_PRIV_KEY_INFO works and a public-only key (e.g. one obtained
from X509_get_pubkey, which caches only the raw public key) is rejected
rather than emitted as a bogus private key.
- d2iTryEd25519Key (wolfcrypt/src/evp_pk.c): derive the public key after
decoding a PKCS#8 private key (v1 carries only the seed) so the decoded
EVP_PKEY is complete.
- d2i_AutoPrivateKey (wolfcrypt/src/evp_pk.c): detect Ed25519 by its
algorithm id and decode the full PKCS#8 (its inner key is an OCTET
STRING, which the RSA/ECC sequence-counting heuristic cannot classify).
- X509_sign / X509_resign_cert / sigTypeFromPKEY / wolfssl_x509_make_der
(src/x509.c): sign a certificate with an Ed25519 key (NULL digest),
resolving the signature type as CTC_ED25519 and building the
SubjectPublicKey from an ed25519_key.
- X509_verify (src/x509.c): verify a certificate's signature with an
Ed25519 EVP_PKEY, exporting the raw public key for the check (the cached
DER is a PKCS#8 private blob, not the public key the verify path wants).
- X509_set_pubkey / X509_get_pubkey (src/x509.c): set and retrieve an
Ed25519 public key, keeping the X.509 public-key buffer as the raw key
bytes to match how DecodeCert/StoreKey store it.
Ed25519 object lifetime goes through the existing wolfSSL_ED25519_new /
wolfSSL_ED25519_free helpers. Their guards (wolfssl/openssl/ed25519.h,
src/pk.c) and the ssl.c include of openssl/ed25519.h are widened to also
cover OPENSSL_EXTRA_X509_SMALL, since the X509 paths above build in that
configuration too. The individual operations are gated on
HAVE_ED25519_KEY_IMPORT / HAVE_ED25519_KEY_EXPORT / HAVE_ED25519_MAKE_KEY
so a build that disables one of those sub-features still compiles.
tests/api.c gains test_wolfSSL_EVP_PKEY_ED25519_openssl, which exercises
the whole sequence: keygen, i2d_PUBKEY, the raw-key constructors
(EVP_PKEY_new_raw_public_key / EVP_PKEY_new_raw_private_key), the PKCS#8
round-trip (EVP_PKEY2PKCS8, i2d_PKCS8_PKEY, d2i_AutoPrivateKey) including a
check that the decoded key re-exports the same SPKI, a negative check that
PKCS#8 export of a public-only key fails cleanly, a self-signed X509_sign
with a NULL digest followed by X509_verify of the result, an X509_get_pubkey
round-trip, and loading the key+cert into an SSL_CTX.
Requires --enable-ed25519 --enable-certgen (key import/export and key
generation are on by default with --enable-ed25519).
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>1 parent dd6da70 commit 219f0d2
7 files changed
Lines changed: 477 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5518 | 5518 | | |
5519 | 5519 | | |
5520 | 5520 | | |
5521 | | - | |
5522 | | - | |
| 5521 | + | |
| 5522 | + | |
5523 | 5523 | | |
5524 | 5524 | | |
5525 | 5525 | | |
| |||
5570 | 5570 | | |
5571 | 5571 | | |
5572 | 5572 | | |
5573 | | - | |
| 5573 | + | |
| 5574 | + | |
5574 | 5575 | | |
5575 | 5576 | | |
5576 | 5577 | | |
| |||
7373 | 7374 | | |
7374 | 7375 | | |
7375 | 7376 | | |
| 7377 | + | |
| 7378 | + | |
| 7379 | + | |
| 7380 | + | |
| 7381 | + | |
| 7382 | + | |
| 7383 | + | |
| 7384 | + | |
| 7385 | + | |
| 7386 | + | |
| 7387 | + | |
| 7388 | + | |
| 7389 | + | |
| 7390 | + | |
| 7391 | + | |
| 7392 | + | |
| 7393 | + | |
| 7394 | + | |
| 7395 | + | |
| 7396 | + | |
| 7397 | + | |
7376 | 7398 | | |
7377 | 7399 | | |
7378 | 7400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6481 | 6481 | | |
6482 | 6482 | | |
6483 | 6483 | | |
| 6484 | + | |
| 6485 | + | |
| 6486 | + | |
| 6487 | + | |
| 6488 | + | |
6484 | 6489 | | |
6485 | 6490 | | |
6486 | 6491 | | |
| |||
6572 | 6577 | | |
6573 | 6578 | | |
6574 | 6579 | | |
| 6580 | + | |
| 6581 | + | |
| 6582 | + | |
| 6583 | + | |
| 6584 | + | |
| 6585 | + | |
| 6586 | + | |
| 6587 | + | |
| 6588 | + | |
| 6589 | + | |
| 6590 | + | |
| 6591 | + | |
| 6592 | + | |
| 6593 | + | |
| 6594 | + | |
| 6595 | + | |
| 6596 | + | |
| 6597 | + | |
| 6598 | + | |
| 6599 | + | |
| 6600 | + | |
| 6601 | + | |
| 6602 | + | |
6575 | 6603 | | |
6576 | 6604 | | |
6577 | 6605 | | |
| |||
9010 | 9038 | | |
9011 | 9039 | | |
9012 | 9040 | | |
| 9041 | + | |
| 9042 | + | |
| 9043 | + | |
| 9044 | + | |
| 9045 | + | |
| 9046 | + | |
9013 | 9047 | | |
9014 | 9048 | | |
9015 | 9049 | | |
| |||
9023 | 9057 | | |
9024 | 9058 | | |
9025 | 9059 | | |
| 9060 | + | |
| 9061 | + | |
| 9062 | + | |
| 9063 | + | |
9026 | 9064 | | |
9027 | 9065 | | |
9028 | 9066 | | |
| |||
9036 | 9074 | | |
9037 | 9075 | | |
9038 | 9076 | | |
| 9077 | + | |
| 9078 | + | |
| 9079 | + | |
| 9080 | + | |
| 9081 | + | |
| 9082 | + | |
| 9083 | + | |
| 9084 | + | |
| 9085 | + | |
| 9086 | + | |
| 9087 | + | |
| 9088 | + | |
| 9089 | + | |
| 9090 | + | |
| 9091 | + | |
| 9092 | + | |
| 9093 | + | |
9039 | 9094 | | |
9040 | 9095 | | |
9041 | 9096 | | |
| |||
9044 | 9099 | | |
9045 | 9100 | | |
9046 | 9101 | | |
9047 | | - | |
| 9102 | + | |
9048 | 9103 | | |
9049 | 9104 | | |
9050 | 9105 | | |
9051 | | - | |
| 9106 | + | |
9052 | 9107 | | |
9053 | 9108 | | |
9054 | 9109 | | |
| |||
12225 | 12280 | | |
12226 | 12281 | | |
12227 | 12282 | | |
| 12283 | + | |
| 12284 | + | |
| 12285 | + | |
| 12286 | + | |
| 12287 | + | |
| 12288 | + | |
| 12289 | + | |
| 12290 | + | |
12228 | 12291 | | |
12229 | 12292 | | |
12230 | 12293 | | |
| |||
12337 | 12400 | | |
12338 | 12401 | | |
12339 | 12402 | | |
| 12403 | + | |
| 12404 | + | |
| 12405 | + | |
12340 | 12406 | | |
12341 | 12407 | | |
12342 | 12408 | | |
| |||
12472 | 12538 | | |
12473 | 12539 | | |
12474 | 12540 | | |
| 12541 | + | |
| 12542 | + | |
| 12543 | + | |
| 12544 | + | |
| 12545 | + | |
| 12546 | + | |
| 12547 | + | |
| 12548 | + | |
| 12549 | + | |
| 12550 | + | |
| 12551 | + | |
| 12552 | + | |
| 12553 | + | |
| 12554 | + | |
| 12555 | + | |
| 12556 | + | |
| 12557 | + | |
| 12558 | + | |
| 12559 | + | |
| 12560 | + | |
| 12561 | + | |
| 12562 | + | |
12475 | 12563 | | |
12476 | 12564 | | |
12477 | 12565 | | |
| |||
12723 | 12811 | | |
12724 | 12812 | | |
12725 | 12813 | | |
| 12814 | + | |
| 12815 | + | |
| 12816 | + | |
| 12817 | + | |
| 12818 | + | |
12726 | 12819 | | |
12727 | 12820 | | |
12728 | 12821 | | |
| |||
12807 | 12900 | | |
12808 | 12901 | | |
12809 | 12902 | | |
| 12903 | + | |
| 12904 | + | |
| 12905 | + | |
| 12906 | + | |
| 12907 | + | |
| 12908 | + | |
12810 | 12909 | | |
12811 | 12910 | | |
12812 | 12911 | | |
| |||
12895 | 12994 | | |
12896 | 12995 | | |
12897 | 12996 | | |
12898 | | - | |
| 12997 | + | |
12899 | 12998 | | |
12900 | 12999 | | |
12901 | 13000 | | |
12902 | 13001 | | |
| 13002 | + | |
| 13003 | + | |
| 13004 | + | |
| 13005 | + | |
| 13006 | + | |
| 13007 | + | |
| 13008 | + | |
| 13009 | + | |
| 13010 | + | |
| 13011 | + | |
| 13012 | + | |
| 13013 | + | |
| 13014 | + | |
12903 | 13015 | | |
12904 | 13016 | | |
12905 | 13017 | | |
| |||
16408 | 16520 | | |
16409 | 16521 | | |
16410 | 16522 | | |
| 16523 | + | |
| 16524 | + | |
| 16525 | + | |
| 16526 | + | |
| 16527 | + | |
| 16528 | + | |
| 16529 | + | |
| 16530 | + | |
| 16531 | + | |
| 16532 | + | |
| 16533 | + | |
| 16534 | + | |
| 16535 | + | |
| 16536 | + | |
| 16537 | + | |
| 16538 | + | |
| 16539 | + | |
| 16540 | + | |
| 16541 | + | |
| 16542 | + | |
| 16543 | + | |
| 16544 | + | |
| 16545 | + | |
| 16546 | + | |
16411 | 16547 | | |
16412 | 16548 | | |
16413 | 16549 | | |
| |||
0 commit comments