aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>2018-04-22 10:18:17 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2018-04-23 21:28:59 +0300
commitc440dfceff97526d2763383afd8da064faef3d0d (patch)
treeefb558eb5e88e64a14f8adf196407b7aac8ef367
parent93591a6134fbc5655c0cf6a25e0b4e0668357971 (diff)
linux-generic: random: split from crypto module
While random and crypto might share some implementation details, in case of linux-generic and linux-DPDK it might be easier to split them to two different files. Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r--platform/linux-generic/Makefile.am1
-rw-r--r--platform/linux-generic/odp_crypto.c42
-rw-r--r--platform/linux-generic/odp_random.c54
3 files changed, 55 insertions, 42 deletions
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index 4f03eab15..7d1d55546 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -175,6 +175,7 @@ __LIB__libodp_linux_la_SOURCES = \
odp_queue_if.c \
odp_queue_lf.c \
odp_queue_scalable.c \
+ odp_random.c \
odp_rwlock.c \
odp_rwlock_recursive.c \
odp_schedule_basic.c \
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index 852f02125..aca822d8a 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -23,7 +23,6 @@
#include <string.h>
#include <stdlib.h>
-#include <openssl/rand.h>
#include <openssl/hmac.h>
#include <openssl/cmac.h>
#include <openssl/evp.h>
@@ -1954,47 +1953,6 @@ int _odp_crypto_term_local(void)
return 0;
}
-odp_random_kind_t odp_random_max_kind(void)
-{
- return ODP_RANDOM_CRYPTO;
-}
-
-int32_t odp_random_data(uint8_t *buf, uint32_t len, odp_random_kind_t kind)
-{
- int rc;
-
- switch (kind) {
- case ODP_RANDOM_BASIC:
- case ODP_RANDOM_CRYPTO:
- rc = RAND_bytes(buf, len);
- return (1 == rc) ? (int)len /*success*/: -1 /*failure*/;
-
- case ODP_RANDOM_TRUE:
- default:
- return -1;
- }
-}
-
-int32_t odp_random_test_data(uint8_t *buf, uint32_t len, uint64_t *seed)
-{
- union {
- uint32_t rand_word;
- uint8_t rand_byte[4];
- } u;
- uint32_t i = 0, j;
- uint32_t seed32 = (*seed) & 0xffffffff;
-
- while (i < len) {
- u.rand_word = rand_r(&seed32);
-
- for (j = 0; j < 4 && i < len; j++, i++)
- *buf++ = u.rand_byte[j];
- }
-
- *seed = seed32;
- return len;
-}
-
odp_crypto_compl_t odp_crypto_compl_from_event(odp_event_t ev)
{
/* This check not mandated by the API specification */
diff --git a/platform/linux-generic/odp_random.c b/platform/linux-generic/odp_random.c
new file mode 100644
index 000000000..22894c473
--- /dev/null
+++ b/platform/linux-generic/odp_random.c
@@ -0,0 +1,54 @@
+/* Copyright (c) 2014-2018, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "config.h"
+
+#include <odp_posix_extensions.h>
+#include <odp_internal.h>
+#include <odp/api/random.h>
+
+#include <openssl/rand.h>
+
+odp_random_kind_t odp_random_max_kind(void)
+{
+ return ODP_RANDOM_CRYPTO;
+}
+
+int32_t odp_random_data(uint8_t *buf, uint32_t len, odp_random_kind_t kind)
+{
+ int rc;
+
+ switch (kind) {
+ case ODP_RANDOM_BASIC:
+ case ODP_RANDOM_CRYPTO:
+ rc = RAND_bytes(buf, len);
+ return (1 == rc) ? (int)len /*success*/: -1 /*failure*/;
+
+ case ODP_RANDOM_TRUE:
+ default:
+ return -1;
+ }
+}
+
+int32_t odp_random_test_data(uint8_t *buf, uint32_t len, uint64_t *seed)
+{
+ union {
+ uint32_t rand_word;
+ uint8_t rand_byte[4];
+ } u;
+ uint32_t i = 0, j;
+ uint32_t seed32 = (*seed) & 0xffffffff;
+
+ while (i < len) {
+ u.rand_word = rand_r(&seed32);
+
+ for (j = 0; j < 4 && i < len; j++, i++)
+ *buf++ = u.rand_byte[j];
+ }
+
+ *seed = seed32;
+ return len;
+}