|
@ -1,4 +1,4 @@ |
|
|
/* $OpenBSD: arc4random.c,v 1.7 2003/02/14 17:12:54 deraadt Exp $ */ |
|
|
|
|
|
|
|
|
/* $OpenBSD: arc4random.c,v 1.8 2003/06/11 21:03:10 deraadt Exp $ */ |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Arc4 random number generator for OpenBSD. |
|
|
* Arc4 random number generator for OpenBSD. |
|
@ -49,8 +49,7 @@ static struct arc4_stream rs; |
|
|
static pid_t arc4_stir_pid; |
|
|
static pid_t arc4_stir_pid; |
|
|
|
|
|
|
|
|
static inline void |
|
|
static inline void |
|
|
arc4_init(as) |
|
|
|
|
|
struct arc4_stream *as; |
|
|
|
|
|
|
|
|
arc4_init(struct arc4_stream *as) |
|
|
{ |
|
|
{ |
|
|
int n; |
|
|
int n; |
|
|
|
|
|
|
|
@ -61,10 +60,7 @@ arc4_init(as) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static inline void |
|
|
static inline void |
|
|
arc4_addrandom(as, dat, datlen) |
|
|
|
|
|
struct arc4_stream *as; |
|
|
|
|
|
u_char *dat; |
|
|
|
|
|
int datlen; |
|
|
|
|
|
|
|
|
arc4_addrandom(struct arc4_stream *as, u_char *dat, int datlen) |
|
|
{ |
|
|
{ |
|
|
int n; |
|
|
int n; |
|
|
u_int8_t si; |
|
|
u_int8_t si; |
|
@ -81,8 +77,7 @@ arc4_addrandom(as, dat, datlen) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void |
|
|
static void |
|
|
arc4_stir(as) |
|
|
|
|
|
struct arc4_stream *as; |
|
|
|
|
|
|
|
|
arc4_stir(struct arc4_stream *as) |
|
|
{ |
|
|
{ |
|
|
int fd; |
|
|
int fd; |
|
|
struct { |
|
|
struct { |
|
@ -119,8 +114,7 @@ arc4_stir(as) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static inline u_int8_t |
|
|
static inline u_int8_t |
|
|
arc4_getbyte(as) |
|
|
|
|
|
struct arc4_stream *as; |
|
|
|
|
|
|
|
|
arc4_getbyte(struct arc4_stream *as) |
|
|
{ |
|
|
{ |
|
|
u_int8_t si, sj; |
|
|
u_int8_t si, sj; |
|
|
|
|
|
|
|
@ -134,8 +128,7 @@ arc4_getbyte(as) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static inline u_int32_t |
|
|
static inline u_int32_t |
|
|
arc4_getword(as) |
|
|
|
|
|
struct arc4_stream *as; |
|
|
|
|
|
|
|
|
arc4_getword(struct arc4_stream *as) |
|
|
{ |
|
|
{ |
|
|
u_int32_t val; |
|
|
u_int32_t val; |
|
|
val = arc4_getbyte(as) << 24; |
|
|
val = arc4_getbyte(as) << 24; |
|
@ -146,7 +139,7 @@ arc4_getword(as) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void |
|
|
void |
|
|
arc4random_stir() |
|
|
|
|
|
|
|
|
arc4random_stir(void) |
|
|
{ |
|
|
{ |
|
|
if (!rs_initialized) { |
|
|
if (!rs_initialized) { |
|
|
arc4_init(&rs); |
|
|
arc4_init(&rs); |
|
@ -156,9 +149,7 @@ arc4random_stir() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void |
|
|
void |
|
|
arc4random_addrandom(dat, datlen) |
|
|
|
|
|
u_char *dat; |
|
|
|
|
|
int datlen; |
|
|
|
|
|
|
|
|
arc4random_addrandom(u_char *dat, int datlen) |
|
|
{ |
|
|
{ |
|
|
if (!rs_initialized) |
|
|
if (!rs_initialized) |
|
|
arc4random_stir(); |
|
|
arc4random_stir(); |
|
@ -166,7 +157,7 @@ arc4random_addrandom(dat, datlen) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
u_int32_t |
|
|
u_int32_t |
|
|
arc4random() |
|
|
|
|
|
|
|
|
arc4random(void) |
|
|
{ |
|
|
{ |
|
|
if (!rs_initialized || arc4_stir_pid != getpid()) |
|
|
if (!rs_initialized || arc4_stir_pid != getpid()) |
|
|
arc4random_stir(); |
|
|
arc4random_stir(); |
|
|