random: add sys_rand8/16/64_get()

add sys_rand8_get(), sys_rand16_get() and sys_rand64_get()

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
Fin Maaß 2024-03-25 23:10:01 +01:00 committed by Carles Cufí
parent 019b813a71
commit 5230b64cf0
1 changed files with 53 additions and 0 deletions

View File

@ -67,6 +67,42 @@ __syscall void sys_rand_get(void *dst, size_t len);
*/
__syscall int sys_csrand_get(void *dst, size_t len);
/**
* @brief Return a 8-bit random value that should pass general
* randomness tests.
*
* @note The random value returned is not a cryptographically secure
* random number value.
*
* @return 8-bit random value.
*/
static inline uint8_t sys_rand8_get(void)
{
uint8_t ret;
sys_rand_get(&ret, sizeof(ret));
return ret;
}
/**
* @brief Return a 16-bit random value that should pass general
* randomness tests.
*
* @note The random value returned is not a cryptographically secure
* random number value.
*
* @return 16-bit random value.
*/
static inline uint16_t sys_rand16_get(void)
{
uint16_t ret;
sys_rand_get(&ret, sizeof(ret));
return ret;
}
/**
* @brief Return a 32-bit random value that should pass general
* randomness tests.
@ -85,6 +121,23 @@ static inline uint32_t sys_rand32_get(void)
return ret;
}
/**
* @brief Return a 64-bit random value that should pass general
* randomness tests.
*
* @note The random value returned is not a cryptographically secure
* random number value.
*
* @return 64-bit random value.
*/
static inline uint64_t sys_rand64_get(void)
{
uint64_t ret;
sys_rand_get(&ret, sizeof(ret));
return ret;
}
#ifdef __cplusplus
}