net: Use NDRNG device in srand_mac()
When calling srand_mac we use a weak seed dependent on the mac address. If present, use a RNG device instead to incerase entropy. Signed-off-by: Matthias Brugger <mbrugger@suse.com> Reviewed-by: Torsten Duwe <duwe@suse.de>
This commit is contained in:
parent
92fdad28cf
commit
ea707dc0aa
@ -10,6 +10,8 @@
|
||||
#define __NET_RAND_H__
|
||||
|
||||
#include <common.h>
|
||||
#include <dm/uclass.h>
|
||||
#include <rng.h>
|
||||
|
||||
/*
|
||||
* Return a seed for the PRNG derived from the eth0 MAC address.
|
||||
@ -37,6 +39,21 @@ static inline unsigned int seed_mac(void)
|
||||
*/
|
||||
static inline void srand_mac(void)
|
||||
{
|
||||
int ret;
|
||||
struct udevice *devp;
|
||||
u32 randv = 0;
|
||||
|
||||
if (IS_ENABLED(CONFIG_DM_RNG)) {
|
||||
ret = uclass_get_device(UCLASS_RNG, 0, &devp);
|
||||
if (ret) {
|
||||
ret = dm_rng_read(devp, &randv, sizeof(randv));
|
||||
if (ret < 0)
|
||||
randv = 0;
|
||||
}
|
||||
}
|
||||
if (randv)
|
||||
srand(randv);
|
||||
else
|
||||
srand(seed_mac());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user