blob: 5ede635c9ac15b87a3d19892063b5362c9f5d615 [file] [log] [blame]
Daniel Kingadc32c02016-05-16 18:25:45 -03001/* BEGIN_HEADER */
2#include "mbedtls/poly1305.h"
3#include <stddef.h>
4/* END_HEADER */
5
6/* BEGIN_CASE depends_on:MBEDTLS_POLY1305_C */
7void mbedtls_poly1305( char *hex_key_string, char *hex_mac_string, char *hex_src_string )
8{
Manuel Pégourié-Gonnard528524b2018-05-09 11:21:21 +02009 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 Kingadc32c02016-05-16 18:25:45 -030013 size_t src_len;
14
Manuel Pégourié-Gonnard528524b2018-05-09 11:21:21 +020015 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 Kingadc32c02016-05-16 18:25:45 -030019
20 src_len = unhexify( src_str, hex_src_string );
21 unhexify( key, hex_key_string );
22
Manuel Pégourié-Gonnardb1ac5e72018-05-09 09:25:00 +020023 mbedtls_poly1305_mac( key, src_str, src_len, mac );
Daniel Kingadc32c02016-05-16 18:25:45 -030024 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 */
31void poly1305_selftest()
32{
33 TEST_ASSERT( mbedtls_poly1305_self_test( 0 ) == 0 );
34}
35/* END_CASE */