Mbed OS Reference
Loading...
Searching...
No Matches
crypto_entropy_driver.h
Go to the documentation of this file.
1/**
2 * \file psa/crypto_entropy_driver.h
3 * \brief PSA entropy source driver module
4 *
5 * This header declares types and function signatures for entropy sources.
6 *
7 * This file is part of the PSA Crypto Driver Model, containing functions for
8 * driver developers to implement to enable hardware to be called in a
9 * standardized way by a PSA Cryptographic API implementation. The functions
10 * comprising the driver model, which driver authors implement, are not
11 * intended to be called by application developers.
12 */
13
14/*
15 * Copyright The Mbed TLS Contributors
16 * SPDX-License-Identifier: Apache-2.0
17 *
18 * Licensed under the Apache License, Version 2.0 (the "License"); you may
19 * not use this file except in compliance with the License.
20 * You may obtain a copy of the License at
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Unless required by applicable law or agreed to in writing, software
25 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 * See the License for the specific language governing permissions and
28 * limitations under the License.
29 */
30#ifndef PSA_CRYPTO_ENTROPY_DRIVER_H
31#define PSA_CRYPTO_ENTROPY_DRIVER_H
32
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/** \defgroup driver_rng Entropy Generation
40 * \ingroup experimental-crypto-psa
41 */
42/**@{*/
43
44/** \brief Initialize an entropy driver
45 *
46 *
47 * \param[in,out] p_context A hardware-specific structure
48 * containing any context information for
49 * the implementation
50 *
51 * \retval #PSA_SUCCESS
52 */
53typedef psa_status_t (*psa_drv_entropy_init_t)(void *p_context);
54
55/** \brief Get a specified number of bits from the entropy source
56 *
57 * It retrives `buffer_size` bytes of data from the entropy source. The entropy
58 * source will always fill the provided buffer to its full size, however, most
59 * entropy sources have biases, and the actual amount of entropy contained in
60 * the buffer will be less than the number of bytes.
61 * The driver will return the actual number of bytes of entropy placed in the
62 * buffer in `p_received_entropy_bytes`.
63 * A PSA Crypto API implementation will likely feed the output of this function
64 * into a Digital Random Bit Generator (DRBG), and typically has a minimum
65 * amount of entropy that it needs.
66 * To accomplish this, the PSA Crypto implementation should be designed to call
67 * this function multiple times until it has received the required amount of
68 * entropy from the entropy source.
69 *
70 * \param[in,out] p_context A hardware-specific structure
71 * containing any context information
72 * for the implementation
73 * \param[out] p_buffer A caller-allocated buffer for the
74 * retrieved entropy to be placed in
75 * \param[in] buffer_size The allocated size of `p_buffer`
76 * \param[out] p_received_entropy_bits The amount of entropy (in bits)
77 * actually provided in `p_buffer`
78 *
79 * \retval #PSA_SUCCESS
80 */
81typedef psa_status_t (*psa_drv_entropy_get_bits_t)(void *p_context,
82 uint8_t *p_buffer,
83 uint32_t buffer_size,
84 uint32_t *p_received_entropy_bits);
85
86/**
87 * \brief A struct containing all of the function pointers needed to interface
88 * to an entropy source
89 *
90 * PSA Crypto API implementations should populate instances of the table as
91 * appropriate upon startup.
92 *
93 * If one of the functions is not implemented, it should be set to NULL.
94 */
95typedef struct {
96 /** The driver-specific size of the entropy context */
97 const size_t context_size;
98 /** Function that performs initialization for the entropy source */
100 /** Function that performs the get_bits operation for the entropy source */
103/**@}*/
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif /* PSA_CRYPTO_ENTROPY_DRIVER_H */
Definitions for all PSA crypto drivers.
psa_status_t(* psa_drv_entropy_get_bits_t)(void *p_context, uint8_t *p_buffer, uint32_t buffer_size, uint32_t *p_received_entropy_bits)
Get a specified number of bits from the entropy source.
psa_status_t(* psa_drv_entropy_init_t)(void *p_context)
Initialize an entropy driver.
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:55
A struct containing all of the function pointers needed to interface to an entropy source.
const size_t context_size
The driver-specific size of the entropy context.
psa_drv_entropy_get_bits_t p_get_bits
Function that performs the get_bits operation for the entropy source.
psa_drv_entropy_init_t p_init
Function that performs initialization for the entropy source.