diff options
author | Jens Wiklander <jens.wiklander@linaro.org> | 2018-05-07 15:48:37 +0200 |
---|---|---|
committer | Jérôme Forissier <jerome.forissier@linaro.org> | 2018-05-22 15:23:06 +0200 |
commit | 433c42576132eb4c57ef6c9a2b912b907ce7d046 (patch) | |
tree | 96fec71d681aca4e39cf971cb62597cc09602791 /lib/libutee | |
parent | a496e4c93036b5d1d37d607449a340d61533e8e5 (diff) |
Add rand() for TA usage
Adds rand() by declaring it in stdlib.h where it's expected to be found.
Implementation is provided in libutee since it depends on
TEE_GenerateRandom().
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Diffstat (limited to 'lib/libutee')
-rw-r--r-- | lib/libutee/tee_api_operations.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/libutee/tee_api_operations.c b/lib/libutee/tee_api_operations.c index 1f214fc3..42d47b66 100644 --- a/lib/libutee/tee_api_operations.c +++ b/lib/libutee/tee_api_operations.c @@ -1791,3 +1791,16 @@ void TEE_GenerateRandom(void *randomBuffer, uint32_t randomBufferLen) if (res != TEE_SUCCESS) TEE_Panic(res); } + +int rand(void) +{ + int rc; + + TEE_GenerateRandom(&rc, sizeof(rc)); + + /* + * RAND_MAX is the larges int, INT_MAX which is all bits but the + * highest bit set. + */ + return rc & RAND_MAX; +} |