test_suite_mpi.c File Reference

#include <polarssl/config.h>
#include <polarssl/bignum.h>
#include <inttypes.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Include dependency graph for test_suite_mpi.c:

Go to the source code of this file.

Data Structures

struct  rnd_buf_info
struct  rnd_pseudo_info
 Info structure for the pseudo random function. More...

Defines

#define ciL   (sizeof(t_uint))
 NOT random function, to match test vectors.
#define CHARS_TO_LIMBS(i)   (((i) + ciL - 1) / ciL)
#define TEST_SUITE_ACTIVE
#define TEST_ASSERT(TEST)

Functions

static int unhexify (unsigned char *obuf, const char *ibuf)
static void hexify (unsigned char *obuf, const unsigned char *ibuf, int len)
static int rnd_std_rand (void *rng_state, unsigned char *output, size_t len)
 This function just returns data from rand().
static int rnd_zero_rand (void *rng_state, unsigned char *output, size_t len)
 This function only returns zeros.
static int rnd_buffer_rand (void *rng_state, unsigned char *output, size_t len)
 This function returns random based on a buffer it receives.
static int rnd_pseudo_rand (void *rng_state, unsigned char *output, size_t len)
 This function returns random based on a pseudo random function.
static int not_rnd_mpi (void *in, unsigned char *out, size_t len)
static int test_assert (int correct, char *test)
int verify_string (char **str)
int verify_int (char *str, int *value)
void test_suite_mpi_read_write_string (int radix_X, char *input_X, int radix_A, char *input_A, int output_size, int result_read, int result_write)
void test_suite_mpi_read_binary (char *input_X, int radix_A, char *input_A)
void test_suite_mpi_write_binary (int radix_X, char *input_X, char *input_A, int output_size, int result)
void test_suite_mpi_read_file (int radix_X, char *input_file, char *input_A, int result)
void test_suite_mpi_write_file (int radix_X, char *input_X, int output_radix, char *output_file)
void test_suite_mpi_get_bit (int radix_X, char *input_X, int pos, int val)
void test_suite_mpi_set_bit (int radix_X, char *input_X, int pos, int val, int radix_Y, char *output_Y)
void test_suite_mpi_lsb (int radix_X, char *input_X, int nr_bits)
void test_suite_mpi_msb (int radix_X, char *input_X, int nr_bits)
void test_suite_mpi_gcd (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A)
void test_suite_mpi_cmp_int (int input_X, int input_A, int result_CMP)
void test_suite_mpi_cmp_mpi (int radix_X, char *input_X, int radix_Y, char *input_Y, int input_A)
void test_suite_mpi_cmp_abs (int radix_X, char *input_X, int radix_Y, char *input_Y, int input_A)
void test_suite_mpi_copy (int input_X, int input_A)
void test_suite_mpi_copy_self (int input_X)
void test_suite_mpi_swap (int input_X, int input_Y)
void test_suite_mpi_add_mpi (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A)
void test_suite_mpi_add_abs (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A)
void test_suite_mpi_add_abs_add_first (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A)
void test_suite_mpi_add_abs_add_second (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A)
void test_suite_mpi_add_int (int radix_X, char *input_X, int input_Y, int radix_A, char *input_A)
void test_suite_mpi_sub_mpi (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A)
void test_suite_mpi_sub_abs (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A, int sub_result)
void test_suite_mpi_sub_int (int radix_X, char *input_X, int input_Y, int radix_A, char *input_A)
void test_suite_mpi_mul_mpi (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A)
void test_suite_mpi_mul_int (int radix_X, char *input_X, int input_Y, int radix_A, char *input_A, char *result_comparison)
void test_suite_mpi_div_mpi (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A, int radix_B, char *input_B, int div_result)
void test_suite_mpi_div_int (int radix_X, char *input_X, int input_Y, int radix_A, char *input_A, int radix_B, char *input_B, int div_result)
void test_suite_mpi_mod_mpi (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A, int div_result)
void test_suite_mpi_mod_int (int radix_X, char *input_X, int input_Y, int input_A, int div_result)
void test_suite_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)
void test_suite_mpi_inv_mod (int radix_X, char *input_X, int radix_Y, char *input_Y, int radix_A, char *input_A, int div_result)
void test_suite_mpi_is_prime (int radix_X, char *input_X, int div_result)
void test_suite_mpi_shift_l (int radix_X, char *input_X, int shift_X, int radix_A, char *input_A)
void test_suite_mpi_shift_r (int radix_X, char *input_X, int shift_X, int radix_A, char *input_A)
void test_suite_mpi_selftest ()
int dep_check (char *str)
int dispatch_test (int cnt, char *params[50])
int get_line (FILE *f, char *buf, size_t len)
int parse_arguments (char *buf, size_t len, char *params[50])
int main ()

Variables

static int test_errors = 0

Define Documentation

#define CHARS_TO_LIMBS (  )     (((i) + ciL - 1) / ciL)

Definition at line 254 of file test_suite_mpi.c.

#define ciL   (sizeof(t_uint))

NOT random function, to match test vectors.

The following are equivalent: mpi_fill_random( x, strlen( str ) / 2, not_rnd, str ); mpi_read_string( x, 16, str ); Warning: no other use is supported!

Definition at line 253 of file test_suite_mpi.c.

#define TEST_ASSERT ( TEST   ) 
Value:
do { test_assert( (TEST) ? 1 : 0, #TEST );  \
             if( test_errors) return;               \
        } while (0)

Definition at line 301 of file test_suite_mpi.c.

#define TEST_SUITE_ACTIVE

Definition at line 286 of file test_suite_mpi.c.


Function Documentation

int dep_check ( char *  str  ) 

Definition at line 1054 of file test_suite_mpi.c.

int dispatch_test ( int  cnt,
char *  params[50] 
)
int get_line ( FILE *  f,
char *  buf,
size_t  len 
)

Definition at line 2083 of file test_suite_mpi.c.

static void hexify ( unsigned char *  obuf,
const unsigned char *  ibuf,
int  len 
) [static]

Definition at line 89 of file test_suite_mpi.c.

Referenced by test_suite_mpi_read_file(), and test_suite_mpi_write_binary().

int main (  ) 
static int not_rnd_mpi ( void *  in,
unsigned char *  out,
size_t  len 
) [static]

Definition at line 255 of file test_suite_mpi.c.

References CHARS_TO_LIMBS, mpi_read_string(), mpi::n, mpi::p, and mpi::s.

int parse_arguments ( char *  buf,
size_t  len,
char *  params[50] 
)

Definition at line 2099 of file test_suite_mpi.c.

static int rnd_buffer_rand ( void *  rng_state,
unsigned char *  output,
size_t  len 
) [static]

This function returns random based on a buffer it receives.

rng_state shall be a pointer to a rnd_buf_info structure.

The number of bytes released from the buffer on each call to the random function is specified by per_call. (Can be between 1 and 4)

After the buffer is empty it will return rand();

Definition at line 167 of file test_suite_mpi.c.

References rnd_buf_info::buf, rnd_buf_info::length, and rnd_std_rand().

static int rnd_pseudo_rand ( void *  rng_state,
unsigned char *  output,
size_t  len 
) [static]

This function returns random based on a pseudo random function.

This means the results should be identical on all systems. Pseudo random is based on the XTEA encryption algorithm to generate pseudorandom.

rng_state shall be a pointer to a rnd_pseudo_info structure.

Definition at line 213 of file test_suite_mpi.c.

References rnd_pseudo_info::key, PUT_UINT32_BE, rnd_std_rand(), rnd_pseudo_info::v0, and rnd_pseudo_info::v1.

static int rnd_std_rand ( void *  rng_state,
unsigned char *  output,
size_t  len 
) [static]

This function just returns data from rand().

Although predictable and often similar on multiple runs, this does not result in identical random on each run. So do not use this if the results of a test depend on the random data that is generated.

rng_state shall be NULL.

Definition at line 122 of file test_suite_mpi.c.

Referenced by rnd_buffer_rand(), rnd_pseudo_rand(), and test_suite_mpi_is_prime().

static int rnd_zero_rand ( void *  rng_state,
unsigned char *  output,
size_t  len 
) [static]

This function only returns zeros.

rng_state shall be NULL.

Definition at line 140 of file test_suite_mpi.c.

static int test_assert ( int  correct,
char *  test 
) [static]

Definition at line 288 of file test_suite_mpi.c.

References test_errors.

void test_suite_mpi_add_abs ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A 
)

Definition at line 724 of file test_suite_mpi.c.

References A, mpi_add_abs(), mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_add_abs_add_first ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A 
)

Definition at line 739 of file test_suite_mpi.c.

References A, mpi_add_abs(), mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_add_abs_add_second ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A 
)

Definition at line 754 of file test_suite_mpi.c.

References A, mpi_add_abs(), mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_add_int ( int  radix_X,
char *  input_X,
int  input_Y,
int  radix_A,
char *  input_A 
)

Definition at line 769 of file test_suite_mpi.c.

References A, mpi_add_int(), mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_add_mpi ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A 
)

Definition at line 709 of file test_suite_mpi.c.

References A, mpi_add_mpi(), mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_cmp_abs ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  input_A 
)

Definition at line 650 of file test_suite_mpi.c.

References mpi_cmp_abs(), mpi_free(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_cmp_int ( int  input_X,
int  input_A,
int  result_CMP 
)

Definition at line 626 of file test_suite_mpi.c.

References mpi_cmp_int(), mpi_free(), mpi_init(), mpi_lset(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_cmp_mpi ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  input_A 
)

Definition at line 637 of file test_suite_mpi.c.

References mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_copy ( int  input_X,
int  input_A 
)

Definition at line 663 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_copy(), mpi_free(), mpi_init(), mpi_lset(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_copy_self ( int  input_X  ) 

Definition at line 680 of file test_suite_mpi.c.

References mpi_cmp_int(), mpi_copy(), mpi_free(), mpi_init(), mpi_lset(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_div_int ( int  radix_X,
char *  input_X,
int  input_Y,
int  radix_A,
char *  input_A,
int  radix_B,
char *  input_B,
int  div_result 
)

Definition at line 890 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_div_int(), mpi_free(), mpi_init(), mpi_read_string(), R, and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_div_mpi ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A,
int  radix_B,
char *  input_B,
int  div_result 
)

Definition at line 865 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_div_mpi(), mpi_free(), mpi_init(), mpi_read_string(), R, and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_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 
)

Definition at line 952 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_exp_mod(), mpi_free(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_gcd ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A 
)

Definition at line 611 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_gcd(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_get_bit ( int  radix_X,
char *  input_X,
int  pos,
int  val 
)

Definition at line 565 of file test_suite_mpi.c.

References mpi_free(), mpi_get_bit(), mpi_init(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_inv_mod ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A,
int  div_result 
)

Definition at line 980 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_inv_mod(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_is_prime ( int  radix_X,
char *  input_X,
int  div_result 
)

Definition at line 1001 of file test_suite_mpi.c.

References mpi_free(), mpi_init(), mpi_is_prime(), mpi_read_string(), rnd_std_rand(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_lsb ( int  radix_X,
char *  input_X,
int  nr_bits 
)

Definition at line 589 of file test_suite_mpi.c.

References mpi_free(), mpi_init(), mpi_lsb(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_mod_int ( int  radix_X,
char *  input_X,
int  input_Y,
int  input_A,
int  div_result 
)

Definition at line 933 of file test_suite_mpi.c.

References mpi_free(), mpi_init(), mpi_mod_int(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_mod_mpi ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A,
int  div_result 
)

Definition at line 913 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_mod_mpi(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_msb ( int  radix_X,
char *  input_X,
int  nr_bits 
)

Definition at line 600 of file test_suite_mpi.c.

References mpi_free(), mpi_init(), mpi_msb(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_mul_int ( int  radix_X,
char *  input_X,
int  input_Y,
int  radix_A,
char *  input_A,
char *  result_comparison 
)

Definition at line 846 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_mul_int(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_mul_mpi ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A 
)

Definition at line 831 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_mul_mpi(), mpi_read_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_read_binary ( char *  input_X,
int  radix_A,
char *  input_A 
)
void test_suite_mpi_read_file ( int  radix_X,
char *  input_file,
char *  input_A,
int  result 
)
void test_suite_mpi_read_write_string ( int  radix_X,
char *  input_X,
int  radix_A,
char *  input_A,
int  output_size,
int  result_read,
int  result_write 
)

Definition at line 433 of file test_suite_mpi.c.

References mpi_free(), mpi_init(), mpi_read_string(), mpi_write_string(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_selftest (  ) 

Definition at line 1044 of file test_suite_mpi.c.

References mpi_self_test(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_set_bit ( int  radix_X,
char *  input_X,
int  pos,
int  val,
int  radix_Y,
char *  output_Y 
)

Definition at line 575 of file test_suite_mpi.c.

References mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), mpi_set_bit(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_shift_l ( int  radix_X,
char *  input_X,
int  shift_X,
int  radix_A,
char *  input_A 
)

Definition at line 1015 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), mpi_shift_l(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_shift_r ( int  radix_X,
char *  input_X,
int  shift_X,
int  radix_A,
char *  input_A 
)

Definition at line 1029 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), mpi_shift_r(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_sub_abs ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A,
int  sub_result 
)

Definition at line 798 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), mpi_sub_abs(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_sub_int ( int  radix_X,
char *  input_X,
int  input_Y,
int  radix_A,
char *  input_A 
)

Definition at line 817 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), mpi_sub_int(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_sub_mpi ( int  radix_X,
char *  input_X,
int  radix_Y,
char *  input_Y,
int  radix_A,
char *  input_A 
)

Definition at line 783 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_read_string(), mpi_sub_mpi(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_swap ( int  input_X,
int  input_Y 
)

Definition at line 692 of file test_suite_mpi.c.

References A, mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_lset(), mpi_swap(), and TEST_ASSERT.

Referenced by dispatch_test().

void test_suite_mpi_write_binary ( int  radix_X,
char *  input_X,
char *  input_A,
int  output_size,
int  result 
)
void test_suite_mpi_write_file ( int  radix_X,
char *  input_X,
int  output_radix,
char *  output_file 
)
static int unhexify ( unsigned char *  obuf,
const char *  ibuf 
) [static]

Definition at line 55 of file test_suite_mpi.c.

Referenced by test_suite_mpi_read_binary().

int verify_int ( char *  str,
int *  value 
)
int verify_string ( char **  str  ) 

Definition at line 306 of file test_suite_mpi.c.


Variable Documentation

int test_errors = 0 [static]

Definition at line 282 of file test_suite_mpi.c.

Referenced by main(), and test_assert().


Generated on 9 Apr 2014 for PolarSSL v1.3.2 by  doxygen 1.6.1