Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
| 2 | #include "mbedtls/poly1305.h" |
| 3 | #include <stddef.h> |
| 4 | /* END_HEADER */ |
| 5 | |
| 6 | /* BEGIN_CASE depends_on:MBEDTLS_POLY1305_C */ |
| 7 | void mbedtls_poly1305( char *hex_key_string, char *hex_mac_string, char *hex_src_string ) |
| 8 | { |
Manuel Pégourié-Gonnard | 528524b | 2018-05-09 11:21:21 +0200 | [diff] [blame] | 9 | unsigned char src_str[375]; /* max size of binary input */ |
| 10 | unsigned char key[32]; /* size set by the standard */ |
| 11 | unsigned char mac[16]; /* size set by the standard */ |
| 12 | unsigned char mac_str[33]; /* hex expansion of the above */ |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 13 | size_t src_len; |
| 14 | |
Manuel Pégourié-Gonnard | 528524b | 2018-05-09 11:21:21 +0200 | [diff] [blame] | 15 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 16 | memset( mac_str, 0x00, sizeof( mac_str ) ); |
| 17 | memset( key, 0x00, sizeof( key ) ); |
| 18 | memset( mac, 0x00, sizeof( mac ) ); |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 19 | |
| 20 | src_len = unhexify( src_str, hex_src_string ); |
| 21 | unhexify( key, hex_key_string ); |
| 22 | |
Manuel Pégourié-Gonnard | b1ac5e7 | 2018-05-09 09:25:00 +0200 | [diff] [blame] | 23 | mbedtls_poly1305_mac( key, src_str, src_len, mac ); |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 24 | hexify( mac_str, mac, 16 ); |
| 25 | |
| 26 | TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 ); |
| 27 | } |
| 28 | /* END_CASE */ |
| 29 | |
| 30 | /* BEGIN_CASE depends_on:MBEDTLS_POLY1305_C:MBEDTLS_SELF_TEST */ |
| 31 | void poly1305_selftest() |
| 32 | { |
| 33 | TEST_ASSERT( mbedtls_poly1305_self_test( 0 ) == 0 ); |
| 34 | } |
| 35 | /* END_CASE */ |