Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/gen/arc4random.c
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | for (n = 0; n < 256; n++) { | ||||
si = rs.s[rs.i]; | si = rs.s[rs.i]; | ||||
rs.j = (rs.j + si + dat[n % datlen]); | rs.j = (rs.j + si + dat[n % datlen]); | ||||
rs.s[rs.i] = rs.s[rs.j]; | rs.s[rs.i] = rs.s[rs.j]; | ||||
rs.s[rs.j] = si; | rs.s[rs.j] = si; | ||||
} | } | ||||
rs.j = rs.i; | rs.j = rs.i; | ||||
} | } | ||||
static size_t | size_t | ||||
arc4_sysctl(u_char *buf, size_t size) | __arc4_sysctl(u_char *buf, size_t size) | ||||
{ | { | ||||
int mib[2]; | int mib[2]; | ||||
size_t len, done; | size_t len, done; | ||||
mib[0] = CTL_KERN; | mib[0] = CTL_KERN; | ||||
mib[1] = KERN_ARND; | mib[1] = KERN_ARND; | ||||
done = 0; | done = 0; | ||||
Show All 14 Lines | |||||
{ | { | ||||
u_char rdat[KEYSIZE]; | u_char rdat[KEYSIZE]; | ||||
int i; | int i; | ||||
if (!rs_initialized) { | if (!rs_initialized) { | ||||
arc4_init(); | arc4_init(); | ||||
rs_initialized = 1; | rs_initialized = 1; | ||||
} | } | ||||
if (arc4_sysctl(rdat, KEYSIZE) != KEYSIZE) { | if (__arc4_sysctl(rdat, KEYSIZE) != KEYSIZE) { | ||||
/* | /* | ||||
* The sysctl cannot fail. If it does fail on some FreeBSD | * The sysctl cannot fail. If it does fail on some FreeBSD | ||||
* derivative or after some future change, just abort so that | * derivative or after some future change, just abort so that | ||||
* the problem will be found and fixed. abort is not normally | * the problem will be found and fixed. abort is not normally | ||||
* suitable for a library but makes sense here. | * suitable for a library but makes sense here. | ||||
*/ | */ | ||||
abort(); | abort(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 147 Lines • Show Last 20 Lines |