From 6c591fab726cb36eab0d16cf127440b439919421 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Thu, 5 May 2011 11:49:20 +0000 Subject: [PATCH] - mpi_init() and mpi_free() only accept a single argument and do not accept variable arguments anymore. This prevents unexpected memory corruption in a number of use cases. --- ChangeLog | 2 + include/polarssl/bignum.h | 12 +- library/bignum.c | 114 ++++++++--------- library/dhm.c | 10 +- library/rsa.c | 49 ++++---- programs/pkey/dh_genprime.c | 4 +- programs/pkey/mpi_demo.c | 10 +- tests/suites/test_suite_debug.function | 4 +- tests/suites/test_suite_mpi.function | 138 ++++++++++++++++----- tests/suites/test_suite_pkcs1_v21.function | 8 +- tests/suites/test_suite_rsa.function | 16 ++- 11 files changed, 230 insertions(+), 137 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88db5f312..a084e5594 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ Changes instead of int for buffer lengths and loop variables for better unsigned / signed use. Renamed internal bigint types t_int and t_dbl to t_uint and t_udbl in the process + * mpi_init() and mpi_free() now only accept a single MPI + argument and do not accept variable argument lists anymore. = Version 0.99-pre4 released on 2011-04-01 Features diff --git a/include/polarssl/bignum.h b/include/polarssl/bignum.h index a6d7d4a5a..38009679f 100644 --- a/include/polarssl/bignum.h +++ b/include/polarssl/bignum.h @@ -92,14 +92,18 @@ extern "C" { #endif /** - * \brief Initialize one or more mpi + * \brief Initialize one MPI + * + * \param X One MPI to initialize. */ -void mpi_init( mpi *X, ... ); +void mpi_init( mpi *X ); /** - * \brief Unallocate one or more mpi + * \brief Unallocate one MPI + * + * \param X One MPI to unallocate. */ -void mpi_free( mpi *X, ... ); +void mpi_free( mpi *X ); /** * \brief Enlarge to the specified number of limbs diff --git a/library/bignum.c b/library/bignum.c index 2b6e23495..2e3595c5e 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -38,7 +38,6 @@ #include "polarssl/bn_mul.h" #include -#include #define ciL (sizeof(t_uint)) /* chars in limb */ #define biL (ciL << 3) /* bits in limb */ @@ -51,51 +50,35 @@ #define CHARS_TO_LIMBS(i) (((i) + ciL - 1) / ciL) /* - * Initialize one or more mpi + * Initialize one MPI */ -void mpi_init( mpi *X, ... ) +void mpi_init( mpi *X ) { - va_list args; + if( X == NULL ) + return; - va_start( args, X ); - - while( X != NULL ) - { - X->s = 1; - X->n = 0; - X->p = NULL; - - X = va_arg( args, mpi* ); - } - - va_end( args ); + X->s = 1; + X->n = 0; + X->p = NULL; } /* - * Unallocate one or more mpi + * Unallocate one MPI */ -void mpi_free( mpi *X, ... ) +void mpi_free( mpi *X ) { - va_list args; + if( X == NULL ) + return; - va_start( args, X ); - - while( X != NULL ) + if( X->p != NULL ) { - if( X->p != NULL ) - { - memset( X->p, 0, X->n * ciL ); - free( X->p ); - } - - X->s = 1; - X->n = 0; - X->p = NULL; - - X = va_arg( args, mpi* ); + memset( X->p, 0, X->n * ciL ); + free( X->p ); } - va_end( args ); + X->s = 1; + X->n = 0; + X->p = NULL; } /* @@ -258,7 +241,7 @@ int mpi_read_string( mpi *X, int radix, const char *s ) if( radix < 2 || radix > 16 ) return( POLARSSL_ERR_MPI_BAD_INPUT_DATA ); - mpi_init( &T, NULL ); + mpi_init( &T ); slen = strlen( s ); @@ -309,7 +292,7 @@ int mpi_read_string( mpi *X, int radix, const char *s ) cleanup: - mpi_free( &T, NULL ); + mpi_free( &T ); return( ret ); } @@ -366,7 +349,7 @@ int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen ) } p = s; - mpi_init( &T, NULL ); + mpi_init( &T ); if( X->s == -1 ) *p++ = '-'; @@ -405,7 +388,7 @@ int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen ) cleanup: - mpi_free( &T, NULL ); + mpi_free( &T ); return( ret ); } @@ -771,7 +754,7 @@ int mpi_sub_abs( mpi *X, const mpi *A, const mpi *B ) if( mpi_cmp_abs( A, B ) < 0 ) return( POLARSSL_ERR_MPI_NEGATIVE_VALUE ); - mpi_init( &TB, NULL ); + mpi_init( &TB ); if( X == B ) { @@ -797,7 +780,7 @@ int mpi_sub_abs( mpi *X, const mpi *A, const mpi *B ) cleanup: - mpi_free( &TB, NULL ); + mpi_free( &TB ); return( ret ); } @@ -969,7 +952,7 @@ int mpi_mul_mpi( mpi *X, const mpi *A, const mpi *B ) size_t i, j; mpi TA, TB; - mpi_init( &TA, &TB, NULL ); + mpi_init( &TA ); mpi_init( &TB ); if( X == A ) { MPI_CHK( mpi_copy( &TA, A ) ); A = &TA; } if( X == B ) { MPI_CHK( mpi_copy( &TB, B ) ); B = &TB; } @@ -992,7 +975,7 @@ int mpi_mul_mpi( mpi *X, const mpi *A, const mpi *B ) cleanup: - mpi_free( &TB, &TA, NULL ); + mpi_free( &TB ); mpi_free( &TA ); return( ret ); } @@ -1025,7 +1008,8 @@ int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B ) if( mpi_cmp_int( B, 0 ) == 0 ) return( POLARSSL_ERR_MPI_DIVISION_BY_ZERO ); - mpi_init( &X, &Y, &Z, &T1, &T2, NULL ); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); + mpi_init( &T1 ); mpi_init( &T2 ); if( mpi_cmp_abs( A, B ) < 0 ) { @@ -1170,7 +1154,8 @@ int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B ) cleanup: - mpi_free( &X, &Y, &Z, &T1, &T2, NULL ); + mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); + mpi_free( &T1 ); mpi_free( &T2 ); return( ret ); } @@ -1363,7 +1348,7 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR ) * Init temps and window size */ mpi_montg_init( &mm, N ); - mpi_init( &RR, &T, NULL ); + mpi_init( &RR ); mpi_init( &T ); memset( W, 0, sizeof( W ) ); i = mpi_msb( E ); @@ -1514,11 +1499,12 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR ) cleanup: for( i = (one << (wsize - 1)); i < (one << wsize); i++ ) - mpi_free( &W[i], NULL ); + mpi_free( &W[i] ); - if( _RR != NULL ) - mpi_free( &W[1], &T, NULL ); - else mpi_free( &W[1], &T, &RR, NULL ); + mpi_free( &W[1] ); mpi_free( &T ); + + if( _RR == NULL ) + mpi_free( &RR ); return( ret ); } @@ -1532,7 +1518,7 @@ int mpi_gcd( mpi *G, const mpi *A, const mpi *B ) size_t lz, lzt; mpi TG, TA, TB; - mpi_init( &TG, &TA, &TB, NULL ); + mpi_init( &TG ); mpi_init( &TA ); mpi_init( &TB ); MPI_CHK( mpi_copy( &TA, A ) ); MPI_CHK( mpi_copy( &TB, B ) ); @@ -1570,7 +1556,7 @@ int mpi_gcd( mpi *G, const mpi *A, const mpi *B ) cleanup: - mpi_free( &TB, &TA, &TG, NULL ); + mpi_free( &TG ); mpi_free( &TA ); mpi_free( &TB ); return( ret ); } @@ -1605,8 +1591,9 @@ int mpi_inv_mod( mpi *X, const mpi *A, const mpi *N ) if( mpi_cmp_int( N, 0 ) <= 0 ) return( POLARSSL_ERR_MPI_BAD_INPUT_DATA ); - mpi_init( &TA, &TU, &U1, &U2, &G, - &TB, &TV, &V1, &V2, NULL ); + mpi_init( &TA ); mpi_init( &TU ); mpi_init( &U1 ); mpi_init( &U2 ); + mpi_init( &G ); mpi_init( &TB ); mpi_init( &TV ); + mpi_init( &V1 ); mpi_init( &V2 ); MPI_CHK( mpi_gcd( &G, A, N ) ); @@ -1681,8 +1668,9 @@ int mpi_inv_mod( mpi *X, const mpi *A, const mpi *N ) cleanup: - mpi_free( &V2, &V1, &TV, &TB, &G, - &U2, &U1, &TU, &TA, NULL ); + mpi_free( &TA ); mpi_free( &TU ); mpi_free( &U1 ); mpi_free( &U2 ); + mpi_free( &G ); mpi_free( &TB ); mpi_free( &TV ); + mpi_free( &V1 ); mpi_free( &V2 ); return( ret ); } @@ -1728,7 +1716,8 @@ int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ) if( mpi_cmp_int( X, 2 ) == 0 ) return( 0 ); - mpi_init( &W, &R, &T, &A, &RR, NULL ); + mpi_init( &W ); mpi_init( &R ); mpi_init( &T ); mpi_init( &A ); + mpi_init( &RR ); xs = X->s; X->s = 1; @@ -1821,7 +1810,8 @@ cleanup: X->s = xs; - mpi_free( &RR, &A, &T, &R, &W, NULL ); + mpi_free( &W ); mpi_free( &R ); mpi_free( &T ); mpi_free( &A ); + mpi_free( &RR ); return( ret ); } @@ -1839,7 +1829,7 @@ int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag, if( nbits < 3 || nbits > 4096 ) return( POLARSSL_ERR_MPI_BAD_INPUT_DATA ); - mpi_init( &Y, NULL ); + mpi_init( &Y ); n = BITS_TO_LIMBS( nbits ); @@ -1888,7 +1878,7 @@ int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag, cleanup: - mpi_free( &Y, NULL ); + mpi_free( &Y ); return( ret ); } @@ -1914,7 +1904,8 @@ int mpi_self_test( int verbose ) int ret, i; mpi A, E, N, X, Y, U, V; - mpi_init( &A, &E, &N, &X, &Y, &U, &V, NULL ); + mpi_init( &A ); mpi_init( &E ); mpi_init( &N ); mpi_init( &X ); + mpi_init( &Y ); mpi_init( &U ); mpi_init( &V ); MPI_CHK( mpi_read_string( &A, 16, "EFE021C2645FD1DC586E69184AF4A31E" \ @@ -2052,7 +2043,8 @@ cleanup: if( ret != 0 && verbose != 0 ) printf( "Unexpected error, return code = %08X\n", ret ); - mpi_free( &V, &U, &Y, &X, &N, &E, &A, NULL ); + mpi_free( &A ); mpi_free( &E ); mpi_free( &N ); mpi_free( &X ); + mpi_free( &Y ); mpi_free( &U ); mpi_free( &V ); if( verbose != 0 ) printf( "\n" ); diff --git a/library/dhm.c b/library/dhm.c index 59e78f89f..9c8daef7f 100644 --- a/library/dhm.c +++ b/library/dhm.c @@ -74,7 +74,7 @@ static int dhm_check_range( const mpi *public_param, const mpi *P ) mpi L, U; int ret = POLARSSL_ERR_DHM_BAD_INPUT_DATA; - mpi_init( &L, &U, NULL ); + mpi_init( &L ); mpi_init( &U ); mpi_lset( &L, 2 ); mpi_sub_int( &U, P, 2 ); @@ -84,7 +84,7 @@ static int dhm_check_range( const mpi *public_param, const mpi *P ) ret = 0; } - mpi_free( &L, &U, NULL ); + mpi_free( &L ); mpi_free( &U ); return( ret ); } @@ -270,9 +270,9 @@ cleanup: */ void dhm_free( dhm_context *ctx ) { - mpi_free( &ctx->RP, &ctx->K, &ctx->GY, - &ctx->GX, &ctx->X, &ctx->G, - &ctx->P, NULL ); + mpi_free( &ctx->RP ); mpi_free( &ctx->K ); mpi_free( &ctx->GY ); + mpi_free( &ctx->GX ); mpi_free( &ctx->X ); mpi_free( &ctx->G ); + mpi_free( &ctx->P ); } #if defined(POLARSSL_SELF_TEST) diff --git a/library/rsa.c b/library/rsa.c index 4d3fc4c42..3018eb417 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -68,7 +68,7 @@ int rsa_gen_key( rsa_context *ctx, if( f_rng == NULL || nbits < 128 || exponent < 3 ) return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); - mpi_init( &P1, &Q1, &H, &G, NULL ); + mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G ); /* * find primes P and Q with Q < P so that: @@ -116,7 +116,7 @@ int rsa_gen_key( rsa_context *ctx, cleanup: - mpi_free( &G, &H, &Q1, &P1, NULL ); + mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G ); if( ret != 0 ) { @@ -166,7 +166,9 @@ int rsa_check_privkey( const rsa_context *ctx ) if( !ctx->P.p || !ctx->Q.p || !ctx->D.p ) return( POLARSSL_ERR_RSA_KEY_CHECK_FAILED ); - mpi_init( &PQ, &DE, &P1, &Q1, &H, &I, &G, &G2, &L1, &L2, NULL ); + mpi_init( &PQ ); mpi_init( &DE ); mpi_init( &P1 ); mpi_init( &Q1 ); + mpi_init( &H ); mpi_init( &I ); mpi_init( &G ); mpi_init( &G2 ); + mpi_init( &L1 ); mpi_init( &L2 ); MPI_CHK( mpi_mul_mpi( &PQ, &ctx->P, &ctx->Q ) ); MPI_CHK( mpi_mul_mpi( &DE, &ctx->D, &ctx->E ) ); @@ -182,20 +184,25 @@ int rsa_check_privkey( const rsa_context *ctx ) /* * Check for a valid PKCS1v2 private key */ - if( mpi_cmp_mpi( &PQ, &ctx->N ) == 0 && - mpi_cmp_int( &L2, 0 ) == 0 && - mpi_cmp_int( &I, 1 ) == 0 && - mpi_cmp_int( &G, 1 ) == 0 ) + if( mpi_cmp_mpi( &PQ, &ctx->N ) != 0 || + mpi_cmp_int( &L2, 0 ) != 0 || + mpi_cmp_int( &I, 1 ) != 0 || + mpi_cmp_int( &G, 1 ) != 0 ) { - mpi_free( &G, &I, &H, &Q1, &P1, &DE, &PQ, &G2, &L1, &L2, NULL ); - return( 0 ); + ret = POLARSSL_ERR_RSA_KEY_CHECK_FAILED; } cleanup: - mpi_free( &G, &I, &H, &Q1, &P1, &DE, &PQ, &G2, &L1, &L2, NULL ); - return( POLARSSL_ERR_RSA_KEY_CHECK_FAILED | ret ); + mpi_free( &PQ ); mpi_free( &DE ); mpi_free( &P1 ); mpi_free( &Q1 ); + mpi_free( &H ); mpi_free( &I ); mpi_free( &G ); mpi_free( &G2 ); + mpi_free( &L1 ); mpi_free( &L2 ); + + if( ret != 0 ) + return( POLARSSL_ERR_RSA_KEY_CHECK_FAILED | ret ); + + return( 0 ); } /* @@ -209,13 +216,13 @@ int rsa_public( rsa_context *ctx, size_t olen; mpi T; - mpi_init( &T, NULL ); + mpi_init( &T ); MPI_CHK( mpi_read_binary( &T, input, ctx->len ) ); if( mpi_cmp_mpi( &T, &ctx->N ) >= 0 ) { - mpi_free( &T, NULL ); + mpi_free( &T ); return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); } @@ -225,7 +232,7 @@ int rsa_public( rsa_context *ctx, cleanup: - mpi_free( &T, NULL ); + mpi_free( &T ); if( ret != 0 ) return( POLARSSL_ERR_RSA_PUBLIC_FAILED | ret ); @@ -244,13 +251,13 @@ int rsa_private( rsa_context *ctx, size_t olen; mpi T, T1, T2; - mpi_init( &T, &T1, &T2, NULL ); + mpi_init( &T ); mpi_init( &T1 ); mpi_init( &T2 ); MPI_CHK( mpi_read_binary( &T, input, ctx->len ) ); if( mpi_cmp_mpi( &T, &ctx->N ) >= 0 ) { - mpi_free( &T, NULL ); + mpi_free( &T ); return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); } @@ -285,7 +292,7 @@ int rsa_private( rsa_context *ctx, cleanup: - mpi_free( &T, &T1, &T2, NULL ); + mpi_free( &T ); mpi_free( &T1 ); mpi_free( &T2 ); if( ret != 0 ) return( POLARSSL_ERR_RSA_PRIVATE_FAILED | ret ); @@ -1006,10 +1013,10 @@ int rsa_pkcs1_verify( rsa_context *ctx, */ void rsa_free( rsa_context *ctx ) { - mpi_free( &ctx->RQ, &ctx->RP, &ctx->RN, - &ctx->QP, &ctx->DQ, &ctx->DP, - &ctx->Q, &ctx->P, &ctx->D, - &ctx->E, &ctx->N, NULL ); + mpi_free( &ctx->RQ ); mpi_free( &ctx->RP ); mpi_free( &ctx->RN ); + mpi_free( &ctx->QP ); mpi_free( &ctx->DQ ); mpi_free( &ctx->DP ); + mpi_free( &ctx->Q ); mpi_free( &ctx->P ); mpi_free( &ctx->D ); + mpi_free( &ctx->E ); mpi_free( &ctx->N ); } #if defined(POLARSSL_SELF_TEST) diff --git a/programs/pkey/dh_genprime.c b/programs/pkey/dh_genprime.c index 72a291693..840a569b8 100644 --- a/programs/pkey/dh_genprime.c +++ b/programs/pkey/dh_genprime.c @@ -49,7 +49,7 @@ int main( void ) havege_state hs; FILE *fout; - mpi_init( &G, &P, &Q, NULL ); + mpi_init( &G ); mpi_init( &P ); mpi_init( &Q ); mpi_read_string( &G, 10, GENERATOR ); printf( "\n . Seeding the random number generator..." ); @@ -113,7 +113,7 @@ int main( void ) exit: - mpi_free( &Q, &P, &G, NULL ); + mpi_free( &G ); mpi_free( &P ); mpi_free( &Q ); #else printf( "\n ! Prime-number generation is not available.\n\n" ); #endif diff --git a/programs/pkey/mpi_demo.c b/programs/pkey/mpi_demo.c index 008d33486..b29f9a1e1 100644 --- a/programs/pkey/mpi_demo.c +++ b/programs/pkey/mpi_demo.c @@ -35,8 +35,9 @@ int main( void ) { mpi E, P, Q, N, H, D, X, Y, Z; - mpi_init( &E, &P, &Q, &N, &H, - &D, &X, &Y, &Z, NULL ); + mpi_init( &E ); mpi_init( &P ); mpi_init( &Q ); mpi_init( &N ); + mpi_init( &H ); mpi_init( &D ); mpi_init( &X ); mpi_init( &Y ); + mpi_init( &Z ); mpi_read_string( &P, 10, "2789" ); mpi_read_string( &Q, 10, "3203" ); @@ -69,8 +70,9 @@ int main( void ) mpi_write_file( " Z (decrypted) = Y^D mod N = ", &Z, 10, NULL ); printf( "\n" ); - mpi_free( &Z, &Y, &X, &D, &H, - &N, &Q, &P, &E, NULL ); + mpi_free( &E ); mpi_free( &P ); mpi_free( &Q ); mpi_free( &N ); + mpi_free( &H ); mpi_free( &D ); mpi_free( &X ); mpi_free( &Y ); + mpi_free( &Z ); #ifdef WIN32 printf( " Press Enter to exit this program.\n" ); diff --git a/tests/suites/test_suite_debug.function b/tests/suites/test_suite_debug.function index 4efa1e972..0172de6c5 100644 --- a/tests/suites/test_suite_debug.function +++ b/tests/suites/test_suite_debug.function @@ -45,7 +45,7 @@ debug_print_mpi:radix:value:file:line:prefix:result_str struct buffer_data buffer; mpi val; - mpi_init( &val, NULL ); + mpi_init( &val ); memset( &ssl, 0, sizeof( ssl_context ) ); memset( buffer.buf, 0, 2000 ); @@ -57,6 +57,8 @@ debug_print_mpi:radix:value:file:line:prefix:result_str debug_print_mpi( &ssl, 0, {file}, {line}, {prefix}, &val); TEST_ASSERT( strcmp( buffer.buf, {result_str} ) == 0 ); + + mpi_free( &val ); } END_CASE diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index 7755ab2f8..c31589e8f 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -18,7 +18,7 @@ mpi_read_write_string:radix_X:input_X:radix_A:input_A:output_size:result_read:re char str[1000]; size_t len = {output_size}; - mpi_init(&X, NULL); + mpi_init( &X ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == {result_read} ); if( {result_read} == 0 ) @@ -29,6 +29,8 @@ mpi_read_write_string:radix_X:input_X:radix_A:input_A:output_size:result_read:re TEST_ASSERT( strcasecmp( str, {input_A} ) == 0 ); } } + + mpi_free( &X ); } END_CASE @@ -41,13 +43,15 @@ mpi_read_binary:input_X:radix_A:input_A size_t len = 1000; size_t input_len; - mpi_init(&X, NULL); + mpi_init( &X ); input_len = unhexify( buf, {input_X} ); TEST_ASSERT( mpi_read_binary( &X, buf, input_len ) == 0 ); TEST_ASSERT( mpi_write_string( &X, {radix_A}, (char *) str, &len ) == 0 ); TEST_ASSERT( strcmp( (char *) str, {input_A} ) == 0 ); + + mpi_free( &X ); } END_CASE @@ -62,7 +66,7 @@ mpi_write_binary:radix_X:input_X:input_A:output_size:result memset( buf, 0x00, 1000 ); memset( str, 0x00, 1000 ); - mpi_init(&X, NULL); + mpi_init( &X ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); @@ -77,6 +81,8 @@ mpi_write_binary:radix_X:input_X:input_A:output_size:result TEST_ASSERT( strcasecmp( (char *) str, {input_A} ) == 0 ); } + + mpi_free( &X ); } END_CASE @@ -92,7 +98,7 @@ mpi_read_file:radix_X:input_file:input_A:result memset( buf, 0x00, 1000 ); memset( str, 0x00, 1000 ); - mpi_init(&X, NULL); + mpi_init( &X ); file = fopen( {input_file}, "r" ); TEST_ASSERT( mpi_read_file( &X, {radix_X}, file ) == {result} ); @@ -107,6 +113,8 @@ mpi_read_file:radix_X:input_file:input_A:result TEST_ASSERT( strcasecmp( (char *) str, {input_A} ) == 0 ); } + + mpi_free( &X ); } END_CASE @@ -116,7 +124,7 @@ mpi_write_file:radix_X:input_X:output_radix:output_file mpi X, Y; FILE *file_out, *file_in; - mpi_init( &X, &Y, NULL ); + mpi_init( &X ); mpi_init( &Y ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); @@ -129,6 +137,8 @@ mpi_write_file:radix_X:input_X:output_radix:output_file fclose(file_in); TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == 0 ); + + mpi_free( &X ); mpi_free( &Y ); } END_CASE @@ -136,10 +146,12 @@ BEGIN_CASE mpi_lsb:radix_X:input_X:nr_bits { mpi X; - mpi_init(&X, NULL); + mpi_init( &X ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_lsb( &X ) == {nr_bits} ); + + mpi_free( &X ); } END_CASE @@ -147,10 +159,12 @@ BEGIN_CASE mpi_msb:radix_X:input_X:nr_bits { mpi X; - mpi_init(&X, NULL); + mpi_init( &X ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_msb( &X ) == {nr_bits} ); + + mpi_free( &X ); } END_CASE @@ -158,13 +172,15 @@ BEGIN_CASE mpi_gcd:radix_X:input_X:radix_Y:input_Y:radix_A:input_A { mpi A, X, Y, Z; - mpi_init(&A, &X, &Y, &Z, NULL); + mpi_init( &A ); mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_gcd( &Z, &X, &Y ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); + + mpi_free( &A ); mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); } END_CASE @@ -172,10 +188,12 @@ BEGIN_CASE mpi_cmp_int:input_X:input_A:result_CMP { mpi X; - mpi_init(&X, NULL); + mpi_init( &X ); TEST_ASSERT( mpi_lset( &X, {input_X} ) == 0); TEST_ASSERT( mpi_cmp_int( &X, {input_A} ) == {result_CMP}); + + mpi_free( &X ); } END_CASE @@ -183,11 +201,13 @@ BEGIN_CASE mpi_cmp_mpi:radix_X:input_X:radix_Y:input_Y:input_A { mpi X, Y; - mpi_init(&X, &Y, NULL); + mpi_init( &X ); mpi_init( &Y ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == {input_A} ); + + mpi_free( &X ); mpi_free( &Y ); } END_CASE @@ -195,11 +215,13 @@ BEGIN_CASE mpi_cmp_abs:radix_X:input_X:radix_Y:input_Y:input_A { mpi X, Y; - mpi_init(&X, &Y, NULL); + mpi_init( &X ); mpi_init( &Y ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); TEST_ASSERT( mpi_cmp_abs( &X, &Y ) == {input_A} ); + + mpi_free( &X ); mpi_free( &Y ); } END_CASE @@ -207,7 +229,7 @@ BEGIN_CASE mpi_copy:input_X:input_A { mpi X, Y, A; - mpi_init(&X, &Y, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &A ); TEST_ASSERT( mpi_lset( &X, {input_X} ) == 0 ); TEST_ASSERT( mpi_lset( &Y, {input_A} ) == 0 ); @@ -217,6 +239,8 @@ mpi_copy:input_X:input_A TEST_ASSERT( mpi_copy( &Y, &X ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Y, &A ) != 0 ); + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &A ); } END_CASE @@ -224,11 +248,13 @@ BEGIN_CASE mpi_copy_self:input_X { mpi X; - mpi_init(&X, NULL); + mpi_init( &X ); TEST_ASSERT( mpi_lset( &X, {input_X} ) == 0 ); TEST_ASSERT( mpi_copy( &X, &X ) == 0 ); TEST_ASSERT( mpi_cmp_int( &X, {input_X} ) == 0 ); + + mpi_free( &X ); } END_CASE @@ -236,7 +262,7 @@ BEGIN_CASE mpi_swap:input_X:input_Y { mpi X, Y, A; - mpi_init(&X, &Y, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &A ); TEST_ASSERT( mpi_lset( &X, {input_X} ) == 0 ); TEST_ASSERT( mpi_lset( &Y, {input_Y} ) == 0 ); @@ -246,6 +272,8 @@ mpi_swap:input_X:input_Y mpi_swap( &X, &Y ); TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) != 0 ); TEST_ASSERT( mpi_cmp_mpi( &Y, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &A ); } END_CASE @@ -253,13 +281,15 @@ BEGIN_CASE mpi_add_mpi:radix_X:input_X:radix_Y:input_Y:radix_A:input_A { mpi X, Y, Z, A; - mpi_init(&X, &Y, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_add_mpi( &Z, &X, &Y ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -267,13 +297,15 @@ BEGIN_CASE mpi_add_abs:radix_X:input_X:radix_Y:input_Y:radix_A:input_A { mpi X, Y, Z, A; - mpi_init(&X, &Y, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_add_abs( &Z, &X, &Y ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -281,13 +313,15 @@ BEGIN_CASE mpi_add_abs_add_first:radix_X:input_X:radix_Y:input_Y:radix_A:input_A { mpi X, Y, A; - mpi_init(&X, &Y, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_add_abs( &X, &X, &Y ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &A ); } END_CASE @@ -295,13 +329,15 @@ BEGIN_CASE mpi_add_abs_add_second:radix_X:input_X:radix_Y:input_Y:radix_A:input_A { mpi X, Y, A; - mpi_init(&X, &Y, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_add_abs( &Y, &X, &Y ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Y, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &A ); } END_CASE @@ -309,12 +345,14 @@ BEGIN_CASE mpi_add_int:radix_X:input_X:input_Y:radix_A:input_A { mpi X, Z, A; - mpi_init(&X, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_add_int( &Z, &X, {input_Y} ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -322,13 +360,15 @@ BEGIN_CASE mpi_sub_mpi:radix_X:input_X:radix_Y:input_Y:radix_A:input_A { mpi X, Y, Z, A; - mpi_init(&X, &Y, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_sub_mpi( &Z, &X, &Y ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -337,7 +377,7 @@ mpi_sub_abs:radix_X:input_X:radix_Y:input_Y:radix_A:input_A:sub_result { mpi X, Y, Z, A; int res; - mpi_init(&X, &Y, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); @@ -347,6 +387,8 @@ mpi_sub_abs:radix_X:input_X:radix_Y:input_Y:radix_A:input_A:sub_result TEST_ASSERT( res == {sub_result} ); if( res == 0 ) TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -354,12 +396,14 @@ BEGIN_CASE mpi_sub_int:radix_X:input_X:input_Y:radix_A:input_A { mpi X, Z, A; - mpi_init(&X, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_sub_int( &Z, &X, {input_Y} ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -367,13 +411,15 @@ BEGIN_CASE mpi_mul_mpi:radix_X:input_X:radix_Y:input_Y:radix_A:input_A { mpi X, Y, Z, A; - mpi_init(&X, &Y, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_mul_mpi( &Z, &X, &Y ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -381,12 +427,14 @@ BEGIN_CASE mpi_mul_int:radix_X:input_X:input_Y:radix_A:input_A:result_comparison { mpi X, Z, A; - mpi_init(&X, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_mul_int( &Z, &X, {input_Y} ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) {result_comparison} 0 ); + + mpi_free( &X ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -395,7 +443,8 @@ mpi_div_mpi:radix_X:input_X:radix_Y:input_Y:radix_A:input_A:radix_B:input_B:div_ { mpi X, Y, Q, R, A, B; int res; - mpi_init(&X, &Y, &Q, &R, &A, &B, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &Q ); mpi_init( &R ); + mpi_init( &A ); mpi_init( &B ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); @@ -408,6 +457,9 @@ mpi_div_mpi:radix_X:input_X:radix_Y:input_Y:radix_A:input_A:radix_B:input_B:div_ TEST_ASSERT( mpi_cmp_mpi( &Q, &A ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &R, &B ) == 0 ); } + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &Q ); mpi_free( &R ); + mpi_free( &A ); mpi_free( &B ); } END_CASE @@ -416,7 +468,8 @@ mpi_div_int:radix_X:input_X:input_Y:radix_A:input_A:radix_B:input_B:div_result { mpi X, Q, R, A, B; int res; - mpi_init(&X, &Q, &R, &A, &B, NULL); + mpi_init( &X ); mpi_init( &Q ); mpi_init( &R ); mpi_init( &A ); + mpi_init( &B ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); @@ -428,6 +481,9 @@ mpi_div_int:radix_X:input_X:input_Y:radix_A:input_A:radix_B:input_B:div_result TEST_ASSERT( mpi_cmp_mpi( &Q, &A ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &R, &B ) == 0 ); } + + mpi_free( &X ); mpi_free( &Q ); mpi_free( &R ); mpi_free( &A ); + mpi_free( &B ); } END_CASE @@ -436,7 +492,7 @@ mpi_mod_mpi:radix_X:input_X:radix_Y:input_Y:radix_A:input_A:div_result { mpi X, Y, Z, A; int res; - mpi_init(&X, &Y, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); @@ -447,6 +503,8 @@ mpi_mod_mpi:radix_X:input_X:radix_Y:input_Y:radix_A:input_A:div_result { TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); } + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -456,7 +514,7 @@ mpi_mod_int:radix_X:input_X:input_Y:input_A:div_result mpi X; int res; t_uint r; - mpi_init(&X, NULL); + mpi_init( &X ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); res = mpi_mod_int( &r, &X, {input_Y} ); @@ -465,6 +523,8 @@ mpi_mod_int:radix_X:input_X:input_Y:input_A:div_result { TEST_ASSERT( r == {input_A} ); } + + mpi_free( &X ); } END_CASE @@ -473,7 +533,8 @@ mpi_exp_mod:radix_A:input_A:radix_E:input_E:radix_N:input_N:radix_RR:input_RR:ra { mpi A, E, N, RR, Z, X; int res; - mpi_init(&A, &E, &N, &RR, &Z, &X, NULL); + mpi_init( &A ); mpi_init( &E ); mpi_init( &N ); + mpi_init( &RR ); mpi_init( &Z ); mpi_init( &X ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_read_string( &E, {radix_E}, {input_E} ) == 0 ); @@ -489,6 +550,9 @@ mpi_exp_mod:radix_A:input_A:radix_E:input_E:radix_N:input_N:radix_RR:input_RR:ra { TEST_ASSERT( mpi_cmp_mpi( &Z, &X ) == 0 ); } + + mpi_free( &A ); mpi_free( &E ); mpi_free( &N ); + mpi_free( &RR ); mpi_free( &Z ); mpi_free( &X ); } END_CASE @@ -497,7 +561,7 @@ mpi_inv_mod:radix_X:input_X:radix_Y:input_Y:radix_A:input_A:div_result { mpi X, Y, Z, A; int res; - mpi_init(&X, &Y, &Z, &A, NULL); + mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 ); @@ -508,6 +572,8 @@ mpi_inv_mod:radix_X:input_X:radix_Y:input_Y:radix_A:input_A:div_result { TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 ); } + + mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A ); } END_CASE @@ -516,11 +582,13 @@ mpi_is_prime:radix_X:input_X:div_result { mpi X; int res; - mpi_init(&X, NULL); + mpi_init( &X ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); res = mpi_is_prime( &X, myrand, NULL ); TEST_ASSERT( res == {div_result} ); + + mpi_free( &X ); } END_CASE @@ -528,12 +596,14 @@ BEGIN_CASE mpi_shift_l:radix_X:input_X:shift_X:radix_A:input_A { mpi X, A; - mpi_init(&X, &A, NULL); + mpi_init( &X ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_shift_l( &X, {shift_X} ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &A ); } END_CASE @@ -541,12 +611,14 @@ BEGIN_CASE mpi_shift_r:radix_X:input_X:shift_X:radix_A:input_A { mpi X, A; - mpi_init(&X, &A, NULL); + mpi_init( &X ); mpi_init( &A ); TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 ); TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 ); TEST_ASSERT( mpi_shift_r( &X, {shift_X} ) == 0 ); TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 ); + + mpi_free( &X ); mpi_free( &A ); } END_CASE diff --git a/tests/suites/test_suite_pkcs1_v21.function b/tests/suites/test_suite_pkcs1_v21.function index aa85f75d6..53b97b252 100644 --- a/tests/suites/test_suite_pkcs1_v21.function +++ b/tests/suites/test_suite_pkcs1_v21.function @@ -58,7 +58,7 @@ pkcs1_rsaes_oaep_decrypt:mod:radix_P:input_P:radix_Q:input_Q:radix_N:input_N:rad size_t output_len; size_t msg_len; - mpi_init( &P1, &Q1, &H, &G, NULL ); + mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G ); rsa_init( &ctx, RSA_PKCS_V21, {hash} ); memset( message_str, 0x00, 1000 ); @@ -91,6 +91,8 @@ pkcs1_rsaes_oaep_decrypt:mod:radix_P:input_P:radix_Q:input_Q:radix_N:input_N:rad TEST_ASSERT( strncasecmp( (char *) output_str, {result_hex_str}, strlen( {result_hex_str} ) ) == 0 ); } + + mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G ); } END_CASE @@ -111,7 +113,7 @@ pkcs1_rsassa_pss_sign:mod:radix_P:input_P:radix_Q:input_Q:radix_N:input_N:radix_ info.buf = rnd_buf; info.per_call = 1; - mpi_init( &P1, &Q1, &H, &G, NULL ); + mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G ); rsa_init( &ctx, RSA_PKCS_V21, {hash} ); memset( message_str, 0x00, 1000 ); @@ -185,6 +187,8 @@ pkcs1_rsassa_pss_sign:mod:radix_P:input_P:radix_Q:input_Q:radix_N:input_N:radix_ TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 ); } + + mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G ); } END_CASE diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function index 832b5d9cc..2ac03b8f7 100644 --- a/tests/suites/test_suite_rsa.function +++ b/tests/suites/test_suite_rsa.function @@ -28,7 +28,7 @@ rsa_pkcs1_sign:message_hex_string:padding_mode:digest:mod:radix_P:input_P:radix_ mpi P1, Q1, H, G; int msg_len; - mpi_init( &P1, &Q1, &H, &G, NULL ); + mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G ); rsa_init( &ctx, {padding_mode}, 0 ); memset( message_str, 0x00, 1000 ); @@ -102,6 +102,8 @@ rsa_pkcs1_sign:message_hex_string:padding_mode:digest:mod:radix_P:input_P:radix_ TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 ); } + + mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G ); } END_CASE @@ -184,7 +186,7 @@ rsa_pkcs1_sign_raw:message_hex_string:hash_result_string:padding_mode:mod:radix_ mpi P1, Q1, H, G; int msg_len, hash_len; - mpi_init( &P1, &Q1, &H, &G, NULL ); + mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G ); rsa_init( &ctx, {padding_mode}, 0 ); memset( message_str, 0x00, 1000 ); @@ -217,6 +219,8 @@ rsa_pkcs1_sign_raw:message_hex_string:hash_result_string:padding_mode:mod:radix_ hexify( output_str, output, ctx.len ); TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 ); + + mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G ); } END_CASE @@ -325,7 +329,7 @@ rsa_pkcs1_decrypt:message_hex_string:padding_mode:mod:radix_P:input_P:radix_Q:in mpi P1, Q1, H, G; size_t output_len; - mpi_init( &P1, &Q1, &H, &G, NULL ); + mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G ); rsa_init( &ctx, {padding_mode}, 0 ); memset( message_str, 0x00, 1000 ); @@ -359,6 +363,8 @@ rsa_pkcs1_decrypt:message_hex_string:padding_mode:mod:radix_P:input_P:radix_Q:in TEST_ASSERT( strncasecmp( (char *) output_str, {result_hex_str}, strlen( {result_hex_str} ) ) == 0 ); } + + mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G ); } END_CASE @@ -402,7 +408,7 @@ rsa_private:message_hex_string:mod:radix_P:input_P:radix_Q:input_Q:radix_N:input rsa_context ctx; mpi P1, Q1, H, G; - mpi_init( &P1, &Q1, &H, &G, NULL ); + mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G ); rsa_init( &ctx, RSA_PKCS_V15, 0 ); memset( message_str, 0x00, 1000 ); @@ -435,6 +441,8 @@ rsa_private:message_hex_string:mod:radix_P:input_P:radix_Q:input_Q:radix_N:input TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 ); } + + mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G ); } END_CASE