10#ifndef PSA_CRYPTO_RANDOM_IMPL_H
11#define PSA_CRYPTO_RANDOM_IMPL_H
15#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
24#if defined(MBEDTLS_CTR_DRBG_C)
27#undef MBEDTLS_PSA_HMAC_DRBG_MD_TYPE
29#elif defined(MBEDTLS_HMAC_DRBG_C)
32#if defined(MBEDTLS_MD_CAN_SHA512) && defined(MBEDTLS_MD_CAN_SHA256)
34#if SIZE_MAX > 0xffffffff
36#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA512
39#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA256
41#elif defined(MBEDTLS_MD_CAN_SHA512)
42#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA512
43#elif defined(MBEDTLS_MD_CAN_SHA256)
44#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA256
46#error "No hash algorithm available for HMAC_DBRG."
51#error "No DRBG module available for the psa_crypto module."
56#if defined(MBEDTLS_CTR_DRBG_C)
57#define MBEDTLS_PSA_RANDOM_MAX_REQUEST MBEDTLS_CTR_DRBG_MAX_REQUEST
58#elif defined(MBEDTLS_HMAC_DRBG_C)
59#define MBEDTLS_PSA_RANDOM_MAX_REQUEST MBEDTLS_HMAC_DRBG_MAX_REQUEST
62#if defined(MBEDTLS_CTR_DRBG_C)
64#elif defined(MBEDTLS_HMAC_DRBG_C)
72 mbedtls_psa_drbg_context_t
drbg;
79static inline void mbedtls_psa_drbg_init(mbedtls_psa_drbg_context_t *p_rng)
81#if defined(MBEDTLS_CTR_DRBG_C)
83#elif defined(MBEDTLS_HMAC_DRBG_C)
92static inline void mbedtls_psa_drbg_free(mbedtls_psa_drbg_context_t *p_rng)
94#if defined(MBEDTLS_CTR_DRBG_C)
96#elif defined(MBEDTLS_HMAC_DRBG_C)
112static inline int mbedtls_psa_drbg_seed(mbedtls_psa_drbg_context_t *drbg_ctx,
114 const unsigned char *custom,
size_t len)
116#if defined(MBEDTLS_CTR_DRBG_C)
118#elif defined(MBEDTLS_HMAC_DRBG_C)
This file contains definitions and functions for the CTR_DRBG pseudorandom generator.
void mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *ctx)
This function resets CTR_DRBG context to the state immediately after initial call of mbedtls_ctr_drbg...
void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context *ctx)
This function initializes the CTR_DRBG context, and prepares it for mbedtls_ctr_drbg_seed() or mbedtl...
int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
This function seeds and sets up the CTR_DRBG entropy source for future reseeds.
Entropy accumulator implementation.
int mbedtls_entropy_func(void *data, unsigned char *output, size_t len)
Retrieve entropy from the accumulator (Maximum length: MBEDTLS_ENTROPY_BLOCK_SIZE) (Thread-safe if MB...
The HMAC_DRBG pseudorandom generator.
int mbedtls_hmac_drbg_seed(mbedtls_hmac_drbg_context *ctx, const mbedtls_md_info_t *md_info, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
HMAC_DRBG initial seeding.
void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx)
HMAC_DRBG context initialization.
void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context *ctx)
This function resets HMAC_DRBG context to the state immediately after initial call of mbedtls_hmac_dr...
size_t len
Definition initial.c:23
const mbedtls_md_info_t * mbedtls_md_info_from_type(mbedtls_md_type_t md_type)
This function returns the message-digest information associated with the given digest type.
Internal utility functions for use of PSA Crypto.
The CTR_DRBG context structure.
Definition ctr_drbg.h:185
Entropy context structure.
Definition entropy.h:106
Definition hmac_drbg.h:74
Definition psa_crypto_random_impl.h:68
mbedtls_psa_drbg_context_t drbg
Definition psa_crypto_random_impl.h:72
mbedtls_entropy_context entropy
Definition psa_crypto_random_impl.h:71