Merge pull request #4703 from gilles-peskine-arm/mpi_montmul-null-3.0
Fix several bugs with the value 0 in bignum
This commit is contained in:
commit
aa5938edb3
21 changed files with 1371 additions and 504 deletions
|
@ -81,8 +81,12 @@ Bugfix
|
|||
in line with version 1.0.0 of the specification. Fix #4162.
|
||||
* Fix a bug in ECDSA that would cause it to fail when the hash is all-bits
|
||||
zero. Fixes #1792
|
||||
* mbedtls_mpi_read_string on "-0" produced an MPI object that was not treated
|
||||
as equal to 0 in all cases. Fix it to produce the same object as "0".
|
||||
* Fix some cases in the bignum module where the library constructed an
|
||||
unintended representation of the value 0 which was not processed
|
||||
correctly by some bignum operations. This could happen when
|
||||
mbedtls_mpi_read_string() was called on "-0", or when
|
||||
mbedtls_mpi_mul_mpi() and mbedtls_mpi_mul_int() was called with one of
|
||||
the arguments being negative and the other being 0. Fixes #4643.
|
||||
|
||||
Changes
|
||||
* Fix the setting of the read timeout in the DTLS sample programs.
|
||||
|
|
7
ChangeLog.d/mpi_exp_mod-zero.txt
Normal file
7
ChangeLog.d/mpi_exp_mod-zero.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
Bugfix
|
||||
* Fix a null pointer dereference when mbedtls_mpi_exp_mod() was called with
|
||||
A=0 represented with 0 limbs. Up to and including Mbed TLS 2.26, this bug
|
||||
could not be triggered by code that constructed A with one of the
|
||||
mbedtls_mpi_read_xxx functions (including in particular TLS code) since
|
||||
those always built an mpi object with at least one limb.
|
||||
Credit to OSS-Fuzz. Fixes #4641.
|
4
ChangeLog.d/mpi_gcd-0.txt
Normal file
4
ChangeLog.d/mpi_gcd-0.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Bugfix
|
||||
* Fix mbedtls_mpi_gcd(G,A,B) when the value of B is zero. This had no
|
||||
effect on Mbed TLS's internal use of mbedtls_mpi_gcd(), but may affect
|
||||
applications that call mbedtls_mpi_gcd() directly. Fixes #4642.
|
9
ChangeLog.d/mpi_read_zero.txt
Normal file
9
ChangeLog.d/mpi_read_zero.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
Changes
|
||||
* mbedtls_mpi_read_binary(), mbedtls_mpi_read_binary_le() and
|
||||
mbedtls_mpi_read_string() now construct an mbedtls_mpi object with 0 limbs
|
||||
when their input has length 0. Note that this is an implementation detail
|
||||
and can change at any time, so this change should be transparent, but it
|
||||
may result in mbedtls_mpi_write_binary() or mbedtls_mpi_write_string()
|
||||
now writing an empty string where it previously wrote one or more
|
||||
zero digits when operating from values constructed with an mpi_read
|
||||
function and some mpi operations.
|
111
library/bignum.c
111
library/bignum.c
|
@ -203,7 +203,13 @@ static int mbedtls_mpi_resize_clear( mbedtls_mpi *X, size_t limbs )
|
|||
}
|
||||
|
||||
/*
|
||||
* Copy the contents of Y into X
|
||||
* Copy the contents of Y into X.
|
||||
*
|
||||
* This function is not constant-time. Leading zeros in Y may be removed.
|
||||
*
|
||||
* Ensure that X does not shrink. This is not guaranteed by the public API,
|
||||
* but some code in the bignum module relies on this property, for example
|
||||
* in mbedtls_mpi_exp_mod().
|
||||
*/
|
||||
int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y )
|
||||
{
|
||||
|
@ -217,7 +223,11 @@ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y )
|
|||
|
||||
if( Y->n == 0 )
|
||||
{
|
||||
mbedtls_mpi_free( X );
|
||||
if( X->n != 0 )
|
||||
{
|
||||
X->s = 1;
|
||||
memset( X->p, 0, X->n * ciL );
|
||||
}
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
@ -502,6 +512,12 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s )
|
|||
|
||||
mbedtls_mpi_init( &T );
|
||||
|
||||
if( s[0] == 0 )
|
||||
{
|
||||
mbedtls_mpi_free( X );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
if( s[0] == '-' )
|
||||
{
|
||||
++s;
|
||||
|
@ -1625,6 +1641,7 @@ int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t i, j;
|
||||
mbedtls_mpi TA, TB;
|
||||
int result_is_zero = 0;
|
||||
MPI_VALIDATE_RET( X != NULL );
|
||||
MPI_VALIDATE_RET( A != NULL );
|
||||
MPI_VALIDATE_RET( B != NULL );
|
||||
|
@ -1637,10 +1654,14 @@ int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
for( i = A->n; i > 0; i-- )
|
||||
if( A->p[i - 1] != 0 )
|
||||
break;
|
||||
if( i == 0 )
|
||||
result_is_zero = 1;
|
||||
|
||||
for( j = B->n; j > 0; j-- )
|
||||
if( B->p[j - 1] != 0 )
|
||||
break;
|
||||
if( j == 0 )
|
||||
result_is_zero = 1;
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i + j ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 0 ) );
|
||||
|
@ -1648,7 +1669,14 @@ int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
for( ; j > 0; j-- )
|
||||
mpi_mul_hlp( i, A->p, X->p + j - 1, B->p[j - 1] );
|
||||
|
||||
X->s = A->s * B->s;
|
||||
/* If the result is 0, we don't shortcut the operation, which reduces
|
||||
* but does not eliminate side channels leaking the zero-ness. We do
|
||||
* need to take care to set the sign bit properly since the library does
|
||||
* not fully support an MPI object with a value of 0 and s == -1. */
|
||||
if( result_is_zero )
|
||||
X->s = 1;
|
||||
else
|
||||
X->s = A->s * B->s;
|
||||
|
||||
cleanup:
|
||||
|
||||
|
@ -2175,6 +2203,11 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
|
|||
#endif
|
||||
|
||||
j = N->n + 1;
|
||||
/* All W[i] and X must have at least N->n limbs for the mpi_montmul()
|
||||
* and mpi_montred() calls later. Here we ensure that W[1] and X are
|
||||
* large enough, and later we'll grow other W[i] to the same length.
|
||||
* They must not be shrunk midway through this function!
|
||||
*/
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, j ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &W[1], j ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &T, j * 2 ) );
|
||||
|
@ -2209,10 +2242,18 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
|
|||
* W[1] = A * R^2 * R^-1 mod N = A * R mod N
|
||||
*/
|
||||
if( mbedtls_mpi_cmp_mpi( A, N ) >= 0 )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &W[1], A, N ) );
|
||||
/* This should be a no-op because W[1] is already that large before
|
||||
* mbedtls_mpi_mod_mpi(), but it's necessary to avoid an overflow
|
||||
* in mpi_montmul() below, so let's make sure. */
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &W[1], N->n + 1 ) );
|
||||
}
|
||||
else
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &W[1], A ) );
|
||||
|
||||
/* Note that this is safe because W[1] always has at least N->n limbs
|
||||
* (it grew above and was preserved by mbedtls_mpi_copy()). */
|
||||
mpi_montmul( &W[1], &RR, N, mm, &T );
|
||||
|
||||
/*
|
||||
|
@ -2368,19 +2409,67 @@ int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B
|
|||
lz = mbedtls_mpi_lsb( &TA );
|
||||
lzt = mbedtls_mpi_lsb( &TB );
|
||||
|
||||
/* The loop below gives the correct result when A==0 but not when B==0.
|
||||
* So have a special case for B==0. Leverage the fact that we just
|
||||
* calculated the lsb and lsb(B)==0 iff B is odd or 0 to make the test
|
||||
* slightly more efficient than cmp_int(). */
|
||||
if( lzt == 0 && mbedtls_mpi_get_bit( &TB, 0 ) == 0 )
|
||||
{
|
||||
ret = mbedtls_mpi_copy( G, A );
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( lzt < lz )
|
||||
lz = lzt;
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TA, lz ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TB, lz ) );
|
||||
|
||||
TA.s = TB.s = 1;
|
||||
|
||||
/* We mostly follow the procedure described in HAC 14.54, but with some
|
||||
* minor differences:
|
||||
* - Sequences of multiplications or divisions by 2 are grouped into a
|
||||
* single shift operation.
|
||||
* - The procedure in HAC assumes that 0 < TB <= TA.
|
||||
* - The condition TB <= TA is not actually necessary for correctness.
|
||||
* TA and TB have symmetric roles except for the loop termination
|
||||
* condition, and the shifts at the beginning of the loop body
|
||||
* remove any significance from the ordering of TA vs TB before
|
||||
* the shifts.
|
||||
* - If TA = 0, the loop goes through 0 iterations and the result is
|
||||
* correctly TB.
|
||||
* - The case TB = 0 was short-circuited above.
|
||||
*
|
||||
* For the correctness proof below, decompose the original values of
|
||||
* A and B as
|
||||
* A = sa * 2^a * A' with A'=0 or A' odd, and sa = +-1
|
||||
* B = sb * 2^b * B' with B'=0 or B' odd, and sb = +-1
|
||||
* Then gcd(A, B) = 2^{min(a,b)} * gcd(A',B'),
|
||||
* and gcd(A',B') is odd or 0.
|
||||
*
|
||||
* At the beginning, we have TA = |A| and TB = |B| so gcd(A,B) = gcd(TA,TB).
|
||||
* The code maintains the following invariant:
|
||||
* gcd(A,B) = 2^k * gcd(TA,TB) for some k (I)
|
||||
*/
|
||||
|
||||
/* Proof that the loop terminates:
|
||||
* At each iteration, either the right-shift by 1 is made on a nonzero
|
||||
* value and the nonnegative integer bitlen(TA) + bitlen(TB) decreases
|
||||
* by at least 1, or the right-shift by 1 is made on zero and then
|
||||
* TA becomes 0 which ends the loop (TB cannot be 0 if it is right-shifted
|
||||
* since in that case TB is calculated from TB-TA with the condition TB>TA).
|
||||
*/
|
||||
while( mbedtls_mpi_cmp_int( &TA, 0 ) != 0 )
|
||||
{
|
||||
/* Divisions by 2 preserve the invariant (I). */
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TA, mbedtls_mpi_lsb( &TA ) ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TB, mbedtls_mpi_lsb( &TB ) ) );
|
||||
|
||||
/* Set either TA or TB to |TA-TB|/2. Since TA and TB are both odd,
|
||||
* TA-TB is even so the division by 2 has an integer result.
|
||||
* Invariant (I) is preserved since any odd divisor of both TA and TB
|
||||
* also divides |TA-TB|/2, and any odd divisor of both TA and |TA-TB|/2
|
||||
* also divides TB, and any odd divisior of both TB and |TA-TB|/2 also
|
||||
* divides TA.
|
||||
*/
|
||||
if( mbedtls_mpi_cmp_mpi( &TA, &TB ) >= 0 )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( &TA, &TA, &TB ) );
|
||||
|
@ -2391,8 +2480,18 @@ int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B
|
|||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( &TB, &TB, &TA ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TB, 1 ) );
|
||||
}
|
||||
/* Note that one of TA or TB is still odd. */
|
||||
}
|
||||
|
||||
/* By invariant (I), gcd(A,B) = 2^k * gcd(TA,TB) for some k.
|
||||
* At the loop exit, TA = 0, so gcd(TA,TB) = TB.
|
||||
* - If there was at least one loop iteration, then one of TA or TB is odd,
|
||||
* and TA = 0, so TB is odd and gcd(TA,TB) = gcd(A',B'). In this case,
|
||||
* lz = min(a,b) so gcd(A,B) = 2^lz * TB.
|
||||
* - If there was no loop iteration, then A was 0, and gcd(A,B) = B.
|
||||
* In this case, lz = 0 and B = TB so gcd(A,B) = B = 2^lz * TB as well.
|
||||
*/
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &TB, lz ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( G, &TB ) );
|
||||
|
||||
|
|
|
@ -59,6 +59,10 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
#include "mbedtls/bignum.h"
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MBEDTLS_TEST_RESULT_SUCCESS = 0,
|
||||
|
@ -210,4 +214,25 @@ void mbedtls_test_err_add_check( int high, int low,
|
|||
const char *file, int line);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
/** Read an MPI from a string.
|
||||
*
|
||||
* Like mbedtls_mpi_read_string(), but size the resulting bignum based
|
||||
* on the number of digits in the string. In particular, construct a
|
||||
* bignum with 0 limbs for an empty string, and a bignum with leading 0
|
||||
* limbs if the string has sufficiently many leading 0 digits.
|
||||
*
|
||||
* This is important so that the "0 (null)" and "0 (1 limb)" and
|
||||
* "leading zeros" test cases do what they claim.
|
||||
*
|
||||
* \param[out] X The MPI object to populate. It must be initialized.
|
||||
* \param radix The radix (2 to 16).
|
||||
* \param[in] s The null-terminated string to read from.
|
||||
*
|
||||
* \return \c 0 on success, an \c MBEDTLS_ERR_MPI_xxx error code otherwise.
|
||||
*/
|
||||
/* Since the library has exactly the desired behavior, this is trivial. */
|
||||
int mbedtls_test_read_mpi( mbedtls_mpi *X, int radix, const char *s );
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
#endif /* TEST_HELPERS_H */
|
||||
|
|
|
@ -259,3 +259,18 @@ void mbedtls_test_err_add_check( int high, int low,
|
|||
}
|
||||
}
|
||||
#endif /* MBEDTLS_TEST_HOOKS */
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
int mbedtls_test_read_mpi( mbedtls_mpi *X, int radix, const char *s )
|
||||
{
|
||||
/* mbedtls_mpi_read_string() currently retains leading zeros.
|
||||
* It always allocates at least one limb for the value 0. */
|
||||
if( s[0] == 0 )
|
||||
{
|
||||
mbedtls_mpi_free( X );
|
||||
return( 0 );
|
||||
}
|
||||
else
|
||||
return( mbedtls_mpi_read_string( X, radix, s ) );
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -417,7 +417,7 @@ void get_integer( const data_t *input,
|
|||
}
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
ret = mbedtls_mpi_read_string( &expected_mpi, 16, expected_hex );
|
||||
ret = mbedtls_test_read_mpi( &expected_mpi, 16, expected_hex );
|
||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
if( ret == MBEDTLS_ERR_MPI_BAD_INPUT_DATA )
|
||||
{
|
||||
|
|
|
@ -179,9 +179,7 @@ void mbedtls_debug_print_mpi( int radix, char * value, char * file, int line,
|
|||
|
||||
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
||||
|
||||
/* If value is empty, keep val->n == 0. */
|
||||
if( value[0] != 0 )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &val, radix, value ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &val, radix, value ) == 0 );
|
||||
|
||||
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
||||
|
||||
|
|
|
@ -70,18 +70,36 @@ dhm_do_dhm:10:"93450983094850938450983409623":1:10:"9345098304850938450983409622
|
|||
Diffie-Hellman full exchange: 286-bit
|
||||
dhm_do_dhm:10:"93450983094850938450983409623982317398171298719873918739182739712938719287391879381271":36:10:"9345098309485093845098340962223981329819812792137312973297123912791271":0
|
||||
|
||||
Diffie-Hellman trivial subgroup #1
|
||||
dhm_do_dhm:10:"23":1:10:"1":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman trivial subgroup #2
|
||||
dhm_do_dhm:10:"23":1:10:"-1":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman small modulus
|
||||
dhm_do_dhm:10:"3":1:10:"5":MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED+MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman zero modulus
|
||||
dhm_do_dhm:10:"0":1:10:"5":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman with G=0
|
||||
dhm_do_dhm:10:"93450983094850938450983409623":13:10:"0":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman with G=1
|
||||
dhm_do_dhm:10:"93450983094850938450983409623":13:10:"1":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman with G=-1
|
||||
dhm_do_dhm:10:"93450983094850938450983409623":13:10:"-1":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman with G=P-1
|
||||
dhm_do_dhm:10:"93450983094850938450983409623":13:10:"93450983094850938450983409622":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman with G=P-2
|
||||
dhm_do_dhm:10:"93450983094850938450983409623":13:10:"93450983094850938450983409621":0
|
||||
|
||||
Diffie-Hellman with G=P
|
||||
dhm_do_dhm:10:"93450983094850938450983409623":13:10:"93450983094850938450983409623":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman with G=P+1
|
||||
dhm_do_dhm:10:"93450983094850938450983409623":13:10:"93450983094850938450983409624":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
Diffie-Hellman with G=P+2
|
||||
dhm_do_dhm:10:"93450983094850938450983409623":13:10:"93450983094850938450983409625":0
|
||||
|
||||
Diffie-Hellman: x_size < 0
|
||||
dhm_do_dhm:10:"93450983094850938450983409623":-1:10:"9345098304850938450983409622":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
|
||||
|
||||
|
|
|
@ -116,8 +116,8 @@ void dhm_do_dhm( int radix_P, char *input_P, int x_size,
|
|||
/*
|
||||
* Set params
|
||||
*/
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx_srv.P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx_srv.G, radix_G, input_G ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx_srv.P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx_srv.G, radix_G, input_G ) == 0 );
|
||||
pub_cli_len = mbedtls_mpi_size( &ctx_srv.P );
|
||||
TEST_ASSERT( check_get_value( &ctx_srv, MBEDTLS_DHM_PARAM_P, &ctx_srv.P ) );
|
||||
TEST_ASSERT( check_get_value( &ctx_srv, MBEDTLS_DHM_PARAM_G, &ctx_srv.G ) );
|
||||
|
@ -239,7 +239,7 @@ void dhm_make_public( int P_bytes, int radix_G, char *input_G, int result )
|
|||
TEST_ASSERT( mbedtls_mpi_shift_l( &P, ( P_bytes * 8 ) - 1 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_set_bit( &P, 0, 1 ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &G, radix_G, input_G ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &G, radix_G, input_G ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_dhm_set_group( &ctx, &P, &G ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_make_public( &ctx, (int) mbedtls_mpi_size( &P ),
|
||||
|
@ -263,8 +263,8 @@ void dhm_file( char * filename, char * p, char * g, int len )
|
|||
mbedtls_dhm_init( &ctx );
|
||||
mbedtls_mpi_init( &P ); mbedtls_mpi_init( &G );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, 16, p ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &G, 16, g ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, 16, p ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &G, 16, g ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_dhm_parse_dhmfile( &ctx, filename ) == 0 );
|
||||
|
||||
|
|
|
@ -157,21 +157,21 @@ void ecdh_primitive_testvec( int id, data_t * rnd_buf_A, char * xA_str,
|
|||
mbedtls_test_rnd_buffer_rand,
|
||||
&rnd_info_A ) == 0 );
|
||||
TEST_ASSERT( ! mbedtls_ecp_is_zero( &qA ) );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &check, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.X, &check ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &check, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.Y, &check ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dB, &qB,
|
||||
mbedtls_test_rnd_buffer_rand,
|
||||
&rnd_info_B ) == 0 );
|
||||
TEST_ASSERT( ! mbedtls_ecp_is_zero( &qB ) );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, xB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &check, 16, xB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.X, &check ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, yB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &check, 16, yB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.Y, &check ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, z_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &check, 16, z_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zA, &qB, &dA,
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
|
|
|
@ -92,9 +92,9 @@ void ecdsa_prim_test_vectors( int id, char * d_str, char * xQ_str,
|
|||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_string( &Q, 16, xQ_str, yQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &r_check, 16, r_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &s_check, 16, s_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &r_check, 16, r_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &s_check, 16, s_str ) == 0 );
|
||||
rnd_info.fallback_f_rng = mbedtls_test_rnd_std_rand;
|
||||
rnd_info.fallback_p_rng = NULL;
|
||||
rnd_info.buf = rnd_buf->x;
|
||||
|
@ -157,9 +157,9 @@ void ecdsa_det_test_vectors( int id, char * d_str, int md_alg, char * msg,
|
|||
memset( hash, 0, sizeof( hash ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &r_check, 16, r_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &s_check, 16, s_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &r_check, 16, r_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &s_check, 16, s_str ) == 0 );
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
@ -388,7 +388,7 @@ void ecdsa_write_restart( int id, char *d_str, int md_alg,
|
|||
memset( sig, 0, sizeof( sig ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &ctx.grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.d, 16, d_str ) == 0 );
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
|
|
@ -82,9 +82,9 @@ void ecp_check_pub( int grp_id, char * x_hex, char * y_hex, char * z_hex,
|
|||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, grp_id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.X, 16, x_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.Y, 16, y_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.Z, 16, z_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.X, 16, x_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.Y, 16, y_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.Z, 16, z_hex ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &P ) == ret );
|
||||
|
||||
|
@ -135,13 +135,13 @@ void ecp_test_vect_restart( int id,
|
|||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dA, 16, dA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xA, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yA, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dA, 16, dA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xA, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yA, 16, yA_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dB, 16, dB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xZ, 16, xZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yZ, 16, yZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dB, 16, dB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xZ, 16, xZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yZ, 16, yZ_str ) == 0 );
|
||||
|
||||
mbedtls_ecp_set_max_ops( (unsigned) max_ops );
|
||||
|
||||
|
@ -222,13 +222,13 @@ void ecp_muladd_restart( int id, char *xR_str, char *yR_str,
|
|||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &u1, 16, u1_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &u2, 16, u2_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xR, 16, xR_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yR, 16, yR_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &u1, 16, u1_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &u2, 16, u2_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xR, 16, xR_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yR, 16, yR_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q.X, 16, xQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q.Y, 16, yQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q.X, 16, xQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q.Y, 16, yQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_lset( &Q.Z, 1 ) == 0 );
|
||||
|
||||
mbedtls_ecp_set_max_ops( (unsigned) max_ops );
|
||||
|
@ -285,14 +285,14 @@ void ecp_test_vect( int id, char * dA_str, char * xA_str, char * yA_str,
|
|||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &grp.G ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dA, 16, dA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xA, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yA, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dB, 16, dB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xB, 16, xB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yB, 16, yB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xZ, 16, xZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yZ, 16, yZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dA, 16, dA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xA, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yA, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dB, 16, dB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xB, 16, xB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yB, 16, yB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xZ, 16, xZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yZ, 16, yZ_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &grp.G,
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
|
@ -342,11 +342,11 @@ void ecp_test_vec_x( int id, char * dA_hex, char * xA_hex, char * dB_hex,
|
|||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &grp.G ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dA, 16, dA_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dB, 16, dB_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xA, 16, xA_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xB, 16, xB_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xS, 16, xS_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dA, 16, dA_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dB, 16, dB_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xA, 16, xA_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xB, 16, xB_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xS, 16, xS_hex ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &grp.G,
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
|
@ -508,7 +508,7 @@ void ecp_fast_mod( int id, char * N_str )
|
|||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &R );
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, 16, N_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, 16, N_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( grp.modp != NULL );
|
||||
|
||||
|
@ -547,9 +547,9 @@ void ecp_write_binary( int id, char * x, char * y, char * z, int format,
|
|||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.Z, 16, z ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.Z, 16, z ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_point_write_binary( &grp, &P, format,
|
||||
&olen, buf, blen ) == ret );
|
||||
|
@ -579,9 +579,9 @@ void ecp_read_binary( int id, data_t * buf, char * x, char * y, char * z,
|
|||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Z, 16, z ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Z, 16, z ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_binary( &grp, &P, buf->x, buf->len ) == ret );
|
||||
|
||||
|
@ -623,9 +623,9 @@ void mbedtls_ecp_tls_read_point( int id, data_t * buf, char * x, char * y,
|
|||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Z, 16, z ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Z, 16, z ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &P, &vbuf, buf->len ) == ret );
|
||||
|
||||
|
@ -760,7 +760,7 @@ void mbedtls_ecp_check_privkey( int id, char * key_hex, int ret )
|
|||
mbedtls_mpi_init( &d );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &d, 16, key_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &d, 16, key_hex ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_privkey( &grp, &d ) == ret );
|
||||
|
||||
|
@ -789,7 +789,7 @@ void mbedtls_ecp_check_pub_priv( int id_pub, char * Qx_pub, char * Qy_pub,
|
|||
if( id != MBEDTLS_ECP_DP_NONE )
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &prv.grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_string( &prv.Q, 16, Qx, Qy ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.d, 16, d ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.d, 16, d ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pub_priv( &pub, &prv,
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,6 +6,18 @@
|
|||
#define MPI_MAX_BITS_LARGER_THAN_792
|
||||
#endif
|
||||
|
||||
/* Check the validity of the sign bit in an MPI object. Reject representations
|
||||
* that are not supported by the rest of the library and indicate a bug when
|
||||
* constructing the value. */
|
||||
static int sign_is_valid( const mbedtls_mpi *X )
|
||||
{
|
||||
if( X->s != 1 && X->s != -1 )
|
||||
return( 0 ); // invalid sign bit, e.g. 0
|
||||
if( mbedtls_mpi_bitlen( X ) == 0 && X->s != 1 )
|
||||
return( 0 ); // negative zero
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
typedef struct mbedtls_test_mpi_random
|
||||
{
|
||||
data_t *data;
|
||||
|
@ -150,6 +162,7 @@ void mpi_read_write_string( int radix_X, char * input_X, int radix_A,
|
|||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == result_read );
|
||||
if( result_read == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_write_string( &X, radix_A, str, output_size, &len ) == result_write );
|
||||
if( result_write == 0 )
|
||||
{
|
||||
|
@ -174,6 +187,7 @@ void mbedtls_mpi_read_binary( data_t * buf, int radix_A, char * input_A )
|
|||
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &X, buf->x, buf->len ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_write_string( &X, radix_A, str, sizeof( str ), &len ) == 0 );
|
||||
TEST_ASSERT( strcmp( (char *) str, input_A ) == 0 );
|
||||
|
||||
|
@ -193,6 +207,7 @@ void mbedtls_mpi_read_binary_le( data_t * buf, int radix_A, char * input_A )
|
|||
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary_le( &X, buf->x, buf->len ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_write_string( &X, radix_A, str, sizeof( str ), &len ) == 0 );
|
||||
TEST_ASSERT( strcmp( (char *) str, input_A ) == 0 );
|
||||
|
||||
|
@ -214,7 +229,7 @@ void mbedtls_mpi_write_binary( int radix_X, char * input_X,
|
|||
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
buflen = mbedtls_mpi_size( &X );
|
||||
if( buflen > (size_t) output_size )
|
||||
|
@ -246,7 +261,7 @@ void mbedtls_mpi_write_binary_le( int radix_X, char * input_X,
|
|||
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
buflen = mbedtls_mpi_size( &X );
|
||||
if( buflen > (size_t) output_size )
|
||||
|
@ -287,6 +302,7 @@ void mbedtls_mpi_read_file( int radix_X, char * input_file,
|
|||
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
buflen = mbedtls_mpi_size( &X );
|
||||
TEST_ASSERT( mbedtls_mpi_write_binary( &X, buf, buflen ) == 0 );
|
||||
|
||||
|
@ -310,7 +326,7 @@ void mbedtls_mpi_write_file( int radix_X, char * input_X, int output_radix,
|
|||
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
file_out = fopen( output_file, "w" );
|
||||
TEST_ASSERT( file_out != NULL );
|
||||
|
@ -336,7 +352,7 @@ void mbedtls_mpi_get_bit( int radix_X, char * input_X, int pos, int val )
|
|||
{
|
||||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_get_bit( &X, pos ) == val );
|
||||
|
||||
exit:
|
||||
|
@ -351,12 +367,13 @@ void mbedtls_mpi_set_bit( int radix_X, char * input_X, int pos, int val,
|
|||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, output_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, output_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_set_bit( &X, pos, val ) == result );
|
||||
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == 0 );
|
||||
}
|
||||
|
||||
|
@ -371,7 +388,7 @@ void mbedtls_mpi_lsb( int radix_X, char * input_X, int nr_bits )
|
|||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_lsb( &X ) == (size_t) nr_bits );
|
||||
|
||||
exit:
|
||||
|
@ -385,7 +402,7 @@ void mbedtls_mpi_bitlen( int radix_X, char * input_X, int nr_bits )
|
|||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_bitlen( &X ) == (size_t) nr_bits );
|
||||
|
||||
exit:
|
||||
|
@ -400,10 +417,11 @@ void mbedtls_mpi_gcd( int radix_X, char * input_X, int radix_Y,
|
|||
mbedtls_mpi A, X, Y, Z;
|
||||
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_gcd( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -432,8 +450,8 @@ void mbedtls_mpi_cmp_mpi( int radix_X, char * input_X, int radix_Y,
|
|||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == input_A );
|
||||
|
||||
exit:
|
||||
|
@ -451,8 +469,8 @@ void mbedtls_mpi_lt_mpi_ct( int size_X, char * input_X,
|
|||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, input_Y ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_grow( &X, size_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_grow( &Y, size_Y ) == 0 );
|
||||
|
@ -473,8 +491,8 @@ void mbedtls_mpi_cmp_abs( int radix_X, char * input_X, int radix_Y,
|
|||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_abs( &X, &Y ) == input_A );
|
||||
|
||||
exit:
|
||||
|
@ -483,55 +501,125 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_copy_sint( int input_X, int input_Y )
|
||||
void mbedtls_mpi_copy( char *src_hex, char *dst_hex )
|
||||
{
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi src, dst, ref;
|
||||
mbedtls_mpi_init( &src );
|
||||
mbedtls_mpi_init( &dst );
|
||||
mbedtls_mpi_init( &ref );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &src, 16, src_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ref, 16, dst_hex ) == 0 );
|
||||
|
||||
/* mbedtls_mpi_copy() */
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dst, 16, dst_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &dst, &src ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &dst ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &dst, &src ) == 0 );
|
||||
|
||||
/* mbedtls_mpi_safe_cond_assign(), assignment done */
|
||||
mbedtls_mpi_free( &dst );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dst, 16, dst_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_safe_cond_assign( &dst, &src, 1 ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &dst ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &dst, &src ) == 0 );
|
||||
|
||||
/* mbedtls_mpi_safe_cond_assign(), assignment not done */
|
||||
mbedtls_mpi_free( &dst );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dst, 16, dst_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_safe_cond_assign( &dst, &src, 0 ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &dst ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &dst, &ref ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &src );
|
||||
mbedtls_mpi_free( &dst );
|
||||
mbedtls_mpi_free( &ref );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_copy_self( char *input_X )
|
||||
{
|
||||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &A );
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &X, &X ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, 16, input_X ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &A );
|
||||
mbedtls_mpi_free( &X );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_swap( char *X_hex, char *Y_hex )
|
||||
{
|
||||
mbedtls_mpi X, Y, X0, Y0;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
mbedtls_mpi_init( &X0 ); mbedtls_mpi_init( &Y0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_lset( &X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_lset( &Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X0, 16, X_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y0, 16, Y_hex ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &Y, &X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &Y, input_X ) == 0 );
|
||||
/* mbedtls_mpi_swap() */
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, X_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, Y_hex ) == 0 );
|
||||
mbedtls_mpi_swap( &X, &Y );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( sign_is_valid( &Y ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y0 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &X0 ) == 0 );
|
||||
|
||||
/* mbedtls_mpi_safe_cond_swap(), swap done */
|
||||
mbedtls_mpi_free( &X );
|
||||
mbedtls_mpi_free( &Y );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, X_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, Y_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_safe_cond_swap( &X, &Y, 1 ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( sign_is_valid( &Y ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y0 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &X0 ) == 0 );
|
||||
|
||||
/* mbedtls_mpi_safe_cond_swap(), swap not done */
|
||||
mbedtls_mpi_free( &X );
|
||||
mbedtls_mpi_free( &Y );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, X_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, Y_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_safe_cond_swap( &X, &Y, 0 ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( sign_is_valid( &Y ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &X0 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &Y0 ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
|
||||
mbedtls_mpi_free( &X0 ); mbedtls_mpi_free( &Y0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_copy_binary( data_t *input_X, data_t *input_Y )
|
||||
void mpi_swap_self( char *X_hex )
|
||||
{
|
||||
mbedtls_mpi X, Y, X0;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &X0 );
|
||||
mbedtls_mpi X, X0;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &X0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &X, input_X->x, input_X->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &Y, input_Y->x, input_Y->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &X0, input_X->x, input_X->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, X_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X0, 16, X_hex ) == 0 );
|
||||
|
||||
mbedtls_mpi_swap( &X, &X );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &X0 ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &Y, &X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &X0 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &X0 ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &X0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_copy_self( int input_X )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_lset( &X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &X, &X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &X, input_X ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X );
|
||||
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &X0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
@ -542,130 +630,20 @@ void mbedtls_mpi_shrink( int before, int used, int min, int after )
|
|||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_grow( &X, before ) == 0 );
|
||||
TEST_ASSERT( used <= before );
|
||||
memset( X.p, 0x2a, used * sizeof( mbedtls_mpi_uint ) );
|
||||
if( used > 0 )
|
||||
{
|
||||
size_t used_bit_count = used * 8 * sizeof( mbedtls_mpi_uint );
|
||||
TEST_ASSERT( mbedtls_mpi_set_bit( &X, used_bit_count - 1, 1 ) == 0 );
|
||||
}
|
||||
TEST_EQUAL( X.n, (size_t) before );
|
||||
TEST_ASSERT( mbedtls_mpi_shrink( &X, min ) == 0 );
|
||||
TEST_ASSERT( X.n == (size_t) after );
|
||||
TEST_EQUAL( X.n, (size_t) after );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_safe_cond_assign( int x_sign, char * x_str, int y_sign,
|
||||
char * y_str )
|
||||
{
|
||||
mbedtls_mpi X, Y, XX;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &XX );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, x_str ) == 0 );
|
||||
X.s = x_sign;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y_str ) == 0 );
|
||||
Y.s = y_sign;
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &XX, &X ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_safe_cond_assign( &X, &Y, 0 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &XX ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_safe_cond_assign( &X, &Y, 1 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &XX );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_safe_cond_swap( int x_sign, char * x_str, int y_sign,
|
||||
char * y_str )
|
||||
{
|
||||
mbedtls_mpi X, Y, XX, YY;
|
||||
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
mbedtls_mpi_init( &XX ); mbedtls_mpi_init( &YY );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, x_str ) == 0 );
|
||||
X.s = x_sign;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y_str ) == 0 );
|
||||
Y.s = y_sign;
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &XX, &X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &YY, &Y ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_safe_cond_swap( &X, &Y, 0 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &XX ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &YY ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_safe_cond_swap( &X, &Y, 1 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &XX ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &YY ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
|
||||
mbedtls_mpi_free( &XX ); mbedtls_mpi_free( &YY );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_swap_sint( int input_X, int input_Y )
|
||||
{
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_lset( &X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_lset( &Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &Y, input_Y ) == 0 );
|
||||
|
||||
mbedtls_mpi_swap( &X, &Y );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &X, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &Y, input_X ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_swap_binary( data_t *input_X, data_t *input_Y )
|
||||
{
|
||||
mbedtls_mpi X, Y, X0, Y0;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
mbedtls_mpi_init( &X0 ); mbedtls_mpi_init( &Y0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &X, input_X->x, input_X->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &Y, input_Y->x, input_Y->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &X0, input_X->x, input_X->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &Y0, input_Y->x, input_Y->len ) == 0 );
|
||||
|
||||
mbedtls_mpi_swap( &X, &Y );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y0 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &X0 ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
|
||||
mbedtls_mpi_free( &X0 ); mbedtls_mpi_free( &Y0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_swap_self( data_t *input_X )
|
||||
{
|
||||
mbedtls_mpi X, X0;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &X0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &X, input_X->x, input_X->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &X0, input_X->x, input_X->len ) == 0 );
|
||||
|
||||
mbedtls_mpi_swap( &X, &X );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &X0 ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &X0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_add_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A )
|
||||
|
@ -673,19 +651,22 @@ void mbedtls_mpi_add_mpi( int radix_X, char * input_X, int radix_Y,
|
|||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_mpi( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
/* result == first operand */
|
||||
TEST_ASSERT( mbedtls_mpi_add_mpi( &X, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
/* result == second operand */
|
||||
TEST_ASSERT( mbedtls_mpi_add_mpi( &Y, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Y ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -700,18 +681,21 @@ void mbedtls_mpi_add_mpi_inplace( int radix_X, char * input_X, int radix_A,
|
|||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_sub_abs( &X, &X, &X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &X, 0 ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_abs( &X, &X, &X ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_mpi( &X, &X, &X ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -727,19 +711,22 @@ void mbedtls_mpi_add_abs( int radix_X, char * input_X, int radix_Y,
|
|||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_abs( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
/* result == first operand */
|
||||
TEST_ASSERT( mbedtls_mpi_add_abs( &X, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
/* result == second operand */
|
||||
TEST_ASSERT( mbedtls_mpi_add_abs( &Y, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Y ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -754,9 +741,10 @@ void mbedtls_mpi_add_int( int radix_X, char * input_X, int input_Y,
|
|||
mbedtls_mpi X, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_int( &Z, &X, input_Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -771,19 +759,22 @@ void mbedtls_mpi_sub_mpi( int radix_X, char * input_X, int radix_Y,
|
|||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_sub_mpi( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
/* result == first operand */
|
||||
TEST_ASSERT( mbedtls_mpi_sub_mpi( &X, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
/* result == second operand */
|
||||
TEST_ASSERT( mbedtls_mpi_sub_mpi( &Y, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Y ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -800,23 +791,26 @@ void mbedtls_mpi_sub_abs( int radix_X, char * input_X, int radix_Y,
|
|||
int res;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
|
||||
res = mbedtls_mpi_sub_abs( &Z, &X, &Y );
|
||||
TEST_ASSERT( res == sub_result );
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
if( res == 0 )
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
/* result == first operand */
|
||||
TEST_ASSERT( mbedtls_mpi_sub_abs( &X, &X, &Y ) == sub_result );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
if( sub_result == 0 )
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
/* result == second operand */
|
||||
TEST_ASSERT( mbedtls_mpi_sub_abs( &Y, &X, &Y ) == sub_result );
|
||||
TEST_ASSERT( sign_is_valid( &Y ) );
|
||||
if( sub_result == 0 )
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &A ) == 0 );
|
||||
|
||||
|
@ -832,9 +826,10 @@ void mbedtls_mpi_sub_int( int radix_X, char * input_X, int input_Y,
|
|||
mbedtls_mpi X, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_sub_int( &Z, &X, input_Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -849,10 +844,11 @@ void mbedtls_mpi_mul_mpi( int radix_X, char * input_X, int radix_Y,
|
|||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_mul_mpi( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -868,9 +864,10 @@ void mbedtls_mpi_mul_int( int radix_X, char * input_X, int input_Y,
|
|||
mbedtls_mpi X, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_mul_int( &Z, &X, input_Y ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
if( strcmp( result_comparison, "==" ) == 0 )
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
else if( strcmp( result_comparison, "!=" ) == 0 )
|
||||
|
@ -893,14 +890,16 @@ void mbedtls_mpi_div_mpi( int radix_X, char * input_X, int radix_Y,
|
|||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &R );
|
||||
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &B );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &B, radix_B, input_B ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &B, radix_B, input_B ) == 0 );
|
||||
res = mbedtls_mpi_div_mpi( &Q, &R, &X, &Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &Q ) );
|
||||
TEST_ASSERT( sign_is_valid( &R ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Q, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R, &B ) == 0 );
|
||||
}
|
||||
|
@ -921,13 +920,15 @@ void mbedtls_mpi_div_int( int radix_X, char * input_X, int input_Y,
|
|||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &R ); mbedtls_mpi_init( &A );
|
||||
mbedtls_mpi_init( &B );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &B, radix_B, input_B ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &B, radix_B, input_B ) == 0 );
|
||||
res = mbedtls_mpi_div_int( &Q, &R, &X, input_Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &Q ) );
|
||||
TEST_ASSERT( sign_is_valid( &R ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Q, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R, &B ) == 0 );
|
||||
}
|
||||
|
@ -947,13 +948,14 @@ void mbedtls_mpi_mod_mpi( int radix_X, char * input_X, int radix_Y,
|
|||
int res;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
res = mbedtls_mpi_mod_mpi( &X, &X, &Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
}
|
||||
|
||||
|
@ -971,7 +973,7 @@ void mbedtls_mpi_mod_int( int radix_X, char * input_X, int input_Y,
|
|||
mbedtls_mpi_uint r;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
res = mbedtls_mpi_mod_int( &r, &X, input_Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
|
@ -987,26 +989,41 @@ exit:
|
|||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_exp_mod( int radix_A, char * input_A, int radix_E,
|
||||
char * input_E, int radix_N, char * input_N,
|
||||
int radix_RR, char * input_RR, int radix_X,
|
||||
char * input_X, int div_result )
|
||||
int radix_X, char * input_X, int exp_result )
|
||||
{
|
||||
mbedtls_mpi A, E, N, RR, Z, X;
|
||||
int res;
|
||||
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N );
|
||||
mbedtls_mpi_init( &RR ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
if( strlen( input_RR ) )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &RR, radix_RR, input_RR ) == 0 );
|
||||
|
||||
res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR );
|
||||
TEST_ASSERT( res == div_result );
|
||||
res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, NULL );
|
||||
TEST_ASSERT( res == exp_result );
|
||||
if( res == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &X ) == 0 );
|
||||
}
|
||||
|
||||
/* Now test again with the speed-up parameter supplied as an output. */
|
||||
res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR );
|
||||
TEST_ASSERT( res == exp_result );
|
||||
if( res == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &X ) == 0 );
|
||||
}
|
||||
|
||||
/* Now test again with the speed-up parameter supplied in calculated form. */
|
||||
res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR );
|
||||
TEST_ASSERT( res == exp_result );
|
||||
if( res == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &X ) == 0 );
|
||||
}
|
||||
|
||||
|
@ -1040,7 +1057,7 @@ void mbedtls_mpi_exp_mod_size( int A_bytes, int E_bytes, int N_bytes,
|
|||
TEST_ASSERT( mbedtls_mpi_set_bit( &N, 0, 1 ) == 0 );
|
||||
|
||||
if( strlen( input_RR ) )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &RR, radix_RR, input_RR ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &RR, radix_RR, input_RR ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR ) == exp_result );
|
||||
|
||||
|
@ -1059,13 +1076,14 @@ void mbedtls_mpi_inv_mod( int radix_X, char * input_X, int radix_Y,
|
|||
int res;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
res = mbedtls_mpi_inv_mod( &Z, &X, &Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
{
|
||||
TEST_ASSERT( sign_is_valid( &Z ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
}
|
||||
|
||||
|
@ -1081,7 +1099,7 @@ void mbedtls_mpi_is_prime( int radix_X, char * input_X, int div_result )
|
|||
int res;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
res = mbedtls_mpi_is_prime_ext( &X, 40, mbedtls_test_rnd_std_rand, NULL );
|
||||
TEST_ASSERT( res == div_result );
|
||||
|
||||
|
@ -1141,6 +1159,7 @@ void mbedtls_mpi_gen_prime( int bits, int flags, int ref_ret )
|
|||
|
||||
TEST_ASSERT( actual_bits >= (size_t) bits );
|
||||
TEST_ASSERT( actual_bits <= (size_t) bits + 1 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_is_prime_ext( &X, 40,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
|
@ -1167,9 +1186,10 @@ void mbedtls_mpi_shift_l( int radix_X, char * input_X, int shift_X,
|
|||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_shift_l( &X, shift_X ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -1184,9 +1204,10 @@ void mbedtls_mpi_shift_r( int radix_X, char * input_X, int shift_X,
|
|||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_shift_r( &X, shift_X ) == 0 );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -1228,6 +1249,7 @@ void mpi_fill_random( int wanted_bytes, int rng_bytes,
|
|||
TEST_ASSERT( mbedtls_mpi_size( &X ) + leading_zeros ==
|
||||
(size_t) wanted_bytes );
|
||||
TEST_ASSERT( (int) bytes_left == rng_bytes - wanted_bytes );
|
||||
TEST_ASSERT( sign_is_valid( &X ) );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -1285,6 +1307,7 @@ void mpi_random_many( int min, data_t *bound_bytes, int iterations )
|
|||
TEST_EQUAL( 0, mbedtls_mpi_random( &result, min, &upper_bound,
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
|
||||
TEST_ASSERT( sign_is_valid( &result ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &result, &upper_bound ) < 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &result, min ) >= 0 );
|
||||
if( full_stats )
|
||||
|
@ -1366,6 +1389,7 @@ void mpi_random_sizes( int min, data_t *bound_bytes, int nlimbs, int before )
|
|||
bound_bytes->x, bound_bytes->len ) );
|
||||
TEST_EQUAL( 0, mbedtls_mpi_random( &result, min, &upper_bound,
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_ASSERT( sign_is_valid( &result ) );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &result, &upper_bound ) < 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &result, min ) >= 0 );
|
||||
|
||||
|
|
|
@ -403,8 +403,8 @@ void pk_rsa_verify_test_vec( data_t * message_str, int digest, int mod,
|
|||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
||||
rsa->len = mod / 8;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->E, radix_E, input_E ) == 0 );
|
||||
|
||||
|
||||
if( mbedtls_md_info_from_type( digest ) != NULL )
|
||||
|
@ -446,8 +446,8 @@ void pk_rsa_verify_ext_test_vec( data_t * message_str, int digest,
|
|||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
||||
rsa->len = mod / 8;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->E, radix_E, input_E ) == 0 );
|
||||
|
||||
|
||||
if( digest != MBEDTLS_MD_NONE )
|
||||
|
@ -534,7 +534,7 @@ void pk_sign_verify_restart( int pk_type, int grp_id, char *d_str,
|
|||
|
||||
TEST_ASSERT( mbedtls_pk_setup( &prv, mbedtls_pk_info_from_type( pk_type ) ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &mbedtls_pk_ec( prv )->grp, grp_id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &mbedtls_pk_ec( prv )->d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &mbedtls_pk_ec( prv )->d, 16, d_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_setup( &pub, mbedtls_pk_info_from_type( pk_type ) ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &mbedtls_pk_ec( pub )->grp, grp_id ) == 0 );
|
||||
|
@ -720,8 +720,8 @@ void pk_rsa_encrypt_test_vec( data_t * message, int mod, int radix_N,
|
|||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
||||
rsa->len = mod / 8;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_encrypt( &pk, message->x, message->len,
|
||||
output, &olen, sizeof( output ),
|
||||
|
@ -759,12 +759,12 @@ void pk_rsa_decrypt_test_vec( data_t * cipher, int mod, int radix_P,
|
|||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
||||
/* load public key */
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
/* load private key */
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_import( rsa, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( rsa ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_complete( rsa ) == 0 );
|
||||
|
|
|
@ -30,8 +30,8 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
|
|||
MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
@ -80,10 +80,10 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
|
|||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
|
@ -288,10 +288,10 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
|
|||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
|
@ -336,8 +336,8 @@ void pkcs1_rsassa_v15_verify( int mod, int radix_N, char * input_N,
|
|||
MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
|
|
@ -373,12 +373,18 @@ mbedtls_rsa_private:"59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d041
|
|||
RSA Private (Data larger than N)
|
||||
mbedtls_rsa_private:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":2048:16:"e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17":16:"c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89":16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8":MBEDTLS_ERR_RSA_PRIVATE_FAILED + MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
RSA Private (Data = 0 )
|
||||
mbedtls_rsa_private:"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000":2048:16:"e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17":16:"c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89":16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000":0
|
||||
|
||||
RSA Public (Correct)
|
||||
mbedtls_rsa_public:"59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f8700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000":2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"1f5e927c13ff231090b0f18c8c3526428ed0f4a7561457ee5afe4d22d5d9220c34ef5b9a34d0c07f7248a1f3d57f95d10f7936b3063e40660b3a7ca3e73608b013f85a6e778ac7c60d576e9d9c0c5a79ad84ceea74e4722eb3553bdb0c2d7783dac050520cb27ca73478b509873cb0dcbd1d51dd8fccb96c29ad314f36d67cc57835d92d94defa0399feb095fd41b9f0b2be10f6041079ed4290040449f8a79aba50b0a1f8cf83c9fb8772b0686ec1b29cb1814bb06f9c024857db54d395a8da9a2c6f9f53b94bec612a0cb306a3eaa9fc80992e85d9d232e37a50cabe48c9343f039601ff7d95d60025e582aec475d031888310e8ec3833b394a5cf0599101e":0
|
||||
|
||||
RSA Public (Data larger than N)
|
||||
mbedtls_rsa_public:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8":MBEDTLS_ERR_RSA_PUBLIC_FAILED + MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
RSA Public (Data = 0)
|
||||
mbedtls_rsa_public:"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000":2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000":0
|
||||
|
||||
RSA Generate Key - 128bit key
|
||||
mbedtls_rsa_gen_key:128:3:0
|
||||
|
||||
|
|
|
@ -99,10 +99,10 @@ void mbedtls_rsa_pkcs1_sign( data_t * message_str, int padding_mode,
|
|||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
|
@ -147,8 +147,8 @@ void mbedtls_rsa_pkcs1_verify( data_t * message_str, int padding_mode,
|
|||
MBEDTLS_MD_NONE ) == 0 );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
@ -187,10 +187,10 @@ void rsa_pkcs1_sign_raw( data_t * hash_result,
|
|||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
|
@ -232,8 +232,8 @@ void rsa_pkcs1_verify_raw( data_t * hash_result,
|
|||
MBEDTLS_MD_NONE ) == 0 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
|
@ -268,8 +268,8 @@ void mbedtls_rsa_pkcs1_encrypt( data_t * message_str, int padding_mode,
|
|||
MBEDTLS_MD_NONE ) == 0 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
|
@ -311,8 +311,8 @@ void rsa_pkcs1_encrypt_bad_rng( data_t * message_str, int padding_mode,
|
|||
MBEDTLS_MD_NONE ) == 0 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
|
@ -361,10 +361,10 @@ void mbedtls_rsa_pkcs1_decrypt( data_t * message_str, int padding_mode,
|
|||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
|
@ -407,14 +407,16 @@ void mbedtls_rsa_public( data_t * message_str, int mod, int radix_N,
|
|||
mbedtls_rsa_init( &ctx2 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
|
||||
/* Check test data consistency */
|
||||
TEST_ASSERT( message_str->len == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_public( &ctx, message_str->x, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
|
@ -466,17 +468,19 @@ void mbedtls_rsa_private( data_t * message_str, int mod, int radix_P,
|
|||
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
|
||||
/* Check test data consistency */
|
||||
TEST_ASSERT( message_str->len == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
|
||||
/* repeat three times to test updating of blinding values */
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
|
@ -542,11 +546,11 @@ void mbedtls_rsa_check_pubkey( int radix_N, char * input_N, int radix_E,
|
|||
|
||||
if( strlen( input_N ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
}
|
||||
if( strlen( input_E ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
}
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
|
@ -574,36 +578,36 @@ void mbedtls_rsa_check_privkey( int mod, int radix_P, char * input_P,
|
|||
ctx.len = mod / 8;
|
||||
if( strlen( input_P ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.P, radix_P, input_P ) == 0 );
|
||||
}
|
||||
if( strlen( input_Q ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.Q, radix_Q, input_Q ) == 0 );
|
||||
}
|
||||
if( strlen( input_N ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.N, radix_N, input_N ) == 0 );
|
||||
}
|
||||
if( strlen( input_E ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.E, radix_E, input_E ) == 0 );
|
||||
}
|
||||
if( strlen( input_D ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.D, radix_D, input_D ) == 0 );
|
||||
}
|
||||
#if !defined(MBEDTLS_RSA_NO_CRT)
|
||||
if( strlen( input_DP ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.DP, radix_DP, input_DP ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.DP, radix_DP, input_DP ) == 0 );
|
||||
}
|
||||
if( strlen( input_DQ ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.DQ, radix_DQ, input_DQ ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.DQ, radix_DQ, input_DQ ) == 0 );
|
||||
}
|
||||
if( strlen( input_QP ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.QP, radix_QP, input_QP ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.QP, radix_QP, input_QP ) == 0 );
|
||||
}
|
||||
#else
|
||||
((void) radix_DP); ((void) input_DP);
|
||||
|
@ -638,45 +642,45 @@ void rsa_check_pubpriv( int mod, int radix_Npub, char * input_Npub,
|
|||
|
||||
if( strlen( input_Npub ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &pub.N, radix_Npub, input_Npub ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &pub.N, radix_Npub, input_Npub ) == 0 );
|
||||
}
|
||||
if( strlen( input_Epub ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &pub.E, radix_Epub, input_Epub ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &pub.E, radix_Epub, input_Epub ) == 0 );
|
||||
}
|
||||
|
||||
if( strlen( input_P ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.P, radix_P, input_P ) == 0 );
|
||||
}
|
||||
if( strlen( input_Q ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.Q, radix_Q, input_Q ) == 0 );
|
||||
}
|
||||
if( strlen( input_N ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.N, radix_N, input_N ) == 0 );
|
||||
}
|
||||
if( strlen( input_E ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.E, radix_E, input_E ) == 0 );
|
||||
}
|
||||
if( strlen( input_D ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.D, radix_D, input_D ) == 0 );
|
||||
}
|
||||
#if !defined(MBEDTLS_RSA_NO_CRT)
|
||||
if( strlen( input_DP ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.DP, radix_DP, input_DP ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.DP, radix_DP, input_DP ) == 0 );
|
||||
}
|
||||
if( strlen( input_DQ ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.DQ, radix_DQ, input_DQ ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.DQ, radix_DQ, input_DQ ) == 0 );
|
||||
}
|
||||
if( strlen( input_QP ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.QP, radix_QP, input_QP ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.QP, radix_QP, input_QP ) == 0 );
|
||||
}
|
||||
#else
|
||||
((void) radix_DP); ((void) input_DP);
|
||||
|
@ -737,11 +741,11 @@ void mbedtls_rsa_deduce_primes( int radix_N, char *input_N,
|
|||
mbedtls_mpi_init( &Pp ); mbedtls_mpi_init( &Qp );
|
||||
mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Qp, radix_P, output_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Pp, radix_Q, output_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Qp, radix_P, output_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Pp, radix_Q, output_Q ) == 0 );
|
||||
|
||||
if( corrupt )
|
||||
TEST_ASSERT( mbedtls_mpi_add_int( &D, &D, 2 ) == 0 );
|
||||
|
@ -778,10 +782,10 @@ void mbedtls_rsa_deduce_private_exponent( int radix_P, char *input_P,
|
|||
mbedtls_mpi_init( &E );
|
||||
mbedtls_mpi_init( &R ); mbedtls_mpi_init( &Rp );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Dp, radix_D, output_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Dp, radix_D, output_D ) == 0 );
|
||||
|
||||
if( corrupt )
|
||||
{
|
||||
|
@ -864,19 +868,19 @@ void mbedtls_rsa_import( int radix_N, char *input_N,
|
|||
(const unsigned char *) pers, strlen( pers ) ) == 0 );
|
||||
|
||||
if( have_N )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
|
||||
if( have_P )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
|
||||
if( have_Q )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
|
||||
if( have_D )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &D, radix_D, input_D ) == 0 );
|
||||
|
||||
if( have_E )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
if( !successive )
|
||||
{
|
||||
|
@ -1008,19 +1012,19 @@ void mbedtls_rsa_export( int radix_N, char *input_N,
|
|||
/* Setup RSA context */
|
||||
|
||||
if( have_N )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
|
||||
if( have_P )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
|
||||
if( have_Q )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
|
||||
if( have_D )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &D, radix_D, input_D ) == 0 );
|
||||
|
||||
if( have_E )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx,
|
||||
strlen( input_N ) ? &N : NULL,
|
||||
|
@ -1128,19 +1132,19 @@ void mbedtls_rsa_validate_params( int radix_N, char *input_N,
|
|||
strlen( pers ) ) == 0 );
|
||||
|
||||
if( have_N )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
|
||||
if( have_P )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
|
||||
if( have_Q )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
|
||||
if( have_D )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &D, radix_D, input_D ) == 0 );
|
||||
|
||||
if( have_E )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_validate_params( have_N ? &N : NULL,
|
||||
have_P ? &P : NULL,
|
||||
|
|
|
@ -248,7 +248,7 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
|
|||
(void) rsa_alt;
|
||||
#endif
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &serial, 10, serial_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &serial, 10, serial_str ) == 0 );
|
||||
|
||||
if( ver != -1 )
|
||||
mbedtls_x509write_crt_set_version( &crt, ver );
|
||||
|
|
Loading…
Reference in a new issue