mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #20718 from LP-HAW/fix-sha2prng-init
sys/random: fix SHAxPRNG init_by_array
This commit is contained in:
commit
f2c18b0b58
@ -78,7 +78,7 @@ void random_init(uint32_t s);
|
||||
* slight change for C++, 2004/2/26
|
||||
*
|
||||
* @param init_key array of keys (seeds) to initialize the PRNG
|
||||
* @param key_length number of lements in init_key
|
||||
* @param key_length number of elements in init_key
|
||||
*/
|
||||
void random_init_by_array(uint32_t init_key[], int key_length);
|
||||
|
||||
|
@ -149,7 +149,7 @@ void _random_bytes(uint8_t *bytes, size_t size)
|
||||
void random_init_by_array(uint32_t init_key[], int key_length)
|
||||
{
|
||||
_shax_init(&ctx);
|
||||
_shax_update(&ctx, init_key, key_length);
|
||||
_shax_update(&ctx, init_key, key_length * sizeof(uint32_t));
|
||||
_shax_final(&ctx, digestdata);
|
||||
|
||||
/* copy SHA digestdata to PRNG state */
|
||||
@ -161,7 +161,7 @@ void random_init_by_array(uint32_t init_key[], int key_length)
|
||||
|
||||
void random_init(uint32_t seed)
|
||||
{
|
||||
random_init_by_array((uint32_t *)&seed, sizeof(seed));
|
||||
random_init_by_array((uint32_t *)&seed, 1);
|
||||
}
|
||||
|
||||
uint32_t random_uint32(void)
|
||||
|
@ -57,7 +57,7 @@ static void test_prng_sha1prng_java_u32(void)
|
||||
/* seed the generator with 8 bytes similar to the java reference
|
||||
* implementation
|
||||
*/
|
||||
random_init_by_array(seed, sizeof(seed));
|
||||
random_init_by_array(seed, ARRAY_SIZE(seed));
|
||||
|
||||
/* request random samples */
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(seq_seed1); i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user