diff mbox

[API-NEXT,PATCHv4,2/7] api: random: add ability to generate repeatable random data

Message ID 1478133719-10981-2-git-send-email-bill.fischofer@linaro.org
State Superseded
Headers show

Commit Message

Bill Fischofer Nov. 3, 2016, 12:41 a.m. UTC
Add the new API odp_random_seeded_data() to allow generation of repeatable
deterministic random data from a user-specified seed value that is
updated by each call. Sequences of calls using the same initial seed value
will generate the same pseudo-random sequence.

The caller may specify the kind of data that is to be generated however
the only required kind that need be supported is ODP_RANDOM_BASIC.
Attempts to generate repeatable ODP_RANDOM_TRUE are contradictory and
should be failed.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
 include/odp/api/spec/random.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

-- 
2.7.4
diff mbox

Patch

diff --git a/include/odp/api/spec/random.h b/include/odp/api/spec/random.h
index 62f2376..69d35c8 100644
--- a/include/odp/api/spec/random.h
+++ b/include/odp/api/spec/random.h
@@ -59,6 +59,28 @@  typedef enum {
 int odp_random_data(uint8_t *buf, uint32_t len, odp_random_kind_t kind);
 
 /**
+ * Generate repeatable random byte data
+ *
+ * For testing purposes it is often useful to generate "random" sequences
+ * that are repeatable. This is accomplished by supplying a seed value that
+ * is used for pseudo-random data generation. The caller provides
+ *
+ * @param[out]    buf  Output buffer
+ * @param         len  Length of output buffer in bytes
+ * @param         kind Specifies the type of random data required. Request
+ *                     will fail if the implementation is unable to provide
+ *                     repeatable random of the requested type. This is
+ *                     always true for true random and may be true for
+ *                     cryptographic random.
+ * @param[in,out] seed Seed value to use
+ *
+ * @return Number of bytes written
+ * @retval <0 on failure
+ */
+int odp_random_seeded_data(uint8_t *buf, uint32_t len,
+			   odp_random_kind_t kind, uint32_t *seed);
+
+/**
  * @}
  */