Revert commit 66c0185a3 and follow-on patches.
[pgsql.git] / contrib / pgcrypto / sql / pgp-decrypt.sql
blob49a0267bbcbccfa776d387a82cbe853f1b75aa27
1 --
2 -- pgp decrypt tests
3 --
5 --  Checking ciphers
6 select pgp_sym_decrypt(dearmor('
7 -----BEGIN PGP MESSAGE-----
8 Comment: dat1.blowfish.sha1.mdc.s2k3.z0
10 jA0EBAMCfFNwxnvodX9g0jwB4n4s26/g5VmKzVab1bX1SmwY7gvgvlWdF3jKisvS
11 yA6Ce1QTMK3KdL2MPfamsTUSAML8huCJMwYQFfE=
12 =JcP+
13 -----END PGP MESSAGE-----
14 '), 'foobar');
16 select pgp_sym_decrypt(dearmor('
17 -----BEGIN PGP MESSAGE-----
18 Comment: dat1.aes.sha1.mdc.s2k3.z0
20 jA0EBwMCci97v0Q6Z0Zg0kQBsVf5Oe3iC+FBzUmuMV9KxmAyOMyjCc/5i8f1Eest
21 UTAsG35A1vYs02VARKzGz6xI2UHwFUirP+brPBg3Ee7muOx8pA==
22 =XtrP
23 -----END PGP MESSAGE-----
24 '), 'foobar');
26 select pgp_sym_decrypt(dearmor('
27 -----BEGIN PGP MESSAGE-----
28 Comment: dat1.aes192.sha1.mdc.s2k3.z0
30 jA0ECAMCI7YQpWqp3D1g0kQBCjB7GlX7+SQeXNleXeXQ78ZAPNliquGDq9u378zI
31 5FPTqAhIB2/2fjY8QEIs1ai00qphjX2NitxV/3Wn+6dufB4Q4g==
32 =rCZt
33 -----END PGP MESSAGE-----
34 '), 'foobar');
36 select pgp_sym_decrypt(dearmor('
37 -----BEGIN PGP MESSAGE-----
38 Comment: dat1.aes256.sha1.mdc.s2k3.z0
40 jA0ECQMC4f/5djqCC1Rg0kQBTHEPsD+Sw7biBsM2er3vKyGPAQkuTBGKC5ie7hT/
41 lceMfQdbAg6oTFyJpk/wH18GzRDphCofg0X8uLgkAKMrpcmgog==
42 =fB6S
43 -----END PGP MESSAGE-----
44 '), 'foobar');
46 -- Checking MDC modes
47 select pgp_sym_decrypt(dearmor('
48 -----BEGIN PGP MESSAGE-----
49 Comment: dat1.aes.sha1.nomdc.s2k3.z0
51 jA0EBwMCnv07rlXqWctgyS2Dm2JfOKCRL4sLSLJUC8RS2cH7cIhKSuLitOtyquB+
52 u9YkgfJfsuRJmgQ9tmo=
53 =60ui
54 -----END PGP MESSAGE-----
55 '), 'foobar');
57 select pgp_sym_decrypt(dearmor('
58 -----BEGIN PGP MESSAGE-----
59 Comment: dat1.aes.sha1.mdc.s2k3.z0
61 jA0EBwMCEeP3idNjQ1Bg0kQBf4G0wX+2QNzLh2YNwYkQgQkfYhn/hLXjV4nK9nsE
62 8Ex1Dsdt5UPvOz8W8VKQRS6loOfOe+yyXil8W3IYFwUpdDUi+Q==
63 =moGf
64 -----END PGP MESSAGE-----
65 '), 'foobar');
67 -- Checking hashes
68 select pgp_sym_decrypt(dearmor('
69 -----BEGIN PGP MESSAGE-----
70 Comment: dat1.aes.md5.mdc.s2k3.z0
72 jA0EBwMClrXXtOXetohg0kQBn0Kl1ymevQZRHkdoYRHgzCwSQEiss7zYff2UNzgO
73 KyRrHf7zEBuZiZ2AG34jNVMOLToj1jJUg5zTSdecUzQVCykWTA==
74 =NyLk
75 -----END PGP MESSAGE-----
76 '), 'foobar');
78 select pgp_sym_decrypt(dearmor('
79 -----BEGIN PGP MESSAGE-----
80 Comment: dat1.aes.sha1.mdc.s2k3.z0
82 jA0EBwMCApbdlrURoWJg0kQBzHM/E0o7djY82bNuspjxjAcPFrrtp0uvDdMQ4z2m
83 /PM8jhgI5vxFYfNQjLl8y3fHYIomk9YflN9K/Q13iq8A8sjeTw==
84 =FxbQ
85 -----END PGP MESSAGE-----
86 '), 'foobar');
88 -- Checking S2K modes
89 select pgp_sym_decrypt(dearmor('
90 -----BEGIN PGP MESSAGE-----
91 Comment: dat1.aes.sha1.mdc.s2k0.z0
93 jAQEBwAC0kQBKTaLAKE3xzps+QIZowqRNb2eAdzBw2LxEW2YD5PgNlbhJdGg+dvw
94 Ah9GXjGS1TVALzTImJbz1uHUZRfhJlFbc5yGQw==
95 =YvkV
96 -----END PGP MESSAGE-----
97 '), 'foobar');
99 select pgp_sym_decrypt(dearmor('
100 -----BEGIN PGP MESSAGE-----
101 Comment: dat1.aes.sha1.mdc.s2k1.z0
103 jAwEBwEC/QTByBLI3b/SRAHPxKzI6SZBo5lAEOD+EsvKQWO4adL9tDY+++Iqy1xK
104 4IaWXVKEj9R2Lr2xntWWMGZtcKtjD2lFFRXXd9dZp1ZThNDz
105 =dbXm
106 -----END PGP MESSAGE-----
107 '), 'foobar');
109 select pgp_sym_decrypt(dearmor('
110 -----BEGIN PGP MESSAGE-----
111 Comment: dat1.aes.sha1.mdc.s2k3.z0
113 jA0EBwMCEq4Su3ZqNEJg0kQB4QG5jBTKF0i04xtH+avzmLhstBNRxvV3nsmB3cwl
114 z+9ZaA/XdSx5ZiFnMym8P6r8uY9rLjjNptvvRHlxIReF+p9MNg==
115 =VJKg
116 -----END PGP MESSAGE-----
117 '), 'foobar');
119 select pgp_sym_decrypt(dearmor('
120 -----BEGIN PGP MESSAGE-----
121 Comment: dat1.aes192.sha1.mdc.s2k0.z0
123 jAQECAAC0kQBBDnQWkgsx9YFaqDfWmpsiyAJ6y2xG/sBvap1dySYEMuZ+wJTXQ9E
124 Cr3i2M7TgVZ0M4jp4QL0adG1lpN5iK7aQeOwMw==
125 =cg+i
126 -----END PGP MESSAGE-----
127 '), 'foobar');
129 select pgp_sym_decrypt(dearmor('
130 -----BEGIN PGP MESSAGE-----
131 Comment: dat1.aes192.sha1.mdc.s2k1.z0
133 jAwECAECruOfyNDFiTnSRAEVoGXm4A9UZKkWljdzjEO/iaE7mIraltIpQMkiqCh9
134 7h8uZ2u9uRBOv222fZodGvc6bvq/4R4hAa/6qSHtm8mdmvGt
135 =aHmC
136 -----END PGP MESSAGE-----
137 '), 'foobar');
139 select pgp_sym_decrypt(dearmor('
140 -----BEGIN PGP MESSAGE-----
141 Comment: dat1.aes192.sha1.mdc.s2k3.z0
143 jA0ECAMCjFn6SRi3SONg0kQBqtSHPaD0m7rXfDAhCWU/ypAsI93GuHGRyM99cvMv
144 q6eF6859ZVnli3BFSDSk3a4e/pXhglxmDYCfjAXkozKNYLo6yw==
145 =K0LS
146 -----END PGP MESSAGE-----
147 '), 'foobar');
149 select pgp_sym_decrypt(dearmor('
150 -----BEGIN PGP MESSAGE-----
151 Comment: dat1.aes256.sha1.mdc.s2k0.z0
153 jAQECQAC0kQB4L1eMbani07XF2ZYiXNK9LW3v8w41oUPl7dStmrJPQFwsdxmrDHu
154 rQr3WbdKdY9ufjOE5+mXI+EFkSPrF9rL9NCq6w==
155 =RGts
156 -----END PGP MESSAGE-----
157 '), 'foobar');
159 select pgp_sym_decrypt(dearmor('
160 -----BEGIN PGP MESSAGE-----
161 Comment: dat1.aes256.sha1.mdc.s2k1.z0
163 jAwECQECKHhrou7ZOIXSRAHWIVP+xjVQcjAVBTt+qh9SNzYe248xFTwozkwev3mO
164 +KVJW0qhk0An+Y2KF99/bYFl9cL5D3Tl43fC8fXGl3x3m7pR
165 =SUrU
166 -----END PGP MESSAGE-----
167 '), 'foobar');
169 select pgp_sym_decrypt(dearmor('
170 -----BEGIN PGP MESSAGE-----
171 Comment: dat1.aes256.sha1.mdc.s2k3.z0
173 jA0ECQMCjc8lwZu8Fz1g0kQBkEzjImi21liep5jj+3dAJ2aZFfUkohi8b3n9z+7+
174 4+NRzL7cMW2RLAFnJbiqXDlRHMwleeuLN1up2WIxsxtYYuaBjA==
175 =XZrG
176 -----END PGP MESSAGE-----
177 '), 'foobar');
179 -- Checking longer passwords
180 select pgp_sym_decrypt(dearmor('
181 -----BEGIN PGP MESSAGE-----
182 Comment: dat1.aes.sha1.mdc.s2k3.z0
184 jA0EBwMCx6dBiuqrYNRg0kQBEo63AvA1SCslxP7ayanLf1H0/hlk2nONVhTwVEWi
185 tTGup1mMz6Cfh1uDRErUuXpx9A0gdMu7zX0o5XjrL7WGDAZdSw==
186 =XKKG
187 -----END PGP MESSAGE-----
188 '), '0123456789abcdefghij');
190 select pgp_sym_decrypt(dearmor('
191 -----BEGIN PGP MESSAGE-----
192 Comment: dat1.aes.sha1.mdc.s2k3.z0
194 jA0EBwMCBDvYuS990iFg0kQBW31UK5OiCjWf5x6KJ8qNNT2HZWQCjCBZMU0XsOC6
195 CMxFKadf144H/vpoV9GA0f22keQgCl0EsTE4V4lweVOPTKCMJg==
196 =gWDh
197 -----END PGP MESSAGE-----
198 '), '0123456789abcdefghij2jk4h5g2j54khg23h54g2kh54g2khj54g23hj54');
200 select pgp_sym_decrypt(dearmor('
201 -----BEGIN PGP MESSAGE-----
202 Comment: dat1.aes.sha1.mdc.s2k3.z0
204 jA0EBwMCqXbFafC+ofVg0kQBejyiPqH0QMERVGfmPOjtAxvyG5KDIJPYojTgVSDt
205 FwsDabdQUz5O7bgNSnxfmyw1OifGF+W2bIn/8W+0rDf8u3+O+Q==
206 =OxOF
207 -----END PGP MESSAGE-----
208 '), 'x');
210 -- Checking various data
211 select digest(pgp_sym_decrypt(dearmor('
212 -----BEGIN PGP MESSAGE-----
213 Comment: dat1.aes.sha1.mdc.s2k3.z0
215 jA0EBwMCGJ+SpuOysINg0kQBJfSjzsW0x4OVcAyr17O7FBvMTwIGeGcJd99oTQU8
216 Xtx3kDqnhUq9Z1fS3qPbi5iNP2A9NxOBxPWz2JzxhydANlgbxg==
217 =W/ik
218 -----END PGP MESSAGE-----
219 '), '0123456789abcdefghij'), 'sha1');
221 select digest(pgp_sym_decrypt(dearmor('
222 -----BEGIN PGP MESSAGE-----
223 Comment: dat2.aes.sha1.mdc.s2k3.z0
225 jA0EBwMCvdpDvidNzMxg0jUBvj8eS2+1t/9/zgemxvhtc0fvdKGGbjH7dleaTJRB
226 SaV9L04ky1qECNDx3XjnoKLC+H7IOQ==
227 =Fxen
228 -----END PGP MESSAGE-----
229 '), '0123456789abcdefghij'), 'sha1');
231 select digest(pgp_sym_decrypt(dearmor('
232 -----BEGIN PGP MESSAGE-----
233 Comment: dat3.aes.sha1.mdc.s2k3.z0
235 jA0EBwMCxQvxJZ3G/HRg0lgBeYmTa7/uDAjPyFwSX4CYBgpZWVn/JS8JzILrcWF8
236 gFnkUKIE0PSaYFp+Yi1VlRfUtRQ/X/LYNGa7tWZS+4VQajz2Xtz4vUeAEiYFYPXk
237 73Hb8m1yRhQK
238 =ivrD
239 -----END PGP MESSAGE-----
240 '), '0123456789abcdefghij'), 'sha1');
242 -- Checking CRLF
243 select digest(pgp_sym_decrypt(dearmor('
244 -----BEGIN PGP MESSAGE-----
245 Comment: crlf mess
247 ww0ECQMCt7VAtby6l4Bi0lgB5KMIZiiF/b3CfMfUyY0eDncsGXtkbu1X+l9brjpMP8eJnY79Amms
248 a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
249 =mBP9
250 -----END PGP MESSAGE-----
251 '), 'key', 'convert-crlf=0'), 'sha1');
253 select digest(pgp_sym_decrypt(dearmor('
254 -----BEGIN PGP MESSAGE-----
255 Comment: crlf mess
257 ww0ECQMCt7VAtby6l4Bi0lgB5KMIZiiF/b3CfMfUyY0eDncsGXtkbu1X+l9brjpMP8eJnY79Amms
258 a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
259 =mBP9
260 -----END PGP MESSAGE-----
261 '), 'key', 'convert-crlf=1'), 'sha1');
263 -- check BUG #11905, problem with messages 6 less than a power of 2.
264 select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
267 -- Negative tests
269 -- Decryption with a certain incorrect key yields an apparent Literal Data
270 -- packet reporting its content to be binary data.  Ciphertext source:
271 -- iterative pgp_sym_encrypt('secret', 'key') until the random prefix gave
272 -- rise to that property.
273 select pgp_sym_decrypt(dearmor('
274 -----BEGIN PGP MESSAGE-----
276 ww0EBwMCxf8PTrQBmJdl0jcB6y2joE7GSLKRv7trbNsF5Z8ou5NISLUg31llVH/S0B2wl4bvzZjV
277 VsxxqLSPzNLAeIspJk5G
278 =mSd/
279 -----END PGP MESSAGE-----
280 '), 'wrong-key', 'debug=1');
282 -- Routine text/binary mismatch.
283 select pgp_sym_decrypt(pgp_sym_encrypt_bytea('P', 'key'), 'key', 'debug=1');
285 -- Decryption with a certain incorrect key yields an apparent BZip2-compressed
286 -- plaintext.  Ciphertext source: iterative pgp_sym_encrypt('secret', 'key')
287 -- until the random prefix gave rise to that property.
288 select pgp_sym_decrypt(dearmor('
289 -----BEGIN PGP MESSAGE-----
291 ww0EBwMC9rK/dMkF5Zlt0jcBlzAQ1mQY2qYbKYbw8h3EZ5Jk0K2IiY92R82TRhWzBIF/8cmXDPtP
292 GXsd65oYJZp3Khz0qfyn
293 =Nmpq
294 -----END PGP MESSAGE-----
295 '), 'wrong-key', 'debug=1');
297 -- Routine use of BZip2 compression.  Ciphertext source:
298 -- echo x | gpg --homedir /nonexistent --personal-compress-preferences bzip2 \
299 --      --personal-cipher-preferences aes --no-emit-version --batch \
300 --      --symmetric --passphrase key --armor
301 select pgp_sym_decrypt(dearmor('
302 -----BEGIN PGP MESSAGE-----
304 jA0EBwMCRhFrAKNcLVJg0mMBLJG1cCASNk/x/3dt1zJ+2eo7jHfjgg3N6wpB3XIe
305 QCwkWJwlBG5pzbO5gu7xuPQN+TbPJ7aQ2sLx3bAHhtYb0i3vV9RO10Gw++yUyd4R
306 UCAAw2JRIISttRHMfDpDuZJpvYo=
307 =AZ9M
308 -----END PGP MESSAGE-----
309 '), 'key', 'debug=1');