summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt/arc4random.c
diff options
context:
space:
mode:
authorderaadt <>2014-07-19 00:08:43 +0000
committerderaadt <>2014-07-19 00:08:43 +0000
commit63559a378edd18f00978f68eeb77fbd0f088a804 (patch)
treed1d1ea706aec9066edcbf60e8dd1c10257101a1d /src/lib/libc/crypt/arc4random.c
parentc08eb4d65e7656f34e0b7949bf7f3102cb5faaeb (diff)
downloadopenbsd-63559a378edd18f00978f68eeb77fbd0f088a804.tar.gz
openbsd-63559a378edd18f00978f68eeb77fbd0f088a804.tar.bz2
openbsd-63559a378edd18f00978f68eeb77fbd0f088a804.zip
Change _rs_allocate so it can combine the two regions (rs and rsx)
into one if a system has an awesome getentropy(). In that case it is valid to totally throw away the rsx state in the child. If the getentropy() is not very good and has a lazy reseed operation, this combining is a bad idea, and the reseed should probably continue to use the "something old, something new" mix. _rs_allocate() can accomodate either method, but not on the fly. ok matthew
Diffstat (limited to 'src/lib/libc/crypt/arc4random.c')
-rw-r--r--src/lib/libc/crypt/arc4random.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c
index d42022c455..3c80beb3b9 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.47 2014/07/18 02:05:55 deraadt Exp $ */ 1/* $OpenBSD: arc4random.c,v 1.48 2014/07/19 00:08:41 deraadt Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -57,17 +57,16 @@ static struct _rs {
57 size_t rs_count; /* bytes till reseed */ 57 size_t rs_count; /* bytes till reseed */
58} *rs; 58} *rs;
59 59
60static inline void *_rs_allocate(size_t len); 60/* Maybe be preserved in fork children, if _rs_allocate() decides. */
61static inline void _rs_forkdetect(void); 61static struct _rsx {
62static inline void _rs_forkdetectsetup(struct _rs *buf, size_t len);
63#include "arc4random.h"
64
65/* Preserved in fork children. */
66static struct {
67 chacha_ctx rs_chacha; /* chacha context for random keystream */ 62 chacha_ctx rs_chacha; /* chacha context for random keystream */
68 u_char rs_buf[RSBUFSZ]; /* keystream blocks */ 63 u_char rs_buf[RSBUFSZ]; /* keystream blocks */
69} *rsx; 64} *rsx;
70 65
66static inline int _rs_allocate(struct _rs **, struct _rsx **);
67static inline void _rs_forkdetect(void);
68#include "arc4random.h"
69
71static inline void _rs_rekey(u_char *dat, size_t datlen); 70static inline void _rs_rekey(u_char *dat, size_t datlen);
72 71
73static inline void 72static inline void
@@ -77,12 +76,7 @@ _rs_init(u_char *buf, size_t n)
77 return; 76 return;
78 77
79 if (rs == NULL) { 78 if (rs == NULL) {
80 if ((rs = _rs_allocate(sizeof(*rs))) == NULL) 79 if (_rs_allocate(&rs, &rsx) == -1)
81 abort();
82 _rs_forkdetectsetup(rs, sizeof(*rs));
83 }
84 if (rsx == NULL) {
85 if ((rsx = _rs_allocate(sizeof(*rsx))) == NULL)
86 abort(); 80 abort();
87 } 81 }
88 82