|
| 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 (C) 2018, ARM Limited, All Rights Reserved |
| 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 | + |
| 33 | +#include "crypto_driver_common.h" |
| 34 | + |
| 35 | +#ifdef __cplusplus |
| 36 | +extern "C" { |
| 37 | +#endif |
| 38 | + |
| 39 | +/** \defgroup driver_rng Entropy Generation |
| 40 | + */ |
| 41 | +/**@{*/ |
| 42 | + |
| 43 | +/** \brief A hardware-specific structure for a entropy providing hardware |
| 44 | + */ |
| 45 | +typedef struct psa_drv_entropy_context_s psa_drv_entropy_context_t; |
| 46 | + |
| 47 | +/** \brief Initialize an entropy driver |
| 48 | + * |
| 49 | + * |
| 50 | + * \param[in,out] p_context A hardware-specific structure |
| 51 | + * containing any context information for |
| 52 | + * the implementation |
| 53 | + * |
| 54 | + * \retval PSA_SUCCESS |
| 55 | + */ |
| 56 | +typedef psa_status_t (*psa_drv_entropy_init_t)(psa_drv_entropy_context_t *p_context); |
| 57 | + |
| 58 | +/** \brief Get a specified number of bits from the entropy source |
| 59 | + * |
| 60 | + * It retrives `buffer_size` bytes of data from the entropy source. The entropy |
| 61 | + * source will always fill the provided buffer to its full size, however, most |
| 62 | + * entropy sources have biases, and the actual amount of entropy contained in |
| 63 | + * the buffer will be less than the number of bytes. |
| 64 | + * The driver will return the actual number of bytes of entropy placed in the |
| 65 | + * buffer in `p_received_entropy_bytes`. |
| 66 | + * A PSA Crypto API implementation will likely feed the output of this function |
| 67 | + * into a Digital Random Bit Generator (DRBG), and typically has a minimum |
| 68 | + * amount of entropy that it needs. |
| 69 | + * To accomplish this, the PSA Crypto implementation should be designed to call |
| 70 | + * this function multiple times until it has received the required amount of |
| 71 | + * entropy from the entropy source. |
| 72 | + * |
| 73 | + * \param[in,out] p_context A hardware-specific structure |
| 74 | + * containing any context information |
| 75 | + * for the implementation |
| 76 | + * \param[out] p_buffer A caller-allocated buffer for the |
| 77 | + * retrieved entropy to be placed in |
| 78 | + * \param[in] buffer_size The allocated size of `p_buffer` |
| 79 | + * \param[out] p_received_entropy_bits The amount of entropy (in bits) |
| 80 | + * actually provided in `p_buffer` |
| 81 | + * |
| 82 | + * \retval PSA_SUCCESS |
| 83 | + */ |
| 84 | +typedef psa_status_t (*psa_drv_entropy_get_bits_t)(psa_drv_entropy_context_t *p_context, |
| 85 | + uint8_t *p_buffer, |
| 86 | + uint32_t buffer_size, |
| 87 | + uint32_t *p_received_entropy_bits); |
| 88 | + |
| 89 | +/** |
| 90 | + * \brief A struct containing all of the function pointers needed to interface |
| 91 | + * to an entropy source |
| 92 | + * |
| 93 | + * PSA Crypto API implementations should populate instances of the table as |
| 94 | + * appropriate upon startup. |
| 95 | + * |
| 96 | + * If one of the functions is not implemented, it should be set to NULL. |
| 97 | + */ |
| 98 | +typedef struct { |
| 99 | + /** Function that performs initialization for the entropy source */ |
| 100 | + psa_drv_entropy_init_t *p_init; |
| 101 | + /** Function that performs the get_bits operation for the entropy source |
| 102 | + */ |
| 103 | + psa_drv_entropy_get_bits_t *p_get_bits; |
| 104 | +} psa_drv_entropy_t; |
| 105 | +/**@}*/ |
| 106 | + |
| 107 | +#ifdef __cplusplus |
| 108 | +} |
| 109 | +#endif |
| 110 | + |
| 111 | +#endif /* PSA_CRYPTO_ENTROPY_DRIVER_H */ |
0 commit comments