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/arc4.h"
markrad 0:cdf462088d13 3 /* END_HEADER */
markrad 0:cdf462088d13 4
markrad 0:cdf462088d13 5 /* BEGIN_DEPENDENCIES
markrad 0:cdf462088d13 6 * depends_on:MBEDTLS_ARC4_C
markrad 0:cdf462088d13 7 * END_DEPENDENCIES
markrad 0:cdf462088d13 8 */
markrad 0:cdf462088d13 9
markrad 0:cdf462088d13 10 /* BEGIN_CASE */
markrad 0:cdf462088d13 11 void mbedtls_arc4_crypt( char *hex_src_string, char *hex_key_string,
markrad 0:cdf462088d13 12 char *hex_dst_string )
markrad 0:cdf462088d13 13 {
markrad 0:cdf462088d13 14 unsigned char src_str[1000];
markrad 0:cdf462088d13 15 unsigned char key_str[1000];
markrad 0:cdf462088d13 16 unsigned char dst_str[1000];
markrad 0:cdf462088d13 17 unsigned char dst_hexstr[2000];
markrad 0:cdf462088d13 18 int src_len, key_len;
markrad 0:cdf462088d13 19 mbedtls_arc4_context ctx;
markrad 0:cdf462088d13 20
markrad 0:cdf462088d13 21 memset(src_str, 0x00, 1000);
markrad 0:cdf462088d13 22 memset(key_str, 0x00, 1000);
markrad 0:cdf462088d13 23 memset(dst_str, 0x00, 1000);
markrad 0:cdf462088d13 24 memset(dst_hexstr, 0x00, 2000);
markrad 0:cdf462088d13 25 mbedtls_arc4_init( &ctx );
markrad 0:cdf462088d13 26
markrad 0:cdf462088d13 27 src_len = unhexify( src_str, hex_src_string );
markrad 0:cdf462088d13 28 key_len = unhexify( key_str, hex_key_string );
markrad 0:cdf462088d13 29
markrad 0:cdf462088d13 30 mbedtls_arc4_setup(&ctx, key_str, key_len);
markrad 0:cdf462088d13 31 TEST_ASSERT( mbedtls_arc4_crypt(&ctx, src_len, src_str, dst_str ) == 0 );
markrad 0:cdf462088d13 32 hexify( dst_hexstr, dst_str, src_len );
markrad 0:cdf462088d13 33
markrad 0:cdf462088d13 34 TEST_ASSERT( strcmp( (char *) dst_hexstr, hex_dst_string ) == 0 );
markrad 0:cdf462088d13 35
markrad 0:cdf462088d13 36 exit:
markrad 0:cdf462088d13 37 mbedtls_arc4_free( &ctx );
markrad 0:cdf462088d13 38 }
markrad 0:cdf462088d13 39 /* END_CASE */
markrad 0:cdf462088d13 40
markrad 0:cdf462088d13 41 /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
markrad 0:cdf462088d13 42 void arc4_selftest()
markrad 0:cdf462088d13 43 {
markrad 0:cdf462088d13 44 TEST_ASSERT( mbedtls_arc4_self_test( 1 ) == 0 );
markrad 0:cdf462088d13 45 }
markrad 0:cdf462088d13 46 /* END_CASE */