7 /* TLS PRNG seeding routines
9 /* #define TLS_INTERNAL
12 /* int tls_ext_seed(nbytes)
15 /* void tls_int_seed()
17 /* tls_ext_seed() requests the specified number of bytes
18 /* from the tlsmgr(8) PRNG pool and updates the local PRNG.
19 /* The result is zero in case of success, -1 otherwise.
21 /* tls_int_seed() mixes the process ID and time of day into
22 /* the PRNG pool. This adds a few bits of entropy with each
23 /* call, provided that the calls aren't made frequently.
27 /* The Secure Mailer license must be distributed with this
31 /* IBM T.J. Watson Research
33 /* Yorktown Heights, NY 10598, USA
39 #include <sys/time.h> /* gettimeofday() */
40 #include <unistd.h> /* getpid() */
44 /* OpenSSL library. */
46 #include <openssl/rand.h> /* RAND_seed() */
48 /* Utility library. */
59 /* Application-specific. */
61 /* tls_int_seed - add entropy to the pool by adding the time and PID */
63 void tls_int_seed(void)
70 if (randseed
.pid
== 0)
71 randseed
.pid
= getpid();
72 GETTIMEOFDAY(&randseed
.tv
);
73 RAND_seed(&randseed
, sizeof(randseed
));
76 /* tls_ext_seed - request entropy from tlsmgr(8) server */
78 int tls_ext_seed(int nbytes
)
83 buf
= vstring_alloc(nbytes
);
84 status
= tls_mgr_seed(buf
, nbytes
);
85 RAND_seed(vstring_str(buf
), VSTRING_LEN(buf
));
87 return (status
== TLS_MGR_STAT_OK
? 0 : -1);