@@ -86,10 +86,13 @@ const curve25519_set_type curve25519_sets[] = {
8686 }
8787};
8888
89- #if (!defined(WOLFSSL_CURVE25519_USE_ED25519 ) && \
89+ /* base point is only referenced by the software scalar-mult paths, which are
90+ * compiled out under WOLF_CRYPTO_CB_ONLY_CURVE25519 */
91+ #if !defined(WOLF_CRYPTO_CB_ONLY_CURVE25519 ) && \
92+ ((!defined(WOLFSSL_CURVE25519_USE_ED25519 ) && \
9093 !(defined(CURVED25519_X64 ) || (defined(WOLFSSL_ARMASM ) && \
9194 defined(__aarch64__ )))) || defined(WOLFSSL_CURVE25519_BLINDING ) || \
92- defined(WC_X25519_NONBLOCK )
95+ defined(WC_X25519_NONBLOCK ))
9396static const word32 kCurve25519BasePoint [CURVE25519_KEYSIZE /sizeof (word32 )] = {
9497#ifdef BIG_ENDIAN_ORDER
9598 0x09000000
@@ -165,6 +168,16 @@ int wc_curve25519_make_pub(int public_size, byte* pub, int private_size,
165168 if (ret != 0 )
166169 return ret ;
167170
171+ #ifdef WOLF_CRYPTO_CB
172+ ret = wc_CryptoCb_Curve25519MakePub (public_size , pub , private_size , priv );
173+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
174+ return ret ;
175+ /* fall-through when unavailable */
176+ #endif
177+
178+ #ifdef WOLF_CRYPTO_CB_ONLY_CURVE25519
179+ return NO_VALID_DEVID ;
180+ #else
168181#ifdef FREESCALE_LTC_ECC
169182 /* input basepoint on Weierstrass curve */
170183 ret = nxp_ltc_curve25519 (& wc_pub , priv , basepoint , kLTC_Weierstrass );
@@ -229,13 +242,15 @@ int wc_curve25519_make_pub(int public_size, byte* pub, int private_size,
229242#endif
230243
231244 return ret ;
245+ #endif /* WOLF_CRYPTO_CB_ONLY_CURVE25519 */
232246}
233247
234248#ifdef WOLFSSL_CURVE25519_BLINDING
235249#ifndef FREESCALE_LTC_ECC
236250#ifndef WOLFSSL_CURVE25519_BLINDING_RAND_CNT
237251 #define WOLFSSL_CURVE25519_BLINDING_RAND_CNT 10
238252#endif
253+ #ifndef WOLF_CRYPTO_CB_ONLY_CURVE25519
239254static int curve25519_smul_blind (byte * rp , const byte * n , const byte * p ,
240255 WC_RNG * rng )
241256{
@@ -293,6 +308,7 @@ static int curve25519_smul_blind(byte* rp, const byte* n, const byte* p,
293308
294309 return ret ;
295310}
311+ #endif /* !WOLF_CRYPTO_CB_ONLY_CURVE25519 */
296312#endif
297313
298314int wc_curve25519_make_pub_blind (int public_size , byte * pub , int private_size ,
@@ -322,6 +338,16 @@ int wc_curve25519_make_pub_blind(int public_size, byte* pub, int private_size,
322338 if (ret != 0 )
323339 return ret ;
324340
341+ #ifdef WOLF_CRYPTO_CB
342+ ret = wc_CryptoCb_Curve25519MakePub (public_size , pub , private_size , priv );
343+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
344+ return ret ;
345+ /* fall-through when unavailable */
346+ #endif
347+
348+ #ifdef WOLF_CRYPTO_CB_ONLY_CURVE25519
349+ return NO_VALID_DEVID ;
350+ #else
325351#ifdef FREESCALE_LTC_ECC
326352 /* input basepoint on Weierstrass curve */
327353 ret = nxp_ltc_curve25519 (& wc_pub , priv , basepoint , kLTC_Weierstrass );
@@ -341,6 +367,7 @@ int wc_curve25519_make_pub_blind(int public_size, byte* pub, int private_size,
341367 }
342368
343369 return ret ;
370+ #endif /* WOLF_CRYPTO_CB_ONLY_CURVE25519 */
344371}
345372#endif
346373
@@ -359,7 +386,6 @@ int wc_curve25519_generic(int public_size, byte* pub,
359386 * nxp_ltc_curve25519_GetBasePoint() */
360387 return WC_HW_E ;
361388#else
362- #ifndef WOLFSSL_CURVE25519_BLINDING
363389 int ret ;
364390
365391 if ((public_size != CURVE25519_KEYSIZE ) ||
@@ -375,6 +401,17 @@ int wc_curve25519_generic(int public_size, byte* pub,
375401 if (ret != 0 )
376402 return ret ;
377403
404+ #ifdef WOLF_CRYPTO_CB
405+ ret = wc_CryptoCb_Curve25519Generic (public_size , pub , private_size , priv ,
406+ basepoint_size , basepoint );
407+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
408+ return ret ;
409+ /* fall-through when unavailable */
410+ #endif
411+
412+ #ifdef WOLF_CRYPTO_CB_ONLY_CURVE25519
413+ return NO_VALID_DEVID ;
414+ #elif !defined(WOLFSSL_CURVE25519_BLINDING )
378415 fe_init ();
379416
380417 SAVE_VECTOR_REGISTERS (return _svr_ret ;);
@@ -385,15 +422,16 @@ int wc_curve25519_generic(int public_size, byte* pub,
385422
386423 return ret ;
387424#else
388- WC_RNG rng ;
389- int ret ;
425+ {
426+ WC_RNG rng ;
390427
391- ret = wc_InitRng (& rng );
392- if (ret == 0 ) {
393- ret = wc_curve25519_generic_blind (public_size , pub , private_size , priv ,
394- basepoint_size , basepoint , & rng );
428+ ret = wc_InitRng (& rng );
429+ if (ret == 0 ) {
430+ ret = wc_curve25519_generic_blind (public_size , pub , private_size ,
431+ priv , basepoint_size , basepoint , & rng );
395432
396- wc_FreeRng (& rng );
433+ wc_FreeRng (& rng );
434+ }
397435 }
398436
399437 return ret ;
@@ -436,11 +474,23 @@ int wc_curve25519_generic_blind(int public_size, byte* pub,
436474 if (ret != 0 )
437475 return ret ;
438476
477+ #ifdef WOLF_CRYPTO_CB
478+ ret = wc_CryptoCb_Curve25519Generic (public_size , pub , private_size , priv ,
479+ basepoint_size , basepoint );
480+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
481+ return ret ;
482+ /* fall-through when unavailable */
483+ #endif
484+
485+ #ifdef WOLF_CRYPTO_CB_ONLY_CURVE25519
486+ return NO_VALID_DEVID ;
487+ #else
439488 fe_init ();
440489
441490 ret = curve25519_smul_blind (pub , priv , basepoint , rng );
442491
443492 return ret ;
493+ #endif /* WOLF_CRYPTO_CB_ONLY_CURVE25519 */
444494#endif /* FREESCALE_LTC_ECC */
445495}
446496#endif
@@ -1206,7 +1256,8 @@ int wc_curve25519_init_ex(curve25519_key* key, void* heap, int devId)
12061256 #endif
12071257 (void )heap ; /* if needed for XMALLOC/XFREE in future */
12081258
1209- #ifndef FREESCALE_LTC_ECC
1259+ /* field math is implemented in the callback in crypto cb only */
1260+ #if !defined(FREESCALE_LTC_ECC ) && !defined(WOLF_CRYPTO_CB_ONLY_CURVE25519 )
12101261 fe_init ();
12111262 #endif
12121263
0 commit comments