mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 17:15:38 +01:00
Merge pull request #3474 from ronald-cron-arm/common-mbedtls_param_failed
Common mbedtls_param_failed()
This commit is contained in:
commit
ef94c4fcf4
@ -317,18 +317,6 @@ static void cipher_examples( void )
|
||||
printf( "\tsuccess!\r\n" );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
#include "mbedtls/platform_util.h"
|
||||
void mbedtls_param_failed( const char *failure_condition,
|
||||
const char *file,
|
||||
int line )
|
||||
{
|
||||
printf( "%s:%i: Input param failed - %s\n",
|
||||
file, line, failure_condition );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
#endif
|
||||
|
||||
int main( void )
|
||||
{
|
||||
ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||
|
@ -603,18 +603,6 @@ static void usage( void )
|
||||
printf( " and the same sequence of labels.\n" );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
#include "mbedtls/platform_util.h"
|
||||
void mbedtls_param_failed( const char *failure_condition,
|
||||
const char *file,
|
||||
int line )
|
||||
{
|
||||
printf( "%s:%i: Input param failed - %s\n",
|
||||
file, line, failure_condition );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
#endif
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
const char *key_file_name = "master.key";
|
||||
|
@ -53,10 +53,8 @@ int mbedtls_test_platform_setup( void );
|
||||
void mbedtls_test_platform_teardown( void );
|
||||
|
||||
/**
|
||||
* \brief This function translates an ASCII string encoding an
|
||||
* hexadecimal number into the encoded hexadecimal number. The
|
||||
* hexadecimal number is represented as an array of
|
||||
* unsigned char.
|
||||
* \brief This function decodes the hexadecimal representation of
|
||||
* data.
|
||||
*
|
||||
* \note The output buffer can be the same as the input buffer. For
|
||||
* any other overlapping of the input and output buffers, the
|
||||
@ -70,7 +68,7 @@ void mbedtls_test_platform_teardown( void );
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return \c -1 if the output buffer is too small or the input string
|
||||
* is not a valid ASCII encoding of an hexadecimal number.
|
||||
* is not a valid hexadecimal representation.
|
||||
*/
|
||||
int mbedtls_test_unhexify( unsigned char *obuf, size_t obufmax,
|
||||
const char *ibuf, size_t *len );
|
||||
@ -103,4 +101,93 @@ unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen );
|
||||
int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
|
||||
uint32_t a_len, uint32_t b_len );
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *failure_condition;
|
||||
const char *file;
|
||||
int line;
|
||||
}
|
||||
mbedtls_test_param_failed_location_record_t;
|
||||
|
||||
/**
|
||||
* \brief Get the location record of the last call to
|
||||
* mbedtls_test_param_failed().
|
||||
*
|
||||
* \note The call expectation is set up and active until the next call to
|
||||
* mbedtls_test_param_failed_check_expected_call() or
|
||||
* mbedtls_param_failed() that cancels it.
|
||||
*/
|
||||
void mbedtls_test_param_failed_get_location_record(
|
||||
mbedtls_test_param_failed_location_record_t *location_record );
|
||||
|
||||
/**
|
||||
* \brief State that a call to mbedtls_param_failed() is expected.
|
||||
*
|
||||
* \note The call expectation is set up and active until the next call to
|
||||
* mbedtls_test_param_failed_check_expected_call() or
|
||||
* mbedtls_param_failed that cancel it.
|
||||
*/
|
||||
void mbedtls_test_param_failed_expect_call( void );
|
||||
|
||||
/**
|
||||
* \brief Check whether mbedtls_param_failed() has been called as expected.
|
||||
*
|
||||
* \note Check whether mbedtls_param_failed() has been called between the
|
||||
* last call to mbedtls_test_param_failed_expect_call() and the call
|
||||
* to this function.
|
||||
*
|
||||
* \return \c 0 Since the last call to mbedtls_param_failed_expect_call(),
|
||||
* mbedtls_param_failed() has been called.
|
||||
* \c -1 Otherwise.
|
||||
*/
|
||||
int mbedtls_test_param_failed_check_expected_call( void );
|
||||
|
||||
/**
|
||||
* \brief Get the address of the object of type jmp_buf holding the execution
|
||||
* state information used by mbedtls_param_failed() to do a long jump.
|
||||
*
|
||||
* \note If a call to mbedtls_param_failed() is not expected in the sense
|
||||
* that there is no call to mbedtls_test_param_failed_expect_call()
|
||||
* preceding it, then mbedtls_param_failed() will try to restore the
|
||||
* execution to the state stored in the jmp_buf object whose address
|
||||
* is returned by the present function.
|
||||
*
|
||||
* \note This function is intended to provide the parameter of the
|
||||
* setjmp() function to set-up where mbedtls_param_failed() should
|
||||
* long-jump if it has to. It is foreseen to be used as:
|
||||
*
|
||||
* setjmp( mbedtls_test_param_failed_get_state_buf() ).
|
||||
*
|
||||
* \note The type of the returned value is not jmp_buf as jmp_buf is an
|
||||
* an array type (C specification) and a function cannot return an
|
||||
* array type.
|
||||
*
|
||||
* \note The type of the returned value is not jmp_buf* as then the return
|
||||
* value couldn't be used by setjmp(), as its parameter's type is
|
||||
* jmp_buf.
|
||||
*
|
||||
* \return Address of the object of type jmp_buf holding the execution state
|
||||
* information used by mbedtls_param_failed() to do a long jump.
|
||||
*/
|
||||
void* mbedtls_test_param_failed_get_state_buf( void );
|
||||
|
||||
/**
|
||||
* \brief Reset the execution state used by mbedtls_param_failed() to do a
|
||||
* long jump.
|
||||
*
|
||||
* \note If a call to mbedtls_param_failed() is not expected in the sense
|
||||
* that there is no call to mbedtls_test_param_failed_expect_call()
|
||||
* preceding it, then mbedtls_param_failed() will try to restore the
|
||||
* execution state that this function reset.
|
||||
*
|
||||
* \note It is recommended to reset the execution state when the state
|
||||
* is not relevant anymore. That way an unexpected call to
|
||||
* mbedtls_param_failed() will not trigger a long jump with
|
||||
* undefined behavior but rather a long jump that will rather fault.
|
||||
*/
|
||||
void mbedtls_test_param_failed_reset_state( void );
|
||||
#endif /* MBEDTLS_CHECK_PARAMS */
|
||||
|
||||
#endif /* TEST_HELPERS_H */
|
||||
|
@ -1295,9 +1295,7 @@ component_test_check_params_functionality () {
|
||||
scripts/config.py full # includes CHECK_PARAMS
|
||||
# Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
|
||||
scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
|
||||
# Only build and run tests. Do not build sample programs, because
|
||||
# they don't have a mbedtls_param_failed() function.
|
||||
make CC=gcc CFLAGS='-Werror -O1' lib test
|
||||
make CC=gcc CFLAGS='-Werror -O1' all test
|
||||
}
|
||||
|
||||
component_test_check_params_without_platform () {
|
||||
|
@ -19,10 +19,34 @@
|
||||
#include <test/macros.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
#include <setjmp.h>
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Static global variables */
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t expected_call;
|
||||
uint8_t expected_call_happened;
|
||||
|
||||
jmp_buf state;
|
||||
|
||||
mbedtls_test_param_failed_location_record_t location_record;
|
||||
}
|
||||
param_failed_ctx_t;
|
||||
static param_failed_ctx_t param_failed_ctx;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
static mbedtls_platform_context platform_ctx;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
|
||||
int mbedtls_test_platform_setup( void )
|
||||
{
|
||||
int ret = 0;
|
||||
@ -159,3 +183,64 @@ int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
void mbedtls_test_param_failed_get_location_record(
|
||||
mbedtls_test_param_failed_location_record_t *location_record )
|
||||
{
|
||||
*location_record = param_failed_ctx.location_record;
|
||||
}
|
||||
|
||||
void mbedtls_test_param_failed_expect_call( void )
|
||||
{
|
||||
param_failed_ctx.expected_call_happened = 0;
|
||||
param_failed_ctx.expected_call = 1;
|
||||
}
|
||||
|
||||
int mbedtls_test_param_failed_check_expected_call( void )
|
||||
{
|
||||
param_failed_ctx.expected_call = 0;
|
||||
|
||||
if( param_failed_ctx.expected_call_happened != 0 )
|
||||
return( 0 );
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
void* mbedtls_test_param_failed_get_state_buf( void )
|
||||
{
|
||||
return ¶m_failed_ctx.state;
|
||||
}
|
||||
|
||||
void mbedtls_test_param_failed_reset_state( void )
|
||||
{
|
||||
memset( param_failed_ctx.state, 0, sizeof( param_failed_ctx.state ) );
|
||||
}
|
||||
|
||||
void mbedtls_param_failed( const char *failure_condition,
|
||||
const char *file,
|
||||
int line )
|
||||
{
|
||||
/* Record the location of the failure */
|
||||
param_failed_ctx.location_record.failure_condition = failure_condition;
|
||||
param_failed_ctx.location_record.file = file;
|
||||
param_failed_ctx.location_record.line = line;
|
||||
|
||||
/* If we are testing the callback function... */
|
||||
if( param_failed_ctx.expected_call != 0 )
|
||||
{
|
||||
param_failed_ctx.expected_call = 0;
|
||||
param_failed_ctx.expected_call_happened = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ...else try a long jump. If the execution state has not been set-up
|
||||
* or reset then the long jump buffer is all zero's and the call will
|
||||
* with high probability fault, emphasizing there is something to look
|
||||
* at.
|
||||
*/
|
||||
|
||||
longjmp( param_failed_ctx.state, 1 );
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_CHECK_PARAMS */
|
||||
|
@ -74,16 +74,6 @@ typedef struct data_tag
|
||||
#define DISPATCH_UNSUPPORTED_SUITE -5 /* Test suite not supported by the
|
||||
build */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PARAMFAIL_TESTSTATE_IDLE = 0, /* No parameter failure call test */
|
||||
PARAMFAIL_TESTSTATE_PENDING, /* Test call to the parameter failure
|
||||
* is pending */
|
||||
PARAMFAIL_TESTSTATE_CALLED /* The test call to the parameter
|
||||
* failure function has been made */
|
||||
} paramfail_test_state_t;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
|
||||
@ -237,15 +227,16 @@ typedef enum
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_INVALID_PARAM_RET( PARAM_ERR_VALUE, TEST ) \
|
||||
do { \
|
||||
test_info.paramfail_test_state = PARAMFAIL_TESTSTATE_PENDING; \
|
||||
if( (TEST) != (PARAM_ERR_VALUE) || \
|
||||
test_info.paramfail_test_state != PARAMFAIL_TESTSTATE_CALLED ) \
|
||||
{ \
|
||||
test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
goto exit; \
|
||||
} \
|
||||
#define TEST_INVALID_PARAM_RET( PARAM_ERR_VALUE, TEST ) \
|
||||
do { \
|
||||
mbedtls_test_param_failed_expect_call( ); \
|
||||
if( ( ( TEST ) != ( PARAM_ERR_VALUE ) ) || \
|
||||
( mbedtls_test_param_failed_check_expected_call( ) != 0 ) ) \
|
||||
{ \
|
||||
test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
goto exit; \
|
||||
} \
|
||||
mbedtls_test_param_failed_check_expected_call( ); \
|
||||
} while( 0 )
|
||||
|
||||
/**
|
||||
@ -268,16 +259,17 @@ typedef enum
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_INVALID_PARAM( TEST ) \
|
||||
do { \
|
||||
memcpy(jmp_tmp, param_fail_jmp, sizeof(jmp_buf)); \
|
||||
if( setjmp( param_fail_jmp ) == 0 ) \
|
||||
{ \
|
||||
TEST; \
|
||||
test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
goto exit; \
|
||||
} \
|
||||
memcpy(param_fail_jmp, jmp_tmp, sizeof(jmp_buf)); \
|
||||
#define TEST_INVALID_PARAM( TEST ) \
|
||||
do { \
|
||||
memcpy( jmp_tmp, mbedtls_test_param_failed_get_state_buf( ), \
|
||||
sizeof( jmp_tmp ) ); \
|
||||
if( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 ) \
|
||||
{ \
|
||||
TEST; \
|
||||
test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
goto exit; \
|
||||
} \
|
||||
mbedtls_test_param_failed_reset_state( ); \
|
||||
} while( 0 )
|
||||
#endif /* MBEDTLS_CHECK_PARAMS && !MBEDTLS_PARAM_FAILED_ALT */
|
||||
|
||||
@ -359,7 +351,6 @@ typedef enum
|
||||
|
||||
typedef struct
|
||||
{
|
||||
paramfail_test_state_t paramfail_test_state;
|
||||
test_result_t result;
|
||||
const char *test;
|
||||
const char *filename;
|
||||
@ -370,7 +361,6 @@ test_info_t;
|
||||
static test_info_t test_info;
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
jmp_buf param_fail_jmp;
|
||||
jmp_buf jmp_tmp;
|
||||
#endif
|
||||
|
||||
@ -427,30 +417,6 @@ void test_skip( const char *test, int line_no, const char* filename )
|
||||
test_info.filename = filename;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
void mbedtls_param_failed( const char *failure_condition,
|
||||
const char *file,
|
||||
int line )
|
||||
{
|
||||
/* If we are testing the callback function... */
|
||||
if( test_info.paramfail_test_state == PARAMFAIL_TESTSTATE_PENDING )
|
||||
{
|
||||
test_info.paramfail_test_state = PARAMFAIL_TESTSTATE_CALLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ...else we treat this as an error */
|
||||
|
||||
/* Record the location of the failure, but not as a failure yet, in case
|
||||
* it was part of the test */
|
||||
test_fail( failure_condition, line, file );
|
||||
test_info.result = TEST_RESULT_SUCCESS;
|
||||
|
||||
longjmp( param_fail_jmp, 1 );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
static int redirect_output( FILE* out_stream, const char* path )
|
||||
{
|
||||
|
@ -683,7 +683,6 @@ int execute_tests( int argc , const char ** argv )
|
||||
if( unmet_dep_count == 0 )
|
||||
{
|
||||
test_info.result = TEST_RESULT_SUCCESS;
|
||||
test_info.paramfail_test_state = PARAMFAIL_TESTSTATE_IDLE;
|
||||
test_info.step = (unsigned long)( -1 );
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
|
@ -165,17 +165,23 @@ $dispatch_code
|
||||
void execute_function_ptr(TestWrapper_t fp, void **params)
|
||||
{
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
if ( setjmp( param_fail_jmp ) == 0 )
|
||||
mbedtls_test_param_failed_location_record_t location_record;
|
||||
|
||||
if ( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 )
|
||||
{
|
||||
fp( params );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unexpected parameter validation error */
|
||||
mbedtls_test_param_failed_get_location_record( &location_record );
|
||||
test_fail( location_record.failure_condition,
|
||||
location_record.line,
|
||||
location_record.file );
|
||||
test_info.result = TEST_RESULT_FAILED;
|
||||
}
|
||||
|
||||
memset( param_fail_jmp, 0, sizeof(jmp_buf) );
|
||||
mbedtls_test_param_failed_reset_state( );
|
||||
#else
|
||||
fp( params );
|
||||
#endif
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aes_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string, int setkey_result )
|
||||
data_t * dst, int setkey_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_aes_context ctx;
|
||||
@ -23,8 +23,7 @@ void aes_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
{
|
||||
TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
16, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -34,7 +33,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aes_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string, int setkey_result )
|
||||
data_t * dst, int setkey_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_aes_context ctx;
|
||||
@ -48,8 +47,7 @@ void aes_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
{
|
||||
TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_DECRYPT, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
16, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -59,7 +57,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void aes_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string,
|
||||
data_t * src_str, data_t * dst,
|
||||
int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
@ -74,9 +72,8 @@ void aes_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -86,7 +83,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void aes_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string,
|
||||
data_t * src_str, data_t * dst,
|
||||
int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
@ -100,9 +97,8 @@ void aes_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
if( cbc_result == 0)
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -236,7 +232,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aes_encrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_aes_context ctx;
|
||||
@ -249,8 +245,7 @@ void aes_encrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
16, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_free( &ctx );
|
||||
@ -259,7 +254,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aes_decrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_aes_context ctx;
|
||||
@ -272,8 +267,7 @@ void aes_decrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
16, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_free( &ctx );
|
||||
@ -282,7 +276,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aes_encrypt_cfb8( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_aes_context ctx;
|
||||
@ -294,9 +288,8 @@ void aes_encrypt_cfb8( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_free( &ctx );
|
||||
@ -305,7 +298,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aes_decrypt_cfb8( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_aes_context ctx;
|
||||
@ -317,9 +310,8 @@ void aes_decrypt_cfb8( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_free( &ctx );
|
||||
@ -329,17 +321,15 @@ exit:
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_OFB */
|
||||
void aes_encrypt_ofb( int fragment_size, data_t *key_str,
|
||||
data_t *iv_str, data_t *src_str,
|
||||
char *expected_output_string)
|
||||
data_t *expected_output )
|
||||
{
|
||||
unsigned char output[32];
|
||||
unsigned char output_string[65];
|
||||
mbedtls_aes_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
int in_buffer_len;
|
||||
unsigned char* src_str_next;
|
||||
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_string, 0x00, sizeof( output_string ) );
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
TEST_ASSERT( (size_t)fragment_size < sizeof( output ) );
|
||||
@ -354,12 +344,10 @@ void aes_encrypt_ofb( int fragment_size, data_t *key_str,
|
||||
TEST_ASSERT( mbedtls_aes_crypt_ofb( &ctx, fragment_size, &iv_offset,
|
||||
iv_str->x, src_str_next, output ) == 0 );
|
||||
|
||||
mbedtls_test_hexify( output_string, output, fragment_size );
|
||||
TEST_ASSERT( strncmp( (char *) output_string, expected_output_string,
|
||||
( 2 * fragment_size ) ) == 0 );
|
||||
TEST_ASSERT( memcmp( output, expected_output->x, fragment_size ) == 0 );
|
||||
|
||||
in_buffer_len -= fragment_size;
|
||||
expected_output_string += ( fragment_size * 2 );
|
||||
expected_output->x += fragment_size;
|
||||
src_str_next += fragment_size;
|
||||
|
||||
if( in_buffer_len < fragment_size )
|
||||
|
@ -8,8 +8,7 @@
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_arc4_crypt( data_t * src_str, data_t * key_str,
|
||||
data_t * hex_dst_string )
|
||||
void mbedtls_arc4_crypt( data_t * src_str, data_t * key_str, data_t * dst )
|
||||
{
|
||||
unsigned char dst_str[1000];
|
||||
mbedtls_arc4_context ctx;
|
||||
@ -19,11 +18,11 @@ void mbedtls_arc4_crypt( data_t * src_str, data_t * key_str,
|
||||
|
||||
|
||||
mbedtls_arc4_setup(&ctx, key_str->x, key_str->len);
|
||||
TEST_ASSERT( mbedtls_arc4_crypt(&ctx, src_str->len, src_str->x, dst_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_arc4_crypt(&ctx, src_str->len,
|
||||
src_str->x, dst_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( dst_str, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( dst_str, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_arc4_free( &ctx );
|
||||
|
@ -207,14 +207,12 @@ exit:
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aria_encrypt_ecb( data_t *key_str, data_t *src_str,
|
||||
char *hex_dst_string, int setkey_result )
|
||||
data_t *expected_output, int setkey_result )
|
||||
{
|
||||
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
||||
unsigned char output[ARIA_MAX_DATASIZE];
|
||||
mbedtls_aria_context ctx;
|
||||
size_t i;
|
||||
|
||||
memset( dst_str, 0x00, sizeof( dst_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
mbedtls_aria_init( &ctx );
|
||||
|
||||
@ -227,9 +225,9 @@ void aria_encrypt_ecb( data_t *key_str, data_t *src_str,
|
||||
TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i,
|
||||
output + i ) == 0 );
|
||||
}
|
||||
mbedtls_test_hexify( dst_str, output, src_str->len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output->len,
|
||||
expected_output->x, expected_output->len );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -239,14 +237,12 @@ exit:
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aria_decrypt_ecb( data_t *key_str, data_t *src_str,
|
||||
char *hex_dst_string, int setkey_result )
|
||||
data_t *expected_output, int setkey_result )
|
||||
{
|
||||
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
||||
unsigned char output[ARIA_MAX_DATASIZE];
|
||||
mbedtls_aria_context ctx;
|
||||
size_t i;
|
||||
|
||||
memset( dst_str, 0x00, sizeof( dst_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
mbedtls_aria_init( &ctx );
|
||||
|
||||
@ -259,9 +255,9 @@ void aria_decrypt_ecb( data_t *key_str, data_t *src_str,
|
||||
TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i,
|
||||
output + i ) == 0 );
|
||||
}
|
||||
mbedtls_test_hexify( dst_str, output, src_str->len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output->len,
|
||||
expected_output->x, expected_output->len );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -271,14 +267,12 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void aria_encrypt_cbc( data_t *key_str, data_t *iv_str,
|
||||
data_t *src_str, char *hex_dst_string,
|
||||
data_t *src_str, data_t *expected_output,
|
||||
int cbc_result )
|
||||
{
|
||||
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
||||
unsigned char output[ARIA_MAX_DATASIZE];
|
||||
mbedtls_aria_context ctx;
|
||||
|
||||
memset( dst_str, 0x00, sizeof( dst_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
mbedtls_aria_init( &ctx );
|
||||
|
||||
@ -288,9 +282,8 @@ void aria_encrypt_cbc( data_t *key_str, data_t *iv_str,
|
||||
output ) == cbc_result );
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
mbedtls_test_hexify( dst_str, output, src_str->len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output->len,
|
||||
expected_output->x, expected_output->len );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -300,14 +293,12 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void aria_decrypt_cbc( data_t *key_str, data_t *iv_str,
|
||||
data_t *src_str, char *hex_dst_string,
|
||||
data_t *src_str, data_t *expected_output,
|
||||
int cbc_result )
|
||||
{
|
||||
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
||||
unsigned char output[ARIA_MAX_DATASIZE];
|
||||
mbedtls_aria_context ctx;
|
||||
|
||||
memset( dst_str, 0x00, sizeof( dst_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
mbedtls_aria_init( &ctx );
|
||||
|
||||
@ -317,9 +308,8 @@ void aria_decrypt_cbc( data_t *key_str, data_t *iv_str,
|
||||
output ) == cbc_result );
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
mbedtls_test_hexify( dst_str, output, src_str->len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output->len,
|
||||
expected_output->x, expected_output->len );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -329,15 +319,13 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aria_encrypt_cfb128( data_t *key_str, data_t *iv_str,
|
||||
data_t *src_str, char *hex_dst_string,
|
||||
data_t *src_str, data_t *expected_output,
|
||||
int result )
|
||||
{
|
||||
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
||||
unsigned char output[ARIA_MAX_DATASIZE];
|
||||
mbedtls_aria_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
|
||||
memset( dst_str, 0x00, sizeof( dst_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
mbedtls_aria_init( &ctx );
|
||||
|
||||
@ -346,9 +334,9 @@ void aria_encrypt_cfb128( data_t *key_str, data_t *iv_str,
|
||||
src_str->len, &iv_offset,
|
||||
iv_str->x, src_str->x, output )
|
||||
== result );
|
||||
mbedtls_test_hexify( dst_str, output, src_str->len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output->len,
|
||||
expected_output->x, expected_output->len );
|
||||
|
||||
exit:
|
||||
mbedtls_aria_free( &ctx );
|
||||
@ -357,15 +345,13 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aria_decrypt_cfb128( data_t *key_str, data_t *iv_str,
|
||||
data_t *src_str, char *hex_dst_string,
|
||||
data_t *src_str, data_t *expected_output,
|
||||
int result )
|
||||
{
|
||||
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
||||
unsigned char output[ARIA_MAX_DATASIZE];
|
||||
mbedtls_aria_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
|
||||
memset( dst_str, 0x00, sizeof( dst_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
mbedtls_aria_init( &ctx );
|
||||
|
||||
@ -374,9 +360,9 @@ void aria_decrypt_cfb128( data_t *key_str, data_t *iv_str,
|
||||
src_str->len, &iv_offset,
|
||||
iv_str->x, src_str->x, output )
|
||||
== result );
|
||||
mbedtls_test_hexify( dst_str, output, src_str->len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output->len,
|
||||
expected_output->x, expected_output->len );
|
||||
|
||||
exit:
|
||||
mbedtls_aria_free( &ctx );
|
||||
@ -385,16 +371,14 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
|
||||
void aria_encrypt_ctr( data_t *key_str, data_t *iv_str,
|
||||
data_t *src_str, char *hex_dst_string,
|
||||
data_t *src_str, data_t *expected_output,
|
||||
int result )
|
||||
{
|
||||
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
||||
unsigned char output[ARIA_MAX_DATASIZE];
|
||||
unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
|
||||
mbedtls_aria_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
|
||||
memset( dst_str, 0x00, sizeof( dst_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
mbedtls_aria_init( &ctx );
|
||||
|
||||
@ -402,9 +386,9 @@ void aria_encrypt_ctr( data_t *key_str, data_t *iv_str,
|
||||
TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset,
|
||||
iv_str->x, blk, src_str->x, output )
|
||||
== result );
|
||||
mbedtls_test_hexify( dst_str, output, src_str->len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output->len,
|
||||
expected_output->x, expected_output->len );
|
||||
|
||||
exit:
|
||||
mbedtls_aria_free( &ctx );
|
||||
@ -413,16 +397,14 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
|
||||
void aria_decrypt_ctr( data_t *key_str, data_t *iv_str,
|
||||
data_t *src_str, char *hex_dst_string,
|
||||
data_t *src_str, data_t *expected_output,
|
||||
int result )
|
||||
{
|
||||
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
||||
unsigned char output[ARIA_MAX_DATASIZE];
|
||||
unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
|
||||
mbedtls_aria_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
|
||||
memset( dst_str, 0x00, sizeof( dst_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
mbedtls_aria_init( &ctx );
|
||||
|
||||
@ -430,9 +412,9 @@ void aria_decrypt_ctr( data_t *key_str, data_t *iv_str,
|
||||
TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset,
|
||||
iv_str->x, blk, src_str->x, output )
|
||||
== result );
|
||||
mbedtls_test_hexify( dst_str, output, src_str->len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output->len,
|
||||
expected_output->x, expected_output->len );
|
||||
|
||||
exit:
|
||||
mbedtls_aria_free( &ctx );
|
||||
|
@ -167,7 +167,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void blowfish_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string, int setkey_result )
|
||||
data_t * dst, int setkey_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_blowfish_context ctx;
|
||||
@ -181,8 +181,7 @@ void blowfish_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
{
|
||||
TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
8, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -192,7 +191,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void blowfish_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string, int setkey_result )
|
||||
data_t * dst, int setkey_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_blowfish_context ctx;
|
||||
@ -206,8 +205,7 @@ void blowfish_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
{
|
||||
TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
8, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -217,7 +215,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void blowfish_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string,
|
||||
data_t * src_str, data_t * dst,
|
||||
int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
@ -233,9 +231,8 @@ void blowfish_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -245,7 +242,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void blowfish_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string,
|
||||
data_t * src_str, data_t * dst,
|
||||
int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
@ -260,9 +257,8 @@ void blowfish_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
if( cbc_result == 0)
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
|
||||
dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -272,8 +268,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void blowfish_encrypt_cfb64( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string
|
||||
)
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_blowfish_context ctx;
|
||||
@ -286,9 +281,8 @@ void blowfish_encrypt_cfb64( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->len, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
|
||||
dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_blowfish_free( &ctx );
|
||||
@ -297,8 +291,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void blowfish_decrypt_cfb64( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string
|
||||
)
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_blowfish_context ctx;
|
||||
@ -311,9 +304,8 @@ void blowfish_decrypt_cfb64( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->len, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
|
||||
dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_blowfish_free( &ctx );
|
||||
@ -322,7 +314,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
|
||||
void blowfish_encrypt_ctr( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char stream_str[100];
|
||||
unsigned char output[100];
|
||||
@ -337,9 +329,8 @@ void blowfish_encrypt_ctr( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_blowfish_crypt_ctr( &ctx, src_str->len, &iv_offset, iv_str->x, stream_str, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
|
||||
dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_blowfish_free( &ctx );
|
||||
|
@ -175,7 +175,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void camellia_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string, int setkey_result )
|
||||
data_t * dst, int setkey_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_camellia_context ctx;
|
||||
@ -189,8 +189,7 @@ void camellia_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
{
|
||||
TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
16, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -200,7 +199,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void camellia_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string, int setkey_result )
|
||||
data_t * dst, int setkey_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_camellia_context ctx;
|
||||
@ -214,8 +213,7 @@ void camellia_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
{
|
||||
TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
16, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -225,8 +223,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void camellia_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string,
|
||||
int cbc_result )
|
||||
data_t * src_str, data_t * dst, int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_camellia_context ctx;
|
||||
@ -240,9 +237,8 @@ void camellia_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
|
||||
dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -252,7 +248,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void camellia_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string,
|
||||
data_t * src_str, data_t * dst,
|
||||
int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
@ -267,9 +263,8 @@ void camellia_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
|
||||
dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -279,8 +274,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void camellia_encrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str,
|
||||
data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_camellia_context ctx;
|
||||
@ -293,8 +287,7 @@ void camellia_encrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
16, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_camellia_free( &ctx );
|
||||
@ -304,7 +297,7 @@ exit:
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void camellia_decrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str,
|
||||
data_t * hex_dst_string )
|
||||
data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_camellia_context ctx;
|
||||
@ -317,8 +310,7 @@ void camellia_decrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
16, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_camellia_free( &ctx );
|
||||
|
@ -152,7 +152,7 @@ exit:
|
||||
void mbedtls_ccm_auth_decrypt( int cipher_id, data_t * key,
|
||||
data_t * msg, data_t * iv,
|
||||
data_t * add, int tag_len, int result,
|
||||
data_t * hex_msg )
|
||||
data_t * expected_msg )
|
||||
{
|
||||
unsigned char tag[16];
|
||||
mbedtls_ccm_context ctx;
|
||||
@ -172,7 +172,7 @@ void mbedtls_ccm_auth_decrypt( int cipher_id, data_t * key,
|
||||
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( memcmp( msg->x, hex_msg->x, hex_msg->len ) == 0 );
|
||||
TEST_ASSERT( memcmp( msg->x, expected_msg->x, expected_msg->len ) == 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -17,13 +17,6 @@ void chacha20_crypt( data_t *key_str,
|
||||
unsigned char output[375];
|
||||
mbedtls_chacha20_context ctx;
|
||||
|
||||
/*
|
||||
* Buffers to store the ASCII string representation of output and
|
||||
* expected_output_str.
|
||||
*/
|
||||
unsigned char output_string[751] = { '\0' };
|
||||
unsigned char expected_output_string[751] = { '\0' };
|
||||
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( src_str->len == expected_output_str->len );
|
||||
@ -35,12 +28,8 @@ void chacha20_crypt( data_t *key_str,
|
||||
*/
|
||||
TEST_ASSERT( mbedtls_chacha20_crypt( key_str->x, nonce_str->x, counter, src_str->len, src_str->x, output ) == 0 );
|
||||
|
||||
mbedtls_test_hexify( expected_output_string,
|
||||
expected_output_str->x,
|
||||
expected_output_str->len);
|
||||
mbedtls_test_hexify( output_string, output, src_str->len );
|
||||
TEST_ASSERT( strcmp( (char *)output_string,
|
||||
(char *)expected_output_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output_str->len,
|
||||
expected_output_str->x, expected_output_str->len );
|
||||
|
||||
/*
|
||||
* Test the streaming API
|
||||
@ -54,9 +43,8 @@ void chacha20_crypt( data_t *key_str,
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
TEST_ASSERT( mbedtls_chacha20_update( &ctx, src_str->len, src_str->x, output ) == 0 );
|
||||
|
||||
mbedtls_test_hexify( output_string, output, src_str->len );
|
||||
TEST_ASSERT( strcmp( (char *)output_string,
|
||||
(char *)expected_output_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output_str->len,
|
||||
expected_output_str->x, expected_output_str->len );
|
||||
|
||||
/*
|
||||
* Test the streaming API again, piecewise
|
||||
@ -71,9 +59,8 @@ void chacha20_crypt( data_t *key_str,
|
||||
TEST_ASSERT( mbedtls_chacha20_update( &ctx, src_str->len - 1,
|
||||
src_str->x + 1, output + 1 ) == 0 );
|
||||
|
||||
mbedtls_test_hexify( output_string, output, src_str->len );
|
||||
TEST_ASSERT( strcmp( (char *)output_string,
|
||||
(char *)expected_output_string ) == 0 );
|
||||
ASSERT_COMPARE( output, expected_output_str->len,
|
||||
expected_output_str->x, expected_output_str->len );
|
||||
|
||||
mbedtls_chacha20_free( &ctx );
|
||||
}
|
||||
|
@ -15,8 +15,7 @@ void des_check_weak( data_t * key, int ret )
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void des_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string )
|
||||
void des_encrypt_ecb( data_t * key_str, data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_des_context ctx;
|
||||
@ -28,8 +27,7 @@ void des_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
mbedtls_des_setkey_enc( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
8, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_des_free( &ctx );
|
||||
@ -37,8 +35,7 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void des_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string )
|
||||
void des_decrypt_ecb( data_t * key_str, data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_des_context ctx;
|
||||
@ -50,8 +47,7 @@ void des_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
mbedtls_des_setkey_dec( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
8, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_des_free( &ctx );
|
||||
@ -60,8 +56,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void des_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string,
|
||||
int cbc_result )
|
||||
data_t * src_str, data_t * dst, int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_des_context ctx;
|
||||
@ -75,9 +70,8 @@ void des_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
|
||||
dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -87,7 +81,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void des_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string,
|
||||
data_t * src_str, data_t * dst,
|
||||
int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
@ -102,9 +96,8 @@ void des_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
|
||||
dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -114,7 +107,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void des3_encrypt_ecb( int key_count, data_t * key_str,
|
||||
data_t * src_str, data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_des3_context ctx;
|
||||
@ -132,8 +125,7 @@ void des3_encrypt_ecb( int key_count, data_t * key_str,
|
||||
|
||||
TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
8, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_des3_free( &ctx );
|
||||
@ -142,7 +134,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void des3_decrypt_ecb( int key_count, data_t * key_str,
|
||||
data_t * src_str, data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_des3_context ctx;
|
||||
@ -160,8 +152,7 @@ void des3_decrypt_ecb( int key_count, data_t * key_str,
|
||||
|
||||
TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
8, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_des3_free( &ctx );
|
||||
@ -171,7 +162,7 @@ exit:
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void des3_encrypt_cbc( int key_count, data_t * key_str,
|
||||
data_t * iv_str, data_t * src_str,
|
||||
data_t * hex_dst_string, int cbc_result )
|
||||
data_t * dst, int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_des3_context ctx;
|
||||
@ -192,9 +183,8 @@ void des3_encrypt_cbc( int key_count, data_t * key_str,
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -205,7 +195,7 @@ exit:
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void des3_decrypt_cbc( int key_count, data_t * key_str,
|
||||
data_t * iv_str, data_t * src_str,
|
||||
data_t * hex_dst_string, int cbc_result )
|
||||
data_t * dst, int cbc_result )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_des3_context ctx;
|
||||
@ -226,9 +216,8 @@ void des3_decrypt_cbc( int key_count, data_t * key_str,
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
|
||||
dst->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -35,8 +35,8 @@ exit:
|
||||
/* BEGIN_CASE */
|
||||
void gcm_encrypt_and_tag( int cipher_id, data_t * key_str,
|
||||
data_t * src_str, data_t * iv_str,
|
||||
data_t * add_str, data_t * hex_dst_string,
|
||||
int tag_len_bits, data_t * hex_tag_string,
|
||||
data_t * add_str, data_t * dst,
|
||||
int tag_len_bits, data_t * tag,
|
||||
int init_result )
|
||||
{
|
||||
unsigned char output[128];
|
||||
@ -55,11 +55,10 @@ void gcm_encrypt_and_tag( int cipher_id, data_t * key_str,
|
||||
{
|
||||
TEST_ASSERT( mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT, src_str->len, iv_str->x, iv_str->len, add_str->x, add_str->len, src_str->x, output, tag_len, tag_output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( tag_output, hex_tag_string->x,
|
||||
tag_len, hex_tag_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( tag_output, tag->x,
|
||||
tag_len, tag->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -14,13 +14,6 @@ void test_hkdf( int md_alg, data_t *ikm, data_t *salt, data_t *info,
|
||||
{
|
||||
int ret;
|
||||
unsigned char okm[128] = { '\0' };
|
||||
/*
|
||||
* okm_string and expected_okm_string are the ASCII string representations
|
||||
* of km and expected_okm, so their size should be twice the size of
|
||||
* okm and expected_okm, and an extra null-termination.
|
||||
*/
|
||||
unsigned char okm_string[257] = { '\0' };
|
||||
unsigned char expected_okm_string[257] = { '\0' };
|
||||
|
||||
const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md != NULL );
|
||||
@ -31,14 +24,8 @@ void test_hkdf( int md_alg, data_t *ikm, data_t *salt, data_t *info,
|
||||
info->x, info->len, okm, expected_okm->len );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
||||
/*
|
||||
* Run mbedtls_test_hexify on okm and expected_okm so that it looks nicer
|
||||
* if the assertion fails.
|
||||
*/
|
||||
mbedtls_test_hexify( okm_string, okm, expected_okm->len );
|
||||
mbedtls_test_hexify( expected_okm_string,
|
||||
expected_okm->x, expected_okm->len );
|
||||
TEST_ASSERT( !strcmp( (char *)okm_string, (char *)expected_okm_string ) );
|
||||
ASSERT_COMPARE( okm , expected_okm->len,
|
||||
expected_okm->x, expected_okm->len );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -62,12 +49,11 @@ void test_hkdf_extract( int md_alg, char *hex_ikm_string,
|
||||
ikm = mbedtls_test_unhexify_alloc( hex_ikm_string, &ikm_len );
|
||||
salt = mbedtls_test_unhexify_alloc( hex_salt_string, &salt_len );
|
||||
prk = mbedtls_test_unhexify_alloc( hex_prk_string, &prk_len );
|
||||
TEST_ASSERT( prk_len == output_prk_len );
|
||||
|
||||
ret = mbedtls_hkdf_extract( md, salt, salt_len, ikm, ikm_len, output_prk );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
||||
TEST_ASSERT( !memcmp( output_prk, prk, prk_len ) );
|
||||
ASSERT_COMPARE( output_prk, output_prk_len, prk, prk_len );
|
||||
|
||||
exit:
|
||||
mbedtls_free(ikm);
|
||||
@ -103,7 +89,7 @@ void test_hkdf_expand( int md_alg, char *hex_info_string,
|
||||
ret = mbedtls_hkdf_expand( md, prk, prk_len, info, info_len,
|
||||
output_okm, OKM_LEN );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
TEST_ASSERT( !memcmp( output_okm, okm, okm_len ) );
|
||||
ASSERT_COMPARE( output_okm, okm_len, okm, okm_len );
|
||||
|
||||
exit:
|
||||
mbedtls_free(info);
|
||||
|
@ -127,7 +127,7 @@ void md_info( int md_type, char * md_name, int md_size )
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_text( char * text_md_name, char * text_src_string,
|
||||
data_t * hex_hash_string )
|
||||
data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[1000];
|
||||
@ -145,15 +145,14 @@ void md_text( char * text_md_name, char * text_src_string,
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str, strlen( (char *) src_str ), output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hex_hash_string->len ) == 0 );
|
||||
hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hex( char * text_md_name, data_t * src_str,
|
||||
data_t * hex_hash_string )
|
||||
void md_hex( char * text_md_name, data_t * src_str, data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
@ -169,15 +168,15 @@ void md_hex( char * text_md_name, data_t * src_str,
|
||||
TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str->x, src_str->len, output ) );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hex_hash_string->len ) == 0 );
|
||||
hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_text_multi( char * text_md_name, char * text_src_string,
|
||||
data_t * hex_hash_string )
|
||||
data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[1000];
|
||||
@ -211,18 +210,18 @@ void md_text_multi( char * text_md_name, char * text_src_string,
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str + halfway, len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx, output ) );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hex_hash_string->len) == 0 );
|
||||
hash->len) == 0 );
|
||||
|
||||
/* Test clone */
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx_copy, src_str + halfway, len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx_copy, output ) );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hex_hash_string->len ) == 0 );
|
||||
hash->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
@ -231,8 +230,7 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hex_multi( char * text_md_name, data_t * src_str,
|
||||
data_t * hex_hash_string )
|
||||
void md_hex_multi( char * text_md_name, data_t * src_str, data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
@ -261,18 +259,18 @@ void md_hex_multi( char * text_md_name, data_t * src_str,
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str->x + halfway, src_str->len - halfway) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx, output ) );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hex_hash_string->len ) == 0 );
|
||||
hash->len ) == 0 );
|
||||
|
||||
/* Test clone */
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx_copy, src_str->x + halfway, src_str->len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx_copy, output ) );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hex_hash_string->len ) == 0 );
|
||||
hash->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
@ -283,7 +281,7 @@ exit:
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_md_hmac( char * text_md_name, int trunc_size,
|
||||
data_t * key_str, data_t * src_str,
|
||||
data_t * hex_hash_string )
|
||||
data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
@ -299,14 +297,14 @@ void mbedtls_md_hmac( char * text_md_name, int trunc_size,
|
||||
|
||||
TEST_ASSERT ( mbedtls_md_hmac( md_info, key_str->x, key_str->len, src_str->x, src_str->len, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
trunc_size, hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
trunc_size, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hmac_multi( char * text_md_name, int trunc_size, data_t * key_str,
|
||||
data_t * src_str, data_t * hex_hash_string )
|
||||
data_t * src_str, data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
@ -332,8 +330,8 @@ void md_hmac_multi( char * text_md_name, int trunc_size, data_t * key_str,
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x + halfway, src_str->len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
trunc_size, hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
trunc_size, hash->len ) == 0 );
|
||||
|
||||
/* Test again, for reset() */
|
||||
memset( output, 0x00, 100 );
|
||||
@ -343,8 +341,8 @@ void md_hmac_multi( char * text_md_name, int trunc_size, data_t * key_str,
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x + halfway, src_str->len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
trunc_size, hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
trunc_size, hash->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
@ -353,7 +351,7 @@ exit:
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||
void mbedtls_md_file( char * text_md_name, char * filename,
|
||||
data_t * hex_hash_string )
|
||||
data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
@ -368,8 +366,8 @@ void mbedtls_md_file( char * text_md_name, char * filename,
|
||||
|
||||
TEST_ASSERT( mbedtls_md_file( md_info, filename, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hex_hash_string->len ) == 0 );
|
||||
hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD2_C */
|
||||
void md2_text( char * text_src_string, data_t * hex_hash_string )
|
||||
void md2_text( char * text_src_string, data_t * hash )
|
||||
{
|
||||
int ret;
|
||||
unsigned char src_str[100];
|
||||
@ -20,14 +20,13 @@ void md2_text( char * text_src_string, data_t * hex_hash_string )
|
||||
ret = mbedtls_md2_ret( src_str, strlen( (char *) src_str ), output );
|
||||
TEST_ASSERT( ret == 0 ) ;
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
sizeof output,
|
||||
hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
sizeof output, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD4_C */
|
||||
void md4_text( char * text_src_string, data_t * hex_hash_string )
|
||||
void md4_text( char * text_src_string, data_t * hash )
|
||||
{
|
||||
int ret;
|
||||
unsigned char src_str[100];
|
||||
@ -41,14 +40,13 @@ void md4_text( char * text_src_string, data_t * hex_hash_string )
|
||||
ret = mbedtls_md4_ret( src_str, strlen( (char *) src_str ), output );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
sizeof output,
|
||||
hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
sizeof output, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD5_C */
|
||||
void md5_text( char * text_src_string, data_t * hex_hash_string )
|
||||
void md5_text( char * text_src_string, data_t * hash )
|
||||
{
|
||||
int ret;
|
||||
unsigned char src_str[100];
|
||||
@ -62,14 +60,13 @@ void md5_text( char * text_src_string, data_t * hex_hash_string )
|
||||
ret = mbedtls_md5_ret( src_str, strlen( (char *) src_str ), output );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
sizeof output,
|
||||
hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
sizeof output, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */
|
||||
void ripemd160_text( char * text_src_string, data_t * hex_hash_string )
|
||||
void ripemd160_text( char * text_src_string, data_t * hash )
|
||||
{
|
||||
int ret;
|
||||
unsigned char src_str[100];
|
||||
@ -83,9 +80,8 @@ void ripemd160_text( char * text_src_string, data_t * hex_hash_string )
|
||||
ret = mbedtls_ripemd160_ret( src_str, strlen( (char *) src_str ), output );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
sizeof output,
|
||||
hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
sizeof output, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
|
||||
int radix_E, char * input_E, int hash,
|
||||
data_t * message_str, data_t * rnd_buf,
|
||||
data_t * result_hex_str, int result )
|
||||
data_t * result_str, int result )
|
||||
{
|
||||
unsigned char output[128];
|
||||
mbedtls_rsa_context ctx;
|
||||
@ -42,8 +42,8 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
|
||||
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -56,7 +56,7 @@ exit:
|
||||
void pkcs1_rsaes_v15_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, data_t * result_hex_str,
|
||||
int hash, data_t * result_str,
|
||||
char * seed, data_t * message_str,
|
||||
int result )
|
||||
{
|
||||
@ -84,7 +84,7 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
|
||||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
if( result_hex_str->len == 0 )
|
||||
if( result_str->len == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx,
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
@ -102,9 +102,9 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
|
||||
output, 1000 ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
output_len,
|
||||
result_hex_str->len) == 0 );
|
||||
result_str->len) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ void pkcs1_rsassa_v15_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,
|
||||
data_t * message_str, data_t * rnd_buf,
|
||||
data_t * result_hex_str, int result )
|
||||
data_t * result_str, int result )
|
||||
{
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char output[128];
|
||||
@ -305,8 +305,8 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -12,7 +12,7 @@
|
||||
void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char * input_N,
|
||||
int radix_E, char * input_E, int hash,
|
||||
data_t * message_str, data_t * rnd_buf,
|
||||
data_t * result_hex_str, int result )
|
||||
data_t * result_str, int result )
|
||||
{
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
@ -41,8 +41,8 @@ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char * input_N,
|
||||
output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -55,7 +55,7 @@ exit:
|
||||
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, data_t * result_hex_str,
|
||||
int hash, data_t * result_str,
|
||||
char * seed, data_t * message_str,
|
||||
int result )
|
||||
{
|
||||
@ -84,7 +84,7 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char * input_P,
|
||||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
if( result_hex_str->len == 0 )
|
||||
if( result_str->len == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx,
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
@ -104,9 +104,9 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char * input_P,
|
||||
sizeof( output ) ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
output_len,
|
||||
result_hex_str->len ) == 0 );
|
||||
result_str->len ) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ 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,
|
||||
data_t * message_str, data_t * rnd_buf,
|
||||
data_t * result_hex_str, int result )
|
||||
data_t * result_str, int result )
|
||||
{
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char output[256];
|
||||
@ -160,8 +160,8 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char * input_P, int radix_Q,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -9,14 +9,12 @@
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_poly1305( data_t *key, char *hex_mac_string, data_t *src_str )
|
||||
void mbedtls_poly1305( data_t *key, data_t *expected_mac, data_t *src_str )
|
||||
{
|
||||
unsigned char mac[16]; /* size set by the standard */
|
||||
unsigned char mac_str[33]; /* hex expansion of the above */
|
||||
mbedtls_poly1305_context ctx;
|
||||
|
||||
memset( mac_str, 0x00, sizeof( mac_str ) );
|
||||
memset( mac, 0x00, sizeof( mac ) );
|
||||
memset( mac, 0x00, sizeof( mac ) );
|
||||
|
||||
/*
|
||||
* Test the integrated API
|
||||
@ -24,8 +22,8 @@ void mbedtls_poly1305( data_t *key, char *hex_mac_string, data_t *src_str )
|
||||
TEST_ASSERT( mbedtls_poly1305_mac( key->x, src_str->x,
|
||||
src_str->len, mac ) == 0 );
|
||||
|
||||
mbedtls_test_hexify( mac_str, mac, 16 );
|
||||
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );
|
||||
ASSERT_COMPARE( mac, expected_mac->len,
|
||||
expected_mac->x, expected_mac->len );
|
||||
|
||||
/*
|
||||
* Test the streaming API
|
||||
@ -38,8 +36,8 @@ void mbedtls_poly1305( data_t *key, char *hex_mac_string, data_t *src_str )
|
||||
|
||||
TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
|
||||
|
||||
mbedtls_test_hexify( mac_str, mac, 16 );
|
||||
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );
|
||||
ASSERT_COMPARE( mac, expected_mac->len,
|
||||
expected_mac->x, expected_mac->len );
|
||||
|
||||
/*
|
||||
* Test the streaming API again, piecewise
|
||||
@ -56,8 +54,8 @@ void mbedtls_poly1305( data_t *key, char *hex_mac_string, data_t *src_str )
|
||||
|
||||
TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
|
||||
|
||||
mbedtls_test_hexify( mac_str, mac, 16 );
|
||||
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );
|
||||
ASSERT_COMPARE( mac, expected_mac->len,
|
||||
expected_mac->x, expected_mac->len );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -73,8 +71,8 @@ void mbedtls_poly1305( data_t *key, char *hex_mac_string, data_t *src_str )
|
||||
|
||||
TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
|
||||
|
||||
mbedtls_test_hexify( mac_str, mac, 16 );
|
||||
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );
|
||||
ASSERT_COMPARE( mac, expected_mac->len,
|
||||
expected_mac->x, expected_mac->len );
|
||||
}
|
||||
|
||||
mbedtls_poly1305_free( &ctx );
|
||||
|
@ -471,7 +471,7 @@ void mbedtls_rsa_pkcs1_sign( data_t * message_str, 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,
|
||||
data_t * result_hex_str, int result )
|
||||
data_t * result_str, int result )
|
||||
{
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char output[256];
|
||||
@ -507,8 +507,8 @@ void mbedtls_rsa_pkcs1_sign( data_t * message_str, int padding_mode,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -557,7 +557,7 @@ void rsa_pkcs1_sign_raw( data_t * hash_result,
|
||||
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, data_t * result_hex_str )
|
||||
char * input_E, data_t * result_str )
|
||||
{
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
@ -588,8 +588,8 @@ void rsa_pkcs1_sign_raw( data_t * hash_result,
|
||||
hash_result->x, output ) == 0 );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
|
||||
#if defined(MBEDTLS_PKCS1_V15)
|
||||
/* For PKCS#1 v1.5, there is an alternative way to generate signatures */
|
||||
@ -612,9 +612,9 @@ void rsa_pkcs1_sign_raw( data_t * hash_result,
|
||||
|
||||
if( res == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len,
|
||||
result_hex_str->len ) == 0 );
|
||||
result_str->len ) == 0 );
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_PKCS1_V15 */
|
||||
@ -692,7 +692,7 @@ exit:
|
||||
void mbedtls_rsa_pkcs1_encrypt( data_t * message_str, int padding_mode,
|
||||
int mod, int radix_N, char * input_N,
|
||||
int radix_E, char * input_E,
|
||||
data_t * result_hex_str, int result )
|
||||
data_t * result_str, int result )
|
||||
{
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
@ -722,8 +722,8 @@ void mbedtls_rsa_pkcs1_encrypt( data_t * message_str, int padding_mode,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -736,7 +736,7 @@ exit:
|
||||
void rsa_pkcs1_encrypt_bad_rng( data_t * message_str, int padding_mode,
|
||||
int mod, int radix_N, char * input_N,
|
||||
int radix_E, char * input_E,
|
||||
data_t * result_hex_str, int result )
|
||||
data_t * result_str, int result )
|
||||
{
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
@ -762,8 +762,8 @@ void rsa_pkcs1_encrypt_bad_rng( data_t * message_str, int padding_mode,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -777,7 +777,7 @@ void mbedtls_rsa_pkcs1_decrypt( data_t * message_str, 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, data_t * result_hex_str,
|
||||
int max_output, data_t * result_str,
|
||||
int result )
|
||||
{
|
||||
unsigned char output[32];
|
||||
@ -814,9 +814,9 @@ void mbedtls_rsa_pkcs1_decrypt( data_t * message_str, int padding_mode,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
output_len,
|
||||
result_hex_str->len ) == 0 );
|
||||
result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -829,7 +829,7 @@ exit:
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_rsa_public( data_t * message_str, int mod, int radix_N,
|
||||
char * input_N, int radix_E, char * input_E,
|
||||
data_t * result_hex_str, int result )
|
||||
data_t * result_str, int result )
|
||||
{
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
|
||||
@ -853,8 +853,8 @@ void mbedtls_rsa_public( data_t * message_str, int mod, int radix_N,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
/* And now with the copy */
|
||||
@ -869,8 +869,8 @@ void mbedtls_rsa_public( data_t * message_str, int mod, int radix_N,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
ctx.len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len, result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -884,7 +884,7 @@ exit:
|
||||
void mbedtls_rsa_private( data_t * message_str, 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, data_t * result_hex_str,
|
||||
char * input_E, data_t * result_str,
|
||||
int result )
|
||||
{
|
||||
unsigned char output[256];
|
||||
@ -921,9 +921,9 @@ void mbedtls_rsa_private( data_t * message_str, int mod, int radix_P,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx.len,
|
||||
result_hex_str->len ) == 0 );
|
||||
result_str->len ) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -941,9 +941,9 @@ void mbedtls_rsa_private( data_t * message_str, int mod, int radix_P,
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
ctx2.len,
|
||||
result_hex_str->len ) == 0 );
|
||||
result_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -52,7 +52,7 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
|
||||
void mbedtls_sha1( data_t * src_str, data_t * hex_hash_string )
|
||||
void mbedtls_sha1( data_t * src_str, data_t * hash )
|
||||
{
|
||||
unsigned char output[41];
|
||||
|
||||
@ -61,8 +61,7 @@ void mbedtls_sha1( data_t * src_str, data_t * hex_hash_string )
|
||||
|
||||
TEST_ASSERT( mbedtls_sha1_ret( src_str->x, src_str->len, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
20, hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 20, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -123,7 +122,7 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
||||
void sha224( data_t * src_str, data_t * hex_hash_string )
|
||||
void sha224( data_t * src_str, data_t * hash )
|
||||
{
|
||||
unsigned char output[57];
|
||||
|
||||
@ -132,13 +131,12 @@ void sha224( data_t * src_str, data_t * hex_hash_string )
|
||||
|
||||
TEST_ASSERT( mbedtls_sha256_ret( src_str->x, src_str->len, output, 1 ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
28, hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 28, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
||||
void mbedtls_sha256( data_t * src_str, data_t * hex_hash_string )
|
||||
void mbedtls_sha256( data_t * src_str, data_t * hash )
|
||||
{
|
||||
unsigned char output[65];
|
||||
|
||||
@ -147,8 +145,7 @@ void mbedtls_sha256( data_t * src_str, data_t * hex_hash_string )
|
||||
|
||||
TEST_ASSERT( mbedtls_sha256_ret( src_str->x, src_str->len, output, 0 ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
32, hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 32, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -209,7 +206,7 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
||||
void sha384( data_t * src_str, data_t * hex_hash_string )
|
||||
void sha384( data_t * src_str, data_t * hash )
|
||||
{
|
||||
unsigned char output[97];
|
||||
|
||||
@ -218,13 +215,12 @@ void sha384( data_t * src_str, data_t * hex_hash_string )
|
||||
|
||||
TEST_ASSERT( mbedtls_sha512_ret( src_str->x, src_str->len, output, 1 ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
48, hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 48, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
||||
void mbedtls_sha512( data_t * src_str, data_t * hex_hash_string )
|
||||
void mbedtls_sha512( data_t * src_str, data_t * hash )
|
||||
{
|
||||
unsigned char output[129];
|
||||
|
||||
@ -233,8 +229,7 @@ void mbedtls_sha512( data_t * src_str, data_t * hex_hash_string )
|
||||
|
||||
TEST_ASSERT( mbedtls_sha512_ret( src_str->x, src_str->len, output, 0 ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x,
|
||||
64, hex_hash_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 64, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
@ -3824,11 +3824,11 @@ void ssl_tls1_3_key_evolution( int hash_alg,
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ssl_tls_prf( int type, data_t * secret, data_t * random,
|
||||
char *label, data_t *result_hex_str, int exp_ret )
|
||||
char *label, data_t *result_str, int exp_ret )
|
||||
{
|
||||
unsigned char *output;
|
||||
|
||||
output = mbedtls_calloc( 1, result_hex_str->len );
|
||||
output = mbedtls_calloc( 1, result_str->len );
|
||||
if( output == NULL )
|
||||
goto exit;
|
||||
|
||||
@ -3838,12 +3838,12 @@ void ssl_tls_prf( int type, data_t * secret, data_t * random,
|
||||
|
||||
TEST_ASSERT( mbedtls_ssl_tls_prf( type, secret->x, secret->len,
|
||||
label, random->x, random->len,
|
||||
output, result_hex_str->len ) == exp_ret );
|
||||
output, result_str->len ) == exp_ret );
|
||||
|
||||
if( exp_ret == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
result_hex_str->len, result_hex_str->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
|
||||
result_str->len, result_str->len ) == 0 );
|
||||
}
|
||||
exit:
|
||||
|
||||
|
@ -1220,21 +1220,21 @@ void x509_get_time( int tag, char * time_str, int ret, int year, int mon,
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_RSASSA_PSS_SUPPORT */
|
||||
void x509_parse_rsassa_pss_params( data_t * hex_params, int params_tag,
|
||||
void x509_parse_rsassa_pss_params( data_t * params, int params_tag,
|
||||
int ref_msg_md, int ref_mgf_md,
|
||||
int ref_salt_len, int ref_ret )
|
||||
{
|
||||
int my_ret;
|
||||
mbedtls_x509_buf params;
|
||||
mbedtls_x509_buf buf;
|
||||
mbedtls_md_type_t my_msg_md, my_mgf_md;
|
||||
int my_salt_len;
|
||||
|
||||
params.p = hex_params->x;
|
||||
params.len = hex_params->len;
|
||||
params.tag = params_tag;
|
||||
buf.p = params->x;
|
||||
buf.len = params->len;
|
||||
buf.tag = params_tag;
|
||||
|
||||
my_ret = mbedtls_x509_get_rsassa_pss_params( ¶ms, &my_msg_md, &my_mgf_md,
|
||||
&my_salt_len );
|
||||
my_ret = mbedtls_x509_get_rsassa_pss_params( &buf, &my_msg_md, &my_mgf_md,
|
||||
&my_salt_len );
|
||||
|
||||
TEST_ASSERT( my_ret == ref_ret );
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void xtea_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string )
|
||||
data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_xtea_context ctx;
|
||||
@ -20,14 +20,12 @@ void xtea_encrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
mbedtls_xtea_setup( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
8, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void xtea_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
data_t * hex_dst_string )
|
||||
void xtea_decrypt_ecb( data_t * key_str, data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_xtea_context ctx;
|
||||
@ -38,14 +36,13 @@ void xtea_decrypt_ecb( data_t * key_str, data_t * src_str,
|
||||
mbedtls_xtea_setup( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
8, hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void xtea_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_xtea_context ctx;
|
||||
@ -57,15 +54,14 @@ void xtea_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->len, iv_str->x,
|
||||
src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void xtea_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
data_t * src_str, data_t * hex_dst_string )
|
||||
data_t * src_str, data_t * dst )
|
||||
{
|
||||
unsigned char output[100];
|
||||
mbedtls_xtea_context ctx;
|
||||
@ -77,9 +73,8 @@ void xtea_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->len, iv_str->x,
|
||||
src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
|
||||
src_str->len,
|
||||
hex_dst_string->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
src_str->len, dst->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user