mbedtls/tests/suites/test_suite_mdx.function

179 lines
4.8 KiB
Plaintext
Raw Normal View History

/* BEGIN_HEADER */
2015-03-09 18:05:11 +01:00
#include "mbedtls/md2.h"
#include "mbedtls/md4.h"
#include "mbedtls/md5.h"
#include "mbedtls/ripemd160.h"
/* END_HEADER */
/* BEGIN_CASE depends_on:POLARSSL_MD2_C */
void md2_text( char *text_src_string, char *hex_hash_string )
{
2014-01-17 14:23:48 +01:00
unsigned char src_str[100];
unsigned char hash_str[33];
unsigned char output[16];
2014-01-17 14:23:48 +01:00
memset( src_str, 0x00, sizeof src_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
md2( src_str, strlen( (char *) src_str ), output );
2014-01-17 14:23:48 +01:00
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_MD4_C */
void md4_text( char *text_src_string, char *hex_hash_string )
{
2014-01-17 14:23:48 +01:00
unsigned char src_str[100];
unsigned char hash_str[33];
unsigned char output[16];
2014-01-17 14:23:48 +01:00
memset( src_str, 0x00, sizeof src_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
md4( src_str, strlen( (char *) src_str ), output );
2014-01-17 14:23:48 +01:00
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_MD5_C */
void md5_text( char *text_src_string, char *hex_hash_string )
{
2014-01-17 14:23:48 +01:00
unsigned char src_str[100];
unsigned char hash_str[33];
unsigned char output[16];
2014-01-17 14:23:48 +01:00
memset( src_str, 0x00, sizeof src_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
md5( src_str, strlen( (char *) src_str ), output );
2014-01-17 14:23:48 +01:00
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
2014-01-22 13:35:29 +01:00
/* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C */
void ripemd160_text( char *text_src_string, char *hex_hash_string )
2014-01-17 12:42:35 +01:00
{
2014-01-17 14:23:48 +01:00
unsigned char src_str[100];
2014-01-17 12:42:35 +01:00
unsigned char hash_str[41];
unsigned char output[20];
memset(src_str, 0x00, sizeof src_str);
memset(hash_str, 0x00, sizeof hash_str);
memset(output, 0x00, sizeof output);
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
2014-01-17 12:42:35 +01:00
2014-01-22 13:35:29 +01:00
ripemd160( src_str, strlen( (char *) src_str ), output );
2014-01-17 12:42:35 +01:00
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_MD2_C:POLARSSL_FS_IO */
void md2_file( char *filename, char *hex_hash_string )
{
2014-01-17 14:23:48 +01:00
unsigned char hash_str[33];
unsigned char output[16];
2014-01-17 14:23:48 +01:00
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
md2_file( filename, output);
2014-01-17 14:23:48 +01:00
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_MD4_C:POLARSSL_FS_IO */
void md4_file( char *filename, char *hex_hash_string )
{
2014-01-17 14:23:48 +01:00
unsigned char hash_str[33];
unsigned char output[16];
2014-01-17 14:23:48 +01:00
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
md4_file( filename, output);
2014-01-17 14:23:48 +01:00
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_MD5_C:POLARSSL_FS_IO */
void md5_file( char *filename, char *hex_hash_string )
{
2014-01-17 14:23:48 +01:00
unsigned char hash_str[33];
unsigned char output[16];
2014-01-17 14:23:48 +01:00
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
md5_file( filename, output);
2014-01-17 14:23:48 +01:00
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
2014-01-22 13:35:29 +01:00
/* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C:POLARSSL_FS_IO */
void ripemd160_file( char *filename, char *hex_hash_string )
2014-01-17 12:42:35 +01:00
{
unsigned char hash_str[41];
unsigned char output[20];
memset(hash_str, 0x00, sizeof hash_str );
memset(output, 0x00, sizeof output );
2014-01-22 13:35:29 +01:00
ripemd160_file( filename, output);
2014-01-17 14:23:48 +01:00
hexify( hash_str, output, sizeof output );
2014-01-17 12:42:35 +01:00
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
2013-10-10 12:48:03 +02:00
/* BEGIN_CASE depends_on:POLARSSL_MD2_C:POLARSSL_SELF_TEST */
void md2_selftest()
{
TEST_ASSERT( md2_self_test( 0 ) == 0 );
}
/* END_CASE */
2013-10-10 12:48:03 +02:00
/* BEGIN_CASE depends_on:POLARSSL_MD4_C:POLARSSL_SELF_TEST */
void md4_selftest()
{
TEST_ASSERT( md4_self_test( 0 ) == 0 );
}
/* END_CASE */
2013-10-10 12:48:03 +02:00
/* BEGIN_CASE depends_on:POLARSSL_MD5_C:POLARSSL_SELF_TEST */
void md5_selftest()
{
TEST_ASSERT( md5_self_test( 0 ) == 0 );
}
/* END_CASE */
2014-01-17 12:42:35 +01:00
2014-01-22 13:35:29 +01:00
/* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C:POLARSSL_SELF_TEST */
void ripemd160_selftest()
2014-01-17 12:42:35 +01:00
{
2014-01-22 13:35:29 +01:00
TEST_ASSERT( ripemd160_self_test( 0 ) == 0 );
2014-01-17 12:42:35 +01:00
}
/* END_CASE */