Skip to content

Commit 7a326ef

Browse files
authored
Merge pull request #9553 from julek-wolfssl/ed25519-export-key-check
ed25519: validate presence of keys in export functions
2 parents 0a0c430 + dd35f10 commit 7a326ef

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tests/api/test_ed25519.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ int test_wc_Ed25519PublicKeyToDer(void)
490490
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
491491
ExpectIntEQ(wc_ed25519_init(&key), 0);
492492
ExpectIntEQ(wc_Ed25519PublicKeyToDer(&key, derBuf, 0, 0),
493-
WC_NO_ERR_TRACE(BUFFER_E));
493+
WC_NO_ERR_TRACE(PUBLIC_KEY_E));
494494
wc_ed25519_free(&key);
495495

496496
/* Test good args */

wolfcrypt/src/ed25519.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,9 @@ int wc_ed25519_export_public(const ed25519_key* key, byte* out, word32* outLen)
11271127
return BUFFER_E;
11281128
}
11291129

1130+
if (!key->pubKeySet)
1131+
return PUBLIC_KEY_E;
1132+
11301133
*outLen = ED25519_PUB_KEY_SIZE;
11311134
XMEMCPY(out, key->p, ED25519_PUB_KEY_SIZE);
11321135

@@ -1368,7 +1371,7 @@ int wc_ed25519_export_private_only(const ed25519_key* key, byte* out, word32* ou
13681371
int wc_ed25519_export_private(const ed25519_key* key, byte* out, word32* outLen)
13691372
{
13701373
/* sanity checks on arguments */
1371-
if (key == NULL || out == NULL || outLen == NULL)
1374+
if (key == NULL || !key->privKeySet || out == NULL || outLen == NULL)
13721375
return BAD_FUNC_ARG;
13731376

13741377
if (*outLen < ED25519_PRV_KEY_SIZE) {
@@ -1398,6 +1401,8 @@ int wc_ed25519_export_key(const ed25519_key* key,
13981401

13991402
/* export public part */
14001403
ret = wc_ed25519_export_public(key, pub, pubSz);
1404+
if (ret == WC_NO_ERR_TRACE(PUBLIC_KEY_E))
1405+
ret = 0; /* ignore no public key */
14011406

14021407
return ret;
14031408
}

0 commit comments

Comments
 (0)