blob: 36ec8e687d55376f443ceaff9f0eef2b03bb33ce [file] [log] [blame]
Ronald Cronb6d6d4c2020-06-03 10:11:18 +02001/**
2 * \file helpers.h
3 *
4 * \brief This file contains the prototypes of helper functions for the
5 * purpose of testing.
6 */
7
Bence Szépkúti86974652020-06-15 11:59:37 +02008/*
9 * Copyright (C) 2020, ARM Limited, All Rights Reserved
Ronald Cronb6d6d4c2020-06-03 10:11:18 +020010 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License"); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 * This file is part of mbed TLS (https://tls.mbed.org)
25 */
26
27#ifndef TEST_HELPERS_H
28#define TEST_HELPERS_H
29
30#if !defined(MBEDTLS_CONFIG_FILE)
31#include "mbedtls/config.h"
32#else
33#include MBEDTLS_CONFIG_FILE
34#endif
35
Ronald Cronf40529d2020-06-09 16:27:37 +020036#if defined(MBEDTLS_PLATFORM_C)
37#include "mbedtls/platform.h"
38#else
39#include <stdio.h>
40#define mbedtls_fprintf fprintf
41#define mbedtls_snprintf snprintf
42#define mbedtls_calloc calloc
43#define mbedtls_free free
44#define mbedtls_exit exit
45#define mbedtls_time time
46#define mbedtls_time_t time_t
47#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
48#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
49#endif
50
51#include <stddef.h>
52#include <stdint.h>
53
Ronald Crone9c09f12020-06-08 16:44:58 +020054int mbedtls_test_platform_setup( void );
55void mbedtls_test_platform_teardown( void );
Ronald Cronf40529d2020-06-09 16:27:37 +020056
Ronald Cron72d628f2020-06-08 17:05:57 +020057int mbedtls_test_unhexify( unsigned char *obuf, const char *ibuf );
58void mbedtls_test_hexify( unsigned char *obuf,
59 const unsigned char *ibuf,
60 int len );
Ronald Cronf40529d2020-06-09 16:27:37 +020061
62/**
63 * Allocate and zeroize a buffer.
64 *
65 * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
66 *
67 * For convenience, dies if allocation fails.
68 */
Ronald Cron690f3eb2020-06-10 10:42:18 +020069unsigned char *mbedtls_test_zero_alloc( size_t len );
Ronald Cronf40529d2020-06-09 16:27:37 +020070
71/**
72 * Allocate and fill a buffer from hex data.
73 *
74 * The buffer is sized exactly as needed. This allows to detect buffer
75 * overruns (including overreads) when running the test suite under valgrind.
76 *
77 * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
78 *
79 * For convenience, dies if allocation fails.
80 */
Ronald Crona256c702020-06-10 10:53:11 +020081unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen );
Ronald Cronf40529d2020-06-09 16:27:37 +020082
Ronald Cronde70b162020-06-10 11:03:08 +020083int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
84 uint32_t a_len, uint32_t b_len );
Ronald Cronf40529d2020-06-09 16:27:37 +020085
Ronald Cronb6d6d4c2020-06-03 10:11:18 +020086#endif /* TEST_HELPERS_H */