mirror of
https://github.com/apache/nuttx.git
synced 2026-05-24 16:11:56 +08:00
drivers/virtio: Use arc4random_buf to generate MAC address.
Use arc4random_buf instead of rand() to improve randomness quality and avoid using weak PRNG for MAC generation. Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
@@ -624,20 +625,8 @@ static void virtio_net_set_macaddr(FAR struct virtio_net_priv_s *priv)
|
||||
* conflicts with something else on the network.
|
||||
*/
|
||||
|
||||
srand(time(NULL) +
|
||||
#ifdef CONFIG_NETDEV_IFINDEX
|
||||
dev->d_ifindex
|
||||
#else
|
||||
(uintptr_t)dev % 256
|
||||
#endif
|
||||
);
|
||||
|
||||
mac[0] = 0x42;
|
||||
mac[1] = rand() % 256;
|
||||
mac[2] = rand() % 256;
|
||||
mac[3] = rand() % 256;
|
||||
mac[4] = rand() % 256;
|
||||
mac[5] = rand() % 256;
|
||||
arc4random_buf(mac + 1, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user