1
-
2
1
pgcrypto - cryptographic functions for PostgreSQL
3
2
=================================================
4
3
Marko Kreen <marko@l-t.ee>
5
4
5
+ // Note: this document is in asciidoc format.
6
+
6
7
7
8
1. Installation
8
9
-----------------
@@ -17,6 +18,13 @@ The `make installcheck` command is important. It runs regression tests
17
18
for the module. They make sure the functions here produce correct
18
19
results.
19
20
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
+
20
28
21
29
2. Notes
22
30
----------
@@ -71,7 +79,7 @@ are NULL. This may create security risks on careless usage.
71
79
~~~~~~~~~~~~~~~~~~~~~~~~~~~
72
80
73
81
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.
75
83
76
84
77
85
2.4. Security
@@ -140,7 +148,7 @@ MD5 or SHA1 in following respects:
140
148
1. They are slow. As the amount of data is so small, this is only
141
149
way to make brute-forcing passwords hard.
142
150
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
144
152
additional defense against reversing the algorithm.
145
153
3. Include algorithm type in the result, so passwords hashed with
146
154
different algorithms can co-exist.
@@ -198,7 +206,7 @@ Accepted types are: `des`, `xdes`, `md5` and `bf`.
198
206
199
207
Same as above, but lets user specify iteration count for some
200
208
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
202
210
too high count the time to calculate a hash may be several years
203
211
- which is somewhat impractical.
204
212
@@ -217,9 +225,9 @@ a odd number.
217
225
Notes:
218
226
219
227
- 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.
223
231
- See next section about possible values for `crypt-bf`.
224
232
225
233
@@ -230,7 +238,7 @@ Here is a table that should give overview of relative slowness
230
238
of different hashing algorithms.
231
239
232
240
* The goal is to crack a 8-character password, which consists:
233
- 1. Only from lowercase letters
241
+ 1. Only of lowercase letters
234
242
2. Numbers, lower- and uppercase letters.
235
243
* The table below shows how much time it would take to try all
236
244
combinations of characters.
@@ -248,29 +256,26 @@ crypt-md5 2681 2.6 years 2625 years
248
256
crypt-des 362837 7 days 19 years
249
257
sha1 590223 4 days 12 years
250
258
md5 2345086 1 day 3 years
251
- password 143781000 25 mins 18 days
252
259
------------------------------------------------------------
253
260
254
261
* The machine used is 1.5GHz Pentium 4.
255
262
* crypt-des and crypt-md5 algorithm numbers are taken from
256
263
John the Ripper v1.6.38 `-test` output.
257
264
* MD5 numbers are from mdcrack 1.2.
258
265
* 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/)
261
266
* `crypt-bf` numbers are taken using simple program that loops
262
267
over 1000 8-character passwords. That way I can show the speed with
263
268
different number of rounds. For reference: `john -test` shows 213
264
269
loops/sec for crypt-bf/5. (The small difference in results is in
265
270
accordance to the fact that the `crypt-bf` implementation in pgcrypto
266
271
is same one that is used in John the Ripper.)
267
272
268
- Note that the "try all combinations" is not a realistic exercise.
273
+ Note that "try all combinations" is not a realistic exercise.
269
274
Usually password cracking is done with the help of dictionaries, which
270
275
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
272
277
numbers suggest, and a 6-character non-word like password may escape
273
- cracking. Or may not.
278
+ cracking. Or not.
274
279
275
280
276
281
5. PGP encryption
@@ -292,7 +297,7 @@ When encrypting with password:
292
297
293
298
1. Given password is hashed using String2Key (S2K) algorithm. This
294
299
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.
296
301
2. If separate session key is requested, new random key will be
297
302
generated. Otherwise S2K key will be used directly as session key.
298
303
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.
378
383
pgp_key_id(key or msg bytea) RETURNS text
379
384
380
385
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
382
387
encrypted message.
383
388
384
- It can return 2 special key ID's :
389
+ It can return 2 special key IDs :
385
390
386
391
SYMKEY::
387
392
The data is encrypted with symmetric key.
@@ -410,8 +415,8 @@ with CRC and additional formatting.
410
415
5.8. Options for PGP functions
411
416
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
412
417
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:
415
420
416
421
pgp_sym_encrypt(data, psw, 'compress-also=1, cipher-algo=aes256')
417
422
@@ -458,7 +463,7 @@ convert-crlf::
458
463
Applies: pgp_sym_encrypt, pgp_pub_encrypt, pgp_sym_decrypt, pgp_pub_decrypt
459
464
460
465
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
462
467
option is to achieve compatibility with ancient PGP products, as the
463
468
SHA-1 protected packet is from upcoming update to RFC2440. (Currently
464
469
at version RFC2440bis-14.) Recent gnupg.org and pgp.com software
@@ -481,7 +486,7 @@ s2k-mode::
481
486
Which S2K algorithm to use.
482
487
483
488
Values:
484
- 0 - Dangerous! Without salt.
489
+ 0 - Without salt. Dangerous!
485
490
1 - With salt but with fixed iteration count.
486
491
3 - Variable iteration count.
487
492
Default: 3
@@ -536,7 +541,7 @@ Export ascii-armored secret key:
536
541
537
542
gpg -a --export-secret-keys KEYID > secret.key
538
543
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
540
545
pgp_pub_* functions. Or if you can handle binary data, you can drop
541
546
"-a" from gpg.
542
547
@@ -596,7 +601,7 @@ Supported algorithms:
596
601
Modes:
597
602
598
603
* `cbc` - next block depends on previous. (default)
599
- * `ecb` - each block in encrypted separately.
604
+ * `ecb` - each block is encrypted separately.
600
605
(for testing only)
601
606
602
607
Padding:
@@ -694,5 +699,4 @@ http://www.cs.ut.ee/~helger/crypto/[]::
694
699
Collection of cryptology pointers.
695
700
696
701
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