blob: 817353ad11a682e8fb68a335ff0326b7d830a4e3 [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
8/* Copyright (C) 2020, ARM Limited, All Rights Reserved
9 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 *
23 * This file is part of mbed TLS (https://tls.mbed.org)
24 */
25
26#ifndef TEST_HELPERS_H
27#define TEST_HELPERS_H
28
29#if !defined(MBEDTLS_CONFIG_FILE)
30#include "mbedtls/config.h"
31#else
32#include MBEDTLS_CONFIG_FILE
33#endif
34
Ronald Cronf40529d2020-06-09 16:27:37 +020035#if defined(MBEDTLS_PLATFORM_C)
36#include "mbedtls/platform.h"
37#else
38#include <stdio.h>
39#define mbedtls_fprintf fprintf
40#define mbedtls_snprintf snprintf
41#define mbedtls_calloc calloc
42#define mbedtls_free free
43#define mbedtls_exit exit
44#define mbedtls_time time
45#define mbedtls_time_t time_t
46#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
47#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
48#endif
49
50#include <stddef.h>
51#include <stdint.h>
52
Ronald Crone9c09f12020-06-08 16:44:58 +020053int mbedtls_test_platform_setup( void );
54void mbedtls_test_platform_teardown( void );
Ronald Cronf40529d2020-06-09 16:27:37 +020055
56int unhexify( unsigned char *obuf, const char *ibuf );
57void hexify( unsigned char *obuf, const unsigned char *ibuf, int len );
58
59/**
60 * Allocate and zeroize a buffer.
61 *
62 * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
63 *
64 * For convenience, dies if allocation fails.
65 */
66unsigned char *zero_alloc( size_t len );
67
68/**
69 * Allocate and fill a buffer from hex data.
70 *
71 * The buffer is sized exactly as needed. This allows to detect buffer
72 * overruns (including overreads) when running the test suite under valgrind.
73 *
74 * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
75 *
76 * For convenience, dies if allocation fails.
77 */
78unsigned char *unhexify_alloc( const char *ibuf, size_t *olen );
79
80int hexcmp( uint8_t * a, uint8_t * b, uint32_t a_len, uint32_t b_len );
81
Ronald Cronb6d6d4c2020-06-03 10:11:18 +020082#endif /* TEST_HELPERS_H */