@@ -444,14 +444,17 @@ int test_wc_curve25519_export_private_raw_ex(void)
444444 EXPECT_DECLS ;
445445#if defined(HAVE_CURVE25519 )
446446 curve25519_key key ;
447+ WC_RNG rng ;
447448 byte out [CURVE25519_KEYSIZE ];
448449 word32 outLen = sizeof (out );
449450 int endian = EC25519_BIG_ENDIAN ;
450451
452+ XMEMSET (& rng , 0 , sizeof (WC_RNG ));
451453 ExpectIntEQ (wc_curve25519_init (& key ), 0 );
452454
455+ /* Reject export when private key not set (privSet == 0). */
453456 ExpectIntEQ (wc_curve25519_export_private_raw_ex (& key , out , & outLen , endian ),
454- 0 );
457+ WC_NO_ERR_TRACE ( ECC_BAD_ARG_E ) );
455458 /* test bad cases */
456459 ExpectIntEQ (wc_curve25519_export_private_raw_ex (NULL , NULL , NULL , endian ),
457460 WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
@@ -461,12 +464,15 @@ int test_wc_curve25519_export_private_raw_ex(void)
461464 endian ), WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
462465 ExpectIntEQ (wc_curve25519_export_private_raw_ex (& key , out , NULL , endian ),
463466 WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
464- ExpectIntEQ (wc_curve25519_export_private_raw_ex (& key , out , & outLen ,
465- EC25519_LITTLE_ENDIAN ), 0 );
466- outLen = outLen - 2 ;
467+
468+ /* Populate the key, then exercise the buffer-too-small path. */
469+ ExpectIntEQ (wc_InitRng (& rng ), 0 );
470+ ExpectIntEQ (wc_curve25519_make_key (& rng , CURVE25519_KEYSIZE , & key ), 0 );
471+ outLen = CURVE25519_KEYSIZE - 1 ;
467472 ExpectIntEQ (wc_curve25519_export_private_raw_ex (& key , out , & outLen , endian ),
468473 WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
469474
475+ DoExpectIntEQ (wc_FreeRng (& rng ), 0 );
470476 wc_curve25519_free (& key );
471477#endif
472478 return EXPECT_RESULT ();
0 commit comments