62 #include <openssl/rand.h>
77 #define TLS_PRNG_EXCH_SIZE 1024
83 const char *myname =
"tls_prng_exch_open";
87 if ((fd = open(name, O_RDWR | O_CREAT, 0600)) < 0)
88 msg_fatal(
"%s: cannot open PRNG exchange file %s: %m", myname, name);
94 msg_info(
"%s: opened PRNG exchange file %s", myname, name);
102 unsigned char buffer[TLS_PRNG_EXCH_SIZE];
110 msg_fatal(
"cannot lock PRNG exchange file %s: %m", eh->
name);
111 if (lseek(eh->
fd, 0, SEEK_SET) < 0)
112 msg_fatal(
"cannot seek PRNG exchange file %s: %m", eh->
name);
113 if ((count = read(eh->
fd, buffer,
sizeof(buffer))) < 0)
114 msg_fatal(
"cannot read PRNG exchange file %s: %m", eh->
name);
117 RAND_seed(buffer, count);
118 RAND_bytes(buffer,
sizeof(buffer));
120 if (lseek(eh->
fd, 0, SEEK_SET) < 0)
121 msg_fatal(
"cannot seek PRNG exchange file %s: %m", eh->
name);
122 if (write(eh->
fd, buffer,
sizeof(buffer)) !=
sizeof(buffer))
123 msg_fatal(
"cannot write PRNG exchange file %s: %m", eh->
name);
125 msg_fatal(
"cannot unlock PRNG exchange file %s: %m", eh->
name);
132 const char *myname =
"tls_prng_exch_close";
134 if (close(eh->
fd) < 0)
137 msg_info(
"%s: closed PRNG exchange file %s", myname, eh->
name);
TLS_PRNG_SRC * tls_prng_exch_open(const char *)
char * mystrdup(const char *str)
#define MYFLOCK_OP_EXCLUSIVE
void tls_prng_exch_close(TLS_PRNG_SRC *)
int myflock(int fd, int lock_style, int operation)
NORETURN msg_fatal(const char *fmt,...)
void tls_prng_exch_update(TLS_PRNG_SRC *)
void * mymalloc(ssize_t len)
void msg_info(const char *fmt,...)