Joe Hershberger | eafc8db | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 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 | |
Michael Walle | 99e139d | 2012-06-05 11:33:15 +0000 | [diff] [blame] | 12 | #include <common.h> |
Joe Hershberger | eafc8db | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 13 | |
| 14 | /* |
Michael Walle | 99e139d | 2012-06-05 11:33:15 +0000 | [diff] [blame] | 15 | * Return a seed for the PRNG derived from the eth0 MAC address. |
Joe Hershberger | eafc8db | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 16 | */ |
Michael Walle | 99e139d | 2012-06-05 11:33:15 +0000 | [diff] [blame] | 17 | static inline unsigned int seed_mac(void) |
| 18 | { |
| 19 | unsigned char enetaddr[6]; |
| 20 | unsigned int seed; |
| 21 | |
| 22 | /* get our mac */ |
| 23 | eth_getenv_enetaddr("ethaddr", enetaddr); |
| 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 | } |
Joe Hershberger | eafc8db | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 34 | |
| 35 | /* |
Michael Walle | 99e139d | 2012-06-05 11:33:15 +0000 | [diff] [blame] | 36 | * Seed the random number generator using the eth0 MAC address. |
Joe Hershberger | eafc8db | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 37 | */ |
Michael Walle | 99e139d | 2012-06-05 11:33:15 +0000 | [diff] [blame] | 38 | static inline void srand_mac(void) |
| 39 | { |
| 40 | srand(seed_mac()); |
| 41 | } |
Joe Hershberger | eafc8db | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 42 | |
| 43 | #endif /* __NET_RAND_H__ */ |