Skip to content

Commit 796d477

Browse files
authored
Merge pull request #6 from ARMmbed/xoroshiro128
Add local pseudo-RNG to randLIB
2 parents 80f5c49 + c1634ba commit 796d477

File tree

13 files changed

+330
-416
lines changed

13 files changed

+330
-416
lines changed

Makefile

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
2-
# Check if we are compiling for Linux using GCC
3-
ifneq (,$(findstring gcc,$(CC)))
4-
TARGET_IS_LINUX := $(shell $(CC) -dM -E - < /dev/null | grep __linux >/dev/null && echo "yes" || echo "no")
5-
endif
6-
7-
ifeq (yes,$(TARGET_IS_LINUX))
8-
SRCS := $(wildcard linux/*)
9-
else
101
SRCS := $(wildcard source/*)
11-
endif
12-
132
LIB := librand.a
143
EXPORT_HEADERS := mbed-client-randlib
154

linux/randLIB.c

Lines changed: 0 additions & 168 deletions
This file was deleted.

mbed-client-randlib/platform/arm_hal_random.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ extern "C" {
2525
extern void arm_random_module_init(void);
2626
/**
2727
* \brief Get random library seed value.
28+
*
29+
* This function should return as random a value as possible, using
30+
* hardware sources. Repeated calls should return different values if
31+
* at all possible.
2832
*/
2933
extern uint32_t arm_random_seed_get(void);
3034
#ifdef __cplusplus

mbed-client-randlib/randLIB.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,23 @@ extern "C" {
4848
/**
4949
* \brief Init seed for Pseudo Random.
5050
*
51+
* Makes call(s) to the platform's arm_random_seed_get() to seed the
52+
* pseudo-random generator.
53+
*
5154
* \return None
5255
*
5356
*/
5457
extern void randLIB_seed_random(void);
5558

59+
/**
60+
* \brief Update seed for pseudo-random generator
61+
*
62+
* Adds seed information to existing generator, to perturb the
63+
* sequence.
64+
* \param seed 64 bits of data to add to the seed.
65+
*/
66+
extern void randLIB_add_seed(uint64_t seed);
67+
5668
/**
5769
* \brief Generate 8-bit random number.
5870
*
@@ -75,21 +87,29 @@ extern uint16_t randLIB_get_16bit(void);
7587
* \brief Generate 32-bit random number.
7688
*
7789
* \param None
78-
* \return 16-bit random number
90+
* \return 32-bit random number
7991
*
8092
*/
8193
extern uint32_t randLIB_get_32bit(void);
8294

95+
/**
96+
* \brief Generate 64-bit random number.
97+
*
98+
* \param None
99+
* \return 64-bit random number
100+
*
101+
*/
102+
extern uint64_t randLIB_get_64bit(void);
103+
83104
/**
84105
* \brief Generate n-bytes random numbers.
85106
*
86107
* \param data_ptr pointer where random will be stored
87-
* \param eight_bit_boundary how many bytes need random
88-
* \return 0 process valid
89-
* \return -1 Unsupported Parameters
108+
* \param count how many bytes need random
90109
*
110+
* \return data_ptr
91111
*/
92-
extern int8_t randLIB_get_n_bytes_random(uint8_t *data_ptr, uint8_t eight_bit_boundary);
112+
extern void *randLIB_get_n_bytes_random(void *data_ptr, uint8_t count);
93113

94114
/**
95115
* \brief Generate a random number within a range.
@@ -117,6 +137,12 @@ uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max);
117137
*/
118138
uint32_t randLIB_randomise_base(uint32_t base, uint16_t min_factor, uint16_t max_factor);
119139

140+
#ifdef RANDLIB_PRNG
141+
/* \internal Reset the PRNG state to zero (invalid) */
142+
void randLIB_reset(void);
143+
#endif
144+
145+
120146
#ifdef __cplusplus
121147
}
122148
#endif

0 commit comments

Comments
 (0)