diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/crypt/arc4random.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c index 1e338f9968..35d7953002 100644 --- a/src/lib/libc/crypt/arc4random.c +++ b/src/lib/libc/crypt/arc4random.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random.c,v 1.15 2005/11/30 07:51:02 otto Exp $ */ | 1 | /* $OpenBSD: arc4random.c,v 1.16 2007/02/12 19:58:47 otto Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -110,7 +110,7 @@ arc4_stir(struct arc4_stream *as) | |||
| 110 | */ | 110 | */ |
| 111 | for (i = 0; i < 256; i++) | 111 | for (i = 0; i < 256; i++) |
| 112 | (void)arc4_getbyte(as); | 112 | (void)arc4_getbyte(as); |
| 113 | arc4_count = 400000; | 113 | arc4_count = 1600000; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | static inline u_int8_t | 116 | static inline u_int8_t |
| @@ -127,6 +127,14 @@ arc4_getbyte(struct arc4_stream *as) | |||
| 127 | return (as->s[(si + sj) & 0xff]); | 127 | return (as->s[(si + sj) & 0xff]); |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | u_int8_t | ||
| 131 | __arc4_getbyte(void) | ||
| 132 | { | ||
| 133 | if (--arc4_count == 0 || !rs_initialized) | ||
| 134 | arc4random_stir(); | ||
| 135 | return arc4_getbyte(&rs); | ||
| 136 | } | ||
| 137 | |||
| 130 | static inline u_int32_t | 138 | static inline u_int32_t |
| 131 | arc4_getword(struct arc4_stream *as) | 139 | arc4_getword(struct arc4_stream *as) |
| 132 | { | 140 | { |
| @@ -159,7 +167,8 @@ arc4random_addrandom(u_char *dat, int datlen) | |||
| 159 | u_int32_t | 167 | u_int32_t |
| 160 | arc4random(void) | 168 | arc4random(void) |
| 161 | { | 169 | { |
| 162 | if (--arc4_count == 0 || !rs_initialized || arc4_stir_pid != getpid()) | 170 | arc4_count -= 4; |
| 171 | if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != getpid()) | ||
| 163 | arc4random_stir(); | 172 | arc4random_stir(); |
| 164 | return arc4_getword(&rs); | 173 | return arc4_getword(&rs); |
| 165 | } | 174 | } |
