Mbed OS Reference
Loading...
Searching...
No Matches
shared_rng.h
1/*
2 * shared_rng.h
3 *
4 * Copyright (C) 2019-2020, Arm Limited, All Rights Reserved
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 */
20
21#ifndef SHARED_RNG_H
22#define SHARED_RNG_H
23
24#if !defined(MBEDTLS_CONFIG_FILE)
25#include "config.h"
26#else
27#include MBEDTLS_CONFIG_FILE
28#endif
29
30#if defined(MBEDTLS_SSL_CONF_RNG)
31
32#define MBED_SHARED_RNG_NOT_INITIALIZED -1 /**< init_global_rng not called before global_rng */
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#include "mbedtls/hmac_drbg.h"
39#include "mbedtls/entropy.h"
40
41/**
42 * \brief Initializes hmac ready for rng
43 *
44 * \return 0 if successful, or
45 * MBEDTLS_ERR_MD_BAD_INPUT_DATA, or
46 * MBEDTLS_ERR_MD_ALLOC_FAILED, or
47 * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED.
48 */
49int init_global_rng();
50
51/**
52 * \brief Global HMAC_DRBG generate random
53 *
54 * \note Automatically reseeds if reseed_counter is reached or PR is enabled.
55 * \note init_global_rng function must be called
56 * before calling this function!
57 *
58 * \param ctx DRBG context
59 * \param dst Buffer to fill
60 * \param len Length of the buffer
61 *
62 * \return 0 if successful, or
63 * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or
64 * MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG or
65 * MBED_SHARED_RNG_NOT_INITIALIZED
66 */
67int global_rng( void *ctx, unsigned char *dst, size_t len );
68
69/**
70 * \brief Free allocated resources
71 */
72void free_global_rng();
73
74/**
75 * \brief Getter function for global hmac context
76 *
77 * \return global hmac context
78 */
79mbedtls_hmac_drbg_context *get_global_hmac_drbg();
80
81/**
82 * \brief Getter function for global entropy context
83 *
84 * \return global entropy context
85 */
86mbedtls_entropy_context *get_global_entropy();
87
88#ifdef __cplusplus
89}
90#endif
91
92#endif // MBEDTLS_SSL_CONF_RNG
93#endif // SHARED_RNG_H
Configuration options (set of defines)
Entropy accumulator implementation.
The HMAC_DRBG pseudorandom generator.
Entropy context structure.
Definition: entropy.h:129
HMAC_DRBG context.
Definition: hmac_drbg.h:93