summaryrefslogtreecommitdiffstats
path: root/contrib/pgcrypto/expected/pgp-encrypt.out
blob: 8fc558c402bde4400746c05fed376e2b1f3849c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
--
-- PGP encrypt
--
-- ensure consistent test output regardless of the default bytea format
SET bytea_output TO escape;
select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'), 'key');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- check whether the defaults are ok
select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'),
	'key', 'expect-cipher-algo=aes128,
		expect-disable-mdc=0,
		expect-sess-key=0,
		expect-s2k-mode=3,
		expect-s2k-digest-algo=sha1,
		expect-compress-algo=0
		');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- maybe the expect- stuff simply does not work
select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'),
	'key', 'expect-cipher-algo=bf,
		expect-disable-mdc=1,
		expect-sess-key=1,
		expect-s2k-mode=0,
		expect-s2k-digest-algo=md5,
		expect-compress-algo=1
		');
NOTICE:  pgp_decrypt: unexpected cipher_algo: expected 4 got 7
NOTICE:  pgp_decrypt: unexpected s2k_mode: expected 0 got 3
NOTICE:  pgp_decrypt: unexpected s2k_digest_algo: expected 1 got 2
NOTICE:  pgp_decrypt: unexpected use_sess_key: expected 1 got 0
NOTICE:  pgp_decrypt: unexpected disable_mdc: expected 1 got 0
NOTICE:  pgp_decrypt: unexpected compress_algo: expected 1 got 0
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- bytea as text
select pgp_sym_decrypt(pgp_sym_encrypt_bytea('Binary', 'baz'), 'baz');
ERROR:  Not text data
-- text as bytea
select pgp_sym_decrypt_bytea(pgp_sym_encrypt('Text', 'baz'), 'baz');
 pgp_sym_decrypt_bytea 
-----------------------
 Text
(1 row)

-- algorithm change
select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 'cipher-algo=bf'),
	'key', 'expect-cipher-algo=bf');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 'cipher-algo=aes'),
	'key', 'expect-cipher-algo=aes128');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 'cipher-algo=aes192'),
	'key', 'expect-cipher-algo=aes192');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- s2k change
select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 's2k-mode=0'),
	'key', 'expect-s2k-mode=0');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 's2k-mode=1'),
	'key', 'expect-s2k-mode=1');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 's2k-mode=3'),
	'key', 'expect-s2k-mode=3');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- s2k count change
select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 's2k-count=1024'),
	'key', 'expect-s2k-count=1024');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- s2k_count rounds up
select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 's2k-count=65000000'),
	'key', 'expect-s2k-count=65000000');
NOTICE:  pgp_decrypt: unexpected s2k_count: expected 65000000 got 65011712
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- s2k digest change
select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 's2k-digest-algo=md5'),
	'key', 'expect-s2k-digest-algo=md5');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

select pgp_sym_decrypt(
		pgp_sym_encrypt('Secret.', 'key', 's2k-digest-algo=sha1'),
	'key', 'expect-s2k-digest-algo=sha1');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- sess key
select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 'sess-key=0'),
	'key', 'expect-sess-key=0');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 'sess-key=1'),
	'key', 'expect-sess-key=1');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 'sess-key=1, cipher-algo=bf'),
	'key', 'expect-sess-key=1, expect-cipher-algo=bf');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 'sess-key=1, cipher-algo=aes192'),
	'key', 'expect-sess-key=1, expect-cipher-algo=aes192');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

select pgp_sym_decrypt(
	pgp_sym_encrypt('Secret.', 'key', 'sess-key=1, cipher-algo=aes256'),
	'key', 'expect-sess-key=1, expect-cipher-algo=aes256');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- no mdc
select pgp_sym_decrypt(
		pgp_sym_encrypt('Secret.', 'key', 'disable-mdc=1'),
	'key', 'expect-disable-mdc=1');
 pgp_sym_decrypt 
-----------------
 Secret.
(1 row)

-- crlf
select encode(pgp_sym_decrypt_bytea(
	pgp_sym_encrypt(E'1\n2\n3\r\n', 'key', 'convert-crlf=1'),
	'key'), 'hex');
        encode        
----------------------
 310d0a320d0a330d0d0a
(1 row)

-- conversion should be lossless
select encode(digest(pgp_sym_decrypt(
  pgp_sym_encrypt(E'\r\n0\n1\r\r\n\n2\r', 'key', 'convert-crlf=1'),
	'key', 'convert-crlf=1'), 'sha1'), 'hex') as result,
  encode(digest(E'\r\n0\n1\r\r\n\n2\r', 'sha1'), 'hex') as expect;
                  result                  |                  expect                  
------------------------------------------+------------------------------------------
 47bde5d88d6ef8770572b9cbb4278b402aa69966 | 47bde5d88d6ef8770572b9cbb4278b402aa69966
(1 row)