Debian Codegraph @

contrib/pgcrypto/expected/rijndael.out

raw
1 --
2 -- AES cipher (aka Rijndael-128, -192, or -256)
3 --
4 -- some standard Rijndael testvalues
5 SELECT encrypt(
6 '\x00112233445566778899aabbccddeeff',
7 '\x000102030405060708090a0b0c0d0e0f',
8 'aes-ecb/pad:none');
9 encrypt
10 ------------------------------------
11 \x69c4e0d86a7b0430d8cdb78070b4c55a
12 (1 row)
13
14 SELECT encrypt(
15 '\x00112233445566778899aabbccddeeff',
16 '\x000102030405060708090a0b0c0d0e0f1011121314151617',
17 'aes-ecb/pad:none');
18 encrypt
19 ------------------------------------
20 \xdda97ca4864cdfe06eaf70a0ec0d7191
21 (1 row)
22
23 SELECT encrypt(
24 '\x00112233445566778899aabbccddeeff',
25 '\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
26 'aes-ecb/pad:none');
27 encrypt
28 ------------------------------------
29 \x8ea2b7ca516745bfeafc49904b496089
30 (1 row)
31
32 -- cbc
33 SELECT encrypt(
34 '\x00112233445566778899aabbccddeeff',
35 '\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
36 'aes-cbc/pad:none');
37 encrypt
38 ------------------------------------
39 \x8ea2b7ca516745bfeafc49904b496089
40 (1 row)
41
42 -- without padding, input not multiple of block size
43 SELECT encrypt(
44 '\x00112233445566778899aabbccddeeff00',
45 '\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
46 'aes-cbc/pad:none');
47 ERROR: encrypt error: Encryption failed
48 -- key padding
49 SELECT encrypt(
50 '\x0011223344',
51 '\x000102030405',
52 'aes-cbc');
53 encrypt
54 ------------------------------------
55 \x189a28932213f017b246678dbc28655f
56 (1 row)
57
58 SELECT encrypt(
59 '\x0011223344',
60 '\x000102030405060708090a0b0c0d0e0f10111213',
61 'aes-cbc');
62 encrypt
63 ------------------------------------
64 \x3b02279162d15580e069d3a71407a556
65 (1 row)
66
67 SELECT encrypt(
68 '\x0011223344',
69 '\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b',
70 'aes-cbc');
71 encrypt
72 ------------------------------------
73 \x4facb6a041d53e0a5a73289170901fe7
74 (1 row)
75
76 -- empty data
77 select encrypt('', 'foo', 'aes');
78 encrypt
79 ------------------------------------
80 \xb48cc3338a2eb293b6007ef72c360d48
81 (1 row)
82
83 -- 10 bytes key
84 select encrypt('foo', '0123456789', 'aes');
85 encrypt
86 ------------------------------------
87 \xf397f03d2819b7172b68d0706fda4693
88 (1 row)
89
90 -- 22 bytes key
91 select encrypt('foo', '0123456789012345678901', 'aes');
92 encrypt
93 ------------------------------------
94 \x5c9db77af02b4678117bcd8a71ae7f53
95 (1 row)
96
97 -- decrypt
98 select encode(decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes'), 'escape');
99 encode
100 --------
101 foo
102 (1 row)
103
104 -- data not multiple of block size
105 select encode(decrypt(encrypt('foo', '0123456', 'aes') || '\x00'::bytea, '0123456', 'aes'), 'escape');
106 ERROR: decrypt error: Decryption failed
107 -- bad padding
108 -- (The input value is the result of encrypt_iv('abcdefghijklmnopqrstuvwxyz', '0123456', 'abcd', 'aes')
109 -- with the 16th byte changed (s/db/eb/) to corrupt the padding of the last block.)
110 select encode(decrypt_iv('\xa21a9c15231465964e3396d32095e67eb52bab05f556a581621dee1b85385789', '0123456', 'abcd', 'aes'), 'escape');
111 ERROR: decrypt_iv error: Decryption failed
112 -- iv
113 select encrypt_iv('foo', '0123456', 'abcd', 'aes');
114 encrypt_iv
115 ------------------------------------
116 \x2c24cb7da91d6d5699801268b0f5adad
117 (1 row)
118
119 select encode(decrypt_iv('\x2c24cb7da91d6d5699801268b0f5adad', '0123456', 'abcd', 'aes'), 'escape');
120 encode
121 --------
122 foo
123 (1 row)
124
125 -- long message
126 select encrypt('Lets try a longer message.', '0123456789', 'aes');
127 encrypt
128 --------------------------------------------------------------------
129 \xd9beb785dd5403ed02f66b755bb191b93ed93ca54930153f2c3b9ec7785056ad
130 (1 row)
131
132 select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes'), '0123456789', 'aes'), 'escape');
133 encode
134 ----------------------------
135 Lets try a longer message.
136 (1 row)
137
138 -- cfb
139 SELECT encrypt(
140 '\x00112233445566778899aabbccddeeff',
141 '\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
142 'aes-cfb/pad:none');
143 encrypt
144 ------------------------------------
145 \xf28122856e1cf9a7216a30d111f3997f
146 (1 row)
147
148 -- without padding, input not multiple of block size
149 SELECT encrypt(
150 '\x00112233445566778899aabbccddeeff00',
151 '\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
152 'aes-cfb/pad:none');
153 encrypt
154 --------------------------------------
155 \xf28122856e1cf9a7216a30d111f3997fcb
156 (1 row)
157
158 -- key padding
159 SELECT encrypt(
160 '\x0011223344',
161 '\x000102030405',
162 'aes-cfb');
163 encrypt
164 --------------
165 \x8145d1a0ef
166 (1 row)
167
168 SELECT encrypt(
169 '\x0011223344',
170 '\x000102030405060708090a0b0c0d0e0f10111213',
171 'aes-cfb');
172 encrypt
173 --------------
174 \x52642c3b9c
175 (1 row)
176
177 SELECT encrypt(
178 '\x0011223344',
179 '\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b',
180 'aes-cfb');
181 encrypt
182 --------------
183 \xc93b4468a4
184 (1 row)
185
186 -- empty data
187 select encrypt('', 'foo', 'aes-cfb');
188 encrypt
189 ---------
190 \x
191 (1 row)
192
193 -- 10 bytes key
194 select encrypt('foo', '0123456789', 'aes-cfb');
195 encrypt
196 ----------
197 \x6f8ced
198 (1 row)
199
200 -- 22 bytes key
201 select encrypt('foo', '0123456789012345678901', 'aes-cfb');
202 encrypt
203 ----------
204 \xfb47d2
205 (1 row)
206
207 -- decrypt
208 select encode(decrypt(encrypt('foo', '0123456', 'aes-cfb'), '0123456', 'aes-cfb'), 'escape');
209 encode
210 --------
211 foo
212 (1 row)
213
214 -- data not multiple of block size
215 select encode(decrypt(encrypt('foo', '0123456', 'aes-cfb') || '\x00'::bytea, '0123456', 'aes-cfb'), 'escape');
216 encode
217 ---------
218 foo\337
219 (1 row)
220
221 -- bad padding
222 -- (The input value is the result of encrypt_iv('abcdefghijklmnopqrstuvwxyz', '0123456', 'abcd', 'aes-cfb')
223 -- with the 16th byte changed (s/c5/d5/) to corrupt the padding of the last block.)
224 select encode(decrypt_iv('\xf9ad6817cb58d31dd9ba6571fbc4f55d56f65b631f0f437cb828', '0123456', 'abcd', 'aes-cfb'), 'escape');
225 encode
226 -------------------------------------------------
227 abcdefghijklmnoq\243:\205o\x7F\x05z\276\x07\332
228 (1 row)
229
230 -- iv
231 select encrypt_iv('foo', '0123456', 'abcd', 'aes-cfb');
232 encrypt_iv
233 ------------
234 \xfea064
235 (1 row)
236
237 select encode(decrypt_iv('\xfea064', '0123456', 'abcd', 'aes-cfb'), 'escape');
238 encode
239 --------
240 foo
241 (1 row)
242
243 -- long message
244 select encrypt('Lets try a longer message.', '0123456789', 'aes-cfb');
245 encrypt
246 --------------------------------------------------------
247 \x4586f6c6351055051f723b1b0aad52c877eaf0c421d18fd73a28
248 (1 row)
249
250 select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes-cfb'), '0123456789', 'aes-cfb'), 'escape');
251 encode
252 ----------------------------
253 Lets try a longer message.
254 (1 row)
255