1-
21pgcrypto - cryptographic functions for PostgreSQL
32=================================================
43Marko Kreen <marko@l-t.ee>
54
5+ // Note: this document is in asciidoc format.
6+
67
781. Installation
89-----------------
@@ -17,6 +18,13 @@ The `make installcheck` command is important. It runs regression tests
1718for the module. They make sure the functions here produce correct
1819results.
1920
21+ Next, to put the functions into a particular database, run the commands in
22+ file pgcrypto.sql, which has been installed into the shared files directory.
23+
24+ Example using psql:
25+
26+ psql -d DBNAME -f pgcrypto.sql
27+
2028
21292. Notes
2230----------
@@ -71,7 +79,7 @@ are NULL. This may create security risks on careless usage.
7179~~~~~~~~~~~~~~~~~~~~~~~~~~~
7280
7381The `digest_exists()`, `hmac_exists()` and `cipher_exists()` functions
74- are deprecated. The plan is to removethose in PostgreSQL 8.2.
82+ are deprecated. The plan is to removethem in PostgreSQL 8.2.
7583
7684
77852.4. Security
@@ -140,7 +148,7 @@ MD5 or SHA1 in following respects:
1401481. They are slow. As the amount of data is so small, this is only
141149 way to make brute-forcing passwords hard.
1421502. Include random 'salt' with result, so that users having same
143- password would have different crypted passwords. This also
151+ password would have different crypted passwords. Thisis also
144152 additional defense against reversing the algorithm.
1451533. Include algorithm type in the result, so passwords hashed with
146154 different algorithms can co-exist.
@@ -198,7 +206,7 @@ Accepted types are: `des`, `xdes`, `md5` and `bf`.
198206
199207Same as above, but lets user specify iteration count for some
200208algorithms. The higher the count, the more time it takes to hash
201- ti password and therefore the more time to break it. Although with
209+ the password and therefore the more time to break it. Although with
202210too high count the time to calculate a hash may be several years
203211- which is somewhat impractical.
204212
@@ -217,9 +225,9 @@ a odd number.
217225Notes:
218226
219227- Original DES crypt was designed to have the speed of 4 hashes per
220- second on the hardware that time.
221- - Slowerthat 4 hashes per second would probablydamper usability.
222- - Fasterthat 100 hashes per second is probably too fast.
228+ second on the hardwareof that time.
229+ - Slowerthan 4 hashes per second would probablydampen usability.
230+ - Fasterthan 100 hashes per second is probably too fast.
223231- See next section about possible values for `crypt-bf`.
224232
225233
@@ -230,7 +238,7 @@ Here is a table that should give overview of relative slowness
230238of different hashing algorithms.
231239
232240* The goal is to crack a 8-character password, which consists:
233- 1. Onlyfrom lowercase letters
241+ 1. Onlyof lowercase letters
234242 2. Numbers, lower- and uppercase letters.
235243* The table below shows how much time it would take to try all
236244 combinations of characters.
@@ -248,29 +256,26 @@ crypt-md5 2681 2.6 years 2625 years
248256crypt-des 362837 7 days 19 years
249257sha1 590223 4 days 12 years
250258md5 2345086 1 day 3 years
251- password 143781000 25 mins 18 days
252259------------------------------------------------------------
253260
254261* The machine used is 1.5GHz Pentium 4.
255262* crypt-des and crypt-md5 algorithm numbers are taken from
256263 John the Ripper v1.6.38 `-test` output.
257264* MD5 numbers are from mdcrack 1.2.
258265* SHA1 numbers are from lcrack-20031130-beta.
259- * MySQL password() numbers are from my own tests.
260- (http://grue.l-t.ee/~marko/src/mypass/)
261266* `crypt-bf` numbers are taken using simple program that loops
262267 over 1000 8-character passwords. That way I can show the speed with
263268 different number of rounds. For reference: `john -test` shows 213
264269 loops/sec for crypt-bf/5. (The small difference in results is in
265270 accordance to the fact that the `crypt-bf` implementation in pgcrypto
266271 is same one that is used in John the Ripper.)
267272
268- Note thatthe "try all combinations" is not a realistic exercise.
273+ Note that "try all combinations" is not a realistic exercise.
269274Usually password cracking is done with the help of dictionaries, which
270275contain both regular words and various mutations of them. So, even
271- somewhat word-like passwordswill be cracked much faster than the above
276+ somewhat word-like passwordscould be cracked much faster than the above
272277numbers suggest, and a 6-character non-word like password may escape
273- cracking. Ormay not.
278+ cracking. Or not.
274279
275280
2762815. PGP encryption
@@ -292,7 +297,7 @@ When encrypting with password:
292297
2932981. Given password is hashed using String2Key (S2K) algorithm. This
294299 is rather similar to `crypt()` algorithm - purposefully slow
295- and with random salt - butis produces a full-length binary key.
300+ and with random salt - butit produces a full-length binary key.
2963012. If separate session key is requested, new random key will be
297302 generated. Otherwise S2K key will be used directly as session key.
2983033. If S2K key is to be used directly, then only S2K settings will be put
@@ -378,10 +383,10 @@ Options are described in section 5.7.
378383 pgp_key_id(key or msg bytea) RETURNS text
379384
380385It shows you either key ID if given PGP public or secret key. Or it
381- gives the key IDwhat was used for encrypting the data, if given
386+ gives the key IDthat was used for encrypting the data, if given
382387encrypted message.
383388
384- It can return 2 special keyID's :
389+ It can return 2 special keyIDs :
385390
386391SYMKEY::
387392 The data is encrypted with symmetric key.
@@ -410,8 +415,8 @@ with CRC and additional formatting.
4104155.8. Options for PGP functions
411416~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
412417
413- Option are named to be similar to GnuPG. Values should be given after
414- equal sign, different options from each other with commas. Example:
418+ Options are named to be similar to GnuPG. Values should be given after
419+ an equal sign; separate options from each other with commas. Example:
415420
416421 pgp_sym_encrypt(data, psw, 'compress-also=1, cipher-algo=aes256')
417422
@@ -458,7 +463,7 @@ convert-crlf::
458463 Applies: pgp_sym_encrypt, pgp_pub_encrypt, pgp_sym_decrypt, pgp_pub_decrypt
459464
460465disable-mdc::
461- Do not protect data with SHA-1. Only good reason to useis this
466+ Do not protect data with SHA-1. Only good reason to use this
462467 option is to achieve compatibility with ancient PGP products, as the
463468 SHA-1 protected packet is from upcoming update to RFC2440. (Currently
464469 at version RFC2440bis-14.) Recent gnupg.org and pgp.com software
@@ -481,7 +486,7 @@ s2k-mode::
481486 Which S2K algorithm to use.
482487
483488 Values:
484- 0 -Dangerous! Without salt.
489+ 0 - Without salt. Dangerous!
485490 1 - With salt but with fixed iteration count.
486491 3 - Variable iteration count.
487492 Default: 3
@@ -536,7 +541,7 @@ Export ascii-armored secret key:
536541
537542 gpg -a --export-secret-keys KEYID > secret.key
538543
539- You need to use `dearmor()` on them before givinggiving them to
544+ You need to use `dearmor()` on them before giving them to
540545pgp_pub_* functions. Or if you can handle binary data, you can drop
541546"-a" from gpg.
542547
@@ -596,7 +601,7 @@ Supported algorithms:
596601Modes:
597602
598603* `cbc` - next block depends on previous. (default)
599- * `ecb` - each blockin encrypted separately.
604+ * `ecb` - each blockis encrypted separately.
600605 (for testing only)
601606
602607Padding:
@@ -694,5 +699,4 @@ http://www.cs.ut.ee/~helger/crypto/[]::
694699Collection of cryptology pointers.
695700
696701
697- // $PostgreSQL: pgsql/contrib/pgcrypto/README.pgcrypto,v 1.13 2005/08/13 02:06:20 momjian Exp $
698-
702+ // $PostgreSQL: pgsql/contrib/pgcrypto/README.pgcrypto,v 1.14 2005/11/03 02:54:07 tgl Exp $