Add internal function to reseed PSA RNG

Not applicable to an external RNG.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2026-01-16 19:01:48 +01:00
parent 4de8b1043a
commit fb6503bf62

View File

@@ -100,6 +100,8 @@ static inline void mbedtls_psa_drbg_free(mbedtls_psa_drbg_context_t *p_rng)
/** Seed the PSA DRBG.
*
* \param drbg_ctx The DRBG context to seed.
* It must be initialized but not active.
* \param entropy An entropy context to read the seed from.
* \param custom The personalization string.
* This can be \c NULL, in which case the personalization
@@ -121,6 +123,28 @@ static inline int mbedtls_psa_drbg_seed(mbedtls_psa_drbg_context_t *drbg_ctx,
#endif
}
/** Reseed the PSA DRBG.
*
* \param drbg_ctx The DRBG context to reseed.
* It must be active.
* \param additional Additional data to inject.
* \param len The length of \p additional in bytes.
* This can be 0 to simply reseed from the entropy source.
*
* \return \c 0 on success.
* \return An Mbed TLS error code (\c MBEDTLS_ERR_xxx) on failure.
*/
static inline int mbedtls_psa_drbg_reseed(mbedtls_psa_drbg_context_t *drbg_ctx,
const unsigned char *additional,
size_t len)
{
#if defined(MBEDTLS_CTR_DRBG_C)
return mbedtls_ctr_drbg_reseed(drbg_ctx, additional, len);
#elif defined(MBEDTLS_HMAC_DRBG_C)
return mbedtls_hmac_drbg_reseed(drbg_ctx, additional, len);
#endif
}
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
#endif /* PSA_CRYPTO_RANDOM_IMPL_H */