summaryrefslogtreecommitdiff
path: root/core/tee/tee_cryp_utl.c
diff options
context:
space:
mode:
authorAndy Green <andy@warmcat.com>2017-01-26 21:37:10 +0800
committerAndy Green <andy@warmcat.com>2017-02-23 17:39:02 +0800
commit2a5e2ec6b9dad8006f75570fcf99073731919eeb (patch)
tree250fbfe6757e2afa60155b83f763af3fb60c432d /core/tee/tee_cryp_utl.c
parent4f448dff536a5c99a9b1db7fdf3de0d660d13691 (diff)
prng: move old implementation to be weak default
The patch replaces the original entropy scheme using system time with the new api plat_prng_add_jitter_entropy(). The old scheme aimed to get 64 bits of entropy from the current time expressed in 64 bits in ms each time. Most of this was in fact zeros or unchanging for >256s. If you call it twice with 1ms, it actually provides 0 bits of entropy. The replacement scheme aims to get 2 bits of entropy from the counter, which typically operates faster than 1MHz, greater than a thousand times more precision than the old way, each time. For backwards compatibility, the old scheme is retained as the default or arches or platforms that did not provide an override to collect jitter in a better way. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Tested-by: Jerome Forissier <jerome.forissier@linaro.org>
Diffstat (limited to 'core/tee/tee_cryp_utl.c')
-rw-r--r--core/tee/tee_cryp_utl.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/core/tee/tee_cryp_utl.c b/core/tee/tee_cryp_utl.c
index 8f82a504..fa011619 100644
--- a/core/tee/tee_cryp_utl.c
+++ b/core/tee/tee_cryp_utl.c
@@ -31,6 +31,7 @@
#include <utee_defines.h>
#include <tee/tee_cryp_utl.h>
#include <tee/tee_cryp_provider.h>
+#include <kernel/tee_time.h>
#include <rng_support.h>
#include <initcall.h>
@@ -379,11 +380,16 @@ TEE_Result tee_prng_add_entropy(const uint8_t *in, size_t len)
}
/*
- * override this in your platform code to feed the PRNG
- * platform-specific jitter entropy.
+ * Override this in your platform code to feed the PRNG platform-specific
+ * jitter entropy. This implementation does not efficiently deliver entropy
+ * and is here for backwards-compatibility.
*/
__weak void plat_prng_add_jitter_entropy(void)
{
+ TEE_Time current;
+
+ if (tee_time_get_sys_time(&current) == TEE_SUCCESS)
+ tee_prng_add_entropy((uint8_t *)&current, sizeof(current));
}
static TEE_Result tee_cryp_init(void)