First pass at constant flow tests for base64

This contains working CF tests for encode, however I have not yet got
decode to pass the tests.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
Paul Elliott 2021-02-24 15:32:42 +00:00
parent 738d2310a7
commit 69b904b679

View File

@ -13,13 +13,18 @@ void mbedtls_base64_encode( char * src_string, char * dst_string,
{
unsigned char src_str[1000];
unsigned char dst_str[1000];
size_t len;
size_t len, src_len;
memset(src_str, 0x00, 1000);
memset(dst_str, 0x00, 1000);
strncpy( (char *) src_str, src_string, sizeof(src_str) - 1 );
TEST_ASSERT( mbedtls_base64_encode( dst_str, dst_buf_size, &len, src_str, strlen( (char *) src_str ) ) == result );
src_len = strlen( (char *) src_str );
TEST_CF_SECRET( src_str, sizeof( src_str ) );
TEST_ASSERT( mbedtls_base64_encode( dst_str, dst_buf_size, &len, src_str, src_len) == result );
TEST_CF_PUBLIC( src_str, sizeof( src_str ) );
if( result == 0 )
{
TEST_ASSERT( strcmp( (char *) dst_str, dst_string ) == 0 );
@ -57,7 +62,10 @@ void base64_encode_hex( data_t * src, char * dst, int dst_buf_size,
res = zero_alloc( dst_buf_size );
TEST_CF_SECRET( src->x, src->len );
TEST_ASSERT( mbedtls_base64_encode( res, dst_buf_size, &len, src->x, src->len ) == result );
TEST_CF_PUBLIC( src->x, src->len );
if( result == 0 )
{
TEST_ASSERT( len == strlen( dst ) );