Date: Mon, 16 Feb 2004 14:36:13 -0800 (PST) From: Sam Leffler <sam@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 47054 for review Message-ID: <200402162236.i1GMaDPt067121@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=47054 Change 47054 by sam@sam_ebb on 2004/02/16 14:35:16 add get_random_bytes to ease portability Affected files ... .. //depot/projects/netperf+sockets/sys/net80211/ieee80211_freebsd.c#3 edit Differences ... ==== //depot/projects/netperf+sockets/sys/net80211/ieee80211_freebsd.c#3 (text+ko) ==== @@ -60,6 +60,28 @@ return m; } +void +get_random_bytes(void *data, u_int len) +{ + int i = len / sizeof(u_int32_t); + + KASSERT((len % sizeof(u_int32_t)) == 0, + ("len %u not a multiple of word size", len)); + if (!ALIGNED_POINTER(data, u_int32_t)) { + u_int8_t *bp; + + for (bp = data; --i >= 0; bp += sizeof(u_int32_t)) { + u_int32_t v = arc4random(); + memcpy(bp, &v, sizeof(v)); + } + } else { + u_int32_t *dp = data; + + while (--i >= 0) + *dp++ = arc4random(); + } +} + /* * Module glue. *
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200402162236.i1GMaDPt067121>