Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 72bbff4

Browse files
Add alternative output for OpenSSL 3 without legacy loaded
OpenSSL 3 introduced the concept of providers to support modularization, and moved the outdated ciphers to the new legacy provider. In case it's not loaded in the users openssl.cnf file there will be a lot of regress test failures, so add alternative outputs covering those. Also document the need to load the legacy provider in order to use older ciphers with OpenSSL-enabled pgcrypto. This will be backpatched to all supported version once there is sufficient testing in the buildfarm of OpenSSL 3. Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/FEF81714-D479-4512-839B-C769D2605F8A@yesql.se
1 parent 318df80 commit 72bbff4

File tree

6 files changed

+1254
-0
lines changed

6 files changed

+1254
-0
lines changed
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
--
2+
-- Blowfish cipher
3+
--
4+
-- ensure consistent test output regardless of the default bytea format
5+
SET bytea_output TO escape;
6+
-- some standard Blowfish testvalues
7+
SELECT encode(encrypt(
8+
decode('0000000000000000', 'hex'),
9+
decode('0000000000000000', 'hex'),
10+
'bf-ecb/pad:none'), 'hex');
11+
ERROR: encrypt error: Cipher cannot be initialized ?
12+
SELECT encode(encrypt(
13+
decode('ffffffffffffffff', 'hex'),
14+
decode('ffffffffffffffff', 'hex'),
15+
'bf-ecb/pad:none'), 'hex');
16+
ERROR: encrypt error: Cipher cannot be initialized ?
17+
SELECT encode(encrypt(
18+
decode('1000000000000001', 'hex'),
19+
decode('3000000000000000', 'hex'),
20+
'bf-ecb/pad:none'), 'hex');
21+
ERROR: encrypt error: Cipher cannot be initialized ?
22+
SELECT encode(encrypt(
23+
decode('1111111111111111', 'hex'),
24+
decode('1111111111111111', 'hex'),
25+
'bf-ecb/pad:none'), 'hex');
26+
ERROR: encrypt error: Cipher cannot be initialized ?
27+
SELECT encode(encrypt(
28+
decode('0123456789abcdef', 'hex'),
29+
decode('fedcba9876543210', 'hex'),
30+
'bf-ecb/pad:none'), 'hex');
31+
ERROR: encrypt error: Cipher cannot be initialized ?
32+
SELECT encode(encrypt(
33+
decode('01a1d6d039776742', 'hex'),
34+
decode('fedcba9876543210', 'hex'),
35+
'bf-ecb/pad:none'), 'hex');
36+
ERROR: encrypt error: Cipher cannot be initialized ?
37+
SELECT encode(encrypt(
38+
decode('ffffffffffffffff', 'hex'),
39+
decode('0000000000000000', 'hex'),
40+
'bf-ecb/pad:none'), 'hex');
41+
ERROR: encrypt error: Cipher cannot be initialized ?
42+
-- setkey
43+
SELECT encode(encrypt(
44+
decode('fedcba9876543210', 'hex'),
45+
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f', 'hex'),
46+
'bf-ecb/pad:none'), 'hex');
47+
ERROR: encrypt error: Cipher cannot be initialized ?
48+
-- with padding
49+
SELECT encode(encrypt(
50+
decode('01234567890123456789', 'hex'),
51+
decode('33443344334433443344334433443344', 'hex'),
52+
'bf-ecb'), 'hex');
53+
ERROR: encrypt error: Cipher cannot be initialized ?
54+
-- cbc
55+
-- 28 bytes key
56+
SELECT encode(encrypt(
57+
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', 'hex'),
58+
decode('37363534333231204e6f77206973207468652074696d6520666f7220', 'hex'),
59+
'bf-cbc'), 'hex');
60+
ERROR: encrypt error: Key was too big
61+
-- 29 bytes key
62+
SELECT encode(encrypt(
63+
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', 'hex'),
64+
decode('37363534333231204e6f77206973207468652074696d6520666f722000', 'hex'),
65+
'bf-cbc'), 'hex');
66+
ERROR: encrypt error: Key was too big
67+
-- blowfish-448
68+
SELECT encode(encrypt(
69+
decode('fedcba9876543210', 'hex'),
70+
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', 'hex'),
71+
'bf-ecb/pad:none'), 'hex');
72+
ERROR: encrypt error: Key was too big
73+
-- result: c04504012e4e1f53
74+
-- empty data
75+
select encode(encrypt('', 'foo', 'bf'), 'hex');
76+
ERROR: encrypt error: Cipher cannot be initialized ?
77+
-- 10 bytes key
78+
select encode(encrypt('foo', '0123456789', 'bf'), 'hex');
79+
ERROR: encrypt error: Cipher cannot be initialized ?
80+
-- 22 bytes key
81+
select encode(encrypt('foo', '0123456789012345678901', 'bf'), 'hex');
82+
ERROR: encrypt error: Key was too big
83+
-- decrypt
84+
select decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf');
85+
ERROR: encrypt error: Cipher cannot be initialized ?
86+
-- iv
87+
select encode(encrypt_iv('foo', '0123456', 'abcd', 'bf'), 'hex');
88+
ERROR: encrypt_iv error: Cipher cannot be initialized ?
89+
select decrypt_iv(decode('95c7e89322525d59', 'hex'), '0123456', 'abcd', 'bf');
90+
ERROR: decrypt_iv error: Cipher cannot be initialized ?
91+
-- long message
92+
select encode(encrypt('Lets try a longer message.', '0123456789', 'bf'), 'hex');
93+
ERROR: encrypt error: Cipher cannot be initialized ?
94+
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf');
95+
ERROR: encrypt error: Cipher cannot be initialized ?

contrib/pgcrypto/expected/cast5_1.out

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--
2+
-- Cast5 cipher
3+
--
4+
-- ensure consistent test output regardless of the default bytea format
5+
SET bytea_output TO escape;
6+
-- test vectors from RFC2144
7+
-- 128 bit key
8+
SELECT encode(encrypt(
9+
decode('01 23 45 67 89 AB CD EF', 'hex'),
10+
decode('01 23 45 67 12 34 56 78 23 45 67 89 34 56 78 9A', 'hex'),
11+
'cast5-ecb/pad:none'), 'hex');
12+
ERROR: encrypt error: Cipher cannot be initialized ?
13+
-- result: 23 8B 4F E5 84 7E 44 B2
14+
-- 80 bit key
15+
SELECT encode(encrypt(
16+
decode('01 23 45 67 89 AB CD EF', 'hex'),
17+
decode('01 23 45 67 12 34 56 78 23 45', 'hex'),
18+
'cast5-ecb/pad:none'), 'hex');
19+
ERROR: encrypt error: Cipher cannot be initialized ?
20+
-- result: EB 6A 71 1A 2C 02 27 1B
21+
-- 40 bit key
22+
SELECT encode(encrypt(
23+
decode('01 23 45 67 89 AB CD EF', 'hex'),
24+
decode('01 23 45 67 12', 'hex'),
25+
'cast5-ecb/pad:none'), 'hex');
26+
ERROR: encrypt error: Cipher cannot be initialized ?
27+
-- result: 7A C8 16 D1 6E 9B 30 2E
28+
-- cbc
29+
-- empty data
30+
select encode( encrypt('', 'foo', 'cast5'), 'hex');
31+
ERROR: encrypt error: Cipher cannot be initialized ?
32+
-- 10 bytes key
33+
select encode( encrypt('foo', '0123456789', 'cast5'), 'hex');
34+
ERROR: encrypt error: Cipher cannot be initialized ?
35+
-- decrypt
36+
select decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5');
37+
ERROR: encrypt error: Cipher cannot be initialized ?
38+
-- iv
39+
select encode(encrypt_iv('foo', '0123456', 'abcd', 'cast5'), 'hex');
40+
ERROR: encrypt_iv error: Cipher cannot be initialized ?
41+
select decrypt_iv(decode('384a970695ce016a', 'hex'),
42+
'0123456', 'abcd', 'cast5');
43+
ERROR: decrypt_iv error: Cipher cannot be initialized ?
44+
-- long message
45+
select encode(encrypt('Lets try a longer message.', '0123456789', 'cast5'), 'hex');
46+
ERROR: encrypt error: Cipher cannot be initialized ?
47+
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5');
48+
ERROR: encrypt error: Cipher cannot be initialized ?

contrib/pgcrypto/expected/des_1.out

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--
2+
-- DES cipher
3+
--
4+
-- ensure consistent test output regardless of the default bytea format
5+
SET bytea_output TO escape;
6+
-- no official test vectors atm
7+
-- from blowfish.sql
8+
SELECT encode(encrypt(
9+
decode('0123456789abcdef', 'hex'),
10+
decode('fedcba9876543210', 'hex'),
11+
'des-ecb/pad:none'), 'hex');
12+
ERROR: encrypt error: Cipher cannot be initialized ?
13+
-- empty data
14+
select encode( encrypt('', 'foo', 'des'), 'hex');
15+
ERROR: encrypt error: Cipher cannot be initialized ?
16+
-- 8 bytes key
17+
select encode( encrypt('foo', '01234589', 'des'), 'hex');
18+
ERROR: encrypt error: Cipher cannot be initialized ?
19+
-- decrypt
20+
select decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des');
21+
ERROR: encrypt error: Cipher cannot be initialized ?
22+
-- iv
23+
select encode(encrypt_iv('foo', '0123456', 'abcd', 'des'), 'hex');
24+
ERROR: encrypt_iv error: Cipher cannot be initialized ?
25+
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', 'des');
26+
ERROR: decrypt_iv error: Cipher cannot be initialized ?
27+
-- long message
28+
select encode(encrypt('Lets try a longer message.', '01234567', 'des'), 'hex');
29+
ERROR: encrypt error: Cipher cannot be initialized ?
30+
select decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des');
31+
ERROR: encrypt error: Cipher cannot be initialized ?

0 commit comments

Comments
 (0)