aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Wiklander <jens.wiklander@linaro.org>2018-06-14 11:12:00 +0200
committerJérôme Forissier <jerome.forissier@linaro.org>2018-06-18 10:01:13 +0200
commit249c24a353272a94c17898d3dfc0aaf8b2eda032 (patch)
tree7d023e20505151c08475ea176d761c8dedbae225
parent6e954a6e42bd37911605d3b4cd22e4d1d23c2372 (diff)
libmpa: remove mpa_set_random_generator()
MPA is used in two configurations, either in kernel mode or in user mode. In kernel mode random is always drawn with crypto_rng_read() and in user mode utee_cryp_random_number_generate() is used instead. This patch makes the code easier to follow by replacing the call via a function pointer to a normal function call instead. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
-rw-r--r--core/lib/libtomcrypt/src/tee_ltc_provider.c1
-rw-r--r--lib/libmpa/include/mpalib.h4
-rw-r--r--lib/libmpa/mpa_random.c19
-rw-r--r--lib/libutee/arch/arm/utee_misc.c12
-rw-r--r--lib/libutee/tee_api_arith.c1
5 files changed, 16 insertions, 21 deletions
diff --git a/core/lib/libtomcrypt/src/tee_ltc_provider.c b/core/lib/libtomcrypt/src/tee_ltc_provider.c
index 86000421..0c35a340 100644
--- a/core/lib/libtomcrypt/src/tee_ltc_provider.c
+++ b/core/lib/libtomcrypt/src/tee_ltc_provider.c
@@ -467,7 +467,6 @@ static void tee_ltc_alloc_mpa(void)
if (!mem.pool)
panic();
init_mpa_tomcrypt(&mem);
- mpa_set_random_generator(crypto_rng_read);
}
size_t crypto_bignum_num_bytes(struct bignum *a)
diff --git a/lib/libmpa/include/mpalib.h b/lib/libmpa/include/mpalib.h
index 9c502c4a..5c1cd39e 100644
--- a/lib/libmpa/include/mpalib.h
+++ b/lib/libmpa/include/mpalib.h
@@ -336,10 +336,6 @@ MPALIB_EXPORT mpanum mpa_constant_one(void);
* From mpa_Random.c
*/
-typedef uint32_t (*random_generator_cb)(void *buf, size_t blen);
-
-MPALIB_EXPORT void mpa_set_random_generator(random_generator_cb callback);
-
MPALIB_EXPORT void mpa_get_random(mpanum dest, mpanum limit);
/*
diff --git a/lib/libmpa/mpa_random.c b/lib/libmpa/mpa_random.c
index 55d0ea4c..4f4e2da4 100644
--- a/lib/libmpa/mpa_random.c
+++ b/lib/libmpa/mpa_random.c
@@ -5,12 +5,25 @@
#include "mpa.h"
#include <tee_api_types.h>
-static random_generator_cb get_rng_array;
+/*
+ * This code is compiled for both kernel and user mode. How to obtain
+ * random differs since the RNG resides in kernel mode.
+ */
+#ifdef __KERNEL__
+#include <crypto/crypto.h>
+
+static TEE_Result get_rng_array(void *buf, size_t blen)
+{
+ return crypto_rng_read(buf, blen);
+}
+#else
+#include "utee_syscalls.h"
-void mpa_set_random_generator(random_generator_cb callback)
+static TEE_Result get_rng_array(void *buf, size_t blen)
{
- get_rng_array = callback;
+ return utee_cryp_random_number_generate(buf, blen);
}
+#endif
static uint8_t get_random_byte(void)
{
diff --git a/lib/libutee/arch/arm/utee_misc.c b/lib/libutee/arch/arm/utee_misc.c
index 964f5293..636f080f 100644
--- a/lib/libutee/arch/arm/utee_misc.c
+++ b/lib/libutee/arch/arm/utee_misc.c
@@ -15,15 +15,3 @@ unsigned int utee_get_ta_exec_id(void)
/* no execution ID available */
return 0;
}
-
-/*
- * This version of get_rng_array() is used by the libmpa, when used on user side
- * This is why this function is not implemented in libutee for targets with
- * trusted os not split into kernel / user side. In such case, only the
- * get_rng_array() version from the kernel side is used.
- */
-extern TEE_Result get_rng_array(void *buf, size_t blen);
-TEE_Result get_rng_array(void *buf, size_t blen)
-{
- return utee_cryp_random_number_generate(buf, blen);
-}
diff --git a/lib/libutee/tee_api_arith.c b/lib/libutee/tee_api_arith.c
index 749a99a3..0f6c7f1f 100644
--- a/lib/libutee/tee_api_arith.c
+++ b/lib/libutee/tee_api_arith.c
@@ -60,7 +60,6 @@ void _TEE_MathAPI_Init(void)
*/
mem.bn_bits = CFG_TA_BIGNUM_MAX_BITS * 2;
mempool = &mem;
- mpa_set_random_generator(get_rng_array);
}
/*