From a45b6fee91e597c16872a14d20a5aa58e60ea4c9 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Tue, 1 Nov 2022 13:14:28 +0000 Subject: [PATCH 01/13] Extract MPI_CORE(add_mod) from the prototype Signed-off-by: Tom Cosgrove --- library/bignum_mod_raw.c | 13 ++++++++++++- library/bignum_mod_raw.h | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c index b43add77d3..7c17e56029 100644 --- a/library/bignum_mod_raw.c +++ b/library/bignum_mod_raw.c @@ -119,7 +119,18 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, /* END MERGE SLOT 4 */ /* BEGIN MERGE SLOT 5 */ - +void MPI_CORE(add_mod)( mbedtls_mpi_uint *X, + mbedtls_mpi_uint const *A, + mbedtls_mpi_uint const *B, + const mbedtls_mpi_uint *N, + size_t n ) +{ + size_t carry, borrow = 0, fixup; + carry = mbedtls_mpi_core_add( X, A, B, n ); + borrow = mbedtls_mpi_core_sub( X, X, N, n); + fixup = ( carry < borrow ); + (void) mbedtls_mpi_core_add_if( X, N, n, fixup ); +} /* END MERGE SLOT 5 */ /* BEGIN MERGE SLOT 6 */ diff --git a/library/bignum_mod_raw.h b/library/bignum_mod_raw.h index f738e917e1..c57372c94a 100644 --- a/library/bignum_mod_raw.h +++ b/library/bignum_mod_raw.h @@ -155,7 +155,20 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, /* END MERGE SLOT 4 */ /* BEGIN MERGE SLOT 5 */ - +/** + * \brief Perform a known-size modular addition. + * + * Calculate A + B mod N. + * + * \param[out] X The result of the modular addition. + * \param[in] A The left operand. This must be smaller than \p N. + * \param[in] B The right operand. This must be smaller than \p N. + * \param[in] N The modulus. + * \param n Number of limbs of \p X, \p A, \p B and \p N. + */ +void MPI_CORE(add_mod)( mbedtls_mpi_uint *X, mbedtls_mpi_uint const *A, + mbedtls_mpi_uint const *B, const mbedtls_mpi_uint *N, + size_t n ); /* END MERGE SLOT 5 */ /* BEGIN MERGE SLOT 6 */ From 0eea827cbda3a10ca6515e21901b23942b43aa5a Mon Sep 17 00:00:00 2001 From: Werner Lewis Date: Tue, 1 Nov 2022 13:27:29 +0000 Subject: [PATCH 02/13] Rename MPI_CORE(add_mod) to mbedtls_mpi_mod_raw_add Signed-off-by: Werner Lewis --- library/bignum_mod_raw.c | 19 +++++++++---------- library/bignum_mod_raw.h | 22 +++++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c index 7c17e56029..2460329df6 100644 --- a/library/bignum_mod_raw.c +++ b/library/bignum_mod_raw.c @@ -119,17 +119,16 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, /* END MERGE SLOT 4 */ /* BEGIN MERGE SLOT 5 */ -void MPI_CORE(add_mod)( mbedtls_mpi_uint *X, - mbedtls_mpi_uint const *A, - mbedtls_mpi_uint const *B, - const mbedtls_mpi_uint *N, - size_t n ) +void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X, + mbedtls_mpi_uint const *A, + mbedtls_mpi_uint const *B, + const mbedtls_mpi_uint *N, + size_t limbs ) { - size_t carry, borrow = 0, fixup; - carry = mbedtls_mpi_core_add( X, A, B, n ); - borrow = mbedtls_mpi_core_sub( X, X, N, n); - fixup = ( carry < borrow ); - (void) mbedtls_mpi_core_add_if( X, N, n, fixup ); + size_t carry, borrow = 0; + carry = mbedtls_mpi_core_add( X, A, B, limbs ); + borrow = mbedtls_mpi_core_sub( X, X, N, limbs); + (void) mbedtls_mpi_core_add_if( X, N, limbs, ( carry < borrow ) ); } /* END MERGE SLOT 5 */ diff --git a/library/bignum_mod_raw.h b/library/bignum_mod_raw.h index c57372c94a..7b82c0639e 100644 --- a/library/bignum_mod_raw.h +++ b/library/bignum_mod_raw.h @@ -158,17 +158,21 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, /** * \brief Perform a known-size modular addition. * - * Calculate A + B mod N. + * Calculate `A + B modulo N` where \p A, \p B, and \p N have the same size. * - * \param[out] X The result of the modular addition. - * \param[in] A The left operand. This must be smaller than \p N. - * \param[in] B The right operand. This must be smaller than \p N. - * \param[in] N The modulus. - * \param n Number of limbs of \p X, \p A, \p B and \p N. + * \param[out] X The result of the modular addition. + * \param[in] A Little-endian presentation of the left operand. This + * must be smaller than \p N. + * \param[in] B Little-endian presentation of the right operand. This + * must be smaller than \p N. + * \param[in] N Little-endian presentation of the modulus. + * \param limbs Number of limbs of \p X, \p A, \p B and \p N. */ -void MPI_CORE(add_mod)( mbedtls_mpi_uint *X, mbedtls_mpi_uint const *A, - mbedtls_mpi_uint const *B, const mbedtls_mpi_uint *N, - size_t n ); +void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X, + mbedtls_mpi_uint const *A, + mbedtls_mpi_uint const *B, + const mbedtls_mpi_uint *N, + size_t limbs ); /* END MERGE SLOT 5 */ /* BEGIN MERGE SLOT 6 */ From 9fa91ebcb906ad93218d92bbf816bdad17f9f198 Mon Sep 17 00:00:00 2001 From: Werner Lewis Date: Tue, 1 Nov 2022 13:36:51 +0000 Subject: [PATCH 03/13] Use modulus structure in mbedtls_mpi_mod_raw_add Signed-off-by: Werner Lewis --- library/bignum_mod_raw.c | 9 ++++----- library/bignum_mod_raw.h | 12 ++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c index 2460329df6..01f5a4423f 100644 --- a/library/bignum_mod_raw.c +++ b/library/bignum_mod_raw.c @@ -122,13 +122,12 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X, mbedtls_mpi_uint const *A, mbedtls_mpi_uint const *B, - const mbedtls_mpi_uint *N, - size_t limbs ) + const mbedtls_mpi_mod_modulus *N ) { size_t carry, borrow = 0; - carry = mbedtls_mpi_core_add( X, A, B, limbs ); - borrow = mbedtls_mpi_core_sub( X, X, N, limbs); - (void) mbedtls_mpi_core_add_if( X, N, limbs, ( carry < borrow ) ); + carry = mbedtls_mpi_core_add( X, A, B, N->limbs ); + borrow = mbedtls_mpi_core_sub( X, X, N->p, N->limbs ); + (void) mbedtls_mpi_core_add_if( X, N->p, N->limbs, ( carry < borrow ) ); } /* END MERGE SLOT 5 */ diff --git a/library/bignum_mod_raw.h b/library/bignum_mod_raw.h index 7b82c0639e..d6522381bb 100644 --- a/library/bignum_mod_raw.h +++ b/library/bignum_mod_raw.h @@ -162,17 +162,17 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, * * \param[out] X The result of the modular addition. * \param[in] A Little-endian presentation of the left operand. This - * must be smaller than \p N. + * must be smaller than \p N, and have the same number of + * limbs. * \param[in] B Little-endian presentation of the right operand. This - * must be smaller than \p N. - * \param[in] N Little-endian presentation of the modulus. - * \param limbs Number of limbs of \p X, \p A, \p B and \p N. + * must be smaller than \p N, and have the same number of + * limbs. + * \param[in] N The address of the modulus. */ void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X, mbedtls_mpi_uint const *A, mbedtls_mpi_uint const *B, - const mbedtls_mpi_uint *N, - size_t limbs ); + const mbedtls_mpi_mod_modulus *N ); /* END MERGE SLOT 5 */ /* BEGIN MERGE SLOT 6 */ From baa34b6248b29a5c8153137b0b292dfa82095e6a Mon Sep 17 00:00:00 2001 From: Werner Lewis Date: Tue, 1 Nov 2022 15:37:50 +0000 Subject: [PATCH 04/13] Add test function for mpi_mod_raw_add Signed-off-by: Werner Lewis --- .../suites/test_suite_bignum_mod_raw.function | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/suites/test_suite_bignum_mod_raw.function b/tests/suites/test_suite_bignum_mod_raw.function index 4adccce25b..cf385e0813 100644 --- a/tests/suites/test_suite_bignum_mod_raw.function +++ b/tests/suites/test_suite_bignum_mod_raw.function @@ -287,6 +287,97 @@ exit: /* BEGIN MERGE SLOT 5 */ +/* BEGIN_CASE */ +void mpi_mod_raw_add( char * input_A, char * input_B, + char * input_N, char * input_S ) +{ + mbedtls_mpi_uint *A = NULL; + mbedtls_mpi_uint *B = NULL; + mbedtls_mpi_uint *S = NULL; + mbedtls_mpi_uint *N = NULL; + mbedtls_mpi_uint *X = NULL; + mbedtls_mpi_mod_modulus m; + size_t A_limbs, B_limbs, N_limbs, S_limbs; + + mbedtls_mpi_mod_modulus_init( &m ); + + TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ) ); + TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &B, &B_limbs, input_B ) ); + TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &N_limbs, input_N ) ); + TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &S, &S_limbs, input_S ) ); + + /* All inputs must have have the same number of limbs. */ + TEST_EQUAL( A_limbs, B_limbs ); + TEST_EQUAL( S_limbs, N_limbs ); + TEST_EQUAL( A_limbs, S_limbs ); + + size_t limbs = A_limbs; + size_t bytes = limbs * sizeof( *A ); + + ASSERT_ALLOC( X, limbs ); + + TEST_EQUAL( mbedtls_mpi_mod_modulus_setup( + &m, N, limbs, + MBEDTLS_MPI_MOD_EXT_REP_BE, + MBEDTLS_MPI_MOD_REP_MONTGOMERY + ), 0 ); + + /* A + B => Correct result */ + mbedtls_mpi_mod_raw_add( X, A, B, &m ); + ASSERT_COMPARE( X, bytes, S, bytes ); + + /* A + B: alias X to A => Correct result */ + memcpy( X, A, bytes ); + mbedtls_mpi_mod_raw_add( X, X, B, &m ); + ASSERT_COMPARE( X, bytes, S, bytes ); + + /* A + B: alias X to B => Correct result */ + memcpy( X, B, bytes ); + mbedtls_mpi_mod_raw_add( X, A, X, &m ); + ASSERT_COMPARE( X, bytes, S, bytes ); + + if ( memcmp(A, B, bytes ) == 0 ) + { + /* A == B: alias A and B */ + + /* A + A => Correct result */ + mbedtls_mpi_mod_raw_add( X, A, A, &m ); + ASSERT_COMPARE( X, bytes, S, bytes ); + + /* A + A, alias X to A => Correct result */ + memcpy( X, A, bytes ); + mbedtls_mpi_mod_raw_add( X, A, A, &m ); + ASSERT_COMPARE( X, bytes, S, bytes ); + } + else + { + /* A != B: test B + A */ + + /* B + A => Correct result */ + mbedtls_mpi_mod_raw_add( X, B, A, &m ); + ASSERT_COMPARE( X, bytes, S, bytes ); + + /* B + A: alias X to A => Correct result */ + memcpy( X, A, bytes ); + mbedtls_mpi_mod_raw_add( X, B, X, &m ); + ASSERT_COMPARE( X, bytes, S, bytes ); + + /* B + A: alias X to B => Correct result */ + memcpy( X, B, bytes ); + mbedtls_mpi_mod_raw_add( X, X, A, &m ); + ASSERT_COMPARE( X, bytes, S, bytes ); + } + +exit: + mbedtls_free( A ); + mbedtls_free( B ); + mbedtls_free( S ); + mbedtls_free( N ); + mbedtls_free( X ); + + mbedtls_mpi_mod_modulus_free( &m ); +} +/* END_CASE */ /* END MERGE SLOT 5 */ /* BEGIN MERGE SLOT 6 */ From d391b8ce612d5472e3cb7a86ff8f69e642a43ba2 Mon Sep 17 00:00:00 2001 From: Werner Lewis Date: Tue, 8 Nov 2022 15:53:47 +0000 Subject: [PATCH 05/13] Change types and move const before type Signed-off-by: Werner Lewis --- library/bignum_mod_raw.c | 6 +++--- library/bignum_mod_raw.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c index 01f5a4423f..94dcf7724c 100644 --- a/library/bignum_mod_raw.c +++ b/library/bignum_mod_raw.c @@ -120,11 +120,11 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, /* BEGIN MERGE SLOT 5 */ void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X, - mbedtls_mpi_uint const *A, - mbedtls_mpi_uint const *B, + const mbedtls_mpi_uint *A, + const mbedtls_mpi_uint *B, const mbedtls_mpi_mod_modulus *N ) { - size_t carry, borrow = 0; + mbedtls_mpi_uint carry, borrow; carry = mbedtls_mpi_core_add( X, A, B, N->limbs ); borrow = mbedtls_mpi_core_sub( X, X, N->p, N->limbs ); (void) mbedtls_mpi_core_add_if( X, N->p, N->limbs, ( carry < borrow ) ); diff --git a/library/bignum_mod_raw.h b/library/bignum_mod_raw.h index d6522381bb..bcb4a1596c 100644 --- a/library/bignum_mod_raw.h +++ b/library/bignum_mod_raw.h @@ -170,8 +170,8 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, * \param[in] N The address of the modulus. */ void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X, - mbedtls_mpi_uint const *A, - mbedtls_mpi_uint const *B, + const mbedtls_mpi_uint *A, + const mbedtls_mpi_uint *B, const mbedtls_mpi_mod_modulus *N ); /* END MERGE SLOT 5 */ From 1a277d9ad69eb75d8934d356838680116daf3ff6 Mon Sep 17 00:00:00 2001 From: Werner Lewis Date: Tue, 8 Nov 2022 15:55:17 +0000 Subject: [PATCH 06/13] Replace comparison with XOR Signed-off-by: Werner Lewis --- library/bignum_mod_raw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c index 94dcf7724c..8889f55410 100644 --- a/library/bignum_mod_raw.c +++ b/library/bignum_mod_raw.c @@ -127,7 +127,7 @@ void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X, mbedtls_mpi_uint carry, borrow; carry = mbedtls_mpi_core_add( X, A, B, N->limbs ); borrow = mbedtls_mpi_core_sub( X, X, N->p, N->limbs ); - (void) mbedtls_mpi_core_add_if( X, N->p, N->limbs, ( carry < borrow ) ); + (void) mbedtls_mpi_core_add_if( X, N->p, N->limbs, (unsigned char) ( carry ^ borrow ) ); } /* END MERGE SLOT 5 */ From f9075762455005d036ce2529df4a6138b2841284 Mon Sep 17 00:00:00 2001 From: Werner Lewis Date: Tue, 8 Nov 2022 16:01:06 +0000 Subject: [PATCH 07/13] Pass correct arguments in test Signed-off-by: Werner Lewis --- tests/suites/test_suite_bignum_mod_raw.function | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/suites/test_suite_bignum_mod_raw.function b/tests/suites/test_suite_bignum_mod_raw.function index cf385e0813..c510ac5d89 100644 --- a/tests/suites/test_suite_bignum_mod_raw.function +++ b/tests/suites/test_suite_bignum_mod_raw.function @@ -344,9 +344,9 @@ void mpi_mod_raw_add( char * input_A, char * input_B, mbedtls_mpi_mod_raw_add( X, A, A, &m ); ASSERT_COMPARE( X, bytes, S, bytes ); - /* A + A, alias X to A => Correct result */ + /* A + A: X, A, B all aliased together => Correct result */ memcpy( X, A, bytes ); - mbedtls_mpi_mod_raw_add( X, A, A, &m ); + mbedtls_mpi_mod_raw_add( X, X, X, &m ); ASSERT_COMPARE( X, bytes, S, bytes ); } else From e4c0a6c3ba7348dc1d4e9d0d653c11bccf02bad4 Mon Sep 17 00:00:00 2001 From: Werner Lewis Date: Thu, 17 Nov 2022 11:19:58 +0000 Subject: [PATCH 08/13] Change cast to correct type Signed-off-by: Werner Lewis --- library/bignum_mod_raw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c index 8889f55410..6ffe0a7e63 100644 --- a/library/bignum_mod_raw.c +++ b/library/bignum_mod_raw.c @@ -127,7 +127,7 @@ void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X, mbedtls_mpi_uint carry, borrow; carry = mbedtls_mpi_core_add( X, A, B, N->limbs ); borrow = mbedtls_mpi_core_sub( X, X, N->p, N->limbs ); - (void) mbedtls_mpi_core_add_if( X, N->p, N->limbs, (unsigned char) ( carry ^ borrow ) ); + (void) mbedtls_mpi_core_add_if( X, N->p, N->limbs, (unsigned) ( carry ^ borrow ) ); } /* END MERGE SLOT 5 */ From 54d87bf5c29ea0bac64f84b4d67d58e8804a14f5 Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Thu, 24 Nov 2022 15:47:02 +0000 Subject: [PATCH 09/13] Take limb count from the modulus in mod_raw_add tests Signed-off-by: Tom Cosgrove --- tests/suites/test_suite_bignum_mod_raw.function | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/suites/test_suite_bignum_mod_raw.function b/tests/suites/test_suite_bignum_mod_raw.function index c510ac5d89..7b1bda708c 100644 --- a/tests/suites/test_suite_bignum_mod_raw.function +++ b/tests/suites/test_suite_bignum_mod_raw.function @@ -296,9 +296,9 @@ void mpi_mod_raw_add( char * input_A, char * input_B, mbedtls_mpi_uint *S = NULL; mbedtls_mpi_uint *N = NULL; mbedtls_mpi_uint *X = NULL; - mbedtls_mpi_mod_modulus m; size_t A_limbs, B_limbs, N_limbs, S_limbs; + mbedtls_mpi_mod_modulus m; mbedtls_mpi_mod_modulus_init( &m ); TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ) ); @@ -306,14 +306,14 @@ void mpi_mod_raw_add( char * input_A, char * input_B, TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &N_limbs, input_N ) ); TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &S, &S_limbs, input_S ) ); - /* All inputs must have have the same number of limbs. */ - TEST_EQUAL( A_limbs, B_limbs ); - TEST_EQUAL( S_limbs, N_limbs ); - TEST_EQUAL( A_limbs, S_limbs ); - - size_t limbs = A_limbs; + /* Modulus gives the number of limbs; all inputs must have the same. */ + size_t limbs = N_limbs; size_t bytes = limbs * sizeof( *A ); + TEST_EQUAL( A_limbs, limbs ); + TEST_EQUAL( B_limbs, limbs ); + TEST_EQUAL( S_limbs, limbs ); + ASSERT_ALLOC( X, limbs ); TEST_EQUAL( mbedtls_mpi_mod_modulus_setup( From abddad4af88b2aa9c2e6c09448112efd529a18a7 Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Thu, 24 Nov 2022 15:54:16 +0000 Subject: [PATCH 10/13] Add note about aliasing of operands for mbedtls_mpi_mod_raw_add() Signed-off-by: Tom Cosgrove --- library/bignum_mod_raw.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/library/bignum_mod_raw.h b/library/bignum_mod_raw.h index bcb4a1596c..56a9f860d6 100644 --- a/library/bignum_mod_raw.h +++ b/library/bignum_mod_raw.h @@ -158,15 +158,19 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, /** * \brief Perform a known-size modular addition. * - * Calculate `A + B modulo N` where \p A, \p B, and \p N have the same size. + * Calculate `A + B modulo N`. + * + * The number of limbs in each operand, and the result, is given by the + * modulus \p N. + * + * \p X may be aliased to \p A or \p B, or even both, but may not overlap + * either otherwise. * * \param[out] X The result of the modular addition. * \param[in] A Little-endian presentation of the left operand. This - * must be smaller than \p N, and have the same number of - * limbs. + * must be smaller than \p N. * \param[in] B Little-endian presentation of the right operand. This - * must be smaller than \p N, and have the same number of - * limbs. + * must be smaller than \p N. * \param[in] N The address of the modulus. */ void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X, From 1923009cdb6f60964f80c84d3493dbfa47ec6cc4 Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Thu, 24 Nov 2022 15:56:53 +0000 Subject: [PATCH 11/13] Add test generation for mbedtls_mpi_mod_raw_add() Signed-off-by: Tom Cosgrove --- scripts/mbedtls_dev/bignum_mod_raw.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/mbedtls_dev/bignum_mod_raw.py b/scripts/mbedtls_dev/bignum_mod_raw.py index 60f2feded6..ee144aa1ec 100644 --- a/scripts/mbedtls_dev/bignum_mod_raw.py +++ b/scripts/mbedtls_dev/bignum_mod_raw.py @@ -42,6 +42,25 @@ class BignumModRawTarget(test_data_generation.BaseTarget): # BEGIN MERGE SLOT 5 +class BignumModRawAdd(bignum_common.ModOperationCommon, + BignumModRawTarget): + """Test cases for bignum mpi_mod_raw_add().""" + symbol = "+" + test_function = "mpi_mod_raw_add" + test_name = "mbedtls_mpi_mod_raw_add" + input_style = "fixed" + arity = 2 + + def arguments(self) -> List[str]: + return [bignum_common.quote_str(n) for n in [self.arg_a, + self.arg_b, + self.arg_n] + ] + self.result() + + def result(self) -> List[str]: + result = (self.int_a + self.int_b) % self.int_n + return [self.format_result(result)] + # END MERGE SLOT 5 # BEGIN MERGE SLOT 6 From 50fc127a4e3ef8d3ac2ca1c5c51f9fd6f1065fcd Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Thu, 24 Nov 2022 21:29:23 +0000 Subject: [PATCH 12/13] Change order of test arguments for bignum_mod_raw to simplify Python script Signed-off-by: Tom Cosgrove --- scripts/mbedtls_dev/bignum_mod_raw.py | 6 ------ tests/suites/test_suite_bignum_mod_raw.function | 5 +++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/scripts/mbedtls_dev/bignum_mod_raw.py b/scripts/mbedtls_dev/bignum_mod_raw.py index ee144aa1ec..4c53a7f4c1 100644 --- a/scripts/mbedtls_dev/bignum_mod_raw.py +++ b/scripts/mbedtls_dev/bignum_mod_raw.py @@ -51,12 +51,6 @@ class BignumModRawAdd(bignum_common.ModOperationCommon, input_style = "fixed" arity = 2 - def arguments(self) -> List[str]: - return [bignum_common.quote_str(n) for n in [self.arg_a, - self.arg_b, - self.arg_n] - ] + self.result() - def result(self) -> List[str]: result = (self.int_a + self.int_b) % self.int_n return [self.format_result(result)] diff --git a/tests/suites/test_suite_bignum_mod_raw.function b/tests/suites/test_suite_bignum_mod_raw.function index 7b1bda708c..148386189a 100644 --- a/tests/suites/test_suite_bignum_mod_raw.function +++ b/tests/suites/test_suite_bignum_mod_raw.function @@ -288,8 +288,9 @@ exit: /* BEGIN MERGE SLOT 5 */ /* BEGIN_CASE */ -void mpi_mod_raw_add( char * input_A, char * input_B, - char * input_N, char * input_S ) +void mpi_mod_raw_add( char * input_N, + char * input_A, char * input_B, + char * input_S ) { mbedtls_mpi_uint *A = NULL; mbedtls_mpi_uint *B = NULL; From ddad40b1de89f2b65090af1c8723d0352a700b71 Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Fri, 25 Nov 2022 14:18:52 +0000 Subject: [PATCH 13/13] Free the modulus before the data in it in mod_raw_add tests Signed-off-by: Tom Cosgrove --- tests/suites/test_suite_bignum_mod_raw.function | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/suites/test_suite_bignum_mod_raw.function b/tests/suites/test_suite_bignum_mod_raw.function index 148386189a..1939493816 100644 --- a/tests/suites/test_suite_bignum_mod_raw.function +++ b/tests/suites/test_suite_bignum_mod_raw.function @@ -370,13 +370,13 @@ void mpi_mod_raw_add( char * input_N, } exit: + mbedtls_mpi_mod_modulus_free( &m ); + mbedtls_free( A ); mbedtls_free( B ); mbedtls_free( S ); mbedtls_free( N ); mbedtls_free( X ); - - mbedtls_mpi_mod_modulus_free( &m ); } /* END_CASE */ /* END MERGE SLOT 5 */