Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
| 2 | #include "mbedtls/chacha20.h" |
| 3 | /* END_HEADER */ |
| 4 | |
| 5 | /* BEGIN_DEPENDENCIES |
| 6 | * depends_on:MBEDTLS_CHACHA20_C |
| 7 | * END_DEPENDENCIES |
| 8 | */ |
Daniel King | 6155cc8 | 2016-05-18 11:51:22 -0300 | [diff] [blame^] | 9 | |
| 10 | /* BEGIN_CASE */ |
| 11 | void chacha20_crypt( char *hex_key_string, |
| 12 | char *hex_nonce_string, |
| 13 | int counter, |
| 14 | char *hex_src_string, |
| 15 | char *hex_dst_string ) |
| 16 | { |
| 17 | unsigned char key_str[100]; |
| 18 | unsigned char nonce_str[100]; |
| 19 | unsigned char src_str[10000]; |
| 20 | unsigned char dst_str[10000]; |
| 21 | unsigned char output[10000]; |
| 22 | size_t key_len; |
| 23 | size_t nonce_len; |
| 24 | size_t src_len; |
| 25 | size_t dst_len; |
| 26 | |
| 27 | memset(key_str, 0x00, 100); |
| 28 | memset(nonce_str, 0x00, 100); |
| 29 | memset(src_str, 0x00, 10000); |
| 30 | memset(dst_str, 0x00, 10000); |
| 31 | memset(output, 0x00, 10000); |
| 32 | |
| 33 | key_len = unhexify( key_str, hex_key_string ); |
| 34 | nonce_len = unhexify( nonce_str, hex_nonce_string ); |
| 35 | src_len = unhexify( src_str, hex_src_string ); |
| 36 | dst_len = unhexify( dst_str, hex_dst_string ); |
| 37 | |
| 38 | TEST_ASSERT( src_len == dst_len ); |
| 39 | TEST_ASSERT( key_len == 32U ); |
| 40 | TEST_ASSERT( nonce_len == 12U ); |
| 41 | |
| 42 | TEST_ASSERT( mbedtls_chacha20_crypt( key_str, nonce_str, counter, src_len, src_str, output ) == 0 ); |
| 43 | |
| 44 | hexify( dst_str, output, src_len ); |
| 45 | |
| 46 | TEST_ASSERT( strcmp( (char*) dst_str, hex_dst_string ) == 0); |
| 47 | } |
| 48 | /* END_CASE */ |
| 49 | |
Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 50 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
| 51 | void chacha20_self_test() |
| 52 | { |
| 53 | TEST_ASSERT( mbedtls_chacha20_self_test( 0 ) == 0 ); |
| 54 | } |
| 55 | /* END_CASE */ |