Skip to content

Commit

Permalink
Merge pull request #18372 from benpicco/random_bytes-void
Browse files Browse the repository at this point in the history
random: use void * in random_bytes()
  • Loading branch information
maribu authored Jul 27, 2022
2 parents 7ee1b58 + 1e69740 commit e1ef2a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sys/include/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ uint32_t random_uint32(void);
/**
* @brief writes random bytes in the [0,0xff]-interval to memory
*/
void random_bytes(uint8_t *buf, size_t size);
void random_bytes(void *buf, size_t size);

/**
* @brief generates a random number r with a <= r < b.
Expand Down
5 changes: 3 additions & 2 deletions sys/random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ void auto_init_random(void)
random_init(seed);
}

void random_bytes(uint8_t *target, size_t n)
void random_bytes(void *target, size_t n)
{
uint32_t random;
uint8_t *dst = target;
uint8_t *random_pos = (uint8_t*)&random;
unsigned _n = 0;

Expand All @@ -71,7 +72,7 @@ void random_bytes(uint8_t *target, size_t n)
random = random_uint32();
random_pos = (uint8_t *) &random;
}
*target++ = *random_pos++;
*dst++ = *random_pos++;
}
}

Expand Down

0 comments on commit e1ef2a0

Please sign in to comment.