Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 1 | /** |
| 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 Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 35 | #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 Cron | e9c09f1 | 2020-06-08 16:44:58 +0200 | [diff] [blame] | 53 | int mbedtls_test_platform_setup( void ); |
| 54 | void mbedtls_test_platform_teardown( void ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 55 | |
Ronald Cron | 72d628f | 2020-06-08 17:05:57 +0200 | [diff] [blame^] | 56 | int mbedtls_test_unhexify( unsigned char *obuf, const char *ibuf ); |
| 57 | void mbedtls_test_hexify( unsigned char *obuf, |
| 58 | const unsigned char *ibuf, |
| 59 | int len ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Allocate and zeroize a buffer. |
| 63 | * |
| 64 | * If the size if zero, a pointer to a zeroized 1-byte buffer is returned. |
| 65 | * |
| 66 | * For convenience, dies if allocation fails. |
| 67 | */ |
| 68 | unsigned char *zero_alloc( size_t len ); |
| 69 | |
| 70 | /** |
| 71 | * Allocate and fill a buffer from hex data. |
| 72 | * |
| 73 | * The buffer is sized exactly as needed. This allows to detect buffer |
| 74 | * overruns (including overreads) when running the test suite under valgrind. |
| 75 | * |
| 76 | * If the size if zero, a pointer to a zeroized 1-byte buffer is returned. |
| 77 | * |
| 78 | * For convenience, dies if allocation fails. |
| 79 | */ |
| 80 | unsigned char *unhexify_alloc( const char *ibuf, size_t *olen ); |
| 81 | |
| 82 | int hexcmp( uint8_t * a, uint8_t * b, uint32_t a_len, uint32_t b_len ); |
| 83 | |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 84 | #endif /* TEST_HELPERS_H */ |