Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return length in wc_Curve448PublicKeyToDer with NULL output param #7519

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -26801,6 +26801,58 @@ static int test_wc_Ed448PrivateKeyToDer(void)
return EXPECT_RESULT();
} /* End test_wc_Ed448PrivateKeyToDer*/

/*
* Testing wc_Curve448PrivateKeyToDer
*/
static int test_wc_Curve448PrivateKeyToDer(void)
{
EXPECT_DECLS;
#if defined(HAVE_CURVE448) && defined(HAVE_CURVE448_KEY_EXPORT) && \
(defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
byte output[ONEK_BUF];
curve448_key curve448PrivKey;
WC_RNG rng;
word32 inLen;

XMEMSET(&curve448PrivKey, 0, sizeof(curve448PrivKey));
XMEMSET(&rng, 0, sizeof(WC_RNG));

ExpectIntEQ(wc_curve448_init(&curve448PrivKey), 0);
ExpectIntEQ(wc_InitRng(&rng), 0);
ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &curve448PrivKey),
0);
inLen = (word32)sizeof(output);

/* Bad Cases */
ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, NULL, 0), BAD_FUNC_ARG);
ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, output, inLen), BAD_FUNC_ARG);
ExpectIntEQ(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, 0),
BAD_FUNC_ARG);
/* Good cases */
/* length only */
ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, NULL, inLen), 0);
ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, inLen), 0);

/* Bad Cases */
ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, NULL, 0, 0), BAD_FUNC_ARG);
ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, output, inLen, 0), BAD_FUNC_ARG);
ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 0),
BUFFER_E);
ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 1),
BUFFER_E);
/* Good cases */
/* length only */
ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, inLen, 0), 0);
ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, inLen, 1), 0);
ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 0), 0);
ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 1), 0);

DoExpectIntEQ(wc_FreeRng(&rng), 0);
wc_curve448_free(&curve448PrivKey);
#endif
return EXPECT_RESULT();
} /* End wc_Curve448PrivateKeyToDer*/

/*
* Testing wc_SetSubjectBuffer
*/
Expand Down Expand Up @@ -72011,6 +72063,7 @@ TEST_CASE testCases[] = {
TEST_DECL(test_wc_Ed448PublicKeyToDer),
TEST_DECL(test_wc_Ed448KeyToDer),
TEST_DECL(test_wc_Ed448PrivateKeyToDer),
TEST_DECL(test_wc_Curve448PrivateKeyToDer),

/* Signature API */
TEST_DECL(test_wc_SignatureGetSize_ecc),
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -35328,7 +35328,7 @@ int wc_Curve448PublicKeyToDer(curve448_key* key, byte* output, word32 inLen,
byte pubKey[CURVE448_PUB_KEY_SIZE];
word32 pubKeyLen = (word32)sizeof(pubKey);

if (key == NULL || output == NULL) {
if (key == NULL) {
return BAD_FUNC_ARG;
}

Expand Down