Converted .function file to c-like format and adapted generator code

This commit is contained in:
Paul Bakker 2013-08-20 11:48:36 +02:00
parent 55a7e908f2
commit 33b43f1ec3
30 changed files with 1610 additions and 1433 deletions

View File

@ -31,8 +31,8 @@ open(TEST_DATA, "$test_case_data") or die "Opening test data '$test_case_data':
my $test_data = <TEST_DATA>;
close(TEST_DATA);
my ( $suite_header ) = $test_cases =~ /BEGIN_HEADER\n(.*?)\nEND_HEADER/s;
my ( $suite_defines ) = $test_cases =~ /BEGIN_DEPENDENCIES\n(.*?)\nEND_DEPENDENCIES/s;
my ( $suite_header ) = $test_cases =~ /\/\* BEGIN_HEADER \*\/\n(.*?)\n\/\* END_HEADER \*\//s;
my ( $suite_defines ) = $test_cases =~ /\/\* BEGIN_DEPENDENCIES\n \* (.*?)\n \* END_DEPENDENCIES/s;
my $requirements;
if ($suite_defines =~ /^depends_on:/)
@ -69,23 +69,34 @@ $suite_pre_code
END
while($test_cases =~ /BEGIN_CASE *([\w:]*)\n(\w+):([^\n]*)\n\{\n(.*?)\}\nEND_CASE/sg)
while($test_cases =~ /\/\* BEGIN_CASE *([\w:]*) \*\/\n(.*?)\n\/\* END_CASE \*\//msg)
{
my $function_deps = $1;
my $function_name = $2;
my $function_params = $3;
my $function_code = $4;
my $function_decl = $2;
# Sanity checks of function
if ($function_decl !~ /^void /)
{
die "Test function does not have 'void' as return type\n";
}
if ($function_decl !~ /^void (\w+)\(\s*(.*?)\s*\)\s*{(.*?)}/ms)
{
die "Function declaration not in expected format\n";
}
my $function_name = $1;
my $function_params = $2;
my $function_pre_code;
my $function_post_code;
my @param_decl;
my $param_defs;
my $param_checks;
my @dispatch_params;
my @var_def_arr = split(/:/, $function_params);
my @var_def_arr = split(/,\s*/, $function_params);
my $i = 1;
my $mapping_regex = "".$function_name;
my $mapping_count = 0;
$function_decl =~ s/^void /void test_suite_/;
if ($function_deps =~ /^depends_on:/)
{
( $function_deps ) = $function_deps =~ /^depends_on:(.*)$/;
@ -100,29 +111,28 @@ while($test_cases =~ /BEGIN_CASE *([\w:]*)\n(\w+):([^\n]*)\n\{\n(.*?)\}\nEND_CAS
foreach my $def (@var_def_arr)
{
# Handle the different parameter types
if( substr($def, 0, 1) eq "#" )
if( substr($def, 0, 4) eq "int " )
{
$param_defs .= " int param$i;\n";
$param_checks .= " if( verify_int( params[$i], &param$i ) != 0 ) return( 2 );\n";
push @dispatch_params, "param$i";
$def =~ s/#//;
push @param_decl, "int $def";
$mapping_regex .= ":([\\d\\w |\\+\\-\\(\\)]+)";
$mapping_count++;
}
else
elsif( substr($def, 0, 6) eq "char *" )
{
$param_defs .= " char *param$i = params[$i];\n";
$param_checks .= " if( verify_string( &param$i ) != 0 ) return( 2 );\n";
push @dispatch_params, "param$i";
push @param_decl, "char *$def";
$mapping_regex .= ":[^:]+";
}
else
{
die "Parameter declaration not of supported type (int, char *)\n";
}
$i++;
$function_code =~ s/\{$def\}/$def/g;
}
# Find non-integer values we should map for this function
@ -149,21 +159,16 @@ $param_defs
}
$param_checks
ret = test_suite_$function_name( $call_params );
return ( ret != 0 );
test_suite_$function_name( $call_params );
return ( 0 );
$function_post_code
return ( 3 );
}
else
END
my $function_def = "int test_suite_$function_name(";
$function_def .= join ", ", @param_decl;
$function_def .= ")\n{\n";
$function_code = $function_pre_code . $function_def . $function_code . "\n return( 0 );\n}\n";
$function_code .= $function_post_code;
$test_main =~ s/FUNCTION_CODE/$function_code\n\nFUNCTION_CODE/;
my $function_code = $function_pre_code . $function_decl . "\n" . $function_post_code;
$test_main =~ s/FUNCTION_CODE/$function_code\nFUNCTION_CODE/;
}
# Find specific case dependencies that we should be able to check

View File

@ -242,7 +242,7 @@ int main()
fprintf( stdout, "-------\n" );
fflush( stdout );
}
else if( ret == 0 && test_errors == 0 )
else if( ret == 0 && test_errors == 0 )
{
fprintf( stdout, "PASS\n" );
fflush( stdout );

View File

@ -1,13 +1,15 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/aes.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_AES_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_AES_C
* END_DEPENDENCIES
*/
BEGIN_CASE
aes_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
/* BEGIN_CASE */
void aes_encrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string, int setkey_result )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -21,22 +23,23 @@ aes_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
TEST_ASSERT( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == {setkey_result} );
if( {setkey_result} == 0 )
TEST_ASSERT( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == setkey_result );
if( setkey_result == 0 )
{
TEST_ASSERT( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
hexify( dst_str, output, 16 );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
aes_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
/* BEGIN_CASE */
void aes_decrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string, int setkey_result )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -50,22 +53,24 @@ aes_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
TEST_ASSERT( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == {setkey_result} );
if( {setkey_result} == 0 )
TEST_ASSERT( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == setkey_result );
if( setkey_result == 0 )
{
TEST_ASSERT( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
hexify( dst_str, output, 16 );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
aes_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void aes_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string,
int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -81,23 +86,25 @@ aes_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
data_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
data_len = unhexify( src_str, hex_src_string );
aes_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == {cbc_result} );
if( {cbc_result} == 0 )
TEST_ASSERT( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == cbc_result );
if( cbc_result == 0 )
{
hexify( dst_str, output, data_len );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
aes_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void aes_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string,
int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -113,23 +120,24 @@ aes_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
data_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
data_len = unhexify( src_str, hex_src_string );
aes_setkey_dec( &ctx, key_str, key_len * 8 );
TEST_ASSERT( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == {cbc_result} );
if( {cbc_result} == 0)
TEST_ASSERT( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == cbc_result );
if( cbc_result == 0)
{
hexify( dst_str, output, data_len );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
aes_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void aes_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -146,20 +154,21 @@ aes_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
unhexify( src_str, hex_src_string );
aes_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( aes_crypt_cfb128( &ctx, AES_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
hexify( dst_str, output, 16 );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
aes_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void aes_decrypt_cfb128( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -176,21 +185,21 @@ aes_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
unhexify( src_str, hex_src_string );
aes_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( aes_crypt_cfb128( &ctx, AES_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
hexify( dst_str, output, 16 );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
aes_selftest:
/* BEGIN_CASE */
void aes_selftest()
{
TEST_ASSERT( aes_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,15 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/arc4.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_ARC4_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_ARC4_C
* END_DEPENDENCIES
*/
BEGIN_CASE
arc4_crypt:hex_src_string:hex_key_string:hex_dst_string
/* BEGIN_CASE */
void arc4_crypt( char *hex_src_string, char *hex_key_string,
char *hex_dst_string )
{
unsigned char src_str[1000];
unsigned char key_str[1000];
@ -21,20 +23,20 @@ arc4_crypt:hex_src_string:hex_key_string:hex_dst_string
memset(dst_str, 0x00, 1000);
memset(dst_hexstr, 0x00, 2000);
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, hex_src_string );
key_len = unhexify( key_str, hex_key_string );
arc4_setup(&ctx, key_str, key_len);
TEST_ASSERT( arc4_crypt(&ctx, src_len, src_str, dst_str ) == 0 );
hexify( dst_hexstr, dst_str, src_len );
TEST_ASSERT( strcmp( (char *) dst_hexstr, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_hexstr, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
arc4_selftest:
/* BEGIN_CASE */
void arc4_selftest()
{
TEST_ASSERT( arc4_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,32 +1,34 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/base64.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_BASE64_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_BASE64_C
* END_DEPENDENCIES
*/
BEGIN_CASE
base64_encode:src_string:dst_string:#dst_buf_size:#result
/* BEGIN_CASE */
void base64_encode( char *src_string, char *dst_string, int dst_buf_size,
int result )
{
unsigned char src_str[1000];
unsigned char dst_str[1000];
size_t len = {dst_buf_size};
size_t len = dst_buf_size;
memset(src_str, 0x00, 1000);
memset(dst_str, 0x00, 1000);
strcpy( (char *) src_str, {src_string} );
TEST_ASSERT( base64_encode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == {result} );
if( {result} == 0 )
strcpy( (char *) src_str, src_string );
TEST_ASSERT( base64_encode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == result );
if( result == 0 )
{
TEST_ASSERT( strcmp( (char *) dst_str, {dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
base64_decode:src_string:dst_string:#result
/* BEGIN_CASE */
void base64_decode( char *src_string, char *dst_string, int result )
{
unsigned char src_str[1000];
unsigned char dst_str[1000];
@ -36,18 +38,18 @@ base64_decode:src_string:dst_string:#result
memset(src_str, 0x00, 1000);
memset(dst_str, 0x00, 1000);
strcpy( (char *) src_str, {src_string} );
TEST_ASSERT( res = base64_decode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == {result} );
if( {result} == 0 )
strcpy( (char *) src_str, src_string );
TEST_ASSERT( res = base64_decode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == result );
if( result == 0 )
{
TEST_ASSERT( strcmp( (char *) dst_str, {dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
base64_selftest:
/* BEGIN_CASE */
void base64_selftest()
{
TEST_ASSERT( base64_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,15 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include "polarssl/blowfish.h"
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_BLOWFISH_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_BLOWFISH_C
* END_DEPENDENCIES
*/
BEGIN_CASE
blowfish_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
/* BEGIN_CASE */
void blowfish_encrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string, int setkey_result )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -21,22 +23,23 @@ blowfish_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
TEST_ASSERT( blowfish_setkey( &ctx, key_str, key_len * 8 ) == {setkey_result} );
if( {setkey_result} == 0 )
TEST_ASSERT( blowfish_setkey( &ctx, key_str, key_len * 8 ) == setkey_result );
if( setkey_result == 0 )
{
TEST_ASSERT( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
blowfish_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
/* BEGIN_CASE */
void blowfish_decrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string, int setkey_result )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -50,22 +53,24 @@ blowfish_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
TEST_ASSERT( blowfish_setkey( &ctx, key_str, key_len * 8 ) == {setkey_result} );
if( {setkey_result} == 0 )
TEST_ASSERT( blowfish_setkey( &ctx, key_str, key_len * 8 ) == setkey_result );
if( setkey_result == 0 )
{
TEST_ASSERT( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
blowfish_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void blowfish_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string,
int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -81,24 +86,26 @@ blowfish_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
data_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
data_len = unhexify( src_str, hex_src_string );
blowfish_setkey( &ctx, key_str, key_len * 8 );
TEST_ASSERT( blowfish_crypt_cbc( &ctx, BLOWFISH_ENCRYPT, data_len , iv_str, src_str, output ) == {cbc_result} );
if( {cbc_result} == 0 )
TEST_ASSERT( blowfish_crypt_cbc( &ctx, BLOWFISH_ENCRYPT, data_len , iv_str, src_str, output ) == cbc_result );
if( cbc_result == 0 )
{
hexify( dst_str, output, data_len );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
blowfish_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void blowfish_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string,
int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -114,23 +121,24 @@ blowfish_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
data_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
data_len = unhexify( src_str, hex_src_string );
blowfish_setkey( &ctx, key_str, key_len * 8 );
TEST_ASSERT( blowfish_crypt_cbc( &ctx, BLOWFISH_DECRYPT, data_len , iv_str, src_str, output ) == {cbc_result} );
if( {cbc_result} == 0)
TEST_ASSERT( blowfish_crypt_cbc( &ctx, BLOWFISH_DECRYPT, data_len , iv_str, src_str, output ) == cbc_result );
if( cbc_result == 0)
{
hexify( dst_str, output, data_len );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
blowfish_encrypt_cfb64:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void blowfish_encrypt_cfb64( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -147,20 +155,21 @@ blowfish_encrypt_cfb64:hex_key_string:hex_iv_string:hex_src_string:hex_dst_strin
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
blowfish_setkey( &ctx, key_str, key_len * 8 );
TEST_ASSERT( blowfish_crypt_cfb64( &ctx, BLOWFISH_ENCRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 );
hexify( dst_str, output, src_len );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
blowfish_decrypt_cfb64:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void blowfish_decrypt_cfb64( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -177,20 +186,21 @@ blowfish_decrypt_cfb64:hex_key_string:hex_iv_string:hex_src_string:hex_dst_strin
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
blowfish_setkey( &ctx, key_str, key_len * 8 );
TEST_ASSERT( blowfish_crypt_cfb64( &ctx, BLOWFISH_DECRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 );
hexify( dst_str, output, src_len );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
blowfish_encrypt_ctr:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void blowfish_encrypt_ctr( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -209,14 +219,14 @@ blowfish_encrypt_ctr:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
blowfish_setkey( &ctx, key_str, key_len * 8 );
TEST_ASSERT( blowfish_crypt_ctr( &ctx, src_len, &iv_offset, iv_str, stream_str, src_str, output ) == 0 );
hexify( dst_str, output, src_len );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,15 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/camellia.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_CAMELLIA_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_CAMELLIA_C
* END_DEPENDENCIES
*/
BEGIN_CASE
camellia_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
/* BEGIN_CASE */
void camellia_encrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string, int setkey_result )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -21,22 +23,23 @@ camellia_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
TEST_ASSERT( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == {setkey_result} );
if( {setkey_result} == 0 )
TEST_ASSERT( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == setkey_result );
if( setkey_result == 0 )
{
TEST_ASSERT( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
hexify( dst_str, output, 16 );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
camellia_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
/* BEGIN_CASE */
void camellia_decrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string, int setkey_result )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -50,22 +53,24 @@ camellia_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
TEST_ASSERT( camellia_setkey_dec( &ctx, key_str, key_len * 8 ) == {setkey_result} );
if( {setkey_result} == 0 )
TEST_ASSERT( camellia_setkey_dec( &ctx, key_str, key_len * 8 ) == setkey_result );
if( setkey_result == 0 )
{
TEST_ASSERT( camellia_crypt_ecb( &ctx, CAMELLIA_DECRYPT, src_str, output ) == 0 );
hexify( dst_str, output, 16 );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
camellia_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void camellia_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string,
int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -81,23 +86,25 @@ camellia_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
data_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
data_len = unhexify( src_str, hex_src_string );
camellia_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == {cbc_result} );
if( {cbc_result} == 0 )
TEST_ASSERT( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == cbc_result );
if( cbc_result == 0 )
{
hexify( dst_str, output, data_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
camellia_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void camellia_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string,
int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -113,23 +120,24 @@ camellia_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
data_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
data_len = unhexify( src_str, hex_src_string );
camellia_setkey_dec( &ctx, key_str, key_len * 8 );
TEST_ASSERT( camellia_crypt_cbc( &ctx, CAMELLIA_DECRYPT, data_len, iv_str, src_str, output ) == {cbc_result} );
if( {cbc_result} == 0 )
TEST_ASSERT( camellia_crypt_cbc( &ctx, CAMELLIA_DECRYPT, data_len, iv_str, src_str, output ) == cbc_result );
if( cbc_result == 0 )
{
hexify( dst_str, output, data_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
camellia_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void camellia_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -146,20 +154,21 @@ camellia_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_stri
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
unhexify( src_str, hex_src_string );
camellia_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
hexify( dst_str, output, 16 );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
camellia_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void camellia_decrypt_cfb128( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -176,21 +185,21 @@ camellia_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_stri
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
key_len = unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
unhexify( src_str, hex_src_string );
camellia_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
hexify( dst_str, output, 16 );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
camellia_selftest:
/* BEGIN_CASE */
void camellia_selftest()
{
TEST_ASSERT( camellia_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,15 +1,17 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/cipher.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_CIPHER_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_CIPHER_C
* END_DEPENDENCIES
*/
BEGIN_CASE
enc_dec_buf:#cipher_id:cipher_string:#key_len:#length_val:#pad_mode
/* BEGIN_CASE */
void enc_dec_buf( int cipher_id, char *cipher_string, int key_len,
int length_val, int pad_mode )
{
size_t length = {length_val};
size_t length = length_val;
unsigned char key[32];
unsigned char iv[16];
@ -35,21 +37,21 @@ enc_dec_buf:#cipher_id:cipher_string:#key_len:#length_val:#pad_mode
memset( decbuf, 0, 64 );
/* Check and get info structures */
cipher_info = cipher_info_from_type( {cipher_id} );
cipher_info = cipher_info_from_type( cipher_id );
TEST_ASSERT( NULL != cipher_info );
TEST_ASSERT( cipher_info_from_string( {cipher_string} ) == cipher_info );
TEST_ASSERT( cipher_info_from_string( cipher_string ) == cipher_info );
/* Initialise enc and dec contexts */
TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
TEST_ASSERT( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, {key_len}, POLARSSL_DECRYPT ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx_enc, key, {key_len}, POLARSSL_ENCRYPT ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, key_len, POLARSSL_DECRYPT ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx_enc, key, key_len, POLARSSL_ENCRYPT ) );
if( -1 != {pad_mode} )
if( -1 != pad_mode )
{
TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx_dec, {pad_mode} ) );
TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx_enc, {pad_mode} ) );
TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx_dec, pad_mode ) );
TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx_enc, pad_mode ) );
}
TEST_ASSERT( 0 == cipher_reset( &ctx_dec, iv ) );
@ -91,12 +93,13 @@ enc_dec_buf:#cipher_id:cipher_string:#key_len:#length_val:#pad_mode
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
}
END_CASE
/* END_CASE */
BEGIN_CASE
enc_fail:#cipher_id:#pad_mode:#key_len:#length_val:#ret
/* BEGIN_CASE */
void enc_fail( int cipher_id, int pad_mode, int key_len,
int length_val, int ret )
{
size_t length = {length_val};
size_t length = length_val;
unsigned char key[32];
unsigned char iv[16];
@ -117,26 +120,26 @@ enc_fail:#cipher_id:#pad_mode:#key_len:#length_val:#ret
memset( encbuf, 0, 64 );
/* Check and get info structures */
cipher_info = cipher_info_from_type( {cipher_id} );
cipher_info = cipher_info_from_type( cipher_id );
TEST_ASSERT( NULL != cipher_info );
/* Initialise context */
TEST_ASSERT( 0 == cipher_init_ctx( &ctx, cipher_info ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx, key, {key_len}, POLARSSL_ENCRYPT ) );
TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx, {pad_mode} ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx, key, key_len, POLARSSL_ENCRYPT ) );
TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx, pad_mode ) );
TEST_ASSERT( 0 == cipher_reset( &ctx, iv ) );
/* encode length number of bytes from inbuf */
TEST_ASSERT( 0 == cipher_update( &ctx, inbuf, length, encbuf, &outlen ) );
TEST_ASSERT( {ret} == cipher_finish( &ctx, encbuf + outlen, &outlen ) );
TEST_ASSERT( ret == cipher_finish( &ctx, encbuf + outlen, &outlen ) );
/* done */
TEST_ASSERT( 0 == cipher_free_ctx( &ctx ) );
}
END_CASE
/* END_CASE */
BEGIN_CASE
dec_empty_buf:
/* BEGIN_CASE */
void dec_empty_buf()
{
unsigned char key[32];
unsigned char iv[16];
@ -175,13 +178,14 @@ dec_empty_buf:
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
}
END_CASE
/* END_CASE */
BEGIN_CASE
enc_dec_buf_multipart:#cipher_id:#key_len:#first_length_val:#second_length_val
/* BEGIN_CASE */
void enc_dec_buf_multipart( int cipher_id, int key_len, int first_length_val,
int second_length_val )
{
size_t first_length = {first_length_val};
size_t second_length = {second_length_val};
size_t first_length = first_length_val;
size_t second_length = second_length_val;
size_t length = first_length + second_length;
unsigned char key[32];
unsigned char iv[16];
@ -208,14 +212,14 @@ enc_dec_buf_multipart:#cipher_id:#key_len:#first_length_val:#second_length_val
memset( decbuf, 0, 64 );
/* Initialise enc and dec contexts */
cipher_info = cipher_info_from_type( {cipher_id} );
cipher_info = cipher_info_from_type( cipher_id );
TEST_ASSERT( NULL != cipher_info);
TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
TEST_ASSERT( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, {key_len}, POLARSSL_DECRYPT ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx_enc, key, {key_len}, POLARSSL_ENCRYPT ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, key_len, POLARSSL_DECRYPT ) );
TEST_ASSERT( 0 == cipher_setkey( &ctx_enc, key, key_len, POLARSSL_ENCRYPT ) );
TEST_ASSERT( 0 == cipher_reset( &ctx_dec, iv ) );
TEST_ASSERT( 0 == cipher_reset( &ctx_enc, iv ) );
@ -256,26 +260,26 @@ enc_dec_buf_multipart:#cipher_id:#key_len:#first_length_val:#second_length_val
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
}
END_CASE
/* END_CASE */
BEGIN_CASE
set_padding:#cipher_id:#pad_mode:#ret
/* BEGIN_CASE */
void set_padding( int cipher_id, int pad_mode, int ret )
{
const cipher_info_t *cipher_info;
cipher_context_t ctx;
cipher_info = cipher_info_from_type( {cipher_id} );
cipher_info = cipher_info_from_type( cipher_id );
TEST_ASSERT( NULL != cipher_info );
TEST_ASSERT( 0 == cipher_init_ctx( &ctx, cipher_info ) );
TEST_ASSERT( {ret} == cipher_set_padding_mode( &ctx, {pad_mode} ) );
TEST_ASSERT( ret == cipher_set_padding_mode( &ctx, pad_mode ) );
TEST_ASSERT( 0 == cipher_free_ctx( &ctx ) );
}
END_CASE
/* END_CASE */
BEGIN_CASE
check_padding:#pad_mode:input_str:#ret:#dlen_check
/* BEGIN_CASE */
void check_padding( int pad_mode, char *input_str, int ret, int dlen_check )
{
cipher_info_t cipher_info;
cipher_context_t ctx;
@ -287,19 +291,19 @@ check_padding:#pad_mode:input_str:#ret:#dlen_check
cipher_info.mode = POLARSSL_MODE_CBC;
ctx.cipher_info = &cipher_info;
TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx, {pad_mode} ) );
TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx, pad_mode ) );
ilen = unhexify( input, {input_str} );
ilen = unhexify( input, input_str );
TEST_ASSERT( {ret} == ctx.get_padding( input, ilen, &dlen ) );
if( 0 == {ret} )
TEST_ASSERT( dlen == (size_t) {dlen_check} );
TEST_ASSERT( ret == ctx.get_padding( input, ilen, &dlen ) );
if( 0 == ret )
TEST_ASSERT( dlen == (size_t) dlen_check );
}
END_CASE
/* END_CASE */
BEGIN_CASE
cipher_selftest:
/* BEGIN_CASE */
void cipher_selftest()
{
TEST_ASSERT( cipher_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,4 +1,4 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/ctr_drbg.h>
int test_offset;
@ -9,14 +9,17 @@ int entropy_func( void *data, unsigned char *buf, size_t len )
test_offset += 32;
return( 0 );
}
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_CTR_DRBG_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_CTR_DRBG_C
* END_DEPENDENCIES
*/
BEGIN_CASE
ctr_drbg_validate_pr:add_init_string:entropy_string:add1_string:add2_string:result_str
/* BEGIN_CASE */
void ctr_drbg_validate_pr( char *add_init_string, char *entropy_string,
char *add1_string, char *add2_string,
char *result_str )
{
unsigned char entropy[512];
unsigned char add_init[512];
@ -29,10 +32,10 @@ ctr_drbg_validate_pr:add_init_string:entropy_string:add1_string:add2_string:resu
memset( output_str, 0, 512 );
unhexify( entropy, {entropy_string} );
add_init_len = unhexify( add_init, {add_init_string} );
add1_len = unhexify( add1, {add1_string} );
add2_len = unhexify( add2, {add2_string} );
unhexify( entropy, entropy_string );
add_init_len = unhexify( add_init, add_init_string );
add1_len = unhexify( add1, add1_string );
add2_len = unhexify( add2, add2_string );
test_offset = 0;
TEST_ASSERT( ctr_drbg_init_entropy_len( &ctx, entropy_func, entropy, add_init, add_init_len, 32 ) == 0 );
@ -41,12 +44,14 @@ ctr_drbg_validate_pr:add_init_string:entropy_string:add1_string:add2_string:resu
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 );
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add2, add2_len ) == 0 );
hexify( output_str, buf, 16 );
TEST_ASSERT( strcmp( (char *) output_str, {result_str} ) == 0 );
TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ctr_drbg_validate_nopr:add_init_string:entropy_string:add1_string:add_reseed_string:add2_string:result_str
/* BEGIN_CASE */
void ctr_drbg_validate_nopr( char *add_init_string, char *entropy_string,
char *add1_string, char *add_reseed_string,
char *add2_string, char *result_str )
{
unsigned char entropy[512];
unsigned char add_init[512];
@ -60,11 +65,11 @@ ctr_drbg_validate_nopr:add_init_string:entropy_string:add1_string:add_reseed_str
memset( output_str, 0, 512 );
unhexify( entropy, {entropy_string} );
add_init_len = unhexify( add_init, {add_init_string} );
add1_len = unhexify( add1, {add1_string} );
add_reseed_len = unhexify( add_reseed, {add_reseed_string} );
add2_len = unhexify( add2, {add2_string} );
unhexify( entropy, entropy_string );
add_init_len = unhexify( add_init, add_init_string );
add1_len = unhexify( add1, add1_string );
add_reseed_len = unhexify( add_reseed, add_reseed_string );
add2_len = unhexify( add2, add2_string );
test_offset = 0;
TEST_ASSERT( ctr_drbg_init_entropy_len( &ctx, entropy_func, entropy, add_init, add_init_len, 32 ) == 0 );
@ -73,6 +78,6 @@ ctr_drbg_validate_nopr:add_init_string:entropy_string:add1_string:add_reseed_str
TEST_ASSERT( ctr_drbg_reseed( &ctx, add_reseed, add_reseed_len ) == 0 );
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add2, add2_len ) == 0 );
hexify( output_str, buf, 16 );
TEST_ASSERT( strcmp( (char *) output_str, {result_str} ) == 0 );
TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,4 +1,4 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/debug.h>
struct buffer_data
@ -15,14 +15,16 @@ void string_debug(void *data, int level, const char *str)
memcpy(buffer->ptr, str, strlen(str));
buffer->ptr += strlen(str);
}
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_DEBUG_C:POLARSSL_BIGNUM_C:POLARSSL_SSL_TLS_C:POLARSSL_RSA_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_DEBUG_C:POLARSSL_BIGNUM_C:POLARSSL_SSL_TLS_C:POLARSSL_RSA_C
* END_DEPENDENCIES
*/
BEGIN_CASE
debug_print_crt:crt_file:file:#line:prefix:result_str
/* BEGIN_CASE */
void debug_print_crt( char *crt_file, char *file, int line, char *prefix,
char *result_str )
{
x509_cert crt;
ssl_context ssl;
@ -35,17 +37,18 @@ debug_print_crt:crt_file:file:#line:prefix:result_str
ssl_set_dbg(&ssl, string_debug, &buffer);
TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
debug_print_crt( &ssl, 0, {file}, {line}, {prefix}, &crt);
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
debug_print_crt( &ssl, 0, file, line, prefix, &crt);
TEST_ASSERT( strcmp( buffer.buf, {result_str} ) == 0 );
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
x509_free( &crt );
}
END_CASE
/* END_CASE */
BEGIN_CASE
debug_print_mpi:#radix:value:file:#line:prefix:result_str
/* BEGIN_CASE */
void debug_print_mpi( int radix, char *value, char *file, int line,
char *prefix, char *result_str )
{
ssl_context ssl;
struct buffer_data buffer;
@ -57,15 +60,13 @@ debug_print_mpi:#radix:value:file:#line:prefix:result_str
memset( buffer.buf, 0, 2000 );
buffer.ptr = buffer.buf;
TEST_ASSERT( mpi_read_string( &val, {radix}, {value} ) == 0 );
TEST_ASSERT( mpi_read_string( &val, radix, value ) == 0 );
ssl_set_dbg(&ssl, string_debug, &buffer);
debug_print_mpi( &ssl, 0, {file}, {line}, {prefix}, &val);
debug_print_mpi( &ssl, 0, file, line, prefix, &val);
TEST_ASSERT( strcmp( buffer.buf, {result_str} ) == 0 );
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
mpi_free( &val );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,15 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/des.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_DES_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_DES_C
* END_DEPENDENCIES
*/
BEGIN_CASE
des_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void des_encrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -20,19 +22,20 @@ des_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
des_setkey_enc( &ctx, key_str );
TEST_ASSERT( des_crypt_ecb( &ctx, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
des_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void des_decrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -45,19 +48,20 @@ des_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
des_setkey_dec( &ctx, key_str );
TEST_ASSERT( des_crypt_ecb( &ctx, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
des_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void des_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string, int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -73,23 +77,24 @@ des_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
src_len = unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
des_setkey_enc( &ctx, key_str );
TEST_ASSERT( des_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == {cbc_result} );
if( {cbc_result} == 0 )
TEST_ASSERT( des_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == cbc_result );
if( cbc_result == 0 )
{
hexify( dst_str, output, src_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
des_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void des_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string, int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -105,23 +110,24 @@ des_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
src_len = unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
des_setkey_dec( &ctx, key_str );
TEST_ASSERT( des_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == {cbc_result} );
if( {cbc_result} == 0 )
TEST_ASSERT( des_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == cbc_result );
if( cbc_result == 0 )
{
hexify( dst_str, output, src_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
des3_encrypt_ecb:#key_count:hex_key_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void des3_encrypt_ecb( int key_count, char *hex_key_string,
char *hex_src_string, char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -134,12 +140,12 @@ des3_encrypt_ecb:#key_count:hex_key_string:hex_src_string:hex_dst_string
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
if( {key_count} == 2 )
if( key_count == 2 )
des3_set2key_enc( &ctx, key_str );
else if( {key_count} == 3 )
else if( key_count == 3 )
des3_set3key_enc( &ctx, key_str );
else
TEST_ASSERT( 0 );
@ -147,12 +153,13 @@ des3_encrypt_ecb:#key_count:hex_key_string:hex_src_string:hex_dst_string
TEST_ASSERT( des3_crypt_ecb( &ctx, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
des3_decrypt_ecb:#key_count:hex_key_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void des3_decrypt_ecb( int key_count, char *hex_key_string,
char *hex_src_string, char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -165,12 +172,12 @@ des3_decrypt_ecb:#key_count:hex_key_string:hex_src_string:hex_dst_string
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
if( {key_count} == 2 )
if( key_count == 2 )
des3_set2key_dec( &ctx, key_str );
else if( {key_count} == 3 )
else if( key_count == 3 )
des3_set3key_dec( &ctx, key_str );
else
TEST_ASSERT( 0 );
@ -178,12 +185,14 @@ des3_decrypt_ecb:#key_count:hex_key_string:hex_src_string:hex_dst_string
TEST_ASSERT( des3_crypt_ecb( &ctx, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
des3_encrypt_cbc:#key_count:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void des3_encrypt_cbc( int key_count, char *hex_key_string,
char *hex_iv_string, char *hex_src_string,
char *hex_dst_string, int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -199,30 +208,32 @@ des3_encrypt_cbc:#key_count:hex_key_string:hex_iv_string:hex_src_string:hex_dst_
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
src_len = unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
if( {key_count} == 2 )
if( key_count == 2 )
des3_set2key_enc( &ctx, key_str );
else if( {key_count} == 3 )
else if( key_count == 3 )
des3_set3key_enc( &ctx, key_str );
else
TEST_ASSERT( 0 );
TEST_ASSERT( des3_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == {cbc_result} );
TEST_ASSERT( des3_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == cbc_result );
if( {cbc_result} == 0 )
if( cbc_result == 0 )
{
hexify( dst_str, output, src_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
des3_decrypt_cbc:#key_count:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
/* BEGIN_CASE */
void des3_decrypt_cbc( int key_count, char *hex_key_string,
char *hex_iv_string, char *hex_src_string,
char *hex_dst_string, int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
@ -238,30 +249,30 @@ des3_decrypt_cbc:#key_count:hex_key_string:hex_iv_string:hex_src_string:hex_dst_
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( iv_str, {hex_iv_string} );
src_len = unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
if( {key_count} == 2 )
if( key_count == 2 )
des3_set2key_dec( &ctx, key_str );
else if( {key_count} == 3 )
else if( key_count == 3 )
des3_set3key_dec( &ctx, key_str );
else
TEST_ASSERT( 0 );
TEST_ASSERT( des3_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == {cbc_result} );
TEST_ASSERT( des3_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == cbc_result );
if( {cbc_result} == 0 )
if( cbc_result == 0 )
{
hexify( dst_str, output, src_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
des_key_parity_run:
/* BEGIN_CASE */
void des_key_parity_run()
{
int i, j, cnt;
unsigned char key[DES_KEY_SIZE];
@ -301,11 +312,11 @@ des_key_parity_run:
TEST_ASSERT( des_key_check_key_parity( key ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
des_selftest:
/* BEGIN_CASE */
void des_selftest()
{
TEST_ASSERT( des_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,15 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/dhm.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_DHM_C:POLARSSL_BIGNUM_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_DHM_C:POLARSSL_BIGNUM_C
* END_DEPENDENCIES
*/
BEGIN_CASE
dhm_do_dhm:#NOTUSED:#radix_P:input_P:#radix_G:input_G
/* BEGIN_CASE */
void dhm_do_dhm( int NOTUSED, int radix_P, char *input_P,
int radix_G, char *input_G )
{
dhm_context ctx_srv;
dhm_context ctx_cli;
@ -33,8 +35,8 @@ dhm_do_dhm:#NOTUSED:#radix_P:input_P:#radix_G:input_G
memset( sec_cli, 0x00, 1000 );
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
TEST_ASSERT( mpi_read_string( &ctx_srv.P, {radix_P}, {input_P} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx_srv.G, {radix_G}, {input_G} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx_srv.P, radix_P, input_P ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx_srv.G, radix_G, input_G ) == 0 );
x_size = mpi_size( &ctx_srv.P );
TEST_ASSERT( dhm_make_params( &ctx_srv, x_size, ske, &ske_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
@ -57,4 +59,4 @@ dhm_do_dhm:#NOTUSED:#radix_P:input_P:#radix_G:input_G
dhm_free( &ctx_srv );
dhm_free( &ctx_cli );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,14 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/ecdh.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_ECDH_C:POLARSSL_ECP_C:POLARSSL_BIGNUM_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_ECDH_C:POLARSSL_ECP_C:POLARSSL_BIGNUM_C
* END_DEPENDENCIES
*/
BEGIN_CASE
ecdh_primitive_random:#id
/* BEGIN_CASE */
void ecdh_primitive_random( int id )
{
ecp_group grp;
ecp_point qA, qB;
@ -20,7 +21,7 @@ ecdh_primitive_random:#id
mpi_init( &zA ); mpi_init( &zB );
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( ecdh_gen_public( &grp, &dA, &qA, &rnd_pseudo_rand, &rnd_info )
== 0 );
@ -36,10 +37,12 @@ ecdh_primitive_random:#id
mpi_free( &dA ); mpi_free( &dB );
mpi_free( &zA ); mpi_free( &zB );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecdh_primitive_testvec:#id:dA_str:xA_str:yA_str:dB_str:xB_str:yB_str:z_str
/* BEGIN_CASE */
void ecdh_primitive_testvec( int id, char *dA_str, char *xA_str, char *yA_str,
char *dB_str, char *xB_str, char *yB_str,
char *z_str )
{
ecp_group grp;
ecp_point qA, qB;
@ -50,23 +53,23 @@ ecdh_primitive_testvec:#id:dA_str:xA_str:yA_str:dB_str:xB_str:yB_str:z_str
mpi_init( &dA ); mpi_init( &dB );
mpi_init( &zA ); mpi_init( &zB ); mpi_init( &check );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( ecdh_gen_public( &grp, &dA, &qA, &not_rnd, {dA_str} ) == 0 );
TEST_ASSERT( ecdh_gen_public( &grp, &dA, &qA, &not_rnd, dA_str ) == 0 );
TEST_ASSERT( ! ecp_is_zero( &qA ) );
TEST_ASSERT( mpi_read_string( &check, 16, {xA_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &check, 16, xA_str ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &qA.X, &check ) == 0 );
TEST_ASSERT( mpi_read_string( &check, 16, {yA_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &check, 16, yA_str ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &qA.Y, &check ) == 0 );
TEST_ASSERT( ecdh_gen_public( &grp, &dB, &qB, &not_rnd, {dB_str} ) == 0 );
TEST_ASSERT( ecdh_gen_public( &grp, &dB, &qB, &not_rnd, dB_str ) == 0 );
TEST_ASSERT( ! ecp_is_zero( &qB ) );
TEST_ASSERT( mpi_read_string( &check, 16, {xB_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &check, 16, xB_str ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &qB.X, &check ) == 0 );
TEST_ASSERT( mpi_read_string( &check, 16, {yB_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &check, 16, yB_str ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &qB.Y, &check ) == 0 );
TEST_ASSERT( mpi_read_string( &check, 16, {z_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &check, 16, z_str ) == 0 );
TEST_ASSERT( ecdh_compute_shared( &grp, &zA, &qB, &dA ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &zA, &check ) == 0 );
TEST_ASSERT( ecdh_compute_shared( &grp, &zB, &qA, &dB ) == 0 );
@ -77,10 +80,10 @@ ecdh_primitive_testvec:#id:dA_str:xA_str:yA_str:dB_str:xB_str:yB_str:z_str
mpi_free( &dA ); mpi_free( &dB );
mpi_free( &zA ); mpi_free( &zB ); mpi_free( &check );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecdh_exchange:#id
/* BEGIN_CASE */
void ecdh_exchange( int id )
{
ecdh_context srv, cli;
unsigned char buf[1000];
@ -92,7 +95,7 @@ ecdh_exchange:#id
ecdh_init( &cli );
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
TEST_ASSERT( ecp_use_known_dp( &srv.grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &srv.grp, id ) == 0 );
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
TEST_ASSERT( ecdh_make_params( &srv, &len, buf, 1000,
@ -111,4 +114,4 @@ ecdh_exchange:#id
ecdh_free( &srv );
ecdh_free( &cli );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,14 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/ecdsa.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_ECDSA_C:POLARSSL_ECP_C:POLARSSL_BIGNUM_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_ECDSA_C:POLARSSL_ECP_C:POLARSSL_BIGNUM_C
* END_DEPENDENCIES
*/
BEGIN_CASE
ecdsa_prim_random:#id
/* BEGIN_CASE */
void ecdsa_prim_random( int id )
{
ecp_group grp;
ecp_point Q;
@ -23,7 +24,7 @@ ecdsa_prim_random:#id
/* prepare material for signature */
TEST_ASSERT( rnd_pseudo_rand( &rnd_info, buf, sizeof( buf ) ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( ecp_gen_keypair( &grp, &d, &Q, &rnd_pseudo_rand, &rnd_info )
== 0 );
@ -35,10 +36,12 @@ ecdsa_prim_random:#id
ecp_point_free( &Q );
mpi_free( &d ); mpi_free( &r ); mpi_free( &s );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecdsa_prim_test_vectors:#id:d_str:xQ_str:yQ_str:k_str:hash_str:r_str:s_str
/* BEGIN_CASE */
void ecdsa_prim_test_vectors( int id, char *d_str, char *xQ_str, char *yQ_str,
char *k_str, char *hash_str, char *r_str,
char *s_str )
{
ecp_group grp;
ecp_point Q;
@ -52,15 +55,15 @@ ecdsa_prim_test_vectors:#id:d_str:xQ_str:yQ_str:k_str:hash_str:r_str:s_str
mpi_init( &r_check ); mpi_init( &s_check );
memset( buf, 0, sizeof( buf ) );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_point_read_string( &Q, 16, {xQ_str}, {yQ_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &d, 16, {d_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &r_check, 16, {r_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &s_check, 16, {s_str} ) == 0 );
len = unhexify(buf, {hash_str});
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( ecp_point_read_string( &Q, 16, xQ_str, yQ_str ) == 0 );
TEST_ASSERT( mpi_read_string( &d, 16, d_str ) == 0 );
TEST_ASSERT( mpi_read_string( &r_check, 16, r_str ) == 0 );
TEST_ASSERT( mpi_read_string( &s_check, 16, s_str ) == 0 );
len = unhexify(buf, hash_str);
TEST_ASSERT( ecdsa_sign( &grp, &r, &s, &d, buf, len,
&not_rnd, {k_str} ) == 0 );
&not_rnd, k_str ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &r, &r_check ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &s, &s_check ) == 0 );
@ -72,4 +75,4 @@ ecdsa_prim_test_vectors:#id:d_str:xQ_str:yQ_str:k_str:hash_str:r_str:s_str
mpi_free( &d ); mpi_free( &r ); mpi_free( &s );
mpi_free( &r_check ); mpi_free( &s_check );
}
END_CASE
/* END_CASE */

View File

@ -1,15 +1,17 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/ecp.h>
#define POLARSSL_ECP_PF_UNKNOWN -1
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_ECP_C:POLARSSL_BIGNUM_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_ECP_C:POLARSSL_BIGNUM_C
* END_DEPENDENCIES
*/
BEGIN_CASE
ecp_small_add:#a_zero:x_a:y_a:#b_zero:x_b:y_b:#c_zero:#x_c:#y_c
/* BEGIN_CASE */
void ecp_small_add( int a_zero, char *x_a, char *y_a, int b_zero, char *x_b,
char *y_b, int c_zero, int x_c, int y_c )
{
ecp_group grp;
ecp_point A, B, C;
@ -20,43 +22,44 @@ ecp_small_add:#a_zero:x_a:y_a:#b_zero:x_b:y_b:#c_zero:#x_c:#y_c
TEST_ASSERT( ecp_group_read_string( &grp, 10,
"47", "4", "17", "42", "13" ) == 0 );
if( {a_zero} )
if( a_zero )
ecp_set_zero( &A );
else
TEST_ASSERT( ecp_point_read_string( &A, 10, {x_a}, {y_a} ) == 0 );
TEST_ASSERT( ecp_point_read_string( &A, 10, x_a, y_a ) == 0 );
if( {b_zero} )
if( b_zero )
ecp_set_zero( &B );
else
TEST_ASSERT( ecp_point_read_string( &B, 10, {x_b}, {y_b} ) == 0 );
TEST_ASSERT( ecp_point_read_string( &B, 10, x_b, y_b ) == 0 );
TEST_ASSERT( ecp_add( &grp, &C, &A, &B ) == 0 );
if( {c_zero} )
if( c_zero )
TEST_ASSERT( mpi_cmp_int( &C.Z, 0 ) == 0 );
else
{
TEST_ASSERT( mpi_cmp_int( &C.X, {x_c} ) == 0 );
TEST_ASSERT( mpi_cmp_int( &C.Y, {y_c} ) == 0 );
TEST_ASSERT( mpi_cmp_int( &C.X, x_c ) == 0 );
TEST_ASSERT( mpi_cmp_int( &C.Y, y_c ) == 0 );
}
TEST_ASSERT( ecp_add( &grp, &C, &B, &A ) == 0 );
if( {c_zero} )
if( c_zero )
TEST_ASSERT( mpi_cmp_int( &C.Z, 0 ) == 0 );
else
{
TEST_ASSERT( mpi_cmp_int( &C.X, {x_c} ) == 0 );
TEST_ASSERT( mpi_cmp_int( &C.Y, {y_c} ) == 0 );
TEST_ASSERT( mpi_cmp_int( &C.X, x_c ) == 0 );
TEST_ASSERT( mpi_cmp_int( &C.Y, y_c ) == 0 );
}
ecp_group_free( &grp );
ecp_point_free( &A ); ecp_point_free( &B ); ecp_point_free( &C );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_small_sub:#a_zero:x_a:y_a:#b_zero:x_b:y_b:#c_zero:#x_c:#y_c
/* BEGIN_CASE */
void ecp_small_sub( int a_zero, char *x_a, char *y_a, int b_zero, char *x_b,
char *y_b, int c_zero, int x_c, int y_c )
{
ecp_group grp;
ecp_point A, B, C;
@ -67,33 +70,33 @@ ecp_small_sub:#a_zero:x_a:y_a:#b_zero:x_b:y_b:#c_zero:#x_c:#y_c
TEST_ASSERT( ecp_group_read_string( &grp, 10,
"47", "4", "17", "42", "13" ) == 0 );
if( {a_zero} )
if( a_zero )
ecp_set_zero( &A );
else
TEST_ASSERT( ecp_point_read_string( &A, 10, {x_a}, {y_a} ) == 0 );
TEST_ASSERT( ecp_point_read_string( &A, 10, x_a, y_a ) == 0 );
if( {b_zero} )
if( b_zero )
ecp_set_zero( &B );
else
TEST_ASSERT( ecp_point_read_string( &B, 10, {x_b}, {y_b} ) == 0 );
TEST_ASSERT( ecp_point_read_string( &B, 10, x_b, y_b ) == 0 );
TEST_ASSERT( ecp_sub( &grp, &C, &A, &B ) == 0 );
if( {c_zero} )
if( c_zero )
TEST_ASSERT( mpi_cmp_int( &C.Z, 0 ) == 0 );
else
{
TEST_ASSERT( mpi_cmp_int( &C.X, {x_c} ) == 0 );
TEST_ASSERT( mpi_cmp_int( &C.Y, {y_c} ) == 0 );
TEST_ASSERT( mpi_cmp_int( &C.X, x_c ) == 0 );
TEST_ASSERT( mpi_cmp_int( &C.Y, y_c ) == 0 );
}
ecp_group_free( &grp );
ecp_point_free( &A ); ecp_point_free( &B ); ecp_point_free( &C );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_small_mul:#m_str:#r_zero:#x_r:#y_r:#ret
/* BEGIN_CASE */
void ecp_small_mul( int m_str, int r_zero, int x_r, int y_r, int ret )
{
ecp_group grp;
ecp_point R;
@ -106,26 +109,26 @@ ecp_small_mul:#m_str:#r_zero:#x_r:#y_r:#ret
TEST_ASSERT( ecp_group_read_string( &grp, 10,
"47", "4", "17", "42", "13" ) == 0 );
TEST_ASSERT( mpi_lset( &m, {m_str} ) == 0 );
TEST_ASSERT( mpi_lset( &m, m_str ) == 0 );
TEST_ASSERT( ecp_mul( &grp, &R, &m, &grp.G ) == {ret} );
TEST_ASSERT( ecp_mul( &grp, &R, &m, &grp.G ) == ret );
if( {r_zero} )
if( r_zero )
TEST_ASSERT( mpi_cmp_int( &R.Z, 0 ) == 0 );
else
{
TEST_ASSERT( mpi_cmp_int( &R.X, {x_r} ) == 0 );
TEST_ASSERT( mpi_cmp_int( &R.Y, {y_r} ) == 0 );
TEST_ASSERT( mpi_cmp_int( &R.X, x_r ) == 0 );
TEST_ASSERT( mpi_cmp_int( &R.Y, y_r ) == 0 );
}
ecp_group_free( &grp );
ecp_point_free( &R );
mpi_free( &m );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_small_check_pub:#x:#y:#z:#ret
/* BEGIN_CASE */
void ecp_small_check_pub( int x, int y, int z, int ret )
{
ecp_group grp;
ecp_point P;
@ -136,19 +139,21 @@ ecp_small_check_pub:#x:#y:#z:#ret
TEST_ASSERT( ecp_group_read_string( &grp, 10,
"47", "4", "17", "42", "13" ) == 0 );
TEST_ASSERT( mpi_lset( &P.X, {x} ) == 0 );
TEST_ASSERT( mpi_lset( &P.Y, {y} ) == 0 );
TEST_ASSERT( mpi_lset( &P.Z, {z} ) == 0 );
TEST_ASSERT( mpi_lset( &P.X, x ) == 0 );
TEST_ASSERT( mpi_lset( &P.Y, y ) == 0 );
TEST_ASSERT( mpi_lset( &P.Z, z ) == 0 );
TEST_ASSERT( ecp_check_pubkey( &grp, &P ) == {ret} );
TEST_ASSERT( ecp_check_pubkey( &grp, &P ) == ret );
ecp_group_free( &grp );
ecp_point_free( &P );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_test_vect:#id:dA_str:xA_str:yA_str:dB_str:xB_str:yB_str:xZ_str:yZ_str
/* BEGIN_CASE */
void ecp_test_vect( int id, char *dA_str, char *xA_str, char *yA_str,
char *dB_str, char *xB_str, char *yB_str, char *xZ_str,
char *yZ_str )
{
ecp_group grp;
ecp_point R;
@ -158,18 +163,18 @@ ecp_test_vect:#id:dA_str:xA_str:yA_str:dB_str:xB_str:yB_str:xZ_str:yZ_str
mpi_init( &dA ); mpi_init( &xA ); mpi_init( &yA ); mpi_init( &dB );
mpi_init( &xB ); mpi_init( &yB ); mpi_init( &xZ ); mpi_init( &yZ );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( ecp_check_pubkey( &grp, &grp.G ) == 0 );
TEST_ASSERT( mpi_read_string( &dA, 16, {dA_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &xA, 16, {xA_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &yA, 16, {yA_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &dB, 16, {dB_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &xB, 16, {xB_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &yB, 16, {yB_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &xZ, 16, {xZ_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &yZ, 16, {yZ_str} ) == 0 );
TEST_ASSERT( mpi_read_string( &dA, 16, dA_str ) == 0 );
TEST_ASSERT( mpi_read_string( &xA, 16, xA_str ) == 0 );
TEST_ASSERT( mpi_read_string( &yA, 16, yA_str ) == 0 );
TEST_ASSERT( mpi_read_string( &dB, 16, dB_str ) == 0 );
TEST_ASSERT( mpi_read_string( &xB, 16, xB_str ) == 0 );
TEST_ASSERT( mpi_read_string( &yB, 16, yB_str ) == 0 );
TEST_ASSERT( mpi_read_string( &xZ, 16, xZ_str ) == 0 );
TEST_ASSERT( mpi_read_string( &yZ, 16, yZ_str ) == 0 );
TEST_ASSERT( ecp_mul( &grp, &R, &dA, &grp.G ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &R.X, &xA ) == 0 );
@ -193,10 +198,10 @@ ecp_test_vect:#id:dA_str:xA_str:yA_str:dB_str:xB_str:yB_str:xZ_str:yZ_str
mpi_free( &dA ); mpi_free( &xA ); mpi_free( &yA ); mpi_free( &dB );
mpi_free( &xB ); mpi_free( &yB ); mpi_free( &xZ ); mpi_free( &yZ );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_fast_mod:#id:N_str
/* BEGIN_CASE */
void ecp_fast_mod( int id, char *N_str )
{
ecp_group grp;
mpi N, R;
@ -204,8 +209,8 @@ ecp_fast_mod:#id:N_str
mpi_init( &N ); mpi_init( &R );
ecp_group_init( &grp );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( mpi_read_string( &N, 16, {N_str} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( mpi_read_string( &N, 16, N_str ) == 0 );
/*
* Store correct result before we touch N
@ -224,10 +229,11 @@ ecp_fast_mod:#id:N_str
mpi_free( &N ); mpi_free( &R );
ecp_group_free( &grp );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_write_binary:#id:x:y:z:#format:out:#blen:#ret
/* BEGIN_CASE */
void ecp_write_binary( int id, char *x, char *y, char *z, int format,
char *out, int blen, int ret )
{
ecp_group grp;
ecp_point P;
@ -239,27 +245,28 @@ ecp_write_binary:#id:x:y:z:#format:out:#blen:#ret
ecp_group_init( &grp ); ecp_point_init( &P );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( mpi_read_string( &P.X, 16, {x} ) == 0 );
TEST_ASSERT( mpi_read_string( &P.Y, 16, {y} ) == 0 );
TEST_ASSERT( mpi_read_string( &P.Z, 16, {z} ) == 0 );
TEST_ASSERT( mpi_read_string( &P.X, 16, x ) == 0 );
TEST_ASSERT( mpi_read_string( &P.Y, 16, y ) == 0 );
TEST_ASSERT( mpi_read_string( &P.Z, 16, z ) == 0 );
TEST_ASSERT( ecp_point_write_binary( &grp, &P, {format},
&olen, buf, {blen} ) == {ret} );
TEST_ASSERT( ecp_point_write_binary( &grp, &P, format,
&olen, buf, blen ) == ret );
if( {ret} == 0 )
if( ret == 0 )
{
hexify( str, buf, olen );
TEST_ASSERT( strcasecmp( (char *) str, {out} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) str, out ) == 0 );
}
ecp_group_free( &grp ); ecp_point_free( &P );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_read_binary:#id:input:x:y:z:#ret
/* BEGIN_CASE */
void ecp_read_binary( int id, char *input, char *x, char *y, char *z,
int ret )
{
ecp_group grp;
ecp_point P;
@ -272,17 +279,17 @@ ecp_read_binary:#id:input:x:y:z:#ret
ecp_group_init( &grp ); ecp_point_init( &P );
mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( mpi_read_string( &X, 16, {x} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, 16, {y} ) == 0 );
TEST_ASSERT( mpi_read_string( &Z, 16, {z} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, 16, x ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, 16, y ) == 0 );
TEST_ASSERT( mpi_read_string( &Z, 16, z ) == 0 );
ilen = unhexify( buf, {input} );
ilen = unhexify( buf, input );
TEST_ASSERT( ecp_point_read_binary( &grp, &P, buf, ilen ) == {ret} );
TEST_ASSERT( ecp_point_read_binary( &grp, &P, buf, ilen ) == ret );
if( {ret} == 0 )
if( ret == 0 )
{
TEST_ASSERT( mpi_cmp_mpi( &P.X, &X ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &P.Y, &Y ) == 0 );
@ -292,10 +299,11 @@ ecp_read_binary:#id:input:x:y:z:#ret
ecp_group_free( &grp ); ecp_point_free( &P );
mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_tls_read_point:#id:input:x:y:z:#ret
/* BEGIN_CASE */
void ecp_tls_read_point( int id, char *input, char *x, char *y, char *z,
int ret )
{
ecp_group grp;
ecp_point P;
@ -309,17 +317,17 @@ ecp_tls_read_point:#id:input:x:y:z:#ret
ecp_group_init( &grp ); ecp_point_init( &P );
mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( mpi_read_string( &X, 16, {x} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, 16, {y} ) == 0 );
TEST_ASSERT( mpi_read_string( &Z, 16, {z} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, 16, x ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, 16, y ) == 0 );
TEST_ASSERT( mpi_read_string( &Z, 16, z ) == 0 );
ilen = unhexify( buf, {input} );
ilen = unhexify( buf, input );
TEST_ASSERT( ecp_tls_read_point( &grp, &P, &vbuf, ilen ) == {ret} );
TEST_ASSERT( ecp_tls_read_point( &grp, &P, &vbuf, ilen ) == ret );
if( {ret} == 0 )
if( ret == 0 )
{
TEST_ASSERT( mpi_cmp_mpi( &P.X, &X ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &P.Y, &Y ) == 0 );
@ -330,10 +338,10 @@ ecp_tls_read_point:#id:input:x:y:z:#ret
ecp_group_free( &grp ); ecp_point_free( &P );
mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_tls_write_read_point:#id
/* BEGIN_CASE */
void ecp_tls_write_read_point( int id )
{
ecp_group grp;
ecp_point pt;
@ -344,7 +352,7 @@ ecp_tls_write_read_point:#id
ecp_group_init( &grp );
ecp_point_init( &pt );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
TEST_ASSERT( ecp_tls_write_point( &grp, &grp.G,
@ -381,10 +389,10 @@ ecp_tls_write_read_point:#id
ecp_group_free( &grp );
ecp_point_free( &pt );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_tls_read_group:record:#result:#bits
/* BEGIN_CASE */
void ecp_tls_read_group( char *record, int result, int bits )
{
ecp_group grp;
unsigned char buf[10];
@ -394,23 +402,23 @@ ecp_tls_read_group:record:#result:#bits
ecp_group_init( &grp );
memset( buf, 0x00, sizeof( buf ) );
len = unhexify( buf, {record} );
len = unhexify( buf, record );
ret = ecp_tls_read_group( &grp, &vbuf, len );
TEST_ASSERT( ret == {result} );
TEST_ASSERT( ret == result );
if( ret == 0)
{
TEST_ASSERT( mpi_msb( &grp.P ) == (size_t) {bits} );
TEST_ASSERT( mpi_msb( &grp.P ) == (size_t) bits );
TEST_ASSERT( *vbuf == 0x00 );
}
ecp_group_free( &grp );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_tls_write_read_group:#id
/* BEGIN_CASE */
void ecp_tls_write_read_group( int id )
{
ecp_group grp1, grp2;
unsigned char buf[10];
@ -422,7 +430,7 @@ ecp_tls_write_read_group:#id
ecp_group_init( &grp2 );
memset( buf, 0x00, sizeof( buf ) );
TEST_ASSERT( ecp_use_known_dp( &grp1, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp1, id ) == 0 );
TEST_ASSERT( ecp_tls_write_group( &grp1, &len, buf, 10 ) == 0 );
TEST_ASSERT( ( ret = ecp_tls_read_group( &grp2, &vbuf, len ) ) == 0 );
@ -436,10 +444,10 @@ ecp_tls_write_read_group:#id
ecp_group_free( &grp1 );
ecp_group_free( &grp2 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_check_privkey:#id
/* BEGIN_CASE */
void ecp_check_privkey( int id )
{
ecp_group grp;
mpi d;
@ -447,7 +455,7 @@ ecp_check_privkey:#id
ecp_group_init( &grp );
mpi_init( &d );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( mpi_lset( &d, 0 ) == 0 );
TEST_ASSERT( ecp_check_privkey( &grp, &d ) == POLARSSL_ERR_ECP_GENERIC );
@ -458,10 +466,10 @@ ecp_check_privkey:#id
ecp_group_free( &grp );
mpi_free( &d );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_gen_keypair:#id
/* BEGIN_CASE */
void ecp_gen_keypair( int id )
{
ecp_group grp;
ecp_point Q;
@ -473,7 +481,7 @@ ecp_gen_keypair:#id
mpi_init( &d );
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
TEST_ASSERT( ecp_gen_keypair( &grp, &d, &Q, &rnd_pseudo_rand, &rnd_info )
== 0 );
@ -485,11 +493,11 @@ ecp_gen_keypair:#id
ecp_point_free( &Q );
mpi_free( &d );
}
END_CASE
/* END_CASE */
BEGIN_CASE
ecp_selftest:
/* BEGIN_CASE */
void ecp_selftest()
{
TEST_ASSERT( ecp_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,18 +1,19 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/error.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_ERROR_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_ERROR_C
* END_DEPENDENCIES
*/
BEGIN_CASE
error_strerror:#code:result_str
/* BEGIN_CASE */
void error_strerror( int code, char *result_str )
{
char buf[500];
error_strerror( {code}, buf, 500 );
error_strerror( code, buf, 500 );
TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
TEST_ASSERT( strcmp( buf, result_str ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,17 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/gcm.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_GCM_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_GCM_C
* END_DEPENDENCIES
*/
BEGIN_CASE
gcm_encrypt_and_tag:hex_key_string:hex_src_string:hex_iv_string:hex_add_string:hex_dst_string:#tag_len_bits:hex_tag_string:#init_result
/* BEGIN_CASE */
void gcm_encrypt_and_tag( char *hex_key_string, char *hex_src_string,
char *hex_iv_string, char *hex_add_string,
char *hex_dst_string, int tag_len_bits,
char *hex_tag_string, int init_result )
{
unsigned char key_str[128];
unsigned char src_str[128];
@ -19,7 +23,7 @@ gcm_encrypt_and_tag:hex_key_string:hex_src_string:hex_iv_string:hex_add_string:h
unsigned char tag_output[16];
gcm_context ctx;
unsigned int key_len;
size_t pt_len, iv_len, add_len, tag_len = {tag_len_bits} / 8;
size_t pt_len, iv_len, add_len, tag_len = tag_len_bits / 8;
memset(key_str, 0x00, 128);
memset(src_str, 0x00, 128);
@ -30,26 +34,29 @@ gcm_encrypt_and_tag:hex_key_string:hex_src_string:hex_iv_string:hex_add_string:h
memset(output, 0x00, 128);
memset(tag_output, 0x00, 16);
key_len = unhexify( key_str, {hex_key_string} );
pt_len = unhexify( src_str, {hex_src_string} );
iv_len = unhexify( iv_str, {hex_iv_string} );
add_len = unhexify( add_str, {hex_add_string} );
key_len = unhexify( key_str, hex_key_string );
pt_len = unhexify( src_str, hex_src_string );
iv_len = unhexify( iv_str, hex_iv_string );
add_len = unhexify( add_str, hex_add_string );
TEST_ASSERT( gcm_init( &ctx, key_str, key_len * 8 ) == {init_result} );
if( {init_result} == 0 )
TEST_ASSERT( gcm_init( &ctx, key_str, key_len * 8 ) == init_result );
if( init_result == 0 )
{
TEST_ASSERT( gcm_crypt_and_tag( &ctx, GCM_ENCRYPT, pt_len, iv_str, iv_len, add_str, add_len, src_str, output, tag_len, tag_output ) == 0 );
hexify( dst_str, output, pt_len );
hexify( tag_str, tag_output, tag_len );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) tag_str, {hex_tag_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
TEST_ASSERT( strcmp( (char *) tag_str, hex_tag_string ) == 0 );
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
gcm_decrypt_and_verify:hex_key_string:hex_src_string:hex_iv_string:hex_add_string:#tag_len_bits:hex_tag_string:pt_result:#init_result
/* BEGIN_CASE */
void gcm_decrypt_and_verify( char *hex_key_string, char *hex_src_string,
char *hex_iv_string, char *hex_add_string,
int tag_len_bits, char *hex_tag_string,
char *pt_result, int init_result )
{
unsigned char key_str[128];
unsigned char src_str[128];
@ -60,7 +67,7 @@ gcm_decrypt_and_verify:hex_key_string:hex_src_string:hex_iv_string:hex_add_strin
unsigned char output[128];
gcm_context ctx;
unsigned int key_len;
size_t pt_len, iv_len, add_len, tag_len = {tag_len_bits} / 8;
size_t pt_len, iv_len, add_len, tag_len = tag_len_bits / 8;
int ret;
memset(key_str, 0x00, 128);
@ -71,18 +78,18 @@ gcm_decrypt_and_verify:hex_key_string:hex_src_string:hex_iv_string:hex_add_strin
memset(tag_str, 0x00, 128);
memset(output, 0x00, 128);
key_len = unhexify( key_str, {hex_key_string} );
pt_len = unhexify( src_str, {hex_src_string} );
iv_len = unhexify( iv_str, {hex_iv_string} );
add_len = unhexify( add_str, {hex_add_string} );
unhexify( tag_str, {hex_tag_string} );
key_len = unhexify( key_str, hex_key_string );
pt_len = unhexify( src_str, hex_src_string );
iv_len = unhexify( iv_str, hex_iv_string );
add_len = unhexify( add_str, hex_add_string );
unhexify( tag_str, hex_tag_string );
TEST_ASSERT( gcm_init( &ctx, key_str, key_len * 8 ) == {init_result} );
if( {init_result} == 0 )
TEST_ASSERT( gcm_init( &ctx, key_str, key_len * 8 ) == init_result );
if( init_result == 0 )
{
ret = gcm_auth_decrypt( &ctx, pt_len, iv_str, iv_len, add_str, add_len, tag_str, tag_len, src_str, output );
if( strcmp( "FAIL", {pt_result} ) == 0 )
if( strcmp( "FAIL", pt_result ) == 0 )
{
TEST_ASSERT( ret == POLARSSL_ERR_GCM_AUTH_FAILED );
}
@ -90,15 +97,15 @@ gcm_decrypt_and_verify:hex_key_string:hex_src_string:hex_iv_string:hex_add_strin
{
hexify( dst_str, output, pt_len );
TEST_ASSERT( strcmp( (char *) dst_str, {pt_result} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, pt_result ) == 0 );
}
}
}
END_CASE
/* END_CASE */
BEGIN_CASE
gcm_selftest:
/* BEGIN_CASE */
void gcm_selftest()
{
TEST_ASSERT( gcm_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,11 +1,12 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/sha1.h>
#include <polarssl/sha256.h>
#include <polarssl/sha512.h>
END_HEADER
/* END_HEADER */
BEGIN_CASE
sha1_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha1_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string)
{
unsigned char src_str[10000];
unsigned char key_str[10000];
@ -18,18 +19,19 @@ sha1_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 41);
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
sha1_hmac( key_str, key_len, src_str, src_len, output );
hexify( hash_str, output, 20 );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha224_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha224_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string)
{
unsigned char src_str[10000];
unsigned char key_str[10000];
@ -42,18 +44,19 @@ sha224_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 57);
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
sha256_hmac( key_str, key_len, src_str, src_len, output, 1 );
hexify( hash_str, output, 28 );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha256_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha256_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string)
{
unsigned char src_str[10000];
unsigned char key_str[10000];
@ -66,18 +69,19 @@ sha256_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 65);
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
sha256_hmac( key_str, key_len, src_str, src_len, output, 0 );
hexify( hash_str, output, 32 );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha384_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha384_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string)
{
unsigned char src_str[10000];
unsigned char key_str[10000];
@ -90,18 +94,19 @@ sha384_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 97);
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
sha512_hmac( key_str, key_len, src_str, src_len, output, 1 );
hexify( hash_str, output, 48 );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha512_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha512_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string)
{
unsigned char src_str[10000];
unsigned char key_str[10000];
@ -114,12 +119,12 @@ sha512_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 129);
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
sha512_hmac( key_str, key_len, src_str, src_len, output, 0 );
hexify( hash_str, output, 64 );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,4 +1,4 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/md.h>
#include <polarssl/md2.h>
#include <polarssl/md4.h>
@ -6,14 +6,15 @@ BEGIN_HEADER
#include <polarssl/sha1.h>
#include <polarssl/sha256.h>
#include <polarssl/sha512.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_MD_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_MD_C
* END_DEPENDENCIES
*/
BEGIN_CASE
md_text:text_md_name:text_src_string:hex_hash_string
/* BEGIN_CASE */
void md_text( char *text_md_name, char *text_src_string, char *hex_hash_string )
{
char md_name[100];
unsigned char src_str[1000];
@ -26,21 +27,21 @@ md_text:text_md_name:text_src_string:hex_hash_string
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 100);
strcpy( (char *) src_str, {text_src_string} );
strcpy( (char *) src_str, text_src_string );
strncpy( (char *) md_name, {text_md_name}, 100 );
strncpy( (char *) md_name, text_md_name, 100 );
md_info = md_info_from_string(md_name);
TEST_ASSERT( md_info != NULL );
TEST_ASSERT ( 0 == md( md_info, src_str, strlen( (char *) src_str ), output ) );
hexify( hash_str, output, md_get_size(md_info) );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
md_hex:text_md_name:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void md_hex( char *text_md_name, char *hex_src_string, char *hex_hash_string )
{
char md_name[100];
unsigned char src_str[10000];
@ -54,21 +55,22 @@ md_hex:text_md_name:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, {text_md_name}, 100 );
strncpy( (char *) md_name, text_md_name, 100 );
md_info = md_info_from_string(md_name);
TEST_ASSERT( md_info != NULL );
src_len = unhexify( src_str, {hex_src_string} );
src_len = unhexify( src_str, hex_src_string );
TEST_ASSERT ( 0 == md( md_info, src_str, src_len, output ) );
hexify( hash_str, output, md_get_size(md_info) );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
md_text_multi:text_md_name:text_src_string:hex_hash_string
/* BEGIN_CASE */
void md_text_multi( char *text_md_name, char *text_src_string,
char *hex_hash_string )
{
char md_name[100];
unsigned char src_str[1000];
@ -83,9 +85,9 @@ md_text_multi:text_md_name:text_src_string:hex_hash_string
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 100);
strcpy( (char *) src_str, {text_src_string} );
strcpy( (char *) src_str, text_src_string );
strncpy( (char *) md_name, {text_md_name}, 100 );
strncpy( (char *) md_name, text_md_name, 100 );
md_info = md_info_from_string(md_name);
TEST_ASSERT( md_info != NULL );
TEST_ASSERT ( 0 == md_init_ctx( &ctx, md_info ) );
@ -98,12 +100,13 @@ md_text_multi:text_md_name:text_src_string:hex_hash_string
hexify( hash_str, output, md_get_size(md_info) );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
md_hex_multi:text_md_name:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void md_hex_multi( char *text_md_name, char *hex_src_string,
char *hex_hash_string )
{
char md_name[100];
unsigned char src_str[10000];
@ -118,12 +121,12 @@ md_hex_multi:text_md_name:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, {text_md_name}, 100 );
strncpy( (char *) md_name, text_md_name, 100 );
md_info = md_info_from_string(md_name);
TEST_ASSERT( md_info != NULL );
TEST_ASSERT ( 0 == md_init_ctx( &ctx, md_info ) );
src_len = unhexify( src_str, {hex_src_string} );
src_len = unhexify( src_str, hex_src_string );
TEST_ASSERT ( 0 == md_starts( &ctx ) );
TEST_ASSERT ( ctx.md_ctx != NULL );
@ -133,12 +136,13 @@ md_hex_multi:text_md_name:hex_src_string:hex_hash_string
hexify( hash_str, output, md_get_size(md_info) );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
md_hmac:text_md_name:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void md_hmac( char *text_md_name, int trunc_size, char *hex_key_string,
char *hex_src_string, char *hex_hash_string )
{
char md_name[100];
unsigned char src_str[10000];
@ -154,22 +158,23 @@ md_hmac:text_md_name:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, {text_md_name}, 100 );
strncpy( (char *) md_name, text_md_name, 100 );
md_info = md_info_from_string( md_name );
TEST_ASSERT( md_info != NULL );
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
TEST_ASSERT ( md_hmac( md_info, key_str, key_len, src_str, src_len, output ) == 0 );
hexify( hash_str, output, md_get_size(md_info) );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
md_hmac_multi:text_md_name:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
char *hex_src_string, char *hex_hash_string )
{
char md_name[100];
unsigned char src_str[10000];
@ -186,27 +191,27 @@ md_hmac_multi:text_md_name:#trunc_size:hex_key_string:hex_src_string:hex_hash_st
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, {text_md_name}, 100 );
strncpy( (char *) md_name, text_md_name, 100 );
md_info = md_info_from_string( md_name );
TEST_ASSERT( md_info != NULL );
TEST_ASSERT ( 0 == md_init_ctx( &ctx, md_info ) );
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
TEST_ASSERT ( 0 == md_hmac_starts( &ctx, key_str, key_len ) );
TEST_ASSERT ( ctx.md_ctx != NULL );
TEST_ASSERT ( 0 == md_hmac_update( &ctx, src_str, src_len ) );
TEST_ASSERT ( 0 == md_hmac_finish( &ctx, output ) );
TEST_ASSERT ( 0 == md_free_ctx( &ctx ) );
hexify( hash_str, output, md_get_size(md_info) );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
BEGIN_CASE
md_file:text_md_name:filename:hex_hash_string
/* END_CASE */
/* BEGIN_CASE */
void md_file( char *text_md_name, char *filename, char *hex_hash_string )
{
char md_name[100];
unsigned char hash_str[1000];
@ -217,13 +222,13 @@ md_file:text_md_name:filename:hex_hash_string
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, {text_md_name}, 100 );
strncpy( (char *) md_name, text_md_name, 100 );
md_info = md_info_from_string( md_name );
TEST_ASSERT( md_info != NULL );
md_file( md_info, {filename}, output);
md_file( md_info, filename, output);
hexify( hash_str, output, md_get_size(md_info) );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,11 +1,11 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/md2.h>
#include <polarssl/md4.h>
#include <polarssl/md5.h>
END_HEADER
/* END_HEADER */
BEGIN_CASE depends_on:POLARSSL_MD2_C
md2_text:text_src_string:hex_hash_string
/* BEGIN_CASE depends_on:POLARSSL_MD2_C */
void md2_text( char *text_src_string, char *hex_hash_string )
{
unsigned char src_str[1000];
unsigned char hash_str[1000];
@ -15,17 +15,17 @@ md2_text:text_src_string:hex_hash_string
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 33);
strcpy( (char *) src_str, {text_src_string} );
strcpy( (char *) src_str, text_src_string );
md2( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, 16 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD4_C
md4_text:text_src_string:hex_hash_string
/* BEGIN_CASE depends_on:POLARSSL_MD4_C */
void md4_text( char *text_src_string, char *hex_hash_string )
{
unsigned char src_str[1000];
unsigned char hash_str[1000];
@ -35,17 +35,17 @@ md4_text:text_src_string:hex_hash_string
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 33);
strcpy( (char *) src_str, {text_src_string} );
strcpy( (char *) src_str, text_src_string );
md4( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, 16 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD5_C
md5_text:text_src_string:hex_hash_string
/* BEGIN_CASE depends_on:POLARSSL_MD5_C */
void md5_text( char *text_src_string, char *hex_hash_string )
{
unsigned char src_str[1000];
unsigned char hash_str[1000];
@ -55,17 +55,18 @@ md5_text:text_src_string:hex_hash_string
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 33);
strcpy( (char *) src_str, {text_src_string} );
strcpy( (char *) src_str, text_src_string );
md5( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, 16 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD2_C
md2_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE depends_on:POLARSSL_MD2_C */
void md2_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char key_str[10000];
@ -78,18 +79,19 @@ md2_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 33);
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
md2_hmac( key_str, key_len, src_str, src_len, output );
hexify( hash_str, output, 16 );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD4_C
md4_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE depends_on:POLARSSL_MD4_C */
void md4_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char key_str[10000];
@ -102,18 +104,19 @@ md4_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 33);
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
md4_hmac( key_str, key_len, src_str, src_len, output );
hexify( hash_str, output, 16 );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD5_C
md5_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
/* BEGIN_CASE depends_on:POLARSSL_MD5_C */
void md5_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char key_str[10000];
@ -126,18 +129,18 @@ md5_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 33);
key_len = unhexify( key_str, {hex_key_string} );
src_len = unhexify( src_str, {hex_src_string} );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
md5_hmac( key_str, key_len, src_str, src_len, output );
hexify( hash_str, output, 16 );
TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD2_C
md2_file:filename:hex_hash_string
/* BEGIN_CASE depends_on:POLARSSL_MD2_C */
void md2_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[65];
unsigned char output[33];
@ -145,15 +148,15 @@ md2_file:filename:hex_hash_string
memset(hash_str, 0x00, 65);
memset(output, 0x00, 33);
md2_file( {filename}, output);
md2_file( filename, output);
hexify( hash_str, output, 16 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD4_C
md4_file:filename:hex_hash_string
/* BEGIN_CASE depends_on:POLARSSL_MD4_C */
void md4_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[65];
unsigned char output[33];
@ -161,15 +164,15 @@ md4_file:filename:hex_hash_string
memset(hash_str, 0x00, 65);
memset(output, 0x00, 33);
md4_file( {filename}, output);
md4_file( filename, output);
hexify( hash_str, output, 16 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD5_C
md5_file:filename:hex_hash_string
/* BEGIN_CASE depends_on:POLARSSL_MD5_C */
void md5_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[65];
unsigned char output[33];
@ -177,30 +180,30 @@ md5_file:filename:hex_hash_string
memset(hash_str, 0x00, 65);
memset(output, 0x00, 33);
md5_file( {filename}, output);
md5_file( filename, output);
hexify( hash_str, output, 16 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD2_C
md2_selftest:
/* BEGIN_CASE depends_on:POLARSSL_MD2_C */
void md2_selftest()
{
TEST_ASSERT( md2_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD4_C
md4_selftest:
/* BEGIN_CASE depends_on:POLARSSL_MD4_C */
void md4_selftest()
{
TEST_ASSERT( md4_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE depends_on:POLARSSL_MD5_C
md5_selftest:
/* BEGIN_CASE depends_on:POLARSSL_MD5_C */
void md5_selftest()
{
TEST_ASSERT( md5_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,36 +1,39 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/bignum.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_BIGNUM_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_BIGNUM_C
* END_DEPENDENCIES
*/
BEGIN_CASE
mpi_read_write_string:#radix_X:input_X:#radix_A:input_A:#output_size:#result_read:#result_write
/* BEGIN_CASE */
void 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 )
{
mpi X;
char str[1000];
size_t len = {output_size};
size_t len = output_size;
mpi_init( &X );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == {result_read} );
if( {result_read} == 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( mpi_write_string( &X, radix_A, str, &len ) == result_write );
if( result_write == 0 )
{
TEST_ASSERT( strcasecmp( str, {input_A} ) == 0 );
TEST_ASSERT( strcasecmp( str, input_A ) == 0 );
}
}
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_read_binary:input_X:#radix_A:input_A
/* BEGIN_CASE */
void mpi_read_binary( char *input_X, int radix_A, char *input_A )
{
mpi X;
unsigned char str[1000];
@ -40,18 +43,19 @@ mpi_read_binary:input_X:#radix_A:input_A
mpi_init( &X );
input_len = unhexify( buf, {input_X} );
input_len = unhexify( buf, input_X );
TEST_ASSERT( mpi_read_binary( &X, buf, input_len ) == 0 );
TEST_ASSERT( mpi_write_string( &X, {radix_A}, (char *) str, &len ) == 0 );
TEST_ASSERT( strcmp( (char *) str, {input_A} ) == 0 );
TEST_ASSERT( mpi_write_string( &X, radix_A, (char *) str, &len ) == 0 );
TEST_ASSERT( strcmp( (char *) str, input_A ) == 0 );
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_write_binary:#radix_X:input_X:input_A:#output_size:#result
/* BEGIN_CASE */
void mpi_write_binary( int radix_X, char *input_X, char *input_A,
int output_size, int result )
{
mpi X;
unsigned char str[1000];
@ -63,26 +67,27 @@ mpi_write_binary:#radix_X:input_X:input_A:#output_size:#result
mpi_init( &X );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
buflen = mpi_size( &X );
if( buflen > (size_t) {output_size} )
buflen = (size_t) {output_size};
if( buflen > (size_t) output_size )
buflen = (size_t) output_size;
TEST_ASSERT( mpi_write_binary( &X, buf, buflen ) == {result} );
if( {result} == 0)
TEST_ASSERT( mpi_write_binary( &X, buf, buflen ) == result );
if( result == 0)
{
hexify( str, buf, buflen );
TEST_ASSERT( strcasecmp( (char *) str, {input_A} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) str, input_A ) == 0 );
}
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_read_file:#radix_X:input_file:input_A:#result
/* BEGIN_CASE */
void mpi_read_file( int radix_X, char *input_file, char *input_A,
int result )
{
mpi X;
unsigned char str[1000];
@ -95,169 +100,174 @@ mpi_read_file:#radix_X:input_file:input_A:#result
mpi_init( &X );
file = fopen( {input_file}, "r" );
TEST_ASSERT( mpi_read_file( &X, {radix_X}, file ) == {result} );
file = fopen( input_file, "r" );
TEST_ASSERT( mpi_read_file( &X, radix_X, file ) == result );
fclose(file);
if( {result} == 0 )
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 );
TEST_ASSERT( strcasecmp( (char *) str, input_A ) == 0 );
}
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_write_file:#radix_X:input_X:#output_radix:output_file
/* BEGIN_CASE */
void mpi_write_file( int radix_X, char *input_X, int output_radix,
char *output_file )
{
mpi X, Y;
FILE *file_out, *file_in;
mpi_init( &X ); mpi_init( &Y );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
file_out = fopen( {output_file}, "w" );
file_out = fopen( output_file, "w" );
TEST_ASSERT( file_out != NULL );
TEST_ASSERT( mpi_write_file( NULL, &X, {output_radix}, file_out ) == 0 );
TEST_ASSERT( mpi_write_file( NULL, &X, output_radix, file_out ) == 0 );
fclose(file_out);
file_in = fopen( {output_file}, "r" );
file_in = fopen( output_file, "r" );
TEST_ASSERT( file_in != NULL );
TEST_ASSERT( mpi_read_file( &Y, {output_radix}, file_in ) == 0 );
TEST_ASSERT( mpi_read_file( &Y, output_radix, file_in ) == 0 );
fclose(file_in);
TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == 0 );
mpi_free( &X ); mpi_free( &Y );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_get_bit:#radix_X:input_X:#pos:#val
/* BEGIN_CASE */
void mpi_get_bit( int radix_X, char *input_X, int pos, int val )
{
mpi X;
mpi_init( &X );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_get_bit( &X, {pos} ) == {val} );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_get_bit( &X, pos ) == val );
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_set_bit:#radix_X:input_X:#pos:#val:#radix_Y:output_Y
/* BEGIN_CASE */
void mpi_set_bit( int radix_X, char *input_X, int pos, int val, int radix_Y,
char *output_Y )
{
mpi X, Y;
mpi_init( &X ); mpi_init( &Y );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {output_Y} ) == 0 );
TEST_ASSERT( mpi_set_bit( &X, {pos}, {val} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, output_Y ) == 0 );
TEST_ASSERT( mpi_set_bit( &X, pos, val ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == 0 );
mpi_free( &X ); mpi_free( &Y );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_lsb:#radix_X:input_X:#nr_bits
/* BEGIN_CASE */
void mpi_lsb( int radix_X, char *input_X, int nr_bits )
{
mpi X;
mpi_init( &X );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_lsb( &X ) == (size_t) {nr_bits} );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_lsb( &X ) == (size_t) nr_bits );
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_msb:#radix_X:input_X:#nr_bits
/* BEGIN_CASE */
void mpi_msb( int radix_X, char *input_X, int nr_bits )
{
mpi X;
mpi_init( &X );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_msb( &X ) == (size_t) {nr_bits} );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_msb( &X ) == (size_t) nr_bits );
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_gcd:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A
/* BEGIN_CASE */
void mpi_gcd( int radix_X, char *input_X, int radix_Y, char *input_Y,
int radix_A, char *input_A )
{
mpi A, X, Y, Z;
mpi_init( &A ); mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_gcd( &Z, &X, &Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
mpi_free( &A ); mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_cmp_int:#input_X:#input_A:#result_CMP
/* BEGIN_CASE */
void mpi_cmp_int( int input_X, int input_A, int result_CMP )
{
mpi X;
mpi_init( &X );
TEST_ASSERT( mpi_lset( &X, {input_X} ) == 0);
TEST_ASSERT( mpi_cmp_int( &X, {input_A} ) == {result_CMP});
TEST_ASSERT( mpi_lset( &X, input_X ) == 0);
TEST_ASSERT( mpi_cmp_int( &X, input_A ) == result_CMP);
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_cmp_mpi:#radix_X:input_X:#radix_Y:input_Y:#input_A
/* BEGIN_CASE */
void mpi_cmp_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
int input_A )
{
mpi X, Y;
mpi_init( &X ); mpi_init( &Y );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == {input_A} );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == input_A );
mpi_free( &X ); mpi_free( &Y );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_cmp_abs:#radix_X:input_X:#radix_Y:input_Y:#input_A
/* BEGIN_CASE */
void mpi_cmp_abs( int radix_X, char *input_X, int radix_Y, char *input_Y,
int input_A )
{
mpi X, Y;
mpi_init( &X ); mpi_init( &Y );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_cmp_abs( &X, &Y ) == {input_A} );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
TEST_ASSERT( mpi_cmp_abs( &X, &Y ) == input_A );
mpi_free( &X ); mpi_free( &Y );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_copy:#input_X:#input_A
/* BEGIN_CASE */
void mpi_copy( int input_X, int input_A )
{
mpi X, Y, A;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &A );
TEST_ASSERT( mpi_lset( &X, {input_X} ) == 0 );
TEST_ASSERT( mpi_lset( &Y, {input_A} ) == 0 );
TEST_ASSERT( mpi_lset( &A, {input_A} ) == 0 );
TEST_ASSERT( mpi_lset( &X, input_X ) == 0 );
TEST_ASSERT( mpi_lset( &Y, input_A ) == 0 );
TEST_ASSERT( mpi_lset( &A, input_A ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) != 0 );
TEST_ASSERT( mpi_cmp_mpi( &Y, &A ) == 0 );
TEST_ASSERT( mpi_copy( &Y, &X ) == 0 );
@ -266,31 +276,31 @@ mpi_copy:#input_X:#input_A
mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_copy_self:#input_X
/* BEGIN_CASE */
void mpi_copy_self( int input_X )
{
mpi X;
mpi_init( &X );
TEST_ASSERT( mpi_lset( &X, {input_X} ) == 0 );
TEST_ASSERT( mpi_lset( &X, input_X ) == 0 );
TEST_ASSERT( mpi_copy( &X, &X ) == 0 );
TEST_ASSERT( mpi_cmp_int( &X, {input_X} ) == 0 );
TEST_ASSERT( mpi_cmp_int( &X, input_X ) == 0 );
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_swap:#input_X:#input_Y
/* BEGIN_CASE */
void mpi_swap( int input_X, int input_Y )
{
mpi X, Y, A;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &A );
TEST_ASSERT( mpi_lset( &X, {input_X} ) == 0 );
TEST_ASSERT( mpi_lset( &Y, {input_Y} ) == 0 );
TEST_ASSERT( mpi_lset( &A, {input_X} ) == 0 );
TEST_ASSERT( mpi_lset( &X, input_X ) == 0 );
TEST_ASSERT( mpi_lset( &Y, input_Y ) == 0 );
TEST_ASSERT( mpi_lset( &A, input_X ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) != 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
mpi_swap( &X, &Y );
@ -299,163 +309,173 @@ mpi_swap:#input_X:#input_Y
mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_add_mpi:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A
/* BEGIN_CASE */
void mpi_add_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
int radix_A, char *input_A )
{
mpi X, Y, Z, A;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_add_mpi( &Z, &X, &Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_add_abs:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A
/* BEGIN_CASE */
void mpi_add_abs( int radix_X, char *input_X, int radix_Y, char *input_Y,
int radix_A, char *input_A )
{
mpi X, Y, Z, A;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_add_abs( &Z, &X, &Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_add_abs_add_first:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A
/* BEGIN_CASE */
void mpi_add_abs_add_first( int radix_X, char *input_X, int radix_Y,
char *input_Y, int radix_A, char *input_A )
{
mpi X, Y, A;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_add_abs( &X, &X, &Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_add_abs_add_second:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A
/* BEGIN_CASE */
void mpi_add_abs_add_second( int radix_X, char *input_X, int radix_Y,
char *input_Y, int radix_A, char *input_A )
{
mpi X, Y, A;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_add_abs( &Y, &X, &Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &Y, &A ) == 0 );
mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_add_int:#radix_X:input_X:#input_Y:#radix_A:input_A
/* BEGIN_CASE */
void mpi_add_int( int radix_X, char *input_X, int input_Y, int radix_A,
char *input_A )
{
mpi X, Z, A;
mpi_init( &X ); mpi_init( &Z ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_add_int( &Z, &X, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_add_int( &Z, &X, input_Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
mpi_free( &X ); mpi_free( &Z ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_sub_mpi:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A
/* BEGIN_CASE */
void mpi_sub_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
int radix_A, char *input_A )
{
mpi X, Y, Z, A;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_sub_mpi( &Z, &X, &Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_sub_abs:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A:#sub_result
/* BEGIN_CASE */
void mpi_sub_abs( int radix_X, char *input_X, int radix_Y, char *input_Y,
int radix_A, char *input_A, int sub_result )
{
mpi X, Y, Z, A;
int res;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_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 );
res = mpi_sub_abs( &Z, &X, &Y );
TEST_ASSERT( res == {sub_result} );
TEST_ASSERT( res == sub_result );
if( res == 0 )
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_sub_int:#radix_X:input_X:#input_Y:#radix_A:input_A
/* BEGIN_CASE */
void mpi_sub_int( int radix_X, char *input_X, int input_Y, int radix_A,
char *input_A )
{
mpi X, Z, A;
mpi_init( &X ); mpi_init( &Z ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_sub_int( &Z, &X, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_sub_int( &Z, &X, input_Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
mpi_free( &X ); mpi_free( &Z ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_mul_mpi:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A
/* BEGIN_CASE */
void mpi_mul_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
int radix_A, char *input_A )
{
mpi X, Y, Z, A;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_mul_mpi( &Z, &X, &Y ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_mul_int:#radix_X:input_X:#input_Y:#radix_A:input_A:result_comparison
/* BEGIN_CASE */
void mpi_mul_int( int radix_X, char *input_X, int input_Y, int radix_A,
char *input_A, char *result_comparison )
{
mpi X, Z, A;
mpi_init( &X ); mpi_init( &Z ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_mul_int( &Z, &X, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_mul_int( &Z, &X, input_Y ) == 0 );
if( strcmp( result_comparison, "==" ) == 0 )
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
else if( strcmp( result_comparison, "!=" ) == 0 )
@ -465,22 +485,24 @@ mpi_mul_int:#radix_X:input_X:#input_Y:#radix_A:input_A:result_comparison
mpi_free( &X ); mpi_free( &Z ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_div_mpi:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A:#radix_B:input_B:#div_result
/* BEGIN_CASE */
void 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 )
{
mpi X, Y, Q, R, A, B;
int res;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &Q ); mpi_init( &R );
mpi_init( &A ); mpi_init( &B );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &B, {radix_B}, {input_B} ) == 0 );
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_read_string( &B, radix_B, input_B ) == 0 );
res = mpi_div_mpi( &Q, &R, &X, &Y );
TEST_ASSERT( res == {div_result} );
TEST_ASSERT( res == div_result );
if( res == 0 )
{
TEST_ASSERT( mpi_cmp_mpi( &Q, &A ) == 0 );
@ -490,21 +512,22 @@ mpi_div_mpi:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A:#radix_B:input_B:
mpi_free( &X ); mpi_free( &Y ); mpi_free( &Q ); mpi_free( &R );
mpi_free( &A ); mpi_free( &B );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_div_int:#radix_X:input_X:#input_Y:#radix_A:input_A:#radix_B:input_B:#div_result
/* BEGIN_CASE */
void 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 )
{
mpi X, Q, R, A, B;
int res;
mpi_init( &X ); mpi_init( &Q ); mpi_init( &R ); mpi_init( &A );
mpi_init( &B );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &B, {radix_B}, {input_B} ) == 0 );
res = mpi_div_int( &Q, &R, &X, {input_Y} );
TEST_ASSERT( res == {div_result} );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_read_string( &B, radix_B, input_B ) == 0 );
res = mpi_div_int( &Q, &R, &X, input_Y );
TEST_ASSERT( res == div_result );
if( res == 0 )
{
TEST_ASSERT( mpi_cmp_mpi( &Q, &A ) == 0 );
@ -514,20 +537,21 @@ mpi_div_int:#radix_X:input_X:#input_Y:#radix_A:input_A:#radix_B:input_B:#div_res
mpi_free( &X ); mpi_free( &Q ); mpi_free( &R ); mpi_free( &A );
mpi_free( &B );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_mod_mpi:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A:#div_result
/* BEGIN_CASE */
void mpi_mod_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
int radix_A, char *input_A, int div_result )
{
mpi X, Y, A;
int res;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_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 );
res = mpi_mod_mpi( &X, &X, &Y );
TEST_ASSERT( res == {div_result} );
TEST_ASSERT( res == div_result );
if( res == 0 )
{
TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
@ -535,46 +559,49 @@ mpi_mod_mpi:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A:#div_result
mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_mod_int:#radix_X:input_X:#input_Y:#input_A:#div_result
/* BEGIN_CASE */
void mpi_mod_int( int radix_X, char *input_X, int input_Y, int input_A,
int div_result )
{
mpi X;
int res;
t_uint r;
mpi_init( &X );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
res = mpi_mod_int( &r, &X, {input_Y} );
TEST_ASSERT( res == {div_result} );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
res = mpi_mod_int( &r, &X, input_Y );
TEST_ASSERT( res == div_result );
if( res == 0 )
{
TEST_ASSERT( r == (t_uint) {input_A} );
TEST_ASSERT( r == (t_uint) input_A );
}
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_exp_mod:#radix_A:input_A:#radix_E:input_E:#radix_N:input_N:#radix_RR:input_RR:#radix_X:input_X:#div_result
/* BEGIN_CASE */
void 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 )
{
mpi A, E, N, RR, Z, X;
int res;
mpi_init( &A ); mpi_init( &E ); mpi_init( &N );
mpi_init( &RR ); mpi_init( &Z ); mpi_init( &X );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_read_string( &E, {radix_E}, {input_E} ) == 0 );
TEST_ASSERT( mpi_read_string( &N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_read_string( &E, radix_E, input_E ) == 0 );
TEST_ASSERT( mpi_read_string( &N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
if( strlen( {input_RR} ) )
TEST_ASSERT( mpi_read_string( &RR, {radix_RR}, {input_RR} ) == 0 );
if( strlen( input_RR ) )
TEST_ASSERT( mpi_read_string( &RR, radix_RR, input_RR ) == 0 );
res = mpi_exp_mod( &Z, &A, &E, &N, &RR );
TEST_ASSERT( res == {div_result} );
TEST_ASSERT( res == div_result );
if( res == 0 )
{
TEST_ASSERT( mpi_cmp_mpi( &Z, &X ) == 0 );
@ -583,20 +610,21 @@ mpi_exp_mod:#radix_A:input_A:#radix_E:input_E:#radix_N:input_N:#radix_RR:input_R
mpi_free( &A ); mpi_free( &E ); mpi_free( &N );
mpi_free( &RR ); mpi_free( &Z ); mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_inv_mod:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A:#div_result
/* BEGIN_CASE */
void mpi_inv_mod( int radix_X, char *input_X, int radix_Y, char *input_Y,
int radix_A, char *input_A, int div_result )
{
mpi X, Y, Z, A;
int res;
mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &Y, {radix_Y}, {input_Y} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_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 );
res = mpi_inv_mod( &Z, &X, &Y );
TEST_ASSERT( res == {div_result} );
TEST_ASSERT( res == div_result );
if( res == 0 )
{
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
@ -604,63 +632,58 @@ mpi_inv_mod:#radix_X:input_X:#radix_Y:input_Y:#radix_A:input_A:#div_result
mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_is_prime:#radix_X:input_X:#div_result
/* BEGIN_CASE */
void mpi_is_prime( int radix_X, char *input_X, int div_result )
{
mpi X;
int res;
mpi_init( &X );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
res = mpi_is_prime( &X, rnd_std_rand, NULL );
TEST_ASSERT( res == {div_result} );
TEST_ASSERT( res == div_result );
mpi_free( &X );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_shift_l:#radix_X:input_X:#shift_X:#radix_A:input_A
/* BEGIN_CASE */
void mpi_shift_l( int radix_X, char *input_X, int shift_X, int radix_A,
char *input_A)
{
mpi X, A;
mpi_init( &X ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_shift_l( &X, {shift_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_shift_l( &X, shift_X ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
mpi_free( &X ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_shift_r:#radix_X:input_X:#shift_X:#radix_A:input_A
/* BEGIN_CASE */
void mpi_shift_r( int radix_X, char *input_X, int shift_X, int radix_A,
char *input_A )
{
mpi X, A;
mpi_init( &X ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &X, {radix_X}, {input_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &A, {radix_A}, {input_A} ) == 0 );
TEST_ASSERT( mpi_shift_r( &X, {shift_X} ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_shift_r( &X, shift_X ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
mpi_free( &X ); mpi_free( &A );
}
END_CASE
/* END_CASE */
BEGIN_CASE
mpi_selftest:
/* BEGIN_CASE */
void mpi_selftest()
{
TEST_ASSERT( mpi_self_test( 0 ) == 0 );
}
END_CASE
/* Helper Code
char str[1000];
int len = 1000;
mpi_write_string(&Z, 10, str, &len);
printf("Z: %d %s\n", Z.s, str);
TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
*/
/* END_CASE */

View File

@ -1,13 +1,15 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/pbkdf2.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_PBKDF2_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_PBKDF2_C
* END_DEPENDENCIES
*/
BEGIN_CASE
pbkdf2_hmac:#hash:hex_password_string:hex_salt_string:#it_cnt:#key_len:result_key_string
/* BEGIN_CASE */
void pbkdf2_hmac( int hash, char *hex_password_string, char *hex_salt_string,
int it_cnt, int key_len, char *result_key_string )
{
unsigned char pw_str[100];
unsigned char salt_str[100];
@ -23,18 +25,18 @@ pbkdf2_hmac:#hash:hex_password_string:hex_salt_string:#it_cnt:#key_len:result_ke
memset(salt_str, 0x00, 100);
memset(dst_str, 0x00, 100);
pw_len = unhexify( pw_str, {hex_password_string} );
salt_len = unhexify( salt_str, {hex_salt_string} );
pw_len = unhexify( pw_str, hex_password_string );
salt_len = unhexify( salt_str, hex_salt_string );
info = md_info_from_type( {hash} );
info = md_info_from_type( hash );
TEST_ASSERT( info != NULL );
TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
TEST_ASSERT( pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
{it_cnt}, {key_len}, key ) == 0 );
it_cnt, key_len, key ) == 0 );
TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
hexify( dst_str, key, {key_len} );
TEST_ASSERT( strcmp( (char *) dst_str, {result_key_string} ) == 0 );
hexify( dst_str, key, key_len );
TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,4 +1,4 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/rsa.h>
#include <polarssl/md.h>
#include <polarssl/md2.h>
@ -7,14 +7,18 @@ BEGIN_HEADER
#include <polarssl/sha1.h>
#include <polarssl/sha256.h>
#include <polarssl/sha512.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_PKCS1_V21:POLARSSL_RSA_C:POLARSSL_BIGNUM_C:POLARSSL_SHA1_C:POLARSSL_GENPRIME
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_PKCS1_V21:POLARSSL_RSA_C:POLARSSL_BIGNUM_C:POLARSSL_SHA1_C:POLARSSL_GENPRIME
* END_DEPENDENCIES
*/
BEGIN_CASE
pkcs1_rsaes_oaep_encrypt:#mod:#radix_N:input_N:#radix_E:input_E:#hash:message_hex_string:seed:result_hex_str:#result
/* BEGIN_CASE */
void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char *input_N, int radix_E,
char *input_E, int hash,
char *message_hex_string, char *seed,
char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char output[1000];
@ -24,36 +28,40 @@ pkcs1_rsaes_oaep_encrypt:#mod:#radix_N:input_N:#radix_E:input_E:#hash:message_he
size_t msg_len;
rnd_buf_info info;
info.length = unhexify( rnd_buf, {seed} );
info.length = unhexify( rnd_buf, seed );
info.buf = rnd_buf;
rsa_init( &ctx, RSA_PKCS_V21, {hash} );
rsa_init( &ctx, RSA_PKCS_V21, hash );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8 + ( ( {mod} % 8 ) ? 1 : 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8 + ( ( mod % 8 ) ? 1 : 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
msg_len = unhexify( message_str, {message_hex_string} );
msg_len = unhexify( message_str, message_hex_string );
TEST_ASSERT( rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, RSA_PUBLIC, msg_len, message_str, output ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, RSA_PUBLIC, msg_len, message_str, output ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len );
TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
}
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
pkcs1_rsaes_oaep_decrypt:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N:#radix_E:input_E:#hash:result_hex_str:seed:message_hex_string:#result
/* BEGIN_CASE */
void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
int radix_Q, char *input_Q, int radix_N,
char *input_N, int radix_E, char *input_E,
int hash, char *result_hex_str, char *seed,
char *message_hex_string, int result )
{
unsigned char message_str[1000];
unsigned char output[1000];
@ -64,17 +72,17 @@ pkcs1_rsaes_oaep_decrypt:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N
((void) seed);
mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
rsa_init( &ctx, RSA_PKCS_V21, {hash} );
rsa_init( &ctx, RSA_PKCS_V21, hash );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8 + ( ( {mod} % 8 ) ? 1 : 0 );
TEST_ASSERT( mpi_read_string( &ctx.P, {radix_P}, {input_P} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, {radix_Q}, {input_Q} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8 + ( ( mod % 8 ) ? 1 : 0 );
TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
@ -87,23 +95,27 @@ pkcs1_rsaes_oaep_decrypt:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N
TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
unhexify( message_str, {message_hex_string} );
unhexify( message_str, message_hex_string );
TEST_ASSERT( rsa_pkcs1_decrypt( &ctx, RSA_PRIVATE, &output_len, message_str, output, 1000 ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_pkcs1_decrypt( &ctx, RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len );
TEST_ASSERT( strncasecmp( (char *) output_str, {result_hex_str}, strlen( {result_hex_str} ) ) == 0 );
TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
}
mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
pkcs1_rsassa_pss_sign:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N:#radix_E:input_E:#digest:#hash:message_hex_string:salt:result_hex_str:#result
/* BEGIN_CASE */
void pkcs1_rsassa_pss_sign( int mod, int radix_P, char *input_P, int radix_Q,
char *input_Q, int radix_N, char *input_N,
int radix_E, char *input_E, int digest, int hash,
char *message_hex_string, char *salt,
char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char hash_result[1000];
@ -115,22 +127,22 @@ pkcs1_rsassa_pss_sign:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N:#r
size_t msg_len;
rnd_buf_info info;
info.length = unhexify( rnd_buf, {salt} );
info.length = unhexify( rnd_buf, salt );
info.buf = rnd_buf;
mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
rsa_init( &ctx, RSA_PKCS_V21, {hash} );
rsa_init( &ctx, RSA_PKCS_V21, hash );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8 + ( ( {mod} % 8 ) ? 1 : 0 );
TEST_ASSERT( mpi_read_string( &ctx.P, {radix_P}, {input_P} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, {radix_Q}, {input_Q} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8 + ( ( mod % 8 ) ? 1 : 0 );
TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
@ -143,26 +155,29 @@ pkcs1_rsassa_pss_sign:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N:#r
TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
msg_len = unhexify( message_str, {message_hex_string} );
msg_len = unhexify( message_str, message_hex_string );
if( md_info_from_type( {digest} ) != NULL )
TEST_ASSERT( md( md_info_from_type( {digest} ), message_str, msg_len, hash_result ) == 0 );
if( md_info_from_type( digest ) != NULL )
TEST_ASSERT( md( md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 );
TEST_ASSERT( rsa_pkcs1_sign( &ctx, &rnd_buffer_rand, &info, RSA_PRIVATE, {digest}, 0, hash_result, output ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_pkcs1_sign( &ctx, &rnd_buffer_rand, &info, RSA_PRIVATE, digest, 0, hash_result, output ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len);
TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
}
mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
pkcs1_rsassa_pss_verify:#mod:#radix_N:input_N:#radix_E:input_E:#digest:#hash:message_hex_string:salt:result_hex_str:#result
/* BEGIN_CASE */
void pkcs1_rsassa_pss_verify( int mod, int radix_N, char *input_N, int radix_E,
char *input_E, int digest, int hash,
char *message_hex_string, char *salt,
char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char hash_result[1000];
@ -171,25 +186,25 @@ pkcs1_rsassa_pss_verify:#mod:#radix_N:input_N:#radix_E:input_E:#digest:#hash:mes
size_t msg_len;
((void) salt);
rsa_init( &ctx, RSA_PKCS_V21, {hash} );
rsa_init( &ctx, RSA_PKCS_V21, hash );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( result_str, 0x00, 1000 );
ctx.len = {mod} / 8 + ( ( {mod} % 8 ) ? 1 : 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8 + ( ( mod % 8 ) ? 1 : 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
msg_len = unhexify( message_str, {message_hex_string} );
unhexify( result_str, {result_hex_str} );
msg_len = unhexify( message_str, message_hex_string );
unhexify( result_str, result_hex_str );
if( md_info_from_type( {digest} ) != NULL )
TEST_ASSERT( md( md_info_from_type( {digest} ), message_str, msg_len, hash_result ) == 0 );
if( md_info_from_type( digest ) != NULL )
TEST_ASSERT( md( md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 );
TEST_ASSERT( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, {digest}, 0, hash_result, result_str ) == {result} );
TEST_ASSERT( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, digest, 0, hash_result, result_str ) == result );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,16 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/pkcs5.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_PKCS5_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_PKCS5_C
* END_DEPENDENCIES
*/
BEGIN_CASE
pbkdf2_hmac:#hash:hex_password_string:hex_salt_string:#it_cnt:#key_len:result_key_string
/* BEGIN_CASE */
void pbkdf2_hmac( int hash, char *hex_password_string,
char *hex_salt_string, int it_cnt, int key_len,
char *result_key_string )
{
unsigned char pw_str[100];
unsigned char salt_str[100];
@ -23,18 +26,18 @@ pbkdf2_hmac:#hash:hex_password_string:hex_salt_string:#it_cnt:#key_len:result_ke
memset(salt_str, 0x00, 100);
memset(dst_str, 0x00, 100);
pw_len = unhexify( pw_str, {hex_password_string} );
salt_len = unhexify( salt_str, {hex_salt_string} );
pw_len = unhexify( pw_str, hex_password_string );
salt_len = unhexify( salt_str, hex_salt_string );
info = md_info_from_type( {hash} );
info = md_info_from_type( hash );
TEST_ASSERT( info != NULL );
TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
TEST_ASSERT( pkcs5_pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
{it_cnt}, {key_len}, key ) == 0 );
it_cnt, key_len, key ) == 0 );
TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
hexify( dst_str, key, {key_len} );
TEST_ASSERT( strcmp( (char *) dst_str, {result_key_string} ) == 0 );
hexify( dst_str, key, key_len );
TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,4 +1,4 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/rsa.h>
#include <polarssl/md2.h>
#include <polarssl/md4.h>
@ -8,14 +8,18 @@ BEGIN_HEADER
#include <polarssl/sha512.h>
#include <polarssl/entropy.h>
#include <polarssl/ctr_drbg.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_RSA_C:POLARSSL_BIGNUM_C:POLARSSL_GENPRIME
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_RSA_C:POLARSSL_BIGNUM_C:POLARSSL_GENPRIME
* END_DEPENDENCIES
*/
BEGIN_CASE
rsa_pkcs1_sign:message_hex_string:#padding_mode:#digest:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N:#radix_E:input_E:result_hex_str:#result
/* BEGIN_CASE */
void rsa_pkcs1_sign( char *message_hex_string, int padding_mode, int digest,
int mod, int radix_P, char *input_P, int radix_Q,
char *input_Q, int radix_N, char *input_N, int radix_E,
char *input_E, char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char hash_result[1000];
@ -26,18 +30,18 @@ rsa_pkcs1_sign:message_hex_string:#padding_mode:#digest:#mod:#radix_P:input_P:#r
int msg_len;
mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
rsa_init( &ctx, {padding_mode}, 0 );
rsa_init( &ctx, padding_mode, 0 );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8;
TEST_ASSERT( mpi_read_string( &ctx.P, {radix_P}, {input_P} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, {radix_Q}, {input_Q} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8;
TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
@ -50,26 +54,28 @@ rsa_pkcs1_sign:message_hex_string:#padding_mode:#digest:#mod:#radix_P:input_P:#r
TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
msg_len = unhexify( message_str, {message_hex_string} );
msg_len = unhexify( message_str, message_hex_string );
if( md_info_from_type( {digest} ) != NULL )
TEST_ASSERT( md( md_info_from_type( {digest} ), message_str, msg_len, hash_result ) == 0 );
if( md_info_from_type( digest ) != NULL )
TEST_ASSERT( md( md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 );
TEST_ASSERT( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, {digest}, 0, hash_result, output ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, digest, 0, hash_result, output ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len );
TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
}
mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_pkcs1_verify:message_hex_string:#padding_mode:#digest:#mod:#radix_N:input_N:#radix_E:input_E:result_hex_str:#result
/* BEGIN_CASE */
void rsa_pkcs1_verify( char *message_hex_string, int padding_mode, int digest,
int mod, int radix_N, char *input_N, int radix_E,
char *input_E, char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char hash_result[1000];
@ -77,32 +83,36 @@ rsa_pkcs1_verify:message_hex_string:#padding_mode:#digest:#mod:#radix_N:input_N:
rsa_context ctx;
int msg_len;
rsa_init( &ctx, {padding_mode}, 0 );
rsa_init( &ctx, padding_mode, 0 );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( result_str, 0x00, 1000 );
ctx.len = {mod} / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
msg_len = unhexify( message_str, {message_hex_string} );
unhexify( result_str, {result_hex_str} );
msg_len = unhexify( message_str, message_hex_string );
unhexify( result_str, result_hex_str );
if( md_info_from_type( {digest} ) != NULL )
TEST_ASSERT( md( md_info_from_type( {digest} ), message_str, msg_len, hash_result ) == 0 );
if( md_info_from_type( digest ) != NULL )
TEST_ASSERT( md( md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 );
TEST_ASSERT( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, {digest}, 0, hash_result, result_str ) == {result} );
TEST_ASSERT( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, digest, 0, hash_result, result_str ) == result );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_pkcs1_sign_raw:message_hex_string:hash_result_string:#padding_mode:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N:#radix_E:input_E:result_hex_str
/* BEGIN_CASE */
void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
int padding_mode, int mod, int radix_P, char *input_P,
int radix_Q, char *input_Q, int radix_N,
char *input_N, int radix_E, char *input_E,
char *result_hex_str )
{
unsigned char message_str[1000];
unsigned char hash_result[1000];
@ -113,18 +123,18 @@ rsa_pkcs1_sign_raw:message_hex_string:hash_result_string:#padding_mode:#mod:#rad
int hash_len;
mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
rsa_init( &ctx, {padding_mode}, 0 );
rsa_init( &ctx, padding_mode, 0 );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8;
TEST_ASSERT( mpi_read_string( &ctx.P, {radix_P}, {input_P} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, {radix_Q}, {input_Q} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8;
TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
@ -137,22 +147,25 @@ rsa_pkcs1_sign_raw:message_hex_string:hash_result_string:#padding_mode:#mod:#rad
TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
unhexify( message_str, {message_hex_string} );
hash_len = unhexify( hash_result, {hash_result_string} );
unhexify( message_str, message_hex_string );
hash_len = unhexify( hash_result, hash_result_string );
TEST_ASSERT( rsa_pkcs1_sign( &ctx, NULL, NULL, RSA_PRIVATE, POLARSSL_MD_NONE, hash_len, hash_result, output ) == 0 );
hexify( output_str, output, ctx.len );
TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_pkcs1_verify_raw:message_hex_string:hash_result_string:#padding_mode:#mod:#radix_N:input_N:#radix_E:input_E:result_hex_str:#correct
/* BEGIN_CASE */
void rsa_pkcs1_verify_raw( char *message_hex_string, char *hash_result_string,
int padding_mode, int mod, int radix_N,
char *input_N, int radix_E, char *input_E,
char *result_hex_str, int correct )
{
unsigned char message_str[1000];
unsigned char hash_result[1000];
@ -160,29 +173,31 @@ rsa_pkcs1_verify_raw:message_hex_string:hash_result_string:#padding_mode:#mod:#r
rsa_context ctx;
size_t hash_len;
rsa_init( &ctx, {padding_mode}, 0 );
rsa_init( &ctx, padding_mode, 0 );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( result_str, 0x00, 1000 );
ctx.len = {mod} / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
unhexify( message_str, {message_hex_string} );
hash_len = unhexify( hash_result, {hash_result_string} );
unhexify( result_str, {result_hex_str} );
unhexify( message_str, message_hex_string );
hash_len = unhexify( hash_result, hash_result_string );
unhexify( result_str, result_hex_str );
TEST_ASSERT( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, POLARSSL_MD_NONE, hash_len, hash_result, result_str ) == {correct} );
TEST_ASSERT( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, POLARSSL_MD_NONE, hash_len, hash_result, result_str ) == correct );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_pkcs1_encrypt:message_hex_string:#padding_mode:#mod:#radix_N:input_N:#radix_E:input_E:result_hex_str:#result
/* BEGIN_CASE */
void rsa_pkcs1_encrypt( char *message_hex_string, int padding_mode, int mod,
int radix_N, char *input_N, int radix_E, char *input_E,
char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char output[1000];
@ -193,33 +208,36 @@ rsa_pkcs1_encrypt:message_hex_string:#padding_mode:#mod:#radix_N:input_N:#radix_
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
rsa_init( &ctx, {padding_mode}, 0 );
rsa_init( &ctx, padding_mode, 0 );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
msg_len = unhexify( message_str, {message_hex_string} );
msg_len = unhexify( message_str, message_hex_string );
TEST_ASSERT( rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info, RSA_PUBLIC, msg_len, message_str, output ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info, RSA_PUBLIC, msg_len, message_str, output ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len );
TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
}
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_pkcs1_encrypt_bad_rng:message_hex_string:#padding_mode:#mod:#radix_N:input_N:#radix_E:input_E:result_hex_str:#result
/* BEGIN_CASE */
void rsa_pkcs1_encrypt_bad_rng( char *message_hex_string, int padding_mode,
int mod, int radix_N, char *input_N,
int radix_E, char *input_E,
char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char output[1000];
@ -227,33 +245,36 @@ rsa_pkcs1_encrypt_bad_rng:message_hex_string:#padding_mode:#mod:#radix_N:input_N
rsa_context ctx;
size_t msg_len;
rsa_init( &ctx, {padding_mode}, 0 );
rsa_init( &ctx, padding_mode, 0 );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
msg_len = unhexify( message_str, {message_hex_string} );
msg_len = unhexify( message_str, message_hex_string );
TEST_ASSERT( rsa_pkcs1_encrypt( &ctx, &rnd_zero_rand, NULL, RSA_PUBLIC, msg_len, message_str, output ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_pkcs1_encrypt( &ctx, &rnd_zero_rand, NULL, RSA_PUBLIC, msg_len, message_str, output ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len );
TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
}
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_pkcs1_decrypt:message_hex_string:#padding_mode:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N:#radix_E:input_E:#max_output:result_hex_str:#result
/* BEGIN_CASE */
void rsa_pkcs1_decrypt( char *message_hex_string, int padding_mode, int mod,
int radix_P, char *input_P, int radix_Q, char *input_Q,
int radix_N, char *input_N, int radix_E, char *input_E,
int max_output, char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char output[1000];
@ -263,17 +284,17 @@ rsa_pkcs1_decrypt:message_hex_string:#padding_mode:#mod:#radix_P:input_P:#radix_
size_t output_len;
mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
rsa_init( &ctx, {padding_mode}, 0 );
rsa_init( &ctx, padding_mode, 0 );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8;
TEST_ASSERT( mpi_read_string( &ctx.P, {radix_P}, {input_P} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, {radix_Q}, {input_Q} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8;
TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
@ -286,24 +307,25 @@ rsa_pkcs1_decrypt:message_hex_string:#padding_mode:#mod:#radix_P:input_P:#radix_
TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
unhexify( message_str, {message_hex_string} );
unhexify( message_str, message_hex_string );
output_len = 0;
TEST_ASSERT( rsa_pkcs1_decrypt( &ctx, RSA_PRIVATE, &output_len, message_str, output, {max_output} ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_pkcs1_decrypt( &ctx, RSA_PRIVATE, &output_len, message_str, output, max_output ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len );
TEST_ASSERT( strncasecmp( (char *) output_str, {result_hex_str}, strlen( {result_hex_str} ) ) == 0 );
TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
}
mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_public:message_hex_string:#mod:#radix_N:input_N:#radix_E:input_E:result_hex_str:#result
/* BEGIN_CASE */
void rsa_public( char *message_hex_string, int mod, int radix_N, char *input_N,
int radix_E, char *input_E, char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char output[1000];
@ -315,28 +337,30 @@ rsa_public:message_hex_string:#mod:#radix_N:input_N:#radix_E:input_E:result_hex_
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8;
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
unhexify( message_str, {message_hex_string} );
unhexify( message_str, message_hex_string );
TEST_ASSERT( rsa_public( &ctx, message_str, output ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_public( &ctx, message_str, output ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len );
TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
}
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_private:message_hex_string:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N:#radix_E:input_E:result_hex_str:#result
/* BEGIN_CASE */
void rsa_private( char *message_hex_string, int mod, int radix_P, char *input_P,
int radix_Q, char *input_Q, int radix_N, char *input_N,
int radix_E, char *input_E, char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char output[1000];
@ -351,11 +375,11 @@ rsa_private:message_hex_string:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:i
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
ctx.len = {mod} / 8;
TEST_ASSERT( mpi_read_string( &ctx.P, {radix_P}, {input_P} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, {radix_Q}, {input_Q} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
ctx.len = mod / 8;
TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
@ -368,102 +392,108 @@ rsa_private:message_hex_string:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:i
TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
unhexify( message_str, {message_hex_string} );
unhexify( message_str, message_hex_string );
TEST_ASSERT( rsa_private( &ctx, message_str, output ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_private( &ctx, message_str, output ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len );
TEST_ASSERT( strcasecmp( (char *) output_str, {result_hex_str} ) == 0 );
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
}
mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_check_privkey_null:
/* BEGIN_CASE */
void rsa_check_privkey_null()
{
rsa_context ctx;
memset( &ctx, 0x00, sizeof( rsa_context ) );
TEST_ASSERT( rsa_check_privkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_check_pubkey:#radix_N:input_N:#radix_E:input_E:#result
/* BEGIN_CASE */
void rsa_check_pubkey( int radix_N, char *input_N, int radix_E, char *input_E,
int result )
{
rsa_context ctx;
rsa_init( &ctx, RSA_PKCS_V15, 0 );
if( strlen( {input_N} ) )
if( strlen( input_N ) )
{
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
}
if( strlen( {input_E} ) )
if( strlen( input_E ) )
{
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
}
TEST_ASSERT( rsa_check_pubkey( &ctx ) == {result} );
TEST_ASSERT( rsa_check_pubkey( &ctx ) == result );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_check_privkey:#mod:#radix_P:input_P:#radix_Q:input_Q:#radix_N:input_N:#radix_E:input_E:#radix_D:input_D:#radix_DP:input_DP:#radix_DQ:input_DQ:#radix_QP:input_QP:#result
/* BEGIN_CASE */
void rsa_check_privkey( int mod, int radix_P, char *input_P, int radix_Q,
char *input_Q, int radix_N, char *input_N,
int radix_E, char *input_E, int radix_D, char *input_D,
int radix_DP, char *input_DP, int radix_DQ,
char *input_DQ, int radix_QP, char *input_QP,
int result )
{
rsa_context ctx;
rsa_init( &ctx, RSA_PKCS_V15, 0 );
ctx.len = {mod} / 8;
if( strlen( {input_P} ) )
ctx.len = mod / 8;
if( strlen( input_P ) )
{
TEST_ASSERT( mpi_read_string( &ctx.P, {radix_P}, {input_P} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
}
if( strlen( {input_Q} ) )
if( strlen( input_Q ) )
{
TEST_ASSERT( mpi_read_string( &ctx.Q, {radix_Q}, {input_Q} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
}
if( strlen( {input_N} ) )
if( strlen( input_N ) )
{
TEST_ASSERT( mpi_read_string( &ctx.N, {radix_N}, {input_N} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
}
if( strlen( {input_E} ) )
if( strlen( input_E ) )
{
TEST_ASSERT( mpi_read_string( &ctx.E, {radix_E}, {input_E} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
}
if( strlen( {input_D} ) )
if( strlen( input_D ) )
{
TEST_ASSERT( mpi_read_string( &ctx.D, {radix_D}, {input_D} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.D, radix_D, input_D ) == 0 );
}
if( strlen( {input_DP} ) )
if( strlen( input_DP ) )
{
TEST_ASSERT( mpi_read_string( &ctx.DP, {radix_DP}, {input_DP} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.DP, radix_DP, input_DP ) == 0 );
}
if( strlen( {input_DQ} ) )
if( strlen( input_DQ ) )
{
TEST_ASSERT( mpi_read_string( &ctx.DQ, {radix_DQ}, {input_DQ} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.DQ, radix_DQ, input_DQ ) == 0 );
}
if( strlen( {input_QP} ) )
if( strlen( input_QP ) )
{
TEST_ASSERT( mpi_read_string( &ctx.QP, {radix_QP}, {input_QP} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx.QP, radix_QP, input_QP ) == 0 );
}
TEST_ASSERT( rsa_check_privkey( &ctx ) == {result} );
TEST_ASSERT( rsa_check_privkey( &ctx ) == result );
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_gen_key:#nrbits:#exponent:#result
/* BEGIN_CASE */
void rsa_gen_key( int nrbits, int exponent, int result)
{
rsa_context ctx;
entropy_context entropy;
@ -476,19 +506,19 @@ rsa_gen_key:#nrbits:#exponent:#result
rsa_init( &ctx, 0, 0 );
TEST_ASSERT( rsa_gen_key( &ctx, ctr_drbg_random, &ctr_drbg, {nrbits}, {exponent} ) == {result} );
if( {result} == 0 )
TEST_ASSERT( rsa_gen_key( &ctx, ctr_drbg_random, &ctr_drbg, nrbits, exponent ) == result );
if( result == 0 )
{
TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
}
rsa_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
rsa_selftest:
/* BEGIN_CASE */
void rsa_selftest()
{
TEST_ASSERT( rsa_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,11 +1,11 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/sha1.h>
#include <polarssl/sha256.h>
#include <polarssl/sha512.h>
END_HEADER
/* END_HEADER */
BEGIN_CASE
sha1:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha1( char *hex_src_string, char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char hash_str[10000];
@ -16,17 +16,17 @@ sha1:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 41);
src_len = unhexify( src_str, {hex_src_string} );
src_len = unhexify( src_str, hex_src_string );
sha1( src_str, src_len, output );
hexify( hash_str, output, 20 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha224:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha224(char *hex_src_string, char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char hash_str[10000];
@ -37,17 +37,17 @@ sha224:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 57);
src_len = unhexify( src_str, {hex_src_string} );
src_len = unhexify( src_str, hex_src_string );
sha256( src_str, src_len, output, 1 );
hexify( hash_str, output, 28 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha256:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha256(char *hex_src_string, char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char hash_str[10000];
@ -58,17 +58,17 @@ sha256:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 65);
src_len = unhexify( src_str, {hex_src_string} );
src_len = unhexify( src_str, hex_src_string );
sha256( src_str, src_len, output, 0 );
hexify( hash_str, output, 32 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha384:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha384(char *hex_src_string, char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char hash_str[10000];
@ -79,17 +79,17 @@ sha384:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 97);
src_len = unhexify( src_str, {hex_src_string} );
src_len = unhexify( src_str, hex_src_string );
sha512( src_str, src_len, output, 1 );
hexify( hash_str, output, 48 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha512:hex_src_string:hex_hash_string
/* BEGIN_CASE */
void sha512(char *hex_src_string, char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char hash_str[10000];
@ -100,17 +100,17 @@ sha512:hex_src_string:hex_hash_string
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 129);
src_len = unhexify( src_str, {hex_src_string} );
src_len = unhexify( src_str, hex_src_string );
sha512( src_str, src_len, output, 0);
hexify( hash_str, output, 64 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha1_file:filename:hex_hash_string
/* BEGIN_CASE */
void sha1_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[41];
unsigned char output[21];
@ -118,15 +118,15 @@ sha1_file:filename:hex_hash_string
memset(hash_str, 0x00, 41);
memset(output, 0x00, 21);
sha1_file( {filename}, output);
sha1_file( filename, output);
hexify( hash_str, output, 20 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha224_file:filename:hex_hash_string
/* BEGIN_CASE */
void sha224_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[57];
unsigned char output[29];
@ -134,15 +134,15 @@ sha224_file:filename:hex_hash_string
memset(hash_str, 0x00, 57);
memset(output, 0x00, 29);
sha256_file( {filename}, output, 1);
sha256_file( filename, output, 1);
hexify( hash_str, output, 28 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha256_file:filename:hex_hash_string
/* BEGIN_CASE */
void sha256_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[65];
unsigned char output[33];
@ -150,15 +150,15 @@ sha256_file:filename:hex_hash_string
memset(hash_str, 0x00, 65);
memset(output, 0x00, 33);
sha256_file( {filename}, output, 0);
sha256_file( filename, output, 0);
hexify( hash_str, output, 32 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha384_file:filename:hex_hash_string
/* BEGIN_CASE */
void sha384_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[97];
unsigned char output[49];
@ -166,15 +166,15 @@ sha384_file:filename:hex_hash_string
memset(hash_str, 0x00, 97);
memset(output, 0x00, 49);
sha512_file( {filename}, output, 1);
sha512_file( filename, output, 1);
hexify( hash_str, output, 48 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha512_file:filename:hex_hash_string
/* BEGIN_CASE */
void sha512_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[129];
unsigned char output[65];
@ -182,30 +182,30 @@ sha512_file:filename:hex_hash_string
memset(hash_str, 0x00, 129);
memset(output, 0x00, 65);
sha512_file( {filename}, output, 0);
sha512_file( filename, output, 0);
hexify( hash_str, output, 64 );
TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha1_selftest:
/* BEGIN_CASE */
void sha1_selftest()
{
TEST_ASSERT( sha1_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha256_selftest:
/* BEGIN_CASE */
void sha256_selftest()
{
TEST_ASSERT( sha256_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
sha512_selftest:
/* BEGIN_CASE */
void sha512_selftest()
{
TEST_ASSERT( sha512_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,14 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/version.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_VERSION_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_VERSION_C
* END_DEPENDENCIES
*/
BEGIN_CASE
check_compiletime_version:version_str
/* BEGIN_CASE */
void check_compiletime_version( char *version_str )
{
char build_str[100];
char build_str_full[100];
@ -29,12 +30,12 @@ check_compiletime_version:version_str
TEST_ASSERT( build_int == POLARSSL_VERSION_NUMBER );
TEST_ASSERT( strcmp( build_str, POLARSSL_VERSION_STRING ) == 0 );
TEST_ASSERT( strcmp( build_str_full, POLARSSL_VERSION_STRING_FULL ) == 0 );
TEST_ASSERT( strcmp( {version_str}, POLARSSL_VERSION_STRING ) == 0 );
TEST_ASSERT( strcmp( version_str, POLARSSL_VERSION_STRING ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
check_runtime_version:version_str
/* BEGIN_CASE */
void check_runtime_version( char *version_str )
{
char build_str[100];
char get_str[100];
@ -55,10 +56,10 @@ check_runtime_version:version_str
(get_int >> 24) & 0xFF,
(get_int >> 16) & 0xFF,
(get_int >> 8) & 0xFF );
snprintf( build_str_full, 100, "PolarSSL %s", {version_str} );
snprintf( build_str_full, 100, "PolarSSL %s", version_str );
TEST_ASSERT( strcmp( build_str, {version_str} ) == 0 );
TEST_ASSERT( strcmp( build_str, version_str ) == 0 );
TEST_ASSERT( strcmp( build_str_full, get_str_full ) == 0 );
TEST_ASSERT( strcmp( {version_str}, get_str ) == 0 );
TEST_ASSERT( strcmp( version_str, get_str ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,4 +1,4 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/x509.h>
#include <polarssl/pem.h>
#include <polarssl/oid.h>
@ -23,14 +23,15 @@ int verify_all( void *data, x509_cert *crt, int certificate_depth, int *flags )
return 0;
}
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_X509_PARSE_C:POLARSSL_BIGNUM_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_X509_PARSE_C:POLARSSL_BIGNUM_C
* END_DEPENDENCIES
*/
BEGIN_CASE
x509_cert_info:crt_file:result_str
/* BEGIN_CASE */
void x509_cert_info( char *crt_file, char *result_str )
{
x509_cert crt;
char buf[2000];
@ -39,7 +40,7 @@ x509_cert_info:crt_file:result_str
memset( &crt, 0, sizeof( x509_cert ) );
memset( buf, 0, 2000 );
TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
res = x509parse_cert_info( buf, 2000, "", &crt );
x509_free( &crt );
@ -47,12 +48,12 @@ x509_cert_info:crt_file:result_str
TEST_ASSERT( res != -1 );
TEST_ASSERT( res != -2 );
TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
TEST_ASSERT( strcmp( buf, result_str ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509_crl_info:crl_file:result_str
/* BEGIN_CASE */
void x509_crl_info( char *crl_file, char *result_str )
{
x509_crl crl;
char buf[2000];
@ -61,7 +62,7 @@ x509_crl_info:crl_file:result_str
memset( &crl, 0, sizeof( x509_crl ) );
memset( buf, 0, 2000 );
TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
TEST_ASSERT( x509parse_crlfile( &crl, crl_file ) == 0 );
res = x509parse_crl_info( buf, 2000, "", &crl );
x509_crl_free( &crl );
@ -69,12 +70,14 @@ x509_crl_info:crl_file:result_str
TEST_ASSERT( res != -1 );
TEST_ASSERT( res != -2 );
TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
TEST_ASSERT( strcmp( buf, result_str ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509_verify:crt_file:ca_file:crl_file:cn_name_str:#result:#flags_result:verify_callback
/* BEGIN_CASE */
void x509_verify( char *crt_file, char *ca_file, char *crl_file,
char *cn_name_str, int result, int flags_result,
char *verify_callback )
{
x509_cert crt;
x509_cert ca;
@ -88,21 +91,21 @@ x509_verify:crt_file:ca_file:crl_file:cn_name_str:#result:#flags_result:verify_c
memset( &ca, 0, sizeof( x509_cert ) );
memset( &crl, 0, sizeof( x509_crl ) );
if( strcmp( {cn_name_str}, "NULL" ) != 0 )
cn_name = {cn_name_str};
if( strcmp( cn_name_str, "NULL" ) != 0 )
cn_name = cn_name_str;
if( strcmp( {verify_callback}, "NULL" ) == 0 )
if( strcmp( verify_callback, "NULL" ) == 0 )
f_vrfy = NULL;
else if( strcmp( {verify_callback}, "verify_none" ) == 0 )
else if( strcmp( verify_callback, "verify_none" ) == 0 )
f_vrfy = verify_none;
else if( strcmp( {verify_callback}, "verify_all" ) == 0 )
else if( strcmp( verify_callback, "verify_all" ) == 0 )
f_vrfy = verify_all;
else
TEST_ASSERT( "No known verify callback selected" == 0 );
TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
TEST_ASSERT( x509parse_crtfile( &ca, {ca_file} ) == 0 );
TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
TEST_ASSERT( x509parse_crtfile( &ca, ca_file ) == 0 );
TEST_ASSERT( x509parse_crlfile( &crl, crl_file ) == 0 );
res = x509parse_verify( &crt, &ca, &crl, cn_name, &flags, f_vrfy, NULL );
@ -110,13 +113,13 @@ x509_verify:crt_file:ca_file:crl_file:cn_name_str:#result:#flags_result:verify_c
x509_free( &ca );
x509_crl_free( &crl );
TEST_ASSERT( res == ( {result} ) );
TEST_ASSERT( flags == ( {flags_result} ) );
TEST_ASSERT( res == ( result ) );
TEST_ASSERT( flags == ( flags_result ) );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509_dn_gets:crt_file:entity:result_str
/* BEGIN_CASE */
void x509_dn_gets( char *crt_file, char *entity, char *result_str )
{
x509_cert crt;
char buf[2000];
@ -125,10 +128,10 @@ x509_dn_gets:crt_file:entity:result_str
memset( &crt, 0, sizeof( x509_cert ) );
memset( buf, 0, 2000 );
TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
if( strcmp( {entity}, "subject" ) == 0 )
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
if( strcmp( entity, "subject" ) == 0 )
res = x509parse_dn_gets( buf, 2000, &crt.subject );
else if( strcmp( {entity}, "issuer" ) == 0 )
else if( strcmp( entity, "issuer" ) == 0 )
res = x509parse_dn_gets( buf, 2000, &crt.issuer );
else
TEST_ASSERT( "Unknown entity" == 0 );
@ -138,45 +141,45 @@ x509_dn_gets:crt_file:entity:result_str
TEST_ASSERT( res != -1 );
TEST_ASSERT( res != -2 );
TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
TEST_ASSERT( strcmp( buf, result_str ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509_time_expired:crt_file:entity:#result
/* BEGIN_CASE */
void x509_time_expired( char *crt_file, char *entity, int result )
{
x509_cert crt;
memset( &crt, 0, sizeof( x509_cert ) );
TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
if( strcmp( {entity}, "valid_from" ) == 0 )
TEST_ASSERT( x509parse_time_expired( &crt.valid_from ) == {result} );
else if( strcmp( {entity}, "valid_to" ) == 0 )
TEST_ASSERT( x509parse_time_expired( &crt.valid_to ) == {result} );
if( strcmp( entity, "valid_from" ) == 0 )
TEST_ASSERT( x509parse_time_expired( &crt.valid_from ) == result );
else if( strcmp( entity, "valid_to" ) == 0 )
TEST_ASSERT( x509parse_time_expired( &crt.valid_to ) == result );
else
TEST_ASSERT( "Unknown entity" == 0 );
x509_free( &crt );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509parse_keyfile_rsa:key_file:password:#result
/* BEGIN_CASE */
void x509parse_keyfile_rsa( char *key_file, char *password, int result )
{
rsa_context rsa;
int res;
char *pwd = {password};
char *pwd = password;
memset( &rsa, 0, sizeof( rsa_context ) );
if( strcmp( pwd, "NULL" ) == 0 )
pwd = NULL;
res = x509parse_keyfile_rsa( &rsa, {key_file}, pwd );
res = x509parse_keyfile_rsa( &rsa, key_file, pwd );
TEST_ASSERT( res == {result} );
TEST_ASSERT( res == result );
if( res == 0 )
{
@ -185,19 +188,19 @@ x509parse_keyfile_rsa:key_file:password:#result
rsa_free( &rsa );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509parse_public_keyfile_rsa:key_file:#result
/* BEGIN_CASE */
void x509parse_public_keyfile_rsa( char *key_file, int result )
{
rsa_context rsa;
int res;
memset( &rsa, 0, sizeof( rsa_context ) );
res = x509parse_public_keyfile_rsa( &rsa, {key_file} );
res = x509parse_public_keyfile_rsa( &rsa, key_file );
TEST_ASSERT( res == {result} );
TEST_ASSERT( res == result );
if( res == 0 )
{
@ -206,19 +209,19 @@ x509parse_public_keyfile_rsa:key_file:#result
rsa_free( &rsa );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509parse_public_keyfile_ec:key_file:#result
/* BEGIN_CASE */
void x509parse_public_keyfile_ec( char *key_file, int result )
{
pk_context ctx;
int res;
pk_init( &ctx );
res = x509parse_public_keyfile( &ctx, {key_file} );
res = x509parse_public_keyfile( &ctx, key_file );
TEST_ASSERT( res == {result} );
TEST_ASSERT( res == result );
if( res == 0 )
{
@ -230,19 +233,19 @@ x509parse_public_keyfile_ec:key_file:#result
pk_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509parse_keyfile_ec:key_file:password:#result
/* BEGIN_CASE */
void x509parse_keyfile_ec( char *key_file, char *password, int result )
{
pk_context ctx;
int res;
pk_init( &ctx );
res = x509parse_keyfile( &ctx, {key_file}, {password} );
res = x509parse_keyfile( &ctx, key_file, password );
TEST_ASSERT( res == {result} );
TEST_ASSERT( res == result );
if( res == 0 )
{
@ -254,10 +257,10 @@ x509parse_keyfile_ec:key_file:password:#result
pk_free( &ctx );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509parse_crt:crt_data:result_str:#result
/* BEGIN_CASE */
void x509parse_crt( char *crt_data, char *result_str, int result )
{
x509_cert crt;
unsigned char buf[2000];
@ -268,25 +271,25 @@ x509parse_crt:crt_data:result_str:#result
memset( buf, 0, 2000 );
memset( output, 0, 2000 );
data_len = unhexify( buf, {crt_data} );
data_len = unhexify( buf, crt_data );
TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( {result} ) );
if( ( {result} ) == 0 )
TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( result ) );
if( ( result ) == 0 )
{
res = x509parse_cert_info( (char *) output, 2000, "", &crt );
TEST_ASSERT( res != -1 );
TEST_ASSERT( res != -2 );
TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
}
x509_free( &crt );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509parse_crl:crl_data:result_str:#result
/* BEGIN_CASE */
void x509parse_crl( char *crl_data, char *result_str, int result )
{
x509_crl crl;
unsigned char buf[2000];
@ -297,25 +300,25 @@ x509parse_crl:crl_data:result_str:#result
memset( buf, 0, 2000 );
memset( output, 0, 2000 );
data_len = unhexify( buf, {crl_data} );
data_len = unhexify( buf, crl_data );
TEST_ASSERT( x509parse_crl( &crl, buf, data_len ) == ( {result} ) );
if( ( {result} ) == 0 )
TEST_ASSERT( x509parse_crl( &crl, buf, data_len ) == ( result ) );
if( ( result ) == 0 )
{
res = x509parse_crl_info( (char *) output, 2000, "", &crl );
TEST_ASSERT( res != -1 );
TEST_ASSERT( res != -2 );
TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
}
x509_crl_free( &crl );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509parse_key_rsa:key_data:result_str:#result
/* BEGIN_CASE */
void x509parse_key_rsa( char *key_data, char *result_str, int result )
{
rsa_context rsa;
unsigned char buf[2000];
@ -327,21 +330,21 @@ x509parse_key_rsa:key_data:result_str:#result
memset( buf, 0, 2000 );
memset( output, 0, 2000 );
data_len = unhexify( buf, {key_data} );
data_len = unhexify( buf, key_data );
TEST_ASSERT( x509parse_key_rsa( &rsa, buf, data_len, NULL, 0 ) == ( {result} ) );
if( ( {result} ) == 0 )
TEST_ASSERT( x509parse_key_rsa( &rsa, buf, data_len, NULL, 0 ) == ( result ) );
if( ( result ) == 0 )
{
TEST_ASSERT( 1 );
}
rsa_free( &rsa );
}
END_CASE
/* END_CASE */
BEGIN_CASE
x509_selftest:
/* BEGIN_CASE */
void x509_selftest()
{
TEST_ASSERT( x509_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */

View File

@ -1,16 +1,18 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/x509write.h>
#include <polarssl/x509.h>
#include <polarssl/pem.h>
#include <polarssl/oid.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_X509_WRITE_C:POLARSSL_BIGNUM_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_X509_WRITE_C:POLARSSL_BIGNUM_C
* END_DEPENDENCIES
*/
BEGIN_CASE
x509_cert_req_check:key_file:#md_type:cert_req_check_file
/* BEGIN_CASE */
void x509_cert_req_check( char *key_file, int md_type,
char *cert_req_check_file )
{
rsa_context rsa;
pem_context pem;
@ -41,17 +43,17 @@ x509_cert_req_check:key_file:#md_type:cert_req_check_file
strcpy( cur->name, "NL" );
memset( &rsa, 0, sizeof(rsa_context) );
ret = x509parse_keyfile_rsa( &rsa, {key_file}, NULL );
ret = x509parse_keyfile_rsa( &rsa, key_file, NULL );
TEST_ASSERT( ret == 0 );
if( ret != 0 )
return 0;
return;
ret = x509_write_cert_req( buf, 4000, &rsa, &req_name, {md_type} );
ret = x509_write_cert_req( buf, 4000, &rsa, &req_name, md_type );
TEST_ASSERT( ret >= 0 );
c = buf + 3999 - ret;
f = fopen( {cert_req_check_file}, "r" );
f = fopen( cert_req_check_file, "r" );
TEST_ASSERT( f != NULL );
fread( check_buf, 1, 4000, f );
fclose( f );
@ -71,4 +73,4 @@ x509_cert_req_check:key_file:#md_type:cert_req_check_file
rsa_free( &rsa );
pem_free( &pem );
}
END_CASE
/* END_CASE */

View File

@ -1,13 +1,15 @@
BEGIN_HEADER
/* BEGIN_HEADER */
#include <polarssl/xtea.h>
END_HEADER
/* END_HEADER */
BEGIN_DEPENDENCIES
depends_on:POLARSSL_XTEA_C
END_DEPENDENCIES
/* BEGIN_DEPENDENCIES
*depends_on:POLARSSL_XTEA_C
* END_DEPENDENCIES
*/
BEGIN_CASE
xtea_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void xtea_encrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -20,19 +22,20 @@ xtea_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
xtea_setup( &ctx, key_str );
TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
xtea_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
/* BEGIN_CASE */
void xtea_decrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string )
{
unsigned char key_str[100];
unsigned char src_str[100];
@ -45,20 +48,20 @@ xtea_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
unhexify( key_str, {hex_key_string} );
unhexify( src_str, {hex_src_string} );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
xtea_setup( &ctx, key_str );
TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_DECRYPT, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
}
END_CASE
/* END_CASE */
BEGIN_CASE
xtea_selftest:
/* BEGIN_CASE */
void xtea_selftest()
{
TEST_ASSERT( xtea_self_test( 0 ) == 0 );
}
END_CASE
/* END_CASE */