Skip to content

Commit da9fc25

Browse files
committed
pgcrypto documentation polishing from Marko Kreen, and a small amount
of copy-editing from myself.
1 parent 8bd1cbb commit da9fc25

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

contrib/pgcrypto/README.pgcrypto

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
21
pgcrypto - cryptographic functions for PostgreSQL
32
=================================================
43
Marko Kreen <marko@l-t.ee>
54

5+
// Note: this document is in asciidoc format.
6+
67

78
1. Installation
89
-----------------
@@ -17,6 +18,13 @@ The `make installcheck` command is important. It runs regression tests
1718
for the module. They make sure the functions here produce correct
1819
results.
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

2129
2. Notes
2230
----------
@@ -71,7 +79,7 @@ are NULL. This may create security risks on careless usage.
7179
~~~~~~~~~~~~~~~~~~~~~~~~~~~
7280

7381
The `digest_exists()`, `hmac_exists()` and `cipher_exists()` functions
74-
are deprecated. The plan is to remove those in PostgreSQL 8.2.
82+
are deprecated. The plan is to remove them in PostgreSQL 8.2.
7583

7684

7785
2.4. Security
@@ -140,7 +148,7 @@ MD5 or SHA1 in following respects:
140148
1. They are slow. As the amount of data is so small, this is only
141149
way to make brute-forcing passwords hard.
142150
2. 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. This is also
144152
additional defense against reversing the algorithm.
145153
3. 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

199207
Same as above, but lets user specify iteration count for some
200208
algorithms. 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
202210
too 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.
217225
Notes:
218226

219227
- Original DES crypt was designed to have the speed of 4 hashes per
220-
second on the hardware that time.
221-
- Slower that 4 hashes per second would probably damper usability.
222-
- Faster that 100 hashes per second is probably too fast.
228+
second on the hardware of that time.
229+
- Slower than 4 hashes per second would probably dampen usability.
230+
- Faster than 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
230238
of different hashing algorithms.
231239

232240
* The goal is to crack a 8-character password, which consists:
233-
1. Only from lowercase letters
241+
1. Only of 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
248256
crypt-des 362837 7 days 19 years
249257
sha1 590223 4 days 12 years
250258
md5 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 that the "try all combinations" is not a realistic exercise.
273+
Note that "try all combinations" is not a realistic exercise.
269274
Usually password cracking is done with the help of dictionaries, which
270275
contain both regular words and various mutations of them. So, even
271-
somewhat word-like passwords will be cracked much faster than the above
276+
somewhat word-like passwords could be cracked much faster than the above
272277
numbers suggest, and a 6-character non-word like password may escape
273-
cracking. Or may not.
278+
cracking. Or not.
274279

275280

276281
5. PGP encryption
@@ -292,7 +297,7 @@ When encrypting with password:
292297

293298
1. Given password is hashed using String2Key (S2K) algorithm. This
294299
is rather similar to `crypt()` algorithm - purposefully slow
295-
and with random salt - but is produces a full-length binary key.
300+
and with random salt - but it produces a full-length binary key.
296301
2. If separate session key is requested, new random key will be
297302
generated. Otherwise S2K key will be used directly as session key.
298303
3. 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

380385
It shows you either key ID if given PGP public or secret key. Or it
381-
gives the key ID what was used for encrypting the data, if given
386+
gives the key ID that was used for encrypting the data, if given
382387
encrypted message.
383388

384-
It can return 2 special key ID's:
389+
It can return 2 special key IDs:
385390

386391
SYMKEY::
387392
The data is encrypted with symmetric key.
@@ -410,8 +415,8 @@ with CRC and additional formatting.
410415
5.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

460465
disable-mdc::
461-
Do not protect data with SHA-1. Only good reason to use is 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 giving giving them to
544+
You need to use `dearmor()` on them before giving them to
540545
pgp_pub_* functions. Or if you can handle binary data, you can drop
541546
"-a" from gpg.
542547

@@ -596,7 +601,7 @@ Supported algorithms:
596601
Modes:
597602

598603
* `cbc` - next block depends on previous. (default)
599-
* `ecb` - each block in encrypted separately.
604+
* `ecb` - each block is encrypted separately.
600605
(for testing only)
601606

602607
Padding:
@@ -694,5 +699,4 @@ http://www.cs.ut.ee/~helger/crypto/[]::
694699
Collection 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 $

0 commit comments

Comments
 (0)