summaryrefslogtreecommitdiff
path: root/entropy.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-02-18 15:28:11 +1100
committerDamien Miller <djm@mindrot.org>2001-02-18 15:28:11 +1100
commita1072a8e3728a044acfb96ca1e69aa0cb9c09aeb (patch)
tree170d3d2b900d1df2de9277512948be57c8e6d8db /entropy.c
parent132a8fc4c9c6110e447e669afb42703fba44e703 (diff)
- (djm) Move entropy.c over to mysignal()
Diffstat (limited to 'entropy.c')
-rw-r--r--entropy.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/entropy.c b/entropy.c
index fb81d7822..ed8b8db2c 100644
--- a/entropy.c
+++ b/entropy.c
@@ -33,12 +33,13 @@
33#endif /* HAVE_FLOATINGPOINT_H */ 33#endif /* HAVE_FLOATINGPOINT_H */
34 34
35#include "ssh.h" 35#include "ssh.h"
36#include "misc.h"
36#include "xmalloc.h" 37#include "xmalloc.h"
37#include "atomicio.h" 38#include "atomicio.h"
38#include "pathnames.h" 39#include "pathnames.h"
39#include "log.h" 40#include "log.h"
40 41
41RCSID("$Id: entropy.c,v 1.27 2001/02/18 01:44:29 djm Exp $"); 42RCSID("$Id: entropy.c,v 1.28 2001/02/18 04:28:12 djm Exp $");
42 43
43#ifndef offsetof 44#ifndef offsetof
44# define offsetof(type, member) ((size_t) &((type *)0)->member) 45# define offsetof(type, member) ((size_t) &((type *)0)->member)
@@ -72,7 +73,7 @@ int get_random_bytes(unsigned char *buf, int len)
72 char msg[2]; 73 char msg[2];
73 struct sockaddr_un addr; 74 struct sockaddr_un addr;
74 int addr_len, rval, errors; 75 int addr_len, rval, errors;
75 struct sigaction nsa, osa; 76 mysig_t old_sigpipe;
76 77
77 /* Sanity checks */ 78 /* Sanity checks */
78 if (sizeof(EGD_SOCKET) > sizeof(addr.sun_path)) 79 if (sizeof(EGD_SOCKET) > sizeof(addr.sun_path))
@@ -85,9 +86,7 @@ int get_random_bytes(unsigned char *buf, int len)
85 strlcpy(addr.sun_path, EGD_SOCKET, sizeof(addr.sun_path)); 86 strlcpy(addr.sun_path, EGD_SOCKET, sizeof(addr.sun_path));
86 addr_len = offsetof(struct sockaddr_un, sun_path) + sizeof(EGD_SOCKET); 87 addr_len = offsetof(struct sockaddr_un, sun_path) + sizeof(EGD_SOCKET);
87 88
88 memset(&nsa, 0, sizeof(nsa)); 89 old_sigpipe = mysignal(SIGPIPE, SIG_IGN);
89 nsa.sa_handler = SIG_IGN;
90 (void) sigaction(SIGPIPE, &nsa, &osa);
91 90
92 errors = rval = 0; 91 errors = rval = 0;
93reopen: 92reopen:
@@ -131,7 +130,7 @@ reopen:
131 130
132 rval = 1; 131 rval = 1;
133done: 132done:
134 (void) sigaction(SIGPIPE, &osa, NULL); 133 mysignal(SIG_PIPE, old_sigpipe);
135 if (fd != -1) 134 if (fd != -1)
136 close(fd); 135 close(fd);
137 return(rval); 136 return(rval);
@@ -790,14 +789,14 @@ prng_seed_cleanup(void *junk)
790void 789void
791seed_rng(void) 790seed_rng(void)
792{ 791{
793 void *old_sigchld_handler; 792 mysig_t old_sigchld_handler;
794 793
795 if (!prng_initialised) 794 if (!prng_initialised)
796 fatal("RNG not initialised"); 795 fatal("RNG not initialised");
797 796
798 /* Make sure some other sigchld handler doesn't reap our entropy */ 797 /* Make sure some other sigchld handler doesn't reap our entropy */
799 /* commands */ 798 /* commands */
800 old_sigchld_handler = signal(SIGCHLD, SIG_DFL); 799 old_sigchld_handler = mysignal(SIGCHLD, SIG_DFL);
801 800
802 debug("Seeded RNG with %i bytes from programs", (int)stir_from_programs()); 801 debug("Seeded RNG with %i bytes from programs", (int)stir_from_programs());
803 debug("Seeded RNG with %i bytes from system calls", (int)stir_from_system()); 802 debug("Seeded RNG with %i bytes from system calls", (int)stir_from_system());
@@ -805,7 +804,7 @@ seed_rng(void)
805 if (!RAND_status()) 804 if (!RAND_status())
806 fatal("Not enough entropy in RNG"); 805 fatal("Not enough entropy in RNG");
807 806
808 signal(SIGCHLD, old_sigchld_handler); 807 mysignal(SIGCHLD, old_sigchld_handler);
809 808
810 if (!RAND_status()) 809 if (!RAND_status())
811 fatal("Couldn't initialise builtin random number generator -- exiting."); 810 fatal("Couldn't initialise builtin random number generator -- exiting.");