Check for interrupts in bf and xdes crypt()

Started by Andreas Karlssonabout 10 years ago3 messages
#1Andreas Karlsson
andreas@proxel.se
1 attachment(s)

Hi,

Here is a patch which makes it possible to cancel a query which runs the
crypt() function with the bf or xdes hashing algorithm, e.g.
crypt('foo', gen_salt('bf', 13)). The md5 algorithm does not run for
multiple rounds so there is no reason to patch it.

I noticed this problem when I accidentally picked a too high n for the
number of hash rounds.

I have added a call to CHECK_FOR_INTERRUPTS() after every round, and I
could not measure any performance hit from this.

Andreas

Attachments:

crypt-interrupts-v01.patchtext/x-diff; name=crypt-interrupts-v01.patchDownload
diff --git a/contrib/pgcrypto/crypt-blowfish.c b/contrib/pgcrypto/crypt-blowfish.c
index 4054e6a..6feaefc 100644
--- a/contrib/pgcrypto/crypt-blowfish.c
+++ b/contrib/pgcrypto/crypt-blowfish.c
@@ -33,6 +33,7 @@
  */
 
 #include "postgres.h"
+#include "miscadmin.h"
 
 #include "px-crypt.h"
 #include "px.h"
@@ -670,6 +671,8 @@ _crypt_blowfish_rn(const char *key, const char *setting,
 
 	do
 	{
+		CHECK_FOR_INTERRUPTS();
+
 		data.ctx.P[0] ^= data.expanded_key[0];
 		data.ctx.P[1] ^= data.expanded_key[1];
 		data.ctx.P[2] ^= data.expanded_key[2];
diff --git a/contrib/pgcrypto/crypt-des.c b/contrib/pgcrypto/crypt-des.c
index 6829586..a4aa496 100644
--- a/contrib/pgcrypto/crypt-des.c
+++ b/contrib/pgcrypto/crypt-des.c
@@ -61,6 +61,7 @@
  */
 
 #include "postgres.h"
+#include "miscadmin.h"
 
 #include "px-crypt.h"
 
@@ -540,6 +541,8 @@ do_des(uint32 l_in, uint32 r_in, uint32 *l_out, uint32 *r_out, int count)
 
 	while (count--)
 	{
+		CHECK_FOR_INTERRUPTS();
+
 		/*
 		 * Do each round.
 		 */
#2Jeff Janes
jeff.janes@gmail.com
In reply to: Andreas Karlsson (#1)
Re: Check for interrupts in bf and xdes crypt()

On Tue, Dec 15, 2015 at 12:35 AM, Andreas Karlsson <andreas@proxel.se> wrote:

Hi,

Here is a patch which makes it possible to cancel a query which runs the
crypt() function with the bf or xdes hashing algorithm, e.g. crypt('foo',
gen_salt('bf', 13)). The md5 algorithm does not run for multiple rounds so
there is no reason to patch it.

I noticed this problem when I accidentally picked a too high n for the
number of hash rounds.

I have added a call to CHECK_FOR_INTERRUPTS() after every round, and I could
not measure any performance hit from this.

Looks good to me. Applies, builds, passes make check, does what it
says and says what it does. No need for docs, no noticeable
performance impact.

I've marked it ready for committer. Also recommend for back-patching.

Cheers,

Jeff

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Jeff Janes (#2)
Re: Check for interrupts in bf and xdes crypt()

Jeff Janes wrote:

On Tue, Dec 15, 2015 at 12:35 AM, Andreas Karlsson <andreas@proxel.se> wrote:

Here is a patch which makes it possible to cancel a query which runs the
crypt() function with the bf or xdes hashing algorithm, e.g. crypt('foo',
gen_salt('bf', 13)). The md5 algorithm does not run for multiple rounds so
there is no reason to patch it.

Looks good to me. Applies, builds, passes make check, does what it
says and says what it does. No need for docs, no noticeable
performance impact.

I've marked it ready for committer. Also recommend for back-patching.

Pushed, thanks.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers