1
0
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:
mguetschow 2024-06-03 09:27:00 +00:00 committed by GitHub
commit f2c18b0b58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 4 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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++) {