v / thirdparty / mbedtls / library / psa_crypto_random.h
72 lines · 62 sloc · 2.05 KB · 3d9911f887ecec942f9ae2a5be02d064f233b729
Raw
1/*
2 * PSA crypto random generator internal functions.
3 */
4/*
5 * Copyright The Mbed TLS Contributors
6 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7 */
8
9#ifndef PSA_CRYPTO_RANDOM_H
10#define PSA_CRYPTO_RANDOM_H
11
12#include "common.h"
13
14#if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
15
16#include <psa/crypto.h>
17#include "psa_crypto_random_impl.h"
18
19/** Initialize the PSA random generator.
20 *
21 * \param[out] rng The random generator context to initialize.
22 */
23void psa_random_internal_init(mbedtls_psa_random_context_t *rng);
24
25/** Deinitialize the PSA random generator.
26 *
27 * \param[in,out] rng The random generator context to deinitialize.
28 */
29void psa_random_internal_free(mbedtls_psa_random_context_t *rng);
30
31/** Seed the PSA random generator.
32 *
33 * \note This function is not thread-safe.
34 *
35 * \param[in,out] rng The random generator context to seed.
36 *
37 * \retval #PSA_SUCCESS
38 * Success.
39 * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
40 * The entropy source failed.
41 */
42psa_status_t psa_random_internal_seed(mbedtls_psa_random_context_t *rng);
43
44/**
45 * \brief Generate random bytes. Like psa_generate_random(), but for use
46 * inside the library.
47 *
48 * This function is thread-safe.
49 *
50 * \warning This function **can** fail! Callers MUST check the return status
51 * and MUST NOT use the content of the output buffer if the return
52 * status is not #PSA_SUCCESS.
53 *
54 * \param[in,out] rng The random generator context to seed.
55 * \param[out] output Output buffer for the generated data.
56 * \param output_size Number of bytes to generate and output.
57 *
58 * \retval #PSA_SUCCESS
59 * Success.
60 * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
61 * The random generator needed to reseed, and the entropy
62 * source failed.
63 * \retval #PSA_ERROR_HARDWARE_FAILURE
64 * A hardware accelerator failed.
65 */
66psa_status_t psa_random_internal_generate(
67 mbedtls_psa_random_context_t *rng,
68 uint8_t *output, size_t output_size);
69
70#endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */
71
72#endif /* PSA_CRYPTO_RANDOM_H */
73