diff --git a/contrib/pgcrypto/pgcrypto.c b/contrib/pgcrypto/pgcrypto.c index a441ca7..800ec5a 100644 --- a/contrib/pgcrypto/pgcrypto.c +++ b/contrib/pgcrypto/pgcrypto.c @@ -40,6 +40,10 @@ #include "px-crypt.h" #include "pgcrypto.h" +#ifdef HAVE_SYS_TIME_H +#include +#endif + PG_MODULE_MAGIC; /* private stuff */ @@ -424,12 +428,17 @@ pg_random_bytes(PG_FUNCTION_ARGS) int err; int len = PG_GETARG_INT32(0); bytea *res; + struct timeval tv; if (len < 1 || len > 1024) ereport(ERROR, (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION), errmsg("Length not in range"))); + /* contribute some entropy to pool */ + gettimeofday(&tv, NULL); + px_add_entropy((uint8 *)&tv, sizeof(tv)); + res = palloc(VARHDRSZ + len); SET_VARSIZE(res, VARHDRSZ + len); diff --git a/contrib/pgcrypto/pgp-pgsql.c b/contrib/pgcrypto/pgp-pgsql.c index d4eec03..272f439 100644 --- a/contrib/pgcrypto/pgp-pgsql.c +++ b/contrib/pgcrypto/pgp-pgsql.c @@ -38,6 +38,10 @@ #include "px.h" #include "pgp.h" +#ifdef HAVE_SYS_TIME_H +#include +#endif + /* * public functions */ @@ -99,6 +103,11 @@ add_entropy(text *data1, text *data2, text *data3) { PX_MD *md; uint8 rnd[3]; + struct timeval tv; + + /* always add something to pool */ + gettimeofday(&tv, NULL); + px_add_entropy((uint8 *)&tv, sizeof(tv)); if (!data1 && !data2 && !data3) return;