blob: c608035978535e80c81cf8fc3d67b9da8d42dd04 [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
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_RANDOM_H
27#define TEST_RANDOM_H
28
29#if !defined(MBEDTLS_CONFIG_FILE)
30#include "mbedtls/config.h"
31#else
32#include MBEDTLS_CONFIG_FILE
33#endif
34
Ronald Cron2058d562020-06-09 17:11:47 +020035#include <stddef.h>
36#include <stdint.h>
37
38typedef struct
39{
40 unsigned char *buf;
41 size_t length;
42} rnd_buf_info;
43
44/**
45 * Info structure for the pseudo random function
46 *
47 * Key should be set at the start to a test-unique value.
48 * Do not forget endianness!
49 * State( v0, v1 ) should be set to zero.
50 */
51typedef struct
52{
53 uint32_t key[16];
54 uint32_t v0, v1;
55} rnd_pseudo_info;
56
57/**
58 * This function just returns data from rand().
59 * Although predictable and often similar on multiple
60 * runs, this does not result in identical random on
61 * each run. So do not use this if the results of a
62 * test depend on the random data that is generated.
63 *
64 * rng_state shall be NULL.
65 */
66int rnd_std_rand( void *rng_state, unsigned char *output, size_t len );
67
68/**
69 * This function only returns zeros
70 *
71 * rng_state shall be NULL.
72 */
73int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len );
74
75/**
76 * This function returns random based on a buffer it receives.
77 *
78 * rng_state shall be a pointer to a rnd_buf_info structure.
79 *
80 * The number of bytes released from the buffer on each call to
81 * the random function is specified by per_call. (Can be between
82 * 1 and 4)
83 *
84 * After the buffer is empty it will return rand();
85 */
86int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len );
87
88/**
89 * This function returns random based on a pseudo random function.
90 * This means the results should be identical on all systems.
91 * Pseudo random is based on the XTEA encryption algorithm to
92 * generate pseudorandom.
93 *
94 * rng_state shall be a pointer to a rnd_pseudo_info structure.
95 */
96int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len );
97
Ronald Cronb7eb67f2020-06-09 16:57:42 +020098#endif /* TEST_RANDOM_H */