mirror of
https://github.com/cuberite/polarssl.git
synced 2025-10-04 02:52:38 -04:00
psa: move mbedtls_psa_get_random() to psa_util.c
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
665cf928d9
commit
bb91bcda0e
@ -7394,39 +7394,6 @@ psa_status_t psa_generate_random(uint8_t *output,
|
|||||||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wrapper function allowing the classic API to use the PSA RNG.
|
|
||||||
*
|
|
||||||
* `mbedtls_psa_get_random(MBEDTLS_PSA_RANDOM_STATE, ...)` calls
|
|
||||||
* `psa_generate_random(...)`. The state parameter is ignored since the
|
|
||||||
* PSA API doesn't support passing an explicit state.
|
|
||||||
*
|
|
||||||
* In the non-external case, psa_generate_random() calls an
|
|
||||||
* `mbedtls_xxx_drbg_random` function which has exactly the same signature
|
|
||||||
* and semantics as mbedtls_psa_get_random(). As an optimization,
|
|
||||||
* instead of doing this back-and-forth between the PSA API and the
|
|
||||||
* classic API, psa_crypto_random_impl.h defines `mbedtls_psa_get_random`
|
|
||||||
* as a constant function pointer to `mbedtls_xxx_drbg_random`.
|
|
||||||
*/
|
|
||||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
|
||||||
int mbedtls_psa_get_random(void *p_rng,
|
|
||||||
unsigned char *output,
|
|
||||||
size_t output_size)
|
|
||||||
{
|
|
||||||
/* This function takes a pointer to the RNG state because that's what
|
|
||||||
* classic mbedtls functions using an RNG expect. The PSA RNG manages
|
|
||||||
* its own state internally and doesn't let the caller access that state.
|
|
||||||
* So we just ignore the state parameter, and in practice we'll pass
|
|
||||||
* NULL. */
|
|
||||||
(void) p_rng;
|
|
||||||
psa_status_t status = psa_generate_random(output, output_size);
|
|
||||||
if (status == PSA_SUCCESS) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
|
#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
|
||||||
psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed,
|
psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed,
|
||||||
size_t seed_size)
|
size_t seed_size)
|
||||||
|
@ -338,6 +338,39 @@ mbedtls_ecp_group_id mbedtls_ecc_group_from_psa(psa_ecc_family_t family,
|
|||||||
}
|
}
|
||||||
#endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */
|
#endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */
|
||||||
|
|
||||||
|
/* Wrapper function allowing the classic API to use the PSA RNG.
|
||||||
|
*
|
||||||
|
* `mbedtls_psa_get_random(MBEDTLS_PSA_RANDOM_STATE, ...)` calls
|
||||||
|
* `psa_generate_random(...)`. The state parameter is ignored since the
|
||||||
|
* PSA API doesn't support passing an explicit state.
|
||||||
|
*
|
||||||
|
* In the non-external case, psa_generate_random() calls an
|
||||||
|
* `mbedtls_xxx_drbg_random` function which has exactly the same signature
|
||||||
|
* and semantics as mbedtls_psa_get_random(). As an optimization,
|
||||||
|
* instead of doing this back-and-forth between the PSA API and the
|
||||||
|
* classic API, psa_crypto_random_impl.h defines `mbedtls_psa_get_random`
|
||||||
|
* as a constant function pointer to `mbedtls_xxx_drbg_random`.
|
||||||
|
*/
|
||||||
|
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||||
|
int mbedtls_psa_get_random(void *p_rng,
|
||||||
|
unsigned char *output,
|
||||||
|
size_t output_size)
|
||||||
|
{
|
||||||
|
/* This function takes a pointer to the RNG state because that's what
|
||||||
|
* classic mbedtls functions using an RNG expect. The PSA RNG manages
|
||||||
|
* its own state internally and doesn't let the caller access that state.
|
||||||
|
* So we just ignore the state parameter, and in practice we'll pass
|
||||||
|
* NULL. */
|
||||||
|
(void) p_rng;
|
||||||
|
psa_status_t status = psa_generate_random(output, output_size);
|
||||||
|
if (status == PSA_SUCCESS) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||||
|
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA)
|
#if defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user