Skip to content

Commit

Permalink
Merge pull request #8472 from SparkiDev/ed25519_fix_tests
Browse files Browse the repository at this point in the history
Ed25519: fix tests to compile with feature defines
  • Loading branch information
JacobBarthelmeh authored Feb 19, 2025
2 parents 393c92c + 331a713 commit 373a7d4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
4 changes: 4 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -54486,7 +54486,11 @@ static int test_wolfSSL_private_keys(void)
ExpectNotNull(ssl = SSL_new(ctx));

#if !defined(NO_CHECK_PRIVATE_KEY)
#ifdef HAVE_ED25519_MAKE_KEY
ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
#else
ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
#endif
#endif

SSL_free(ssl);
Expand Down
6 changes: 3 additions & 3 deletions wolfcrypt/src/ge_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -9392,7 +9392,7 @@ B is the Ed25519 base point (x,4/5) with x positive.
int ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a,
const ge_p3 *A, const unsigned char *b)
{
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
signed char *aslide = NULL;
signed char *bslide = NULL;
ge_cached *Ai = NULL; /* A,3A,5A,7A,9A,11A,13A,15A */
Expand All @@ -9413,7 +9413,7 @@ int ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a,
#endif
int i;

#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
if (((aslide = (signed char *)XMALLOC(SLIDE_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER))== NULL) ||
((bslide = (signed char *)XMALLOC(SLIDE_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER))== NULL) ||
((Ai = (ge_cached *)XMALLOC(8 * sizeof(*Ai), NULL, DYNAMIC_TYPE_TMP_BUFFER))== NULL) ||
Expand Down Expand Up @@ -9475,7 +9475,7 @@ int ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a,
}
#endif

#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
out:

XFREE(aslide, NULL, DYNAMIC_TYPE_TMP_BUFFER);
Expand Down
38 changes: 26 additions & 12 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -36708,23 +36708,33 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
#endif
#else
wc_ed25519_init_ex(key, HEAP_HINT, devId);
wc_ed25519_init_ex(key2, HEAP_HINT, devId);
ret = wc_ed25519_init_ex(key, HEAP_HINT, devId);
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
ret = wc_ed25519_init_ex(key2, HEAP_HINT, devId);
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
#if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
wc_ed25519_init_ex(key3, HEAP_HINT, devId);
ret = wc_ed25519_init_ex(key3, HEAP_HINT, devId);
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
#endif
#endif

#ifdef HAVE_ED25519_MAKE_KEY
wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key);
wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key2);
ret = wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key);
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
ret = wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key2);
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
#endif

/* helper functions for signature and key size */
keySz = (word32)wc_ed25519_size(key);
sigSz = (word32)wc_ed25519_sig_size(key);

#if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
#if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
defined(HAVE_ED25519_KEY_IMPORT)
for (i = 0; i < 6; i++) {
outlen = sizeof(out);
Expand Down Expand Up @@ -36799,6 +36809,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
#endif /* HAVE_ED25519_VERIFY */
}

#ifdef HAVE_ED25519_VERIFY
{
/* Run tests for some rare code paths */
/* sig is exactly equal to the order */
Expand Down Expand Up @@ -36871,6 +36882,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
if (ret != WC_NO_ERR_TRACE(SIG_VERIFY_E))
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
}
#endif /* HAVE_ED25519_VERIFY */

ret = ed25519ctx_test();
if (ret != 0)
Expand Down Expand Up @@ -36939,18 +36951,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)

if (XMEMCMP(out, sigs[0], 64))
ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);

#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
wc_ed25519_delete(key3, &key3);
#else
wc_ed25519_free(key3);
#endif
#endif /* NO_ASN */
#endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */

#if defined(HAVE_ED25519_KEY_IMPORT)
ret = ed25519_test_check_key();
if (ret < 0)
goto cleanup;
#endif
#ifdef WOLFSSL_TEST_CERT
ret = ed25519_test_cert();
if (ret < 0)
Expand All @@ -36968,9 +36976,15 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
wc_ed25519_delete(key, &key);
wc_ed25519_delete(key2, &key2);
#if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
wc_ed25519_delete(key3, &key3);
#endif
#else
wc_ed25519_free(key);
wc_ed25519_free(key2);
#if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
wc_ed25519_free(key3);
#endif
#endif

#if defined(HAVE_HASHDRBG) || defined(NO_RC4)
Expand Down

0 comments on commit 373a7d4

Please sign in to comment.