xref: /openbmc/u-boot/net/net_rand.h (revision dd4671cb)
1 /*
2  *	Copied from LiMon - BOOTP.
3  *
4  *	Copyright 1994, 1995, 2000 Neil Russell.
5  *	(See License)
6  *	Copyright 2000 Paolo Scaffardi
7  */
8 
9 #ifndef __NET_RAND_H__
10 #define __NET_RAND_H__
11 
12 #include <common.h>
13 
14 /*
15  * Return a seed for the PRNG derived from the eth0 MAC address.
16  */
17 static inline unsigned int seed_mac(void)
18 {
19 	unsigned char enetaddr[ARP_HLEN];
20 	unsigned int seed;
21 
22 	/* get our mac */
23 	memcpy(enetaddr, eth_get_ethaddr(), ARP_HLEN);
24 
25 	seed = enetaddr[5];
26 	seed ^= enetaddr[4] << 8;
27 	seed ^= enetaddr[3] << 16;
28 	seed ^= enetaddr[2] << 24;
29 	seed ^= enetaddr[1];
30 	seed ^= enetaddr[0] << 8;
31 
32 	return seed;
33 }
34 
35 /*
36  * Seed the random number generator using the eth0 MAC address.
37  */
38 static inline void srand_mac(void)
39 {
40 	srand(seed_mac());
41 }
42 
43 #endif /* __NET_RAND_H__ */
44