mirror of https://github.com/postgres/postgres
* test error handling * add tests for des, 3des, cast5 * add some tests to blowfish, rijndael * Makefile: ability to specify different tests for different crypto libraries, so we can skip des, 3des and cast5 for builtin. Marko KreenREL8_1_STABLE
parent
19b676869a
commit
6a8eb1a7b6
@ -0,0 +1,56 @@ |
||||
-- |
||||
-- 3DES cipher |
||||
-- |
||||
-- test vector from somewhere |
||||
SELECT encode(encrypt( |
||||
decode('80 00 00 00 00 00 00 00', 'hex'), |
||||
decode('01 01 01 01 01 01 01 01 |
||||
01 01 01 01 01 01 01 01 |
||||
01 01 01 01 01 01 01 01', 'hex'), |
||||
'3des-ecb/pad:none'), 'hex'); |
||||
encode |
||||
------------------ |
||||
95f8a5e5dd31d900 |
||||
(1 row) |
||||
|
||||
-- val 95 F8 A5 E5 DD 31 D9 00 |
||||
select encode( encrypt('', 'foo', '3des'), 'hex'); |
||||
encode |
||||
------------------ |
||||
9b641a6936249eb4 |
||||
(1 row) |
||||
|
||||
-- 10 bytes key |
||||
select encode( encrypt('foo', '0123456789', '3des'), 'hex'); |
||||
encode |
||||
------------------ |
||||
6f02b7076a366504 |
||||
(1 row) |
||||
|
||||
-- 22 bytes key |
||||
select encode( encrypt('foo', '0123456789012345678901', '3des'), 'hex'); |
||||
encode |
||||
------------------ |
||||
a44360e699269817 |
||||
(1 row) |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des'); |
||||
decrypt |
||||
--------- |
||||
foo |
||||
(1 row) |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', '3des'), 'hex'); |
||||
encode |
||||
------------------ |
||||
df27c264fb24ed7a |
||||
(1 row) |
||||
|
||||
select decrypt_iv(decode('df27c264fb24ed7a', 'hex'), '0123456', 'abcd', '3des'); |
||||
decrypt_iv |
||||
------------ |
||||
foo |
||||
(1 row) |
||||
|
||||
@ -0,0 +1,73 @@ |
||||
-- |
||||
-- Cast5 cipher |
||||
-- |
||||
-- test vectors from RFC2144 |
||||
-- 128 bit key |
||||
SELECT encode(encrypt( |
||||
decode('01 23 45 67 89 AB CD EF', 'hex'), |
||||
decode('01 23 45 67 12 34 56 78 23 45 67 89 34 56 78 9A', 'hex'), |
||||
'cast5-ecb/pad:none'), 'hex'); |
||||
encode |
||||
------------------ |
||||
238b4fe5847e44b2 |
||||
(1 row) |
||||
|
||||
-- result: 23 8B 4F E5 84 7E 44 B2 |
||||
-- 80 bit key |
||||
SELECT encode(encrypt( |
||||
decode('01 23 45 67 89 AB CD EF', 'hex'), |
||||
decode('01 23 45 67 12 34 56 78 23 45', 'hex'), |
||||
'cast5-ecb/pad:none'), 'hex'); |
||||
encode |
||||
------------------ |
||||
eb6a711a2c02271b |
||||
(1 row) |
||||
|
||||
-- result: EB 6A 71 1A 2C 02 27 1B |
||||
-- 40 bit key |
||||
SELECT encode(encrypt( |
||||
decode('01 23 45 67 89 AB CD EF', 'hex'), |
||||
decode('01 23 45 67 12', 'hex'), |
||||
'cast5-ecb/pad:none'), 'hex'); |
||||
encode |
||||
------------------ |
||||
7ac816d16e9b302e |
||||
(1 row) |
||||
|
||||
-- result: 7A C8 16 D1 6E 9B 30 2E |
||||
-- cbc |
||||
-- empty data |
||||
select encode( encrypt('', 'foo', 'cast5'), 'hex'); |
||||
encode |
||||
------------------ |
||||
a48bd1aabde4de10 |
||||
(1 row) |
||||
|
||||
-- 10 bytes key |
||||
select encode( encrypt('foo', '0123456789', 'cast5'), 'hex'); |
||||
encode |
||||
------------------ |
||||
b07f19255e60cb6d |
||||
(1 row) |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5'); |
||||
decrypt |
||||
--------- |
||||
foo |
||||
(1 row) |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'cast5'), 'hex'); |
||||
encode |
||||
------------------ |
||||
384a970695ce016a |
||||
(1 row) |
||||
|
||||
select decrypt_iv(decode('384a970695ce016a', 'hex'), |
||||
'0123456', 'abcd', 'cast5'); |
||||
decrypt_iv |
||||
------------ |
||||
foo |
||||
(1 row) |
||||
|
||||
@ -0,0 +1,48 @@ |
||||
-- |
||||
-- DES cipher |
||||
-- |
||||
-- no official test vectors atm |
||||
-- from blowfish.sql |
||||
SELECT encode(encrypt( |
||||
decode('0123456789abcdef', 'hex'), |
||||
decode('fedcba9876543210', 'hex'), |
||||
'des-ecb/pad:none'), 'hex'); |
||||
encode |
||||
------------------ |
||||
ed39d950fa74bcc4 |
||||
(1 row) |
||||
|
||||
-- empty data |
||||
select encode( encrypt('', 'foo', 'des'), 'hex'); |
||||
encode |
||||
------------------ |
||||
752111e37a2d7ac3 |
||||
(1 row) |
||||
|
||||
-- 8 bytes key |
||||
select encode( encrypt('foo', '01234589', 'des'), 'hex'); |
||||
encode |
||||
------------------ |
||||
dec0f9c602b647a8 |
||||
(1 row) |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des'); |
||||
decrypt |
||||
--------- |
||||
foo |
||||
(1 row) |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'des'), 'hex'); |
||||
encode |
||||
------------------ |
||||
50735067b073bb93 |
||||
(1 row) |
||||
|
||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', 'des'); |
||||
decrypt_iv |
||||
------------ |
||||
foo |
||||
(1 row) |
||||
|
||||
@ -0,0 +1,26 @@ |
||||
-- |
||||
-- 3DES cipher |
||||
-- |
||||
|
||||
-- test vector from somewhere |
||||
SELECT encode(encrypt( |
||||
decode('80 00 00 00 00 00 00 00', 'hex'), |
||||
decode('01 01 01 01 01 01 01 01 |
||||
01 01 01 01 01 01 01 01 |
||||
01 01 01 01 01 01 01 01', 'hex'), |
||||
'3des-ecb/pad:none'), 'hex'); |
||||
-- val 95 F8 A5 E5 DD 31 D9 00 |
||||
|
||||
select encode( encrypt('', 'foo', '3des'), 'hex'); |
||||
-- 10 bytes key |
||||
select encode( encrypt('foo', '0123456789', '3des'), 'hex'); |
||||
-- 22 bytes key |
||||
select encode( encrypt('foo', '0123456789012345678901', '3des'), 'hex'); |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des'); |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', '3des'), 'hex'); |
||||
select decrypt_iv(decode('df27c264fb24ed7a', 'hex'), '0123456', 'abcd', '3des'); |
||||
|
||||
@ -0,0 +1,42 @@ |
||||
-- |
||||
-- Cast5 cipher |
||||
-- |
||||
|
||||
-- test vectors from RFC2144 |
||||
|
||||
-- 128 bit key |
||||
SELECT encode(encrypt( |
||||
decode('01 23 45 67 89 AB CD EF', 'hex'), |
||||
decode('01 23 45 67 12 34 56 78 23 45 67 89 34 56 78 9A', 'hex'), |
||||
'cast5-ecb/pad:none'), 'hex'); |
||||
-- result: 23 8B 4F E5 84 7E 44 B2 |
||||
|
||||
-- 80 bit key |
||||
SELECT encode(encrypt( |
||||
decode('01 23 45 67 89 AB CD EF', 'hex'), |
||||
decode('01 23 45 67 12 34 56 78 23 45', 'hex'), |
||||
'cast5-ecb/pad:none'), 'hex'); |
||||
-- result: EB 6A 71 1A 2C 02 27 1B |
||||
|
||||
-- 40 bit key |
||||
SELECT encode(encrypt( |
||||
decode('01 23 45 67 89 AB CD EF', 'hex'), |
||||
decode('01 23 45 67 12', 'hex'), |
||||
'cast5-ecb/pad:none'), 'hex'); |
||||
-- result: 7A C8 16 D1 6E 9B 30 2E |
||||
|
||||
-- cbc |
||||
|
||||
-- empty data |
||||
select encode( encrypt('', 'foo', 'cast5'), 'hex'); |
||||
-- 10 bytes key |
||||
select encode( encrypt('foo', '0123456789', 'cast5'), 'hex'); |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5'); |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'cast5'), 'hex'); |
||||
select decrypt_iv(decode('384a970695ce016a', 'hex'), |
||||
'0123456', 'abcd', 'cast5'); |
||||
|
||||
@ -0,0 +1,24 @@ |
||||
-- |
||||
-- DES cipher |
||||
-- |
||||
|
||||
-- no official test vectors atm |
||||
|
||||
-- from blowfish.sql |
||||
SELECT encode(encrypt( |
||||
decode('0123456789abcdef', 'hex'), |
||||
decode('fedcba9876543210', 'hex'), |
||||
'des-ecb/pad:none'), 'hex'); |
||||
|
||||
-- empty data |
||||
select encode( encrypt('', 'foo', 'des'), 'hex'); |
||||
-- 8 bytes key |
||||
select encode( encrypt('foo', '01234589', 'des'), 'hex'); |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des'); |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'des'), 'hex'); |
||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', 'des'); |
||||
|
||||
Loading…
Reference in new issue