mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-24 16:35:38 +00:00
Unit test function for mbedtls_ecp_muladd
Write a simple unit test for mbedtls_ecp_muladd(). Add just one pair of test cases. #2 fails since PR #3512. Thanks to Philippe Antoine (catenacyber) for the test case, found by ecfuzzer. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
80f56733b0
commit
ca91ee4ed8
|
@ -458,6 +458,14 @@ ECP point multiplication rng fail Curve25519
|
||||||
depends_on:MBEDTLS_ECP_DP_CURVE25519_ENABLED
|
depends_on:MBEDTLS_ECP_DP_CURVE25519_ENABLED
|
||||||
ecp_test_mul_rng:MBEDTLS_ECP_DP_CURVE25519:"5AC99F33632E5A768DE7E81BF854C27C46E3FBF2ABBACD29EC4AFF517369C660"
|
ecp_test_mul_rng:MBEDTLS_ECP_DP_CURVE25519:"5AC99F33632E5A768DE7E81BF854C27C46E3FBF2ABBACD29EC4AFF517369C660"
|
||||||
|
|
||||||
|
ECP point muladd secp256r1 #1
|
||||||
|
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||||
|
ecp_muladd:MBEDTLS_ECP_DP_SECP256R1:"01":"04e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e0e1ff20e1ffe120e1e1e173287170a761308491683e345cacaebb500c96e1a7bbd37772968b2c951f0579":"01":"04e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1ffffffff20e120e1e1e1e13a4e135157317b79d4ecf329fed4f9eb00dc67dbddae33faca8b6d8a0255b5ce":"04fab65e09aa5dd948320f86246be1d3fc571e7f799d9005170ed5cc868b67598431a668f96aa9fd0b0eb15f0edf4c7fe1be2885eadcb57e3db4fdd093585d3fa6"
|
||||||
|
|
||||||
|
ECP point muladd secp256r1 #2
|
||||||
|
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||||
|
ecp_muladd:MBEDTLS_ECP_DP_SECP256R1:"01":"04e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1ffffffff20e120e1e1e1e13a4e135157317b79d4ecf329fed4f9eb00dc67dbddae33faca8b6d8a0255b5ce":"01":"04e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e0e1ff20e1ffe120e1e1e173287170a761308491683e345cacaebb500c96e1a7bbd37772968b2c951f0579":"04fab65e09aa5dd948320f86246be1d3fc571e7f799d9005170ed5cc868b67598431a668f96aa9fd0b0eb15f0edf4c7fe1be2885eadcb57e3db4fdd093585d3fa6"
|
||||||
|
|
||||||
ECP test vectors Curve448 (RFC 7748 6.2, after decodeUCoordinate)
|
ECP test vectors Curve448 (RFC 7748 6.2, after decodeUCoordinate)
|
||||||
depends_on:MBEDTLS_ECP_DP_CURVE448_ENABLED
|
depends_on:MBEDTLS_ECP_DP_CURVE448_ENABLED
|
||||||
ecp_test_vec_x:MBEDTLS_ECP_DP_CURVE448:"eb7298a5c0d8c29a1dab27f1a6826300917389449741a974f5bac9d98dc298d46555bce8bae89eeed400584bb046cf75579f51d125498f98":"a01fc432e5807f17530d1288da125b0cd453d941726436c8bbd9c5222c3da7fa639ce03db8d23b274a0721a1aed5227de6e3b731ccf7089b":"ad997351b6106f36b0d1091b929c4c37213e0d2b97e85ebb20c127691d0dad8f1d8175b0723745e639a3cb7044290b99e0e2a0c27a6a301c":"0936f37bc6c1bd07ae3dec7ab5dc06a73ca13242fb343efc72b9d82730b445f3d4b0bd077162a46dcfec6f9b590bfcbcf520cdb029a8b73e":"9d874a5137509a449ad5853040241c5236395435c36424fd560b0cb62b281d285275a740ce32a22dd1740f4aa9161cec95ccc61a18f4ff07"
|
ecp_test_vec_x:MBEDTLS_ECP_DP_CURVE448:"eb7298a5c0d8c29a1dab27f1a6826300917389449741a974f5bac9d98dc298d46555bce8bae89eeed400584bb046cf75579f51d125498f98":"a01fc432e5807f17530d1288da125b0cd453d941726436c8bbd9c5222c3da7fa639ce03db8d23b274a0721a1aed5227de6e3b731ccf7089b":"ad997351b6106f36b0d1091b929c4c37213e0d2b97e85ebb20c127691d0dad8f1d8175b0723745e639a3cb7044290b99e0e2a0c27a6a301c":"0936f37bc6c1bd07ae3dec7ab5dc06a73ca13242fb343efc72b9d82730b445f3d4b0bd077162a46dcfec6f9b590bfcbcf520cdb029a8b73e":"9d874a5137509a449ad5853040241c5236395435c36424fd560b0cb62b281d285275a740ce32a22dd1740f4aa9161cec95ccc61a18f4ff07"
|
||||||
|
|
|
@ -752,6 +752,52 @@ exit:
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* BEGIN_CASE depends_on:MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
|
||||||
|
void ecp_muladd( int id,
|
||||||
|
data_t *u1_bin, data_t *P1_bin,
|
||||||
|
data_t *u2_bin, data_t *P2_bin,
|
||||||
|
data_t *expected_result )
|
||||||
|
{
|
||||||
|
/* Compute R = u1 * P1 + u2 * P2 */
|
||||||
|
mbedtls_ecp_group grp;
|
||||||
|
mbedtls_ecp_point P1, P2, R;
|
||||||
|
mbedtls_mpi u1, u2;
|
||||||
|
uint8_t actual_result[MBEDTLS_ECP_MAX_PT_LEN];
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
mbedtls_ecp_group_init( &grp );
|
||||||
|
mbedtls_ecp_point_init( &P1 );
|
||||||
|
mbedtls_ecp_point_init( &P2 );
|
||||||
|
mbedtls_ecp_point_init( &R );
|
||||||
|
mbedtls_mpi_init( &u1 );
|
||||||
|
mbedtls_mpi_init( &u2 );
|
||||||
|
|
||||||
|
TEST_EQUAL( 0, mbedtls_ecp_group_load( &grp, id ) );
|
||||||
|
TEST_EQUAL( 0, mbedtls_mpi_read_binary( &u1, u1_bin->x, u1_bin->len ) );
|
||||||
|
TEST_EQUAL( 0, mbedtls_mpi_read_binary( &u2, u2_bin->x, u2_bin->len ) );
|
||||||
|
TEST_EQUAL( 0, mbedtls_ecp_point_read_binary( &grp, &P1,
|
||||||
|
P1_bin->x, P1_bin->len ) );
|
||||||
|
TEST_EQUAL( 0, mbedtls_ecp_point_read_binary( &grp, &P2,
|
||||||
|
P2_bin->x, P2_bin->len ) );
|
||||||
|
|
||||||
|
TEST_EQUAL( 0, mbedtls_ecp_muladd( &grp, &R, &u1, &P1, &u2, &P2 ) );
|
||||||
|
TEST_EQUAL( 0, mbedtls_ecp_point_write_binary(
|
||||||
|
&grp, &R, MBEDTLS_ECP_PF_UNCOMPRESSED,
|
||||||
|
&len, actual_result, sizeof( actual_result ) ) );
|
||||||
|
|
||||||
|
ASSERT_COMPARE( expected_result->x, expected_result->len,
|
||||||
|
actual_result, len );
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mbedtls_ecp_group_free( &grp );
|
||||||
|
mbedtls_ecp_point_free( &P1 );
|
||||||
|
mbedtls_ecp_point_free( &P2 );
|
||||||
|
mbedtls_ecp_point_free( &R );
|
||||||
|
mbedtls_mpi_free( &u1 );
|
||||||
|
mbedtls_mpi_free( &u2 );
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void ecp_fast_mod( int id, char * N_str )
|
void ecp_fast_mod( int id, char * N_str )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue