External random generator function, implemented by the platform.
When the compile-time option MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG is enabled, this function replaces Mbed TLS's entropy and DRBG modules for all random generation triggered via PSA crypto interfaces.
- Note
- This random generator must deliver random numbers with cryptographic quality and high performance. It must supply unpredictable numbers with a uniform distribution. The implementation of this function is responsible for ensuring that the random generator is seeded with sufficient entropy. If you have a hardware TRNG which is slow or delivers non-uniform output, declare it as an entropy source with mbedtls_entropy_add_source() instead of enabling this option.
- Parameters
-
[in,out] | context | Pointer to the random generator context. This is all-bits-zero on the first call and preserved between successive calls. |
[out] | output | Output buffer. On success, this buffer contains random data with a uniform distribution. |
| output_size | The size of the output buffer in bytes. |
[out] | output_length | On success, set this value to output_size . |
- Return values
-
PSA_SUCCESS | Success. The output buffer contains output_size bytes of cryptographic-quality random data, and *output_length is set to output_size . |
PSA_ERROR_INSUFFICIENT_ENTROPY | The random generator requires extra entropy and there is no way to obtain entropy under current environment conditions. This error should not happen under normal circumstances since this function is responsible for obtaining as much entropy as it needs. However implementations of this function may return PSA_ERROR_INSUFFICIENT_ENTROPY if there is no way to obtain entropy without blocking indefinitely. |
PSA_ERROR_HARDWARE_FAILURE | A failure of the random generator hardware that isn't covered by PSA_ERROR_INSUFFICIENT_ENTROPY. |