mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-03 21:32:08 +00:00
PPP, magic, use LWIP_RAND() if available
If LWIP_RAND() is available, it is used instead of libc srand()/rand() if PPP_MD5_RANDM is disabled and it is added as a source of randomness if PPP_MD5_RANDM is enabled.
This commit is contained in:
parent
541e3b6eb4
commit
36305e5bd8
@ -112,8 +112,14 @@ static void magic_churnrand(char *rand_data, u32_t rand_len) {
|
|||||||
struct {
|
struct {
|
||||||
/* INCLUDE fields for any system sources of randomness */
|
/* INCLUDE fields for any system sources of randomness */
|
||||||
u32_t jiffies;
|
u32_t jiffies;
|
||||||
|
#ifdef LWIP_RAND
|
||||||
|
u32_t rand;
|
||||||
|
#endif /* LWIP_RAND */
|
||||||
} sys_data;
|
} sys_data;
|
||||||
sys_data.jiffies = sys_jiffies();
|
sys_data.jiffies = sys_jiffies();
|
||||||
|
#ifdef LWIP_RAND
|
||||||
|
sys_data.rand = LWIP_RAND();
|
||||||
|
#endif /* LWIP_RAND */
|
||||||
/* Load sys_data fields here. */
|
/* Load sys_data fields here. */
|
||||||
md5_update(&md5, (u_char *)&sys_data, sizeof(sys_data));
|
md5_update(&md5, (u_char *)&sys_data, sizeof(sys_data));
|
||||||
}
|
}
|
||||||
@ -211,9 +217,10 @@ static u32_t magic_randomseed = 0; /* Seed used for random number generatio
|
|||||||
*/
|
*/
|
||||||
void magic_init(void) {
|
void magic_init(void) {
|
||||||
magic_randomseed += sys_jiffies();
|
magic_randomseed += sys_jiffies();
|
||||||
|
#ifndef LWIP_RAND
|
||||||
/* Initialize the Borland random number generator. */
|
/* Initialize the Borland random number generator. */
|
||||||
srand((unsigned)magic_randomseed);
|
srand((unsigned)magic_randomseed);
|
||||||
|
#endif /* LWIP_RAND */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -247,7 +254,11 @@ void magic_randomize(void) {
|
|||||||
* seeded by the real time clock.
|
* seeded by the real time clock.
|
||||||
*/
|
*/
|
||||||
u32_t magic(void) {
|
u32_t magic(void) {
|
||||||
return ((((u32_t)rand() << 16) + rand()) + magic_randomseed);
|
#ifdef LWIP_RAND
|
||||||
|
return LWIP_RAND() + magic_randomseed;
|
||||||
|
#else /* LWIP_RAND */
|
||||||
|
return (u32_t)rand() << 16 + (u32_t)rand() + magic_randomseed;
|
||||||
|
#endif /* LWIP_RAND */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user