Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VROrA-0000qq-Ab for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Oct 2013 16:00:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VROr9-0005u5-5Q for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Oct 2013 16:00:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VROr7-0005tw-2R for pgsql-bugs@postgresql.org; Wed, 02 Oct 2013 16:00:53 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VROr2-0001YJ-S5 for pgsql-bugs@postgresql.org; Wed, 02 Oct 2013 16:00:52 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1VROqy-0001T7-MV; Wed, 02 Oct 2013 12:00:44 -0400 Date: Wed, 2 Oct 2013 12:00:44 -0400 From: Bruce Momjian To: Richard Neill Cc: Magnus Hagander , postgresql@richardneill.org, pgsql-bugs Subject: Re: BUG #8467: Slightly confusing pgcrypto example in docs Message-ID: <20131002160044.GF21547@momjian.us> References: <52421047.60301@richardneill.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="3V7upXqbjpZ4EhLz" Content-Disposition: inline In-Reply-To: <52421047.60301@richardneill.org> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Sep 24, 2013 at 11:20:55PM +0100, Richard Neill wrote: > I'm sorry about that: I think I need to correct my proposed > correction! I think I've been writing too much C recently, and so I > foolishly mis-read that as returning pswhash, rather than returning > the truth of the comparison. > > What I meant to write, for clarity, was: > > SELECT (pswhash = crypt('entered password', pswhash)) AS pswmatch FROM ... ; > > which would make it obvious that we're returning the boolean named pswmatch. > > > > >>[Also, should the default example perhaps use gen_salt('bf'), as opposed to > >>gen_salt('md5') ?] > > > >This, however, might be a good idea. People should of course always > >read the documentation, but having the examples including the "best > >practice" would probably be a good idea. > > Incidentally, there are 2 other things that confused me in this section. > > 1. Table F-18. Supported algorithms for crypt() has a column > labelled "max password length". It would perhaps also be useful to > know the size of column needed to store the crypted password (my > original crypt using md5 easily fits in a varchar(70), whereas using > bf needs the column to be varchar(100).) > > > 2. Table F-20. Hash algorithm speeds > > What's the difference here between "crypt-md5" and "md5" ? > > If I've rightly read this, the algorithm named "md5" in the crypt() > documentation is named "crypt-md5" here, whereas Table F20's "md5" > algorithm seems to refer to something else - probably the "normal" > version of md5. > > If so, it would be clearer to write that the last 2 lines ("md5" and > "sha1") are for comparison only, and refer to the speed of doing an > ordinary md5/sha1 sum, rather than the md5-variant of crypt(). > > > Anyway, thanks again for your help - Postgres is a wonderful system, > which I've found to be repeatedly useful. Based on your report, I have developed the attached doc patch which clarifies when MD5 hash is being referenced, and when MD5 crypt is. I have also added your other suggestions. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --3V7upXqbjpZ4EhLz Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="md5.diff" diff --git a/doc/src/sgml/pgcrypto.sgml b/doc/src/sgml/pgcrypto.sgml new file mode 100644 index a0eead7..976c7db *** a/doc/src/sgml/pgcrypto.sgml --- b/doc/src/sgml/pgcrypto.sgml *************** hmac(data bytea, key text, type text) re *** 95,102 **** ! The algorithms in crypt() differ from usual hashing algorithms ! like MD5 or SHA1 in the following respects: --- 95,102 ---- ! The algorithms in crypt() differ from the usual ! MD5 or SHA1 hashing algorithms in the following respects: *************** hmac(data bytea, key text, type text) re *** 142,147 **** --- 142,148 ---- Max Password Length Adaptive? Salt Bits + Output length Description *************** hmac(data bytea, key text, type text) re *** 151,156 **** --- 152,158 ---- 72 yes 128 + 60 Blowfish-based, variant 2a *************** hmac(data bytea, key text, type text) re *** 158,163 **** --- 160,166 ---- unlimited no 48 + 34 MD5-based crypt *************** hmac(data bytea, key text, type text) re *** 165,170 **** --- 168,174 ---- 8 yes 24 + 20 Extended DES *************** hmac(data bytea, key text, type text) re *** 172,177 **** --- 176,182 ---- 8 no 12 + 13 Original UNIX crypt *************** UPDATE ... SET pswhash = crypt('new pass *** 205,211 **** Example of authentication: ! SELECT pswhash = crypt('entered password', pswhash) FROM ... ; This returns true if the entered password is correct. --- 210,216 ---- Example of authentication: ! SELECT (pswhash = crypt('entered password', pswhash)) AS pswmatch FROM ... ; This returns true if the entered password is correct. *************** gen_salt(type text [, iter_count integer *** 353,359 **** 12 years ! md5 2345086 1 day 3 years --- 358,364 ---- 12 years ! md5 hash 2345086 1 day 3 years *************** gen_salt(type text [, iter_count integer *** 380,386 **** ! md5 numbers are from mdcrack 1.2. --- 385,391 ---- ! md5 hash numbers are from mdcrack 1.2. *************** gen_random_bytes(count integer) returns *** 1343,1349 **** OpenBSD sys/crypto ! MD5 and SHA1 WIDE Project KAME kame/sys/crypto --- 1348,1354 ---- OpenBSD sys/crypto ! MD5 hash and SHA1 WIDE Project KAME kame/sys/crypto --3V7upXqbjpZ4EhLz Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --3V7upXqbjpZ4EhLz--