blob: e085f16b5dbeb9d3a6245746e5c0f11927aa78ed [file] [log] [blame]
Ronald Cronb7eb67f2020-06-09 16:57:42 +02001/**
2 * \file random.h
3 *
4 * \brief This file contains the prototypes of helper functions to generate
5 * random numbers for the 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 Cronb7eb67f2020-06-09 16:57:42 +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_RANDOM_H
28#define TEST_RANDOM_H
29
30#if !defined(MBEDTLS_CONFIG_FILE)
31#include "mbedtls/config.h"
32#else
33#include MBEDTLS_CONFIG_FILE
34#endif
35
Ronald Cron2058d562020-06-09 17:11:47 +020036#include <stddef.h>
37#include <stdint.h>
38
39typedef struct
40{
41 unsigned char *buf;
42 size_t length;
Ronald Cron351f0ee2020-06-10 12:12:18 +020043} mbedtls_test_rnd_buf_info;
Ronald Cron2058d562020-06-09 17:11:47 +020044
45/**
46 * Info structure for the pseudo random function
47 *
48 * Key should be set at the start to a test-unique value.
49 * Do not forget endianness!
50 * State( v0, v1 ) should be set to zero.
51 */
52typedef struct
53{
54 uint32_t key[16];
55 uint32_t v0, v1;
Ronald Cron351f0ee2020-06-10 12:12:18 +020056} mbedtls_test_rnd_pseudo_info;
Ronald Cron2058d562020-06-09 17:11:47 +020057
58/**
59 * This function just returns data from rand().
60 * Although predictable and often similar on multiple
61 * runs, this does not result in identical random on
62 * each run. So do not use this if the results of a
63 * test depend on the random data that is generated.
64 *
65 * rng_state shall be NULL.
66 */
Ronald Cron351f0ee2020-06-10 12:12:18 +020067int mbedtls_test_rnd_std_rand( void *rng_state,
68 unsigned char *output,
69 size_t len );
Ronald Cron2058d562020-06-09 17:11:47 +020070
71/**
72 * This function only returns zeros
73 *
74 * rng_state shall be NULL.
75 */
Ronald Cron351f0ee2020-06-10 12:12:18 +020076int mbedtls_test_rnd_zero_rand( void *rng_state,
77 unsigned char *output,
78 size_t len );
Ronald Cron2058d562020-06-09 17:11:47 +020079
80/**
81 * This function returns random based on a buffer it receives.
82 *
83 * rng_state shall be a pointer to a rnd_buf_info structure.
84 *
85 * The number of bytes released from the buffer on each call to
86 * the random function is specified by per_call. (Can be between
87 * 1 and 4)
88 *
89 * After the buffer is empty it will return rand();
90 */
Ronald Cron351f0ee2020-06-10 12:12:18 +020091int mbedtls_test_rnd_buffer_rand( void *rng_state,
92 unsigned char *output,
93 size_t len );
Ronald Cron2058d562020-06-09 17:11:47 +020094
95/**
96 * This function returns random based on a pseudo random function.
97 * This means the results should be identical on all systems.
98 * Pseudo random is based on the XTEA encryption algorithm to
99 * generate pseudorandom.
100 *
101 * rng_state shall be a pointer to a rnd_pseudo_info structure.
102 */
Ronald Cron351f0ee2020-06-10 12:12:18 +0200103int mbedtls_test_rnd_pseudo_rand( void *rng_state,
104 unsigned char *output,
105 size_t len );
Ronald Cron2058d562020-06-09 17:11:47 +0200106
Ronald Cronb7eb67f2020-06-09 16:57:42 +0200107#endif /* TEST_RANDOM_H */