diff --git a/tests/api/test_ed25519.c b/tests/api/test_ed25519.c index 88d83d67a..6831f2162 100644 --- a/tests/api/test_ed25519.c +++ b/tests/api/test_ed25519.c @@ -490,7 +490,7 @@ int test_wc_Ed25519PublicKeyToDer(void) WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_ed25519_init(&key), 0); ExpectIntEQ(wc_Ed25519PublicKeyToDer(&key, derBuf, 0, 0), - WC_NO_ERR_TRACE(BUFFER_E)); + WC_NO_ERR_TRACE(PUBLIC_KEY_E)); wc_ed25519_free(&key); /* Test good args */ diff --git a/wolfcrypt/src/ed25519.c b/wolfcrypt/src/ed25519.c index a03efb560..3744e1dfe 100644 --- a/wolfcrypt/src/ed25519.c +++ b/wolfcrypt/src/ed25519.c @@ -1127,6 +1127,9 @@ int wc_ed25519_export_public(const ed25519_key* key, byte* out, word32* outLen) return BUFFER_E; } + if (!key->pubKeySet) + return PUBLIC_KEY_E; + *outLen = ED25519_PUB_KEY_SIZE; XMEMCPY(out, key->p, ED25519_PUB_KEY_SIZE); @@ -1368,7 +1371,7 @@ int wc_ed25519_export_private_only(const ed25519_key* key, byte* out, word32* ou int wc_ed25519_export_private(const ed25519_key* key, byte* out, word32* outLen) { /* sanity checks on arguments */ - if (key == NULL || out == NULL || outLen == NULL) + if (key == NULL || !key->privKeySet || out == NULL || outLen == NULL) return BAD_FUNC_ARG; if (*outLen < ED25519_PRV_KEY_SIZE) { @@ -1398,6 +1401,8 @@ int wc_ed25519_export_key(const ed25519_key* key, /* export public part */ ret = wc_ed25519_export_public(key, pub, pubSz); + if (ret == WC_NO_ERR_TRACE(PUBLIC_KEY_E)) + ret = 0; /* ignore no public key */ return ret; }