Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
external
mbedtls
Commits
33b43f1e
Commit
33b43f1e
authored
Aug 20, 2013
by
Paul Bakker
Browse files
Converted .function file to c-like format and adapted generator code
parent
55a7e908
Changes
30
Hide whitespace changes
Inline
Side-by-side
tests/scripts/generate_code.pl
View file @
33b43f1e
...
...
@@ -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(.*?)\
}\n
END_CASE
/
sg
)
while
(
$test_cases
=~
/
\/\*
BEGIN_CASE *([\w:]*)
\*\/
\n(.*?)\
n\/\*
END_CASE
\*\//m
sg
)
{
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
], ¶m
$i
) != 0 ) return( 2 );
\n
";
push
@dispatch_params
,
"
param
$i
";
$def
=~
s/#//
;
push
@param_decl
,
"
int
$def
";
$mapping_regex
.=
"
:([
\\
d
\\
w |
\\
+
\\
-
\\
(
\\
)]+)
";
$mapping_count
++
;
}
els
e
els
if
(
substr
(
$def
,
0
,
6
)
eq
"
char *
"
)
{
$param_defs
.=
"
char *param
$i
= params[
$i
];
\n
";
$param_checks
.=
"
if( verify_string( ¶m
$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
...
...
tests/suites/main_test.function
View file @
33b43f1e
...
...
@@ -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 );
...
...
tests/suites/test_suite_aes.function
View file @
33b43f1e
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
*/
tests/suites/test_suite_arc4.function
View file @
33b43f1e
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
*/
tests/suites/test_suite_base64.function
View file @
33b43f1e
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
*/
tests/suites/test_suite_blowfish.function
View file @
33b43f1e
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 );