pgcrypto-add-time.diff
application/octet-stream
Filename: pgcrypto-add-time.diff
Type: application/octet-stream
Part: 0
Message:
pgcrypto seeding problem when ssl=on
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| contrib/pgcrypto/pgcrypto.c | 9 | 0 |
| contrib/pgcrypto/pgp-pgsql.c | 9 | 0 |
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 <sys/time.h>
+#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 <sys/time.h>
+#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;