Skip to content

Commit d385ae9

Browse files
committed
add Ed25519 and Ed448 support to the EVP_PKEY layer
- Add WC_EVP_PKEY_ED25519 / WC_EVP_PKEY_ED448 type constants and matching EVP_PKEY_ED25519 / EVP_PKEY_ED448 OpenSSL aliases. - Extend WOLFSSL_EVP_PKEY with ed25519/ed448 fields and ownership bits, and free them in wolfSSL_EVP_PKEY_free(). - Add d2i probe functions that accept both SubjectPublicKeyInfo / PKCS#8 PrivateKeyInfo encodings and raw 32/57-byte key material, and hook them into the d2i_evp_pkey_try() chain. - Map the Ed25519/Ed448 signature OIDs in the relevant lookups and teach the PEM key-format dispatch and SSL_CTX_use_PrivateKey switch about the new types.
1 parent 89dac98 commit d385ae9

7 files changed

Lines changed: 353 additions & 1 deletion

File tree

src/pk.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6262,6 +6262,16 @@ WOLFSSL_EVP_PKEY* wolfSSL_PEM_read_bio_PrivateKey(WOLFSSL_BIO* bio,
62626262
case DHk:
62636263
type = WC_EVP_PKEY_DH;
62646264
break;
6265+
#ifdef HAVE_ED25519
6266+
case ED25519k:
6267+
type = WC_EVP_PKEY_ED25519;
6268+
break;
6269+
#endif
6270+
#ifdef HAVE_ED448
6271+
case ED448k:
6272+
type = WC_EVP_PKEY_ED448;
6273+
break;
6274+
#endif
62656275
default:
62666276
type = WOLFSSL_FATAL_ERROR;
62676277
break;
@@ -6409,6 +6419,16 @@ WOLFSSL_EVP_PKEY* wolfSSL_PEM_read_PrivateKey(XFILE fp, WOLFSSL_EVP_PKEY **key,
64096419
case DHk:
64106420
type = WC_EVP_PKEY_DH;
64116421
break;
6422+
#ifdef HAVE_ED25519
6423+
case ED25519k:
6424+
type = WC_EVP_PKEY_ED25519;
6425+
break;
6426+
#endif
6427+
#ifdef HAVE_ED448
6428+
case ED448k:
6429+
type = WC_EVP_PKEY_ED448;
6430+
break;
6431+
#endif
64126432
default:
64136433
type = WOLFSSL_FATAL_ERROR;
64146434
break;

src/ssl.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17747,6 +17747,14 @@ word32 nid2oid(int nid, int grp)
1774717747
return CTC_SHA3_512wECDSA;
1774817748
#endif
1774917749
#endif /* HAVE_ECC */
17750+
#ifdef HAVE_ED25519
17751+
case WC_NID_ED25519:
17752+
return CTC_ED25519;
17753+
#endif /* HAVE_ED25519 */
17754+
#ifdef HAVE_ED448
17755+
case WC_NID_ED448:
17756+
return CTC_ED448;
17757+
#endif /* HAVE_ED448 */
1775017758
}
1775117759
break;
1775217760

@@ -18131,6 +18139,14 @@ int oid2nid(word32 oid, int grp)
1813118139
return WC_NID_ecdsa_with_SHA3_512;
1813218140
#endif
1813318141
#endif /* HAVE_ECC */
18142+
#ifdef HAVE_ED25519
18143+
case CTC_ED25519:
18144+
return WC_NID_ED25519;
18145+
#endif /* HAVE_ED25519 */
18146+
#ifdef HAVE_ED448
18147+
case CTC_ED448:
18148+
return WC_NID_ED448;
18149+
#endif /* HAVE_ED448 */
1813418150
}
1813518151
break;
1813618152

src/ssl_load.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5256,6 +5256,18 @@ int wolfSSL_CTX_use_PrivateKey(WOLFSSL_CTX *ctx, WOLFSSL_EVP_PKEY *pkey)
52565256
WOLFSSL_MSG("populating ECC key");
52575257
ret = ECC_populate_EVP_PKEY(pkey, pkey->ecc);
52585258
break;
5259+
#endif
5260+
#ifdef HAVE_ED25519
5261+
case WC_EVP_PKEY_ED25519:
5262+
/* DER is already stored in pkey->pkey.ptr by d2i_evp_pkey. */
5263+
WOLFSSL_MSG("populating Ed25519 key");
5264+
break;
5265+
#endif
5266+
#ifdef HAVE_ED448
5267+
case WC_EVP_PKEY_ED448:
5268+
/* DER is already stored in pkey->pkey.ptr by d2i_evp_pkey. */
5269+
WOLFSSL_MSG("populating Ed448 key");
5270+
break;
52595271
#endif
52605272
default:
52615273
ret = 0;

wolfcrypt/src/evp.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
#include <wolfssl/openssl/evp.h>
4242
#include <wolfssl/openssl/kdf.h>
4343
#include <wolfssl/wolfcrypt/wolfmath.h>
44+
#ifdef HAVE_ED25519
45+
#include <wolfssl/wolfcrypt/ed25519.h>
46+
#endif
47+
#ifdef HAVE_ED448
48+
#include <wolfssl/wolfcrypt/ed448.h>
49+
#endif
4450

4551
static const struct s_ent {
4652
const enum wc_HashType macType;
@@ -11679,6 +11685,26 @@ void wolfSSL_EVP_PKEY_free(WOLFSSL_EVP_PKEY* key)
1167911685
break;
1168011686
#endif /* ! NO_DH ... */
1168111687

11688+
#ifdef HAVE_ED25519
11689+
case WC_EVP_PKEY_ED25519:
11690+
if (key->ed25519 != NULL && key->ownEd25519 == 1) {
11691+
wc_ed25519_free(key->ed25519);
11692+
XFREE(key->ed25519, key->heap, DYNAMIC_TYPE_ED25519);
11693+
key->ed25519 = NULL;
11694+
}
11695+
break;
11696+
#endif /* HAVE_ED25519 */
11697+
11698+
#ifdef HAVE_ED448
11699+
case WC_EVP_PKEY_ED448:
11700+
if (key->ed448 != NULL && key->ownEd448 == 1) {
11701+
wc_ed448_free(key->ed448);
11702+
XFREE(key->ed448, key->heap, DYNAMIC_TYPE_ED448);
11703+
key->ed448 = NULL;
11704+
}
11705+
break;
11706+
#endif /* HAVE_ED448 */
11707+
1168211708
#ifdef HAVE_HKDF
1168311709
case WC_EVP_PKEY_HKDF:
1168411710
XFREE(key->hkdfSalt, NULL, DYNAMIC_TYPE_SALT);

0 commit comments

Comments
 (0)