- Added and modified tests (result from coverage)

This commit is contained in:
Paul Bakker 2009-07-12 11:01:32 +00:00
parent 71d59fb4b4
commit ba48cb2fee
2 changed files with 180 additions and 27 deletions

View file

@ -1,35 +1,65 @@
Base test mpi_read_write_string #1
mpi_read_write_string:10:"128":10:"128"
mpi_read_write_string:10:"128":10:"128":100:0:0
Base test mpi_read_write_string #2
mpi_read_write_string:10:"128":16:"80"
mpi_read_write_string:10:"128":16:"80":100:0:0
Base test mpi_read_write_string #3 (Read zero)
mpi_read_write_string:10:"0":10:"0"
mpi_read_write_string:10:"0":10:"0":100:0:0
Base test mpi_read_write_string #3 (Negative decimal)
mpi_read_write_string:10:"-23":10:"-23"
mpi_read_write_string:10:"-23":10:"-23":100:0:0
Base test mpi_read_write_string #3 (Negative hex)
mpi_read_write_string:16:"-20":10:"-32"
mpi_read_write_string:16:"-20":10:"-32":100:0:0
Base test mpi_read_write_string #3 (Negative decimal)
mpi_read_write_string:16:"-23":16:"-23"
mpi_read_write_string:16:"-23":16:"-23":100:0:0
Test mpi_read_write_string #1
mpi_read_write_string:10:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":16:"0941379d00fed1491fe15df284dfde4a142f68aa8d412023195cee66883e6290ffe703f4ea5963bf212713cee46b107c09182b5edcd955adac418bf4918e2889af48e1099d513830cec85c26ac1e158b52620e33ba8692f893efbb2f958b4424"
Test mpi_read_write_string #1 (Invalid character)
mpi_read_write_string:10:"a28":0:"":100:POLARSSL_ERR_MPI_INVALID_CHARACTER:0
Test mpi_read_write_string #2 (Illegal input radix)
mpi_read_write_string:19:"a28":0:"":100:POLARSSL_ERR_MPI_BAD_INPUT_DATA:0
Test mpi_read_write_string #3 (Buffer just fits)
mpi_read_write_string:16:"-23":16:"-23":4:0:0
Test mpi_read_write_string #4 (Buffer too small)
mpi_read_write_string:16:"-23":16:"-23":3:0:POLARSSL_ERR_MPI_BUFFER_TOO_SMALL
Test mpi_read_write_string #5 (Illegal output radix)
mpi_read_write_string:16:"-23":17:"-23":4:0:POLARSSL_ERR_MPI_BAD_INPUT_DATA
Test mpi_read_write_string #6 (Output radix of 15)
mpi_read_write_string:10:"29":15:"1e":100:0:0
Test mpi_read_write_string #7
mpi_read_write_string:10:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":16:"0941379d00fed1491fe15df284dfde4a142f68aa8d412023195cee66883e6290ffe703f4ea5963bf212713cee46b107c09182b5edcd955adac418bf4918e2889af48e1099d513830cec85c26ac1e158b52620e33ba8692f893efbb2f958b4424":200:0:0
Base test mpi_read_binary #1
mpi_read_binary:"0941379d00fed1491fe15df284dfde4a142f68aa8d412023195cee66883e6290ffe703f4ea5963bf212713cee46b107c09182b5edcd955adac418bf4918e2889af48e1099d513830cec85c26ac1e158b52620e33ba8692f893efbb2f958b4424":10:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924"
Base test mpi_write_binary #1
mpi_write_binary:10:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":"0941379d00fed1491fe15df284dfde4a142f68aa8d412023195cee66883e6290ffe703f4ea5963bf212713cee46b107c09182b5edcd955adac418bf4918e2889af48e1099d513830cec85c26ac1e158b52620e33ba8692f893efbb2f958b4424"
mpi_write_binary:10:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":"0941379d00fed1491fe15df284dfde4a142f68aa8d412023195cee66883e6290ffe703f4ea5963bf212713cee46b107c09182b5edcd955adac418bf4918e2889af48e1099d513830cec85c26ac1e158b52620e33ba8692f893efbb2f958b4424":200:0
Test mpi_write_binary #1 (Buffer just fits)
mpi_write_binary:16:"123123123123123123123123123":"0123123123123123123123123123":14:0
Test mpi_write_binary #2 (Buffer too small)
mpi_write_binary:16:"123123123123123123123123123":"123123123123123123123123123":13:POLARSSL_ERR_MPI_BUFFER_TOO_SMALL
Base test mpi_read_file #1
mpi_read_file:10:"data_files/mpi_10":"01f55332c3a48b910f9942f6c914e58bef37a47ee45cb164a5b6b8d1006bf59a059c21449939ebebfdf517d2e1dbac88010d7b1f141e997bd6801ddaec9d05910f4f2de2b2c4d714e2c14a72fc7f17aa428d59c531627f09"
mpi_read_file:10:"data_files/mpi_10":"01f55332c3a48b910f9942f6c914e58bef37a47ee45cb164a5b6b8d1006bf59a059c21449939ebebfdf517d2e1dbac88010d7b1f141e997bd6801ddaec9d05910f4f2de2b2c4d714e2c14a72fc7f17aa428d59c531627f09":0
Test mpi_read_file #1 (Empty file)
mpi_read_file:10:"data_files/hash_file_4":"":POLARSSL_ERR_MPI_FILE_IO_ERROR
Test mpi_read_file #2 (Illegal input)
mpi_read_file:10:"data_files/hash_file_3":"":0
Base test mpi_write_file #1
mpi_write_file:10:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":16:"data_files/mpi_write"
mpi_write_file:10:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":16:"data_files/mpi_write":0
Base test mpi_lsb #1
mpi_lsb:10:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":2
@ -118,6 +148,9 @@ mpi_cmp_abs:10:"-2":10:"-3":-1
Base test mpi_cmp_abs (Negative values) #3
mpi_cmp_abs:10:"-2":10:"-1":1
Base test mpi_cmp_abs (Zero and Zero) #4
mpi_cmp_abs:10:"0":10:"0":0
Base test mpi_cmp_abs (Mix values) #1
mpi_cmp_abs:10:"-2":10:"2":0
@ -151,6 +184,12 @@ mpi_add_abs:10:"-12345678":10:"-642531":10:"12988209"
Test mpi_add_abs #1
mpi_add_abs:10:"-643808006803554439230129854961492699151386107534013432918073439524138264842370630061369715394739134090922937332590384720397133335969549256322620979036686633213903952966175107096769180017646161851573147596390153":10:"56125680981752282333498088313568935051383833838594899821664631784577337171193624243181360054669678410455329112434552942717084003541384594864129940145043086760031292483340068923506115878221189886491132772739661669044958531131327771":10:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924"
Test mpi_add_abs #2 (add to first value)
mpi_add_abs_add_first:10:"123123":10:"123123":10:"246246"
Test mpi_add_abs #3 (add to second value)
mpi_add_abs_add_second:10:"123123":10:"123123":10:"246246"
Base test mpi_add_mpi #1
mpi_add_mpi:10:"12345678":10:"642531":10:"12988209"
@ -277,10 +316,16 @@ mpi_div_mpi:10:"2013305664251822604231073010137627848354723913012380633805538780
Test mpi_div_mpi #2
mpi_div_mpi:10:"476221599179424887669515829231223263939342135681791605842540429321038144633323941248706405375723482912535192363845116154236465184147599697841273424891410002781967962186252583311115708128167171262206919514587899883547279647025952837516324649656913580411611297312678955801899536937577476819667861053063432906071315727948826276092545739432005962781562403795455162483159362585281248265005441715080197800335757871588045959754547836825977169125866324128449699877076762316768127816074587766799018626179199776188490087103869164122906791440101822594139648973454716256383294690817576188762":10:"28911710017320205966167820725313234361535259163045867986277478145081076845846493521348693253530011243988160148063424837895971948244167867236923919506962312185829914482993478947657472351461336729641485069323635424692930278888923450060546465883490944265147851036817433970984747733020522259537":10:"16471581891701794764704009719057349996270239948993452268812975037240586099924712715366967486587417803753916334331355573776945238871512026832810626226164346328807407669366029926221415383560814338828449642265377822759768011406757061063524768140567867350208554439342320410551341675119078050953":10:"1":0
Test mpi_div_mpi #3
mpi_div_mpi:10:"1000":10:"7":10:"142":10:"6":0
Test mpi_div_mpi #4
mpi_div_mpi:10:"777":10:"7":10:"111":10:"0":0
Base test mpi_div_int #1
mpi_div_int:10:"1000":13:10:"76":10:"12":0
Base test mpi_div_mpi #2 (Divide by zero)
Base test mpi_div_int #2 (Divide by zero)
mpi_div_int:10:"1000":0:10:"1":10:"1":POLARSSL_ERR_MPI_DIVISION_BY_ZERO
Base test mpi_div_int #3
@ -322,6 +367,15 @@ mpi_mod_int:10:"1000":-13:0:POLARSSL_ERR_MPI_NEGATIVE_VALUE
Base test mpi_mod_int #5 (Negative modulo)
mpi_mod_int:10:"-1000":-13:0:POLARSSL_ERR_MPI_NEGATIVE_VALUE
Base test mpi_mod_int #6 (By 1)
mpi_mod_int:10:"1000":1:0:0
Base test mpi_mod_int #7 (By 2)
mpi_mod_int:10:"1001":2:1:0
Base test mpi_mod_int #8 (By 2)
mpi_mod_int:10:"1000":2:0:0
Base test mpi_exp_mod #1
mpi_exp_mod:10:"23":10:"13":10:"29":10:"":10:"24":0
@ -391,5 +445,62 @@ mpi_is_prime:10:"827131507221654563937832686696200995595835694437983658840870036
Test mpi_is_prime #2
mpi_is_prime:10:"827131507221654563937832686696200995595835694437983658840870036586124168186967796809117749047430768825822857042432722828096779098498192459819306321073968735177531164565305635281198148032612029767584644305912001":POLARSSL_ERR_MPI_NOT_ACCEPTABLE
Test mpi_is_prime #3
mpi_is_prime:10:"2833419889721787128217599":0
Test mpi_is_prime #4
mpi_is_prime:10:"195845982777569926302400511":0
Test mpi_is_prime #5
mpi_is_prime:10:"4776913109852041418248056622882488319":0
Test mpi_is_prime #5
mpi_is_prime:10:"768614336404564651":0
Test mpi_is_prime #6
mpi_is_prime:10:"201487636602438195784363":0
Test mpi_is_prime #7
mpi_is_prime:10:"845100400152152934331135470251":0
Test mpi_is_prime #8
mpi_is_prime:10:"56713727820156410577229101238628035243":0
Test mpi_is_prime #9
mpi_is_prime:10:"203956878356401977405765866929034577280193993314348263094772646453283062722701277632936616063144088173312372882677123879538709400158306567338328279154499698366071906766440037074217117805690872792848149112022286332144876183376326512083574821647933992961249917319836219304274280243803104015000563790123":0
Test mpi_is_prime #10
mpi_is_prime:10:"531872289054204184185084734375133399408303613982130856645299464930952178606045848877129147820387996428175564228204785846141207532462936339834139412401975338705794646595487324365194792822189473092273993580587964571659678084484152603881094176995594813302284232006001752128168901293560051833646881436219":0
Test mpi_is_prime #11
mpi_is_prime:10:"319705304701141539155720137200974664666792526059405792539680974929469783512821793995613718943171723765238853752439032835985158829038528214925658918372196742089464683960239919950882355844766055365179937610326127675178857306260955550407044463370239890187189750909036833976197804646589380690779463976173":0
Test mpi_is_prime #12
mpi_is_prime:10:"200603822195324642393516294012917598972967449320074999667103434371470616000652036570009912021332527788252300901905236578801044680456930305350440933538867383130165841118050781326291059830545891570648243241795871":0
Test mpi_is_prime #13
mpi_is_prime:10:"827131507221654563937832686696200995595835694437983658840870036586124168186967796809117749047430768825822857042432722828096779098498192459819306321073968735177531164565305635281198148032612029767584644305912099":0
Test mpi_is_prime #14
mpi_is_prime:10:"964274047248418797145090983157197980855078966882276492572788532954904112655338439361306213898569516593744267391754033306465125919199692703323878557833023573312685002670662846477592597659826113460619815244721311":0
Test mpi_is_prime #15
mpi_is_prime:10:"170141183460469231731687303715884105727":0
Test mpi_is_prime #16
mpi_is_prime:10:"2147483647":0
Test mpi_is_prime #17
mpi_is_prime:10:"961748941":0
Test mpi_is_prime #18
mpi_is_prime:10:"179424691":0
Test mpi_is_prime #19
mpi_is_prime:10:"32452867":0
Test mpi_is_prime #20
mpi_is_prime:10:"49979687":0
MPI Selftest
mpi_selftest:

View file

@ -12,17 +12,23 @@ static int myrand( void *rng_state )
END_HEADER
BEGIN_CASE
mpi_read_write_string:radix_X:input_X:radix_A:input_A
mpi_read_write_string:radix_X:input_X:radix_A:input_A:output_size:result_read:result_write
{
mpi X;
char str[1000];
int len = 1000;
int len = {output_size};
mpi_init(&X, NULL);
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_write_string( &X, {radix_A}, str, &len ) == 0 );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == {result_read} );
if( {result_read} == 0 )
{
TEST_ASSERT( mpi_write_string( &X, {radix_A}, str, &len ) == {result_write} );
if( {result_write} == 0 )
{
TEST_ASSERT( strcasecmp( str, {input_A} ) == 0 );
}
}
}
END_CASE
@ -46,7 +52,7 @@ mpi_read_binary:input_X:radix_A:input_A
END_CASE
BEGIN_CASE
mpi_write_binary:radix_X:input_X:input_A
mpi_write_binary:radix_X:input_X:input_A:output_size:result
{
mpi X;
unsigned char str[1000];
@ -61,16 +67,21 @@ mpi_write_binary:radix_X:input_X:input_A
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
buflen = mpi_size( &X );
TEST_ASSERT( mpi_write_binary( &X, buf, buflen ) == 0 );
if( buflen > {output_size} )
buflen = {output_size};
TEST_ASSERT( mpi_write_binary( &X, buf, buflen ) == {result} );
if( {result} == 0)
{
hexify( str, buf, buflen );
TEST_ASSERT( strcasecmp( (char *) str, {input_A} ) == 0 );
}
}
END_CASE
BEGIN_CASE
mpi_read_file:radix_X:input_file:input_A
mpi_read_file:radix_X:input_file:input_A:result
{
mpi X;
unsigned char str[1000];
@ -84,15 +95,18 @@ mpi_read_file:radix_X:input_file:input_A
mpi_init(&X, NULL);
file = fopen( {input_file}, "r" );
TEST_ASSERT( mpi_read_file( &X, {radix_X}, file ) == 0 );
TEST_ASSERT( mpi_read_file( &X, {radix_X}, file ) == {result} );
fclose(file);
if( {result} == 0 )
{
buflen = mpi_size( &X );
TEST_ASSERT( mpi_write_binary( &X, buf, buflen ) == 0 );
hexify( str, buf, buflen );
TEST_ASSERT( strcasecmp( (char *) str, {input_A} ) == 0 );
}
}
END_CASE
@ -263,6 +277,34 @@ mpi_add_abs:radix_X:input_X:radix_Y:input_Y:radix_A:input_A
}
END_CASE
BEGIN_CASE
mpi_add_abs_add_first:radix_X:input_X:radix_Y:input_Y:radix_A:input_A
{
mpi X, Y, A;
mpi_init(&X, &Y, &A, NULL);
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_add_abs( &X, &X, &Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
}
END_CASE
BEGIN_CASE
mpi_add_abs_add_second:radix_X:input_X:radix_Y:input_Y:radix_A:input_A
{
mpi X, Y, A;
mpi_init(&X, &Y, &A, NULL);
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_add_abs( &Y, &X, &Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &Y, &A ) == 0 );
}
END_CASE
BEGIN_CASE
mpi_add_int:radix_X:input_X:input_Y:radix_A:input_A
{