@@ -307,6 +307,10 @@ int test_wc_curve25519_shared_secret_ex(void)
307307 WC_RNG rng ;
308308 byte out [CURVE25519_KEYSIZE ];
309309 word32 outLen = sizeof (out );
310+ #ifndef WOLFSSL_X25519_NO_MASK_PEER
311+ byte outHiBit [CURVE25519_KEYSIZE ];
312+ word32 outHiBitLen = sizeof (out );
313+ #endif
310314 int endian = EC25519_BIG_ENDIAN ;
311315
312316 ExpectIntEQ (wc_curve25519_init (& private_key ), 0 );
@@ -336,11 +340,25 @@ int test_wc_curve25519_shared_secret_ex(void)
336340 ExpectIntEQ (wc_curve25519_shared_secret_ex (& private_key , & public_key , out ,
337341 NULL , endian ), WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
338342
343+ #ifdef WOLFSSL_X25519_NO_MASK_PEER
339344 /* curve25519.c is checking for public_key size less than or equal to 0x7f,
340345 * increasing to 0x8f checks for error being returned */
341- public_key .p .point [CURVE25519_KEYSIZE - 1 ] = 0x8F ;
346+ if (EXPECT_SUCCESS ()) {
347+ public_key .p .point [CURVE25519_KEYSIZE - 1 ] = 0x8F ;
348+ }
342349 ExpectIntEQ (wc_curve25519_shared_secret_ex (& private_key , & public_key , out ,
343350 & outLen , endian ), WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
351+ #else
352+ ExpectIntEQ (wc_curve25519_shared_secret_ex (& private_key , & public_key , out ,
353+ & outLen , endian ), 0 );
354+ if (EXPECT_SUCCESS ()) {
355+ public_key .p .point [CURVE25519_KEYSIZE - 1 ] |= 0x80 ;
356+ }
357+ ExpectIntEQ (wc_curve25519_shared_secret_ex (& private_key , & public_key ,
358+ outHiBit , & outHiBitLen , endian ), 0 );
359+ ExpectIntEQ (outLen , outHiBitLen );
360+ ExpectBufEQ (out , outHiBit , outLen );
361+ #endif
344362
345363 outLen = outLen - 2 ;
346364 ExpectIntEQ (wc_curve25519_shared_secret_ex (& private_key , & public_key , out ,
0 commit comments