mirror of https://github.com/postgres/postgres
This was from before the hex format was available in bytea. Now we can remove the extra explicit encoding/decoding calls and rely on the default output format. Discussion: https://www.postgresql.org/message-id/flat/17dcb4f7-7ac1-e2b6-d5f7-2dfba06cd9ee%40enterprisedb.compull/138/head
parent
00029deaf6
commit
814e1d9ff7
@ -1,95 +1,62 @@ |
||||
-- |
||||
-- Blowfish cipher |
||||
-- |
||||
-- ensure consistent test output regardless of the default bytea format |
||||
SET bytea_output TO escape; |
||||
-- some standard Blowfish testvalues |
||||
SELECT encode(encrypt( |
||||
decode('0000000000000000', 'hex'), |
||||
decode('0000000000000000', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\x0000000000000000', '\x0000000000000000', 'bf-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
SELECT encode(encrypt( |
||||
decode('ffffffffffffffff', 'hex'), |
||||
decode('ffffffffffffffff', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\xffffffffffffffff', '\xffffffffffffffff', 'bf-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
SELECT encode(encrypt( |
||||
decode('1000000000000001', 'hex'), |
||||
decode('3000000000000000', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\x1000000000000001', '\x3000000000000000', 'bf-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
SELECT encode(encrypt( |
||||
decode('1111111111111111', 'hex'), |
||||
decode('1111111111111111', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\x1111111111111111', '\x1111111111111111', 'bf-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
SELECT encode(encrypt( |
||||
decode('0123456789abcdef', 'hex'), |
||||
decode('fedcba9876543210', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'bf-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
SELECT encode(encrypt( |
||||
decode('01a1d6d039776742', 'hex'), |
||||
decode('fedcba9876543210', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\x01a1d6d039776742', '\xfedcba9876543210', 'bf-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
SELECT encode(encrypt( |
||||
decode('ffffffffffffffff', 'hex'), |
||||
decode('0000000000000000', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\xffffffffffffffff', '\x0000000000000000', 'bf-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- setkey |
||||
SELECT encode(encrypt( |
||||
decode('fedcba9876543210', 'hex'), |
||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\xfedcba9876543210', '\xf0e1d2c3b4a5968778695a4b3c2d1e0f', 'bf-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- with padding |
||||
SELECT encode(encrypt( |
||||
decode('01234567890123456789', 'hex'), |
||||
decode('33443344334433443344334433443344', 'hex'), |
||||
'bf-ecb'), 'hex'); |
||||
SELECT encrypt('\x01234567890123456789', '\x33443344334433443344334433443344', 'bf-ecb'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- cbc |
||||
-- 28 bytes key |
||||
SELECT encode(encrypt( |
||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', 'hex'), |
||||
decode('37363534333231204e6f77206973207468652074696d6520666f7220', 'hex'), |
||||
'bf-cbc'), 'hex'); |
||||
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', |
||||
'\x37363534333231204e6f77206973207468652074696d6520666f7220', |
||||
'bf-cbc'); |
||||
ERROR: encrypt error: Key was too big |
||||
-- 29 bytes key |
||||
SELECT encode(encrypt( |
||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', 'hex'), |
||||
decode('37363534333231204e6f77206973207468652074696d6520666f722000', 'hex'), |
||||
'bf-cbc'), 'hex'); |
||||
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', |
||||
'\x37363534333231204e6f77206973207468652074696d6520666f722000', |
||||
'bf-cbc'); |
||||
ERROR: encrypt error: Key was too big |
||||
-- blowfish-448 |
||||
SELECT encode(encrypt( |
||||
decode('fedcba9876543210', 'hex'), |
||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\xfedcba9876543210', |
||||
'\xf0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', |
||||
'bf-ecb/pad:none'); |
||||
ERROR: encrypt error: Key was too big |
||||
-- result: c04504012e4e1f53 |
||||
-- empty data |
||||
select encode(encrypt('', 'foo', 'bf'), 'hex'); |
||||
select encrypt('', 'foo', 'bf'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- 10 bytes key |
||||
select encode(encrypt('foo', '0123456789', 'bf'), 'hex'); |
||||
select encrypt('foo', '0123456789', 'bf'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- 22 bytes key |
||||
select encode(encrypt('foo', '0123456789012345678901', 'bf'), 'hex'); |
||||
select encrypt('foo', '0123456789012345678901', 'bf'); |
||||
ERROR: encrypt error: Key was too big |
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf'); |
||||
select encode(decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf'), 'escape'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'bf'), 'hex'); |
||||
select encrypt_iv('foo', '0123456', 'abcd', 'bf'); |
||||
ERROR: encrypt_iv error: Cipher cannot be initialized ? |
||||
select decrypt_iv(decode('95c7e89322525d59', 'hex'), '0123456', 'abcd', 'bf'); |
||||
select encode(decrypt_iv('\x95c7e89322525d59', '0123456', 'abcd', 'bf'), 'escape'); |
||||
ERROR: decrypt_iv error: Cipher cannot be initialized ? |
||||
-- long message |
||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'bf'), 'hex'); |
||||
select encrypt('Lets try a longer message.', '0123456789', 'bf'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf'); |
||||
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf'), 'escape'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
|
||||
@ -1,48 +1,33 @@ |
||||
-- |
||||
-- Cast5 cipher |
||||
-- |
||||
-- ensure consistent test output regardless of the default bytea format |
||||
SET bytea_output TO escape; |
||||
-- 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'); |
||||
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712345678234567893456789A', 'cast5-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- 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'); |
||||
SELECT encrypt('\x0123456789ABCDEF', '\x01234567123456782345', 'cast5-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- 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'); |
||||
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712', 'cast5-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- result: 7A C8 16 D1 6E 9B 30 2E |
||||
-- cbc |
||||
-- empty data |
||||
select encode( encrypt('', 'foo', 'cast5'), 'hex'); |
||||
select encrypt('', 'foo', 'cast5'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- 10 bytes key |
||||
select encode( encrypt('foo', '0123456789', 'cast5'), 'hex'); |
||||
select encrypt('foo', '0123456789', 'cast5'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5'); |
||||
select encode(decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5'), 'escape'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'cast5'), 'hex'); |
||||
select encrypt_iv('foo', '0123456', 'abcd', 'cast5'); |
||||
ERROR: encrypt_iv error: Cipher cannot be initialized ? |
||||
select decrypt_iv(decode('384a970695ce016a', 'hex'), |
||||
'0123456', 'abcd', 'cast5'); |
||||
select encode(decrypt_iv('\x384a970695ce016a', '0123456', 'abcd', 'cast5'), 'escape'); |
||||
ERROR: decrypt_iv error: Cipher cannot be initialized ? |
||||
-- long message |
||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'cast5'), 'hex'); |
||||
select encrypt('Lets try a longer message.', '0123456789', 'cast5'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5'); |
||||
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5'), 'escape'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
|
||||
@ -1,31 +1,26 @@ |
||||
-- |
||||
-- DES cipher |
||||
-- |
||||
-- ensure consistent test output regardless of the default bytea format |
||||
SET bytea_output TO escape; |
||||
-- no official test vectors atm |
||||
-- from blowfish.sql |
||||
SELECT encode(encrypt( |
||||
decode('0123456789abcdef', 'hex'), |
||||
decode('fedcba9876543210', 'hex'), |
||||
'des-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'des-ecb/pad:none'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- empty data |
||||
select encode( encrypt('', 'foo', 'des'), 'hex'); |
||||
select encrypt('', 'foo', 'des'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- 8 bytes key |
||||
select encode( encrypt('foo', '01234589', 'des'), 'hex'); |
||||
select encrypt('foo', '01234589', 'des'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des'); |
||||
select encode(decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des'), 'escape'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'des'), 'hex'); |
||||
select encrypt_iv('foo', '0123456', 'abcd', 'des'); |
||||
ERROR: encrypt_iv error: Cipher cannot be initialized ? |
||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', 'des'); |
||||
select encode(decrypt_iv('\x50735067b073bb93', '0123456', 'abcd', 'des'), 'escape'); |
||||
ERROR: decrypt_iv error: Cipher cannot be initialized ? |
||||
-- long message |
||||
select encode(encrypt('Lets try a longer message.', '01234567', 'des'), 'hex'); |
||||
select encrypt('Lets try a longer message.', '01234567', 'des'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
select decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des'); |
||||
select encode(decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des'), 'escape'); |
||||
ERROR: encrypt error: Cipher cannot be initialized ? |
||||
|
||||
@ -1,72 +1,72 @@ |
||||
-- |
||||
-- HMAC-MD5 |
||||
-- |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Hi There', |
||||
decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), |
||||
'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
9294727a3638bb1c13f48ef8158bfc9d |
||||
'\x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'::bytea, |
||||
'md5'); |
||||
hmac |
||||
------------------------------------ |
||||
\x9294727a3638bb1c13f48ef8158bfc9d |
||||
(1 row) |
||||
|
||||
-- 2 |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Jefe', |
||||
'what do ya want for nothing?', |
||||
'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
813aead7c4a34bff01a16d61368e7c13 |
||||
'md5'); |
||||
hmac |
||||
------------------------------------ |
||||
\x813aead7c4a34bff01a16d61368e7c13 |
||||
(1 row) |
||||
|
||||
-- 3 |
||||
SELECT encode(hmac( |
||||
decode('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'), |
||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), |
||||
'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
56be34521d144c88dbb8c733f0e8b3f6 |
||||
SELECT hmac( |
||||
'\xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'::bytea, |
||||
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea, |
||||
'md5'); |
||||
hmac |
||||
------------------------------------ |
||||
\x56be34521d144c88dbb8c733f0e8b3f6 |
||||
(1 row) |
||||
|
||||
-- 4 |
||||
SELECT encode(hmac( |
||||
decode('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', 'hex'), |
||||
decode('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'), |
||||
'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
697eaf0aca3a3aea3a75164746ffaa79 |
||||
SELECT hmac( |
||||
'\xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd'::bytea, |
||||
'\x0102030405060708090a0b0c0d0e0f10111213141516171819'::bytea, |
||||
'md5'); |
||||
hmac |
||||
------------------------------------ |
||||
\x697eaf0aca3a3aea3a75164746ffaa79 |
||||
(1 row) |
||||
|
||||
-- 5 |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Test With Truncation', |
||||
decode('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'), |
||||
'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
56461ef2342edc00f9bab995690efd4c |
||||
'\x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c'::bytea, |
||||
'md5'); |
||||
hmac |
||||
------------------------------------ |
||||
\x56461ef2342edc00f9bab995690efd4c |
||||
(1 row) |
||||
|
||||
-- 6 |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Test Using Larger Than Block-Size Key - Hash Key First', |
||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), |
||||
'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd |
||||
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea, |
||||
'md5'); |
||||
hmac |
||||
------------------------------------ |
||||
\x6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd |
||||
(1 row) |
||||
|
||||
-- 7 |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data', |
||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), |
||||
'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
6f630fad67cda0ee1fb1f562db3aa53e |
||||
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea, |
||||
'md5'); |
||||
hmac |
||||
------------------------------------ |
||||
\x6f630fad67cda0ee1fb1f562db3aa53e |
||||
(1 row) |
||||
|
||||
|
||||
@ -1,72 +1,72 @@ |
||||
-- |
||||
-- HMAC-SHA1 |
||||
-- |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Hi There', |
||||
decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), |
||||
'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
675b0b3a1b4ddf4e124872da6c2f632bfed957e9 |
||||
'\x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'::bytea, |
||||
'sha1'); |
||||
hmac |
||||
-------------------------------------------- |
||||
\x675b0b3a1b4ddf4e124872da6c2f632bfed957e9 |
||||
(1 row) |
||||
|
||||
-- 2 |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Jefe', |
||||
'what do ya want for nothing?', |
||||
'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
156d4c35468a0339f3fa57a067bf47f814eb7a57 |
||||
'sha1'); |
||||
hmac |
||||
-------------------------------------------- |
||||
\x156d4c35468a0339f3fa57a067bf47f814eb7a57 |
||||
(1 row) |
||||
|
||||
-- 3 |
||||
SELECT encode(hmac( |
||||
decode('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'), |
||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), |
||||
'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
d730594d167e35d5956fd8003d0db3d3f46dc7bb |
||||
SELECT hmac( |
||||
'\xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'::bytea, |
||||
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea, |
||||
'sha1'); |
||||
hmac |
||||
-------------------------------------------- |
||||
\xd730594d167e35d5956fd8003d0db3d3f46dc7bb |
||||
(1 row) |
||||
|
||||
-- 4 |
||||
SELECT encode(hmac( |
||||
decode('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', 'hex'), |
||||
decode('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'), |
||||
'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
4c9007f4026250c6bc8414f9bf50c86c2d7235da |
||||
SELECT hmac( |
||||
'\xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd'::bytea, |
||||
'\x0102030405060708090a0b0c0d0e0f10111213141516171819'::bytea, |
||||
'sha1'); |
||||
hmac |
||||
-------------------------------------------- |
||||
\x4c9007f4026250c6bc8414f9bf50c86c2d7235da |
||||
(1 row) |
||||
|
||||
-- 5 |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Test With Truncation', |
||||
decode('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'), |
||||
'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
37268b7e21e84da5720c53c4ba03ad1104039fa7 |
||||
'\x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c'::bytea, |
||||
'sha1'); |
||||
hmac |
||||
-------------------------------------------- |
||||
\x37268b7e21e84da5720c53c4ba03ad1104039fa7 |
||||
(1 row) |
||||
|
||||
-- 6 |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Test Using Larger Than Block-Size Key - Hash Key First', |
||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), |
||||
'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
aa4ae5e15272d00e95705637ce8a3b55ed402112 |
||||
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea, |
||||
'sha1'); |
||||
hmac |
||||
-------------------------------------------- |
||||
\xaa4ae5e15272d00e95705637ce8a3b55ed402112 |
||||
(1 row) |
||||
|
||||
-- 7 |
||||
SELECT encode(hmac( |
||||
SELECT hmac( |
||||
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data', |
||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), |
||||
'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
e8e99d0f45237d786d6bbaa7965c7808bbff1a91 |
||||
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea, |
||||
'sha1'); |
||||
hmac |
||||
-------------------------------------------- |
||||
\xe8e99d0f45237d786d6bbaa7965c7808bbff1a91 |
||||
(1 row) |
||||
|
||||
|
||||
@ -1,45 +1,45 @@ |
||||
-- |
||||
-- MD5 message digest |
||||
-- |
||||
SELECT encode(digest('', 'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
d41d8cd98f00b204e9800998ecf8427e |
||||
SELECT digest('', 'md5'); |
||||
digest |
||||
------------------------------------ |
||||
\xd41d8cd98f00b204e9800998ecf8427e |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('a', 'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
0cc175b9c0f1b6a831c399e269772661 |
||||
SELECT digest('a', 'md5'); |
||||
digest |
||||
------------------------------------ |
||||
\x0cc175b9c0f1b6a831c399e269772661 |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('abc', 'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
900150983cd24fb0d6963f7d28e17f72 |
||||
SELECT digest('abc', 'md5'); |
||||
digest |
||||
------------------------------------ |
||||
\x900150983cd24fb0d6963f7d28e17f72 |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('message digest', 'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
f96b697d7cb7938d525a2f31aaf161d0 |
||||
SELECT digest('message digest', 'md5'); |
||||
digest |
||||
------------------------------------ |
||||
\xf96b697d7cb7938d525a2f31aaf161d0 |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyz', 'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
c3fcd3d76192e4007dfb496cca67e13b |
||||
SELECT digest('abcdefghijklmnopqrstuvwxyz', 'md5'); |
||||
digest |
||||
------------------------------------ |
||||
\xc3fcd3d76192e4007dfb496cca67e13b |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
d174ab98d277d9f5a5611c2c9f419d9f |
||||
SELECT digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'md5'); |
||||
digest |
||||
------------------------------------ |
||||
\xd174ab98d277d9f5a5611c2c9f419d9f |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'md5'), 'hex'); |
||||
encode |
||||
---------------------------------- |
||||
57edf4a22be3c955ac49da2e2107b67a |
||||
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'md5'); |
||||
digest |
||||
------------------------------------ |
||||
\x57edf4a22be3c955ac49da2e2107b67a |
||||
(1 row) |
||||
|
||||
|
||||
@ -1,45 +1,45 @@ |
||||
-- |
||||
-- SHA1 message digest |
||||
-- |
||||
SELECT encode(digest('', 'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
da39a3ee5e6b4b0d3255bfef95601890afd80709 |
||||
SELECT digest('', 'sha1'); |
||||
digest |
||||
-------------------------------------------- |
||||
\xda39a3ee5e6b4b0d3255bfef95601890afd80709 |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('a', 'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 |
||||
SELECT digest('a', 'sha1'); |
||||
digest |
||||
-------------------------------------------- |
||||
\x86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('abc', 'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
a9993e364706816aba3e25717850c26c9cd0d89d |
||||
SELECT digest('abc', 'sha1'); |
||||
digest |
||||
-------------------------------------------- |
||||
\xa9993e364706816aba3e25717850c26c9cd0d89d |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('message digest', 'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
c12252ceda8be8994d5fa0290a47231c1d16aae3 |
||||
SELECT digest('message digest', 'sha1'); |
||||
digest |
||||
-------------------------------------------- |
||||
\xc12252ceda8be8994d5fa0290a47231c1d16aae3 |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyz', 'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
32d10c7b8cf96570ca04ce37f2a19d84240d3a89 |
||||
SELECT digest('abcdefghijklmnopqrstuvwxyz', 'sha1'); |
||||
digest |
||||
-------------------------------------------- |
||||
\x32d10c7b8cf96570ca04ce37f2a19d84240d3a89 |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
761c457bf73b14d27e9e9265c46f4b4dda11f940 |
||||
SELECT digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'sha1'); |
||||
digest |
||||
-------------------------------------------- |
||||
\x761c457bf73b14d27e9e9265c46f4b4dda11f940 |
||||
(1 row) |
||||
|
||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha1'), 'hex'); |
||||
encode |
||||
------------------------------------------ |
||||
50abf5706a150990a08b2c5ea40fa0e585554732 |
||||
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha1'); |
||||
digest |
||||
-------------------------------------------- |
||||
\x50abf5706a150990a08b2c5ea40fa0e585554732 |
||||
(1 row) |
||||
|
||||
|
||||
@ -1,31 +1,25 @@ |
||||
-- |
||||
-- 3DES cipher |
||||
-- |
||||
-- ensure consistent test output regardless of the default bytea format |
||||
SET bytea_output TO escape; |
||||
|
||||
-- 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 encrypt('\x8000000000000000', |
||||
'\x010101010101010101010101010101010101010101010101', |
||||
'3des-ecb/pad:none'); |
||||
|
||||
select encode( encrypt('', 'foo', '3des'), 'hex'); |
||||
select encrypt('', 'foo', '3des'); |
||||
-- 10 bytes key |
||||
select encode( encrypt('foo', '0123456789', '3des'), 'hex'); |
||||
select encrypt('foo', '0123456789', '3des'); |
||||
-- 22 bytes key |
||||
select encode( encrypt('foo', '0123456789012345678901', '3des'), 'hex'); |
||||
select encrypt('foo', '0123456789012345678901', '3des'); |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des'); |
||||
select encode(decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des'), 'escape'); |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', '3des'), 'hex'); |
||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', '3des'); |
||||
select encrypt_iv('foo', '0123456', 'abcd', '3des'); |
||||
select encode(decrypt_iv('\x50735067b073bb93', '0123456', 'abcd', '3des'), 'escape'); |
||||
|
||||
-- long message |
||||
select encode(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), 'hex'); |
||||
select decrypt(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), '0123456789012345678901', '3des'); |
||||
select encrypt('Lets try a longer message.', '0123456789012345678901', '3des'); |
||||
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), '0123456789012345678901', '3des'), 'escape'); |
||||
|
||||
@ -1,92 +1,53 @@ |
||||
-- |
||||
-- Blowfish cipher |
||||
-- |
||||
-- ensure consistent test output regardless of the default bytea format |
||||
SET bytea_output TO escape; |
||||
|
||||
-- some standard Blowfish testvalues |
||||
SELECT encode(encrypt( |
||||
decode('0000000000000000', 'hex'), |
||||
decode('0000000000000000', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('ffffffffffffffff', 'hex'), |
||||
decode('ffffffffffffffff', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('1000000000000001', 'hex'), |
||||
decode('3000000000000000', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('1111111111111111', 'hex'), |
||||
decode('1111111111111111', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('0123456789abcdef', 'hex'), |
||||
decode('fedcba9876543210', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('01a1d6d039776742', 'hex'), |
||||
decode('fedcba9876543210', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('ffffffffffffffff', 'hex'), |
||||
decode('0000000000000000', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\x0000000000000000', '\x0000000000000000', 'bf-ecb/pad:none'); |
||||
SELECT encrypt('\xffffffffffffffff', '\xffffffffffffffff', 'bf-ecb/pad:none'); |
||||
SELECT encrypt('\x1000000000000001', '\x3000000000000000', 'bf-ecb/pad:none'); |
||||
SELECT encrypt('\x1111111111111111', '\x1111111111111111', 'bf-ecb/pad:none'); |
||||
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'bf-ecb/pad:none'); |
||||
SELECT encrypt('\x01a1d6d039776742', '\xfedcba9876543210', 'bf-ecb/pad:none'); |
||||
SELECT encrypt('\xffffffffffffffff', '\x0000000000000000', 'bf-ecb/pad:none'); |
||||
|
||||
-- setkey |
||||
SELECT encode(encrypt( |
||||
decode('fedcba9876543210', 'hex'), |
||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\xfedcba9876543210', '\xf0e1d2c3b4a5968778695a4b3c2d1e0f', 'bf-ecb/pad:none'); |
||||
|
||||
-- with padding |
||||
SELECT encode(encrypt( |
||||
decode('01234567890123456789', 'hex'), |
||||
decode('33443344334433443344334433443344', 'hex'), |
||||
'bf-ecb'), 'hex'); |
||||
SELECT encrypt('\x01234567890123456789', '\x33443344334433443344334433443344', 'bf-ecb'); |
||||
|
||||
-- cbc |
||||
|
||||
-- 28 bytes key |
||||
SELECT encode(encrypt( |
||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', 'hex'), |
||||
decode('37363534333231204e6f77206973207468652074696d6520666f7220', 'hex'), |
||||
'bf-cbc'), 'hex'); |
||||
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', |
||||
'\x37363534333231204e6f77206973207468652074696d6520666f7220', |
||||
'bf-cbc'); |
||||
|
||||
-- 29 bytes key |
||||
SELECT encode(encrypt( |
||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', 'hex'), |
||||
decode('37363534333231204e6f77206973207468652074696d6520666f722000', 'hex'), |
||||
'bf-cbc'), 'hex'); |
||||
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', |
||||
'\x37363534333231204e6f77206973207468652074696d6520666f722000', |
||||
'bf-cbc'); |
||||
|
||||
-- blowfish-448 |
||||
SELECT encode(encrypt( |
||||
decode('fedcba9876543210', 'hex'), |
||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', 'hex'), |
||||
'bf-ecb/pad:none'), 'hex'); |
||||
-- result: c04504012e4e1f53 |
||||
SELECT encrypt('\xfedcba9876543210', |
||||
'\xf0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', |
||||
'bf-ecb/pad:none'); |
||||
|
||||
-- empty data |
||||
select encode(encrypt('', 'foo', 'bf'), 'hex'); |
||||
select encrypt('', 'foo', 'bf'); |
||||
-- 10 bytes key |
||||
select encode(encrypt('foo', '0123456789', 'bf'), 'hex'); |
||||
select encrypt('foo', '0123456789', 'bf'); |
||||
-- 22 bytes key |
||||
select encode(encrypt('foo', '0123456789012345678901', 'bf'), 'hex'); |
||||
select encrypt('foo', '0123456789012345678901', 'bf'); |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf'); |
||||
select encode(decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf'), 'escape'); |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'bf'), 'hex'); |
||||
select decrypt_iv(decode('95c7e89322525d59', 'hex'), '0123456', 'abcd', 'bf'); |
||||
select encrypt_iv('foo', '0123456', 'abcd', 'bf'); |
||||
select encode(decrypt_iv('\x95c7e89322525d59', '0123456', 'abcd', 'bf'), 'escape'); |
||||
|
||||
-- long message |
||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'bf'), 'hex'); |
||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf'); |
||||
select encrypt('Lets try a longer message.', '0123456789', 'bf'); |
||||
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf'), 'escape'); |
||||
|
||||
@ -1,47 +1,32 @@ |
||||
-- |
||||
-- Cast5 cipher |
||||
-- |
||||
-- ensure consistent test output regardless of the default bytea format |
||||
SET bytea_output TO escape; |
||||
|
||||
-- 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 |
||||
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712345678234567893456789A', 'cast5-ecb/pad:none'); |
||||
|
||||
-- 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 |
||||
SELECT encrypt('\x0123456789ABCDEF', '\x01234567123456782345', 'cast5-ecb/pad:none'); |
||||
|
||||
-- 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 |
||||
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712', 'cast5-ecb/pad:none'); |
||||
|
||||
-- cbc |
||||
|
||||
-- empty data |
||||
select encode( encrypt('', 'foo', 'cast5'), 'hex'); |
||||
select encrypt('', 'foo', 'cast5'); |
||||
-- 10 bytes key |
||||
select encode( encrypt('foo', '0123456789', 'cast5'), 'hex'); |
||||
select encrypt('foo', '0123456789', 'cast5'); |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5'); |
||||
select encode(decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5'), 'escape'); |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'cast5'), 'hex'); |
||||
select decrypt_iv(decode('384a970695ce016a', 'hex'), |
||||
'0123456', 'abcd', 'cast5'); |
||||
select encrypt_iv('foo', '0123456', 'abcd', 'cast5'); |
||||
select encode(decrypt_iv('\x384a970695ce016a', '0123456', 'abcd', 'cast5'), 'escape'); |
||||
|
||||
-- long message |
||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'cast5'), 'hex'); |
||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5'); |
||||
select encrypt('Lets try a longer message.', '0123456789', 'cast5'); |
||||
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5'), 'escape'); |
||||
|
||||
@ -1,29 +1,24 @@ |
||||
-- |
||||
-- DES cipher |
||||
-- |
||||
-- ensure consistent test output regardless of the default bytea format |
||||
SET bytea_output TO escape; |
||||
|
||||
-- no official test vectors atm |
||||
|
||||
-- from blowfish.sql |
||||
SELECT encode(encrypt( |
||||
decode('0123456789abcdef', 'hex'), |
||||
decode('fedcba9876543210', 'hex'), |
||||
'des-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'des-ecb/pad:none'); |
||||
|
||||
-- empty data |
||||
select encode( encrypt('', 'foo', 'des'), 'hex'); |
||||
select encrypt('', 'foo', 'des'); |
||||
-- 8 bytes key |
||||
select encode( encrypt('foo', '01234589', 'des'), 'hex'); |
||||
select encrypt('foo', '01234589', 'des'); |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des'); |
||||
select encode(decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des'), 'escape'); |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'des'), 'hex'); |
||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', 'des'); |
||||
select encrypt_iv('foo', '0123456', 'abcd', 'des'); |
||||
select encode(decrypt_iv('\x50735067b073bb93', '0123456', 'abcd', 'des'), 'escape'); |
||||
|
||||
-- long message |
||||
select encode(encrypt('Lets try a longer message.', '01234567', 'des'), 'hex'); |
||||
select decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des'); |
||||
select encrypt('Lets try a longer message.', '01234567', 'des'); |
||||
select encode(decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des'), 'escape'); |
||||
|
||||
@ -1,63 +1,60 @@ |
||||
-- |
||||
-- AES cipher (aka Rijndael-128, -192, or -256) |
||||
-- |
||||
-- ensure consistent test output regardless of the default bytea format |
||||
SET bytea_output TO escape; |
||||
|
||||
-- some standard Rijndael testvalues |
||||
SELECT encode(encrypt( |
||||
decode('00112233445566778899aabbccddeeff', 'hex'), |
||||
decode('000102030405060708090a0b0c0d0e0f', 'hex'), |
||||
'aes-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt( |
||||
'\x00112233445566778899aabbccddeeff', |
||||
'\x000102030405060708090a0b0c0d0e0f', |
||||
'aes-ecb/pad:none'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('00112233445566778899aabbccddeeff', 'hex'), |
||||
decode('000102030405060708090a0b0c0d0e0f1011121314151617', 'hex'), |
||||
'aes-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt( |
||||
'\x00112233445566778899aabbccddeeff', |
||||
'\x000102030405060708090a0b0c0d0e0f1011121314151617', |
||||
'aes-ecb/pad:none'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('00112233445566778899aabbccddeeff', 'hex'), |
||||
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', 'hex'), |
||||
'aes-ecb/pad:none'), 'hex'); |
||||
SELECT encrypt( |
||||
'\x00112233445566778899aabbccddeeff', |
||||
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', |
||||
'aes-ecb/pad:none'); |
||||
|
||||
-- cbc |
||||
SELECT encode(encrypt( |
||||
decode('00112233445566778899aabbccddeeff', 'hex'), |
||||
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', 'hex'), |
||||
'aes-cbc/pad:none'), 'hex'); |
||||
SELECT encrypt( |
||||
'\x00112233445566778899aabbccddeeff', |
||||
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', |
||||
'aes-cbc/pad:none'); |
||||
|
||||
-- key padding |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('0011223344', 'hex'), |
||||
decode('000102030405', 'hex'), |
||||
'aes-cbc'), 'hex'); |
||||
SELECT encrypt( |
||||
'\x0011223344', |
||||
'\x000102030405', |
||||
'aes-cbc'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('0011223344', 'hex'), |
||||
decode('000102030405060708090a0b0c0d0e0f10111213', 'hex'), |
||||
'aes-cbc'), 'hex'); |
||||
SELECT encrypt( |
||||
'\x0011223344', |
||||
'\x000102030405060708090a0b0c0d0e0f10111213', |
||||
'aes-cbc'); |
||||
|
||||
SELECT encode(encrypt( |
||||
decode('0011223344', 'hex'), |
||||
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b', 'hex'), |
||||
'aes-cbc'), 'hex'); |
||||
SELECT encrypt( |
||||
'\x0011223344', |
||||
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b', |
||||
'aes-cbc'); |
||||
|
||||
-- empty data |
||||
select encode(encrypt('', 'foo', 'aes'), 'hex'); |
||||
select encrypt('', 'foo', 'aes'); |
||||
-- 10 bytes key |
||||
select encode(encrypt('foo', '0123456789', 'aes'), 'hex'); |
||||
select encrypt('foo', '0123456789', 'aes'); |
||||
-- 22 bytes key |
||||
select encode(encrypt('foo', '0123456789012345678901', 'aes'), 'hex'); |
||||
select encrypt('foo', '0123456789012345678901', 'aes'); |
||||
|
||||
-- decrypt |
||||
select decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes'); |
||||
select encode(decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes'), 'escape'); |
||||
|
||||
-- iv |
||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'aes'), 'hex'); |
||||
select decrypt_iv(decode('2c24cb7da91d6d5699801268b0f5adad', 'hex'), |
||||
'0123456', 'abcd', 'aes'); |
||||
select encrypt_iv('foo', '0123456', 'abcd', 'aes'); |
||||
select encode(decrypt_iv('\x2c24cb7da91d6d5699801268b0f5adad', '0123456', 'abcd', 'aes'), 'escape'); |
||||
|
||||
-- long message |
||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'aes'), 'hex'); |
||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes'), '0123456789', 'aes'); |
||||
select encrypt('Lets try a longer message.', '0123456789', 'aes'); |
||||
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes'), '0123456789', 'aes'), 'escape'); |
||||
|
||||
Loading…
Reference in new issue