> + > +/** > + * Generate repeatable random data for testing purposes > + * > + * 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-provided seed value is > + * updated for each call to continue the sequence. Restarting a series of > + * calls with the same initial seed value will generate the same sequence > of > + * random test data. > + * > + * This function should be used only for testing purposes. Use > + * odp_random_data() for production. > * > - * @todo Define the implication of the use_entropy parameter > + * @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 > */ > -int32_t odp_random_data(uint8_t *buf, int32_t size, odp_bool_t > use_entropy); > +int32_t odp_random_test_data(uint8_t *buf, uint32_t len, > + odp_random_kind_t kind, uint32_t *seed); >
This is from rand_r() documentation: " The value pointed to by the seedp argument of rand_r() provides only a very small amount of state, so this function will be a weak pseudo- random generator. Try drand48_r(3) instead." API should not limit the state size to be so small that e.g. ODP_RANDOM_CRYPTO quality implementation is not possible. So, I think we are back in my previous proposal of implementation specific state size. /** Random number generator state data */ typedef struct odp_random_state_t { // Implementation defined structure size uint32_t random_state[32]; } odp_random_state_t; /** * Initialize random state data with a seed value * * Uses some bits of seed to initialize the state data */ void odp_random_state_init(odp_random_state_t *state, uint64_t seed); /** * Generate repeatable random data for testing purposes * * 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-provided state data is * updated for each call to continue the sequence. A series of calls with the * same initial seeded state data will generate the same sequence of random * test data. Use odp_random_state_init() to initialize or restart the state. * The function is thread safe as long as multiple threads do not use the same * state simultaneously. * * This function should be used only for testing purposes. Use odp_random_data() * for production. */ int32_t odp_random_test_data(uint8_t *buf, uint32_t len, odp_random_kind_t kind, odp_random_state_t *state); For example, these functions could be used with this spec: int random_r(struct random_data *buf, int32_t *result); int srandom_r(unsigned int seed, struct random_data *buf); int initstate_r(unsigned int seed, char *statebuf, size_t statelen, struct random_data *buf); int setstate_r(char *statebuf, struct random_data *buf); Although, those seem to be nonstandard glibc extensions, so might not what to use those in odp-linux, if strict posix API implementation is preferred. -Petri