@@ -376,14 +376,20 @@ int wc_ed25519_make_key(WC_RNG* rng, int keySz, ed25519_key* key)
376376 key -> pubKeySet = 0 ;
377377
378378#ifdef WOLF_CRYPTO_CB
379- if (key -> devId != INVALID_DEVID ) {
379+ #ifndef WOLF_CRYPTO_CB_FIND
380+ if (key -> devId != INVALID_DEVID )
381+ #endif
382+ {
380383 ret = wc_CryptoCb_Ed25519Gen (rng , keySz , key );
381384 if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
382385 return ret ;
383386 /* fall-through when unavailable */
384387 }
385388#endif
386389
390+ #ifdef WOLF_CRYPTO_CB_ONLY_ED25519
391+ return NO_VALID_DEVID ;
392+ #else
387393 ret = wc_RNG_GenerateBlock (rng , key -> k , ED25519_KEY_SIZE );
388394 if (ret != 0 )
389395 return ret ;
@@ -407,6 +413,7 @@ int wc_ed25519_make_key(WC_RNG* rng, int keySz, ed25519_key* key)
407413#endif
408414
409415 return ret ;
416+ #endif /* WOLF_CRYPTO_CB_ONLY_ED25519 */
410417}
411418#endif /* HAVE_ED25519_MAKE_KEY */
412419
@@ -434,6 +441,30 @@ int wc_ed25519_sign_msg_ex(const byte* in, word32 inLen, byte* out,
434441 (void )contextLen ;
435442 (void )type ;
436443 ret = se050_ed25519_sign_msg (in , inLen , out , outLen , key );
444+ #elif defined(WOLF_CRYPTO_CB_ONLY_ED25519 )
445+ ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
446+
447+ if (in == NULL || out == NULL || outLen == NULL || key == NULL ||
448+ (context == NULL && contextLen != 0 )) {
449+ return BAD_FUNC_ARG ;
450+ }
451+
452+ if ((type == Ed25519ph ) &&
453+ (inLen != WC_SHA512_DIGEST_SIZE ))
454+ {
455+ return BAD_LENGTH_E ;
456+ }
457+
458+ #ifndef WOLF_CRYPTO_CB_FIND
459+ if (key -> devId != INVALID_DEVID )
460+ #endif
461+ {
462+ ret = wc_CryptoCb_Ed25519Sign (in , inLen , out , outLen , key , type ,
463+ context , contextLen );
464+ }
465+ if (ret == WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE )) {
466+ ret = NO_VALID_DEVID ;
467+ }
437468#else
438469#ifdef FREESCALE_LTC_ECC
439470 ALIGN16 byte tempBuf [ED25519_PRV_KEY_SIZE ];
@@ -461,7 +492,10 @@ int wc_ed25519_sign_msg_ex(const byte* in, word32 inLen, byte* out,
461492 }
462493
463494#ifdef WOLF_CRYPTO_CB
464- if (key -> devId != INVALID_DEVID ) {
495+ #ifndef WOLF_CRYPTO_CB_FIND
496+ if (key -> devId != INVALID_DEVID )
497+ #endif
498+ {
465499 ret = wc_CryptoCb_Ed25519Sign (in , inLen , out , outLen , key , type ,
466500 context , contextLen );
467501 if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
@@ -599,7 +633,8 @@ int wc_ed25519_sign_msg_ex(const byte* in, word32 inLen, byte* out,
599633 ForceZero (nonce , sizeof (nonce ));
600634#endif /* WOLFSSL_SE050 */
601635
602- #ifdef WOLFSSL_EDDSA_CHECK_PRIV_ON_SIGN
636+ #if defined(WOLFSSL_EDDSA_CHECK_PRIV_ON_SIGN ) && \
637+ !defined(WOLF_CRYPTO_CB_ONLY_ED25519 )
603638 if (ret == 0 ) {
604639 int i ;
605640 byte c = 0 ;
@@ -696,7 +731,7 @@ int wc_ed25519ph_sign_msg(const byte* in, word32 inLen, byte* out,
696731#endif /* HAVE_ED25519_SIGN */
697732
698733#ifdef HAVE_ED25519_VERIFY
699- #ifndef WOLFSSL_SE050
734+ #if !defined( WOLFSSL_SE050 ) && !defined( WOLF_CRYPTO_CB_ONLY_ED25519 )
700735
701736#ifdef WOLFSSL_CHECK_VER_FAULTS
702737static const byte sha512_empty [] = {
@@ -928,7 +963,7 @@ static int ed25519_verify_msg_final_with_sha(const byte* sig, word32 sigLen,
928963
929964 return ret ;
930965}
931- #endif /* WOLFSSL_SE050 */
966+ #endif /* ! WOLFSSL_SE050 && !WOLF_CRYPTO_CB_ONLY_ED25519 */
932967
933968#if defined(WOLFSSL_ED25519_STREAMING_VERIFY ) && !defined(WOLFSSL_SE050 )
934969
@@ -972,6 +1007,30 @@ int wc_ed25519_verify_msg_ex(const byte* sig, word32 sigLen, const byte* msg,
9721007 (void )contextLen ;
9731008 (void )ed25519Ctx ;
9741009 ret = se050_ed25519_verify_msg (sig , sigLen , msg , msgLen , key , res );
1010+ #elif defined(WOLF_CRYPTO_CB_ONLY_ED25519 )
1011+ (void )ed25519Ctx ;
1012+ ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
1013+
1014+ if (sig == NULL || msg == NULL || res == NULL || key == NULL ||
1015+ (context == NULL && contextLen != 0 ))
1016+ return BAD_FUNC_ARG ;
1017+
1018+ if ((type == Ed25519ph ) &&
1019+ (msgLen != WC_SHA512_DIGEST_SIZE ))
1020+ {
1021+ return BAD_LENGTH_E ;
1022+ }
1023+
1024+ #ifndef WOLF_CRYPTO_CB_FIND
1025+ if (key -> devId != INVALID_DEVID )
1026+ #endif
1027+ {
1028+ ret = wc_CryptoCb_Ed25519Verify (sig , sigLen , msg , msgLen , res , key ,
1029+ type , context , contextLen );
1030+ }
1031+ if (ret == WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE )) {
1032+ ret = NO_VALID_DEVID ;
1033+ }
9751034#else
9761035#ifdef WOLFSSL_ED25519_PERSISTENT_SHA
9771036 wc_Sha512 * sha ;
@@ -991,7 +1050,10 @@ int wc_ed25519_verify_msg_ex(const byte* sig, word32 sigLen, const byte* msg,
9911050 }
9921051
9931052#ifdef WOLF_CRYPTO_CB
994- if (key -> devId != INVALID_DEVID ) {
1053+ #ifndef WOLF_CRYPTO_CB_FIND
1054+ if (key -> devId != INVALID_DEVID )
1055+ #endif
1056+ {
9951057 ret = wc_CryptoCb_Ed25519Verify (sig , sigLen , msg , msgLen , res , key ,
9961058 type , context , contextLen );
9971059 if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
0 commit comments