mbed TLS Build

Dependents:   Slave-prot-prod

Committer:
markrad
Date:
Thu Jan 05 00:18:44 2017 +0000
Revision:
0:cdf462088d13
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
markrad 0:cdf462088d13 1 /* BEGIN_HEADER */
markrad 0:cdf462088d13 2 #include "mbedtls/md2.h"
markrad 0:cdf462088d13 3 #include "mbedtls/md4.h"
markrad 0:cdf462088d13 4 #include "mbedtls/md5.h"
markrad 0:cdf462088d13 5 #include "mbedtls/ripemd160.h"
markrad 0:cdf462088d13 6 /* END_HEADER */
markrad 0:cdf462088d13 7
markrad 0:cdf462088d13 8 /* BEGIN_CASE depends_on:MBEDTLS_MD2_C */
markrad 0:cdf462088d13 9 void md2_text( char *text_src_string, char *hex_hash_string )
markrad 0:cdf462088d13 10 {
markrad 0:cdf462088d13 11 unsigned char src_str[100];
markrad 0:cdf462088d13 12 unsigned char hash_str[33];
markrad 0:cdf462088d13 13 unsigned char output[16];
markrad 0:cdf462088d13 14
markrad 0:cdf462088d13 15 memset( src_str, 0x00, sizeof src_str );
markrad 0:cdf462088d13 16 memset( hash_str, 0x00, sizeof hash_str );
markrad 0:cdf462088d13 17 memset( output, 0x00, sizeof output );
markrad 0:cdf462088d13 18
markrad 0:cdf462088d13 19 strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
markrad 0:cdf462088d13 20
markrad 0:cdf462088d13 21 mbedtls_md2( src_str, strlen( (char *) src_str ), output );
markrad 0:cdf462088d13 22 hexify( hash_str, output, sizeof output );
markrad 0:cdf462088d13 23
markrad 0:cdf462088d13 24 TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
markrad 0:cdf462088d13 25 }
markrad 0:cdf462088d13 26 /* END_CASE */
markrad 0:cdf462088d13 27
markrad 0:cdf462088d13 28 /* BEGIN_CASE depends_on:MBEDTLS_MD4_C */
markrad 0:cdf462088d13 29 void md4_text( char *text_src_string, char *hex_hash_string )
markrad 0:cdf462088d13 30 {
markrad 0:cdf462088d13 31 unsigned char src_str[100];
markrad 0:cdf462088d13 32 unsigned char hash_str[33];
markrad 0:cdf462088d13 33 unsigned char output[16];
markrad 0:cdf462088d13 34
markrad 0:cdf462088d13 35 memset( src_str, 0x00, sizeof src_str );
markrad 0:cdf462088d13 36 memset( hash_str, 0x00, sizeof hash_str );
markrad 0:cdf462088d13 37 memset( output, 0x00, sizeof output );
markrad 0:cdf462088d13 38
markrad 0:cdf462088d13 39 strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
markrad 0:cdf462088d13 40
markrad 0:cdf462088d13 41 mbedtls_md4( src_str, strlen( (char *) src_str ), output );
markrad 0:cdf462088d13 42 hexify( hash_str, output, sizeof output );
markrad 0:cdf462088d13 43
markrad 0:cdf462088d13 44 TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
markrad 0:cdf462088d13 45 }
markrad 0:cdf462088d13 46 /* END_CASE */
markrad 0:cdf462088d13 47
markrad 0:cdf462088d13 48 /* BEGIN_CASE depends_on:MBEDTLS_MD5_C */
markrad 0:cdf462088d13 49 void md5_text( char *text_src_string, char *hex_hash_string )
markrad 0:cdf462088d13 50 {
markrad 0:cdf462088d13 51 unsigned char src_str[100];
markrad 0:cdf462088d13 52 unsigned char hash_str[33];
markrad 0:cdf462088d13 53 unsigned char output[16];
markrad 0:cdf462088d13 54
markrad 0:cdf462088d13 55 memset( src_str, 0x00, sizeof src_str );
markrad 0:cdf462088d13 56 memset( hash_str, 0x00, sizeof hash_str );
markrad 0:cdf462088d13 57 memset( output, 0x00, sizeof output );
markrad 0:cdf462088d13 58
markrad 0:cdf462088d13 59 strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
markrad 0:cdf462088d13 60
markrad 0:cdf462088d13 61 mbedtls_md5( src_str, strlen( (char *) src_str ), output );
markrad 0:cdf462088d13 62 hexify( hash_str, output, sizeof output );
markrad 0:cdf462088d13 63
markrad 0:cdf462088d13 64 TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
markrad 0:cdf462088d13 65 }
markrad 0:cdf462088d13 66 /* END_CASE */
markrad 0:cdf462088d13 67
markrad 0:cdf462088d13 68 /* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */
markrad 0:cdf462088d13 69 void ripemd160_text( char *text_src_string, char *hex_hash_string )
markrad 0:cdf462088d13 70 {
markrad 0:cdf462088d13 71 unsigned char src_str[100];
markrad 0:cdf462088d13 72 unsigned char hash_str[41];
markrad 0:cdf462088d13 73 unsigned char output[20];
markrad 0:cdf462088d13 74
markrad 0:cdf462088d13 75 memset(src_str, 0x00, sizeof src_str);
markrad 0:cdf462088d13 76 memset(hash_str, 0x00, sizeof hash_str);
markrad 0:cdf462088d13 77 memset(output, 0x00, sizeof output);
markrad 0:cdf462088d13 78
markrad 0:cdf462088d13 79 strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
markrad 0:cdf462088d13 80
markrad 0:cdf462088d13 81 mbedtls_ripemd160( src_str, strlen( (char *) src_str ), output );
markrad 0:cdf462088d13 82 hexify( hash_str, output, sizeof output );
markrad 0:cdf462088d13 83
markrad 0:cdf462088d13 84 TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
markrad 0:cdf462088d13 85 }
markrad 0:cdf462088d13 86 /* END_CASE */
markrad 0:cdf462088d13 87
markrad 0:cdf462088d13 88 /* BEGIN_CASE depends_on:MBEDTLS_MD2_C:MBEDTLS_SELF_TEST */
markrad 0:cdf462088d13 89 void md2_selftest()
markrad 0:cdf462088d13 90 {
markrad 0:cdf462088d13 91 TEST_ASSERT( mbedtls_md2_self_test( 1 ) == 0 );
markrad 0:cdf462088d13 92 }
markrad 0:cdf462088d13 93 /* END_CASE */
markrad 0:cdf462088d13 94
markrad 0:cdf462088d13 95 /* BEGIN_CASE depends_on:MBEDTLS_MD4_C:MBEDTLS_SELF_TEST */
markrad 0:cdf462088d13 96 void md4_selftest()
markrad 0:cdf462088d13 97 {
markrad 0:cdf462088d13 98 TEST_ASSERT( mbedtls_md4_self_test( 1 ) == 0 );
markrad 0:cdf462088d13 99 }
markrad 0:cdf462088d13 100 /* END_CASE */
markrad 0:cdf462088d13 101
markrad 0:cdf462088d13 102 /* BEGIN_CASE depends_on:MBEDTLS_MD5_C:MBEDTLS_SELF_TEST */
markrad 0:cdf462088d13 103 void md5_selftest()
markrad 0:cdf462088d13 104 {
markrad 0:cdf462088d13 105 TEST_ASSERT( mbedtls_md5_self_test( 1 ) == 0 );
markrad 0:cdf462088d13 106 }
markrad 0:cdf462088d13 107 /* END_CASE */
markrad 0:cdf462088d13 108
markrad 0:cdf462088d13 109 /* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C:MBEDTLS_SELF_TEST */
markrad 0:cdf462088d13 110 void ripemd160_selftest()
markrad 0:cdf462088d13 111 {
markrad 0:cdf462088d13 112 TEST_ASSERT( mbedtls_ripemd160_self_test( 1 ) == 0 );
markrad 0:cdf462088d13 113 }
markrad 0:cdf462088d13 114 /* END_CASE */