| 1 |
-- |
| 2 |
-- AES cipher (aka Rijndael-128, -192, or -256) |
| 3 |
-- |
| 4 |
|
| 5 |
-- some standard Rijndael testvalues |
| 6 |
SELECT encrypt( |
| 7 |
'\x00112233445566778899aabbccddeeff', |
| 8 |
'\x000102030405060708090a0b0c0d0e0f', |
| 9 |
'aes-ecb/pad:none'); |
| 10 |
|
| 11 |
SELECT encrypt( |
| 12 |
'\x00112233445566778899aabbccddeeff', |
| 13 |
'\x000102030405060708090a0b0c0d0e0f1011121314151617', |
| 14 |
'aes-ecb/pad:none'); |
| 15 |
|
| 16 |
SELECT encrypt( |
| 17 |
'\x00112233445566778899aabbccddeeff', |
| 18 |
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', |
| 19 |
'aes-ecb/pad:none'); |
| 20 |
|
| 21 |
-- cbc |
| 22 |
SELECT encrypt( |
| 23 |
'\x00112233445566778899aabbccddeeff', |
| 24 |
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', |
| 25 |
'aes-cbc/pad:none'); |
| 26 |
|
| 27 |
-- without padding, input not multiple of block size |
| 28 |
SELECT encrypt( |
| 29 |
'\x00112233445566778899aabbccddeeff00', |
| 30 |
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', |
| 31 |
'aes-cbc/pad:none'); |
| 32 |
|
| 33 |
-- key padding |
| 34 |
|
| 35 |
SELECT encrypt( |
| 36 |
'\x0011223344', |
| 37 |
'\x000102030405', |
| 38 |
'aes-cbc'); |
| 39 |
|
| 40 |
SELECT encrypt( |
| 41 |
'\x0011223344', |
| 42 |
'\x000102030405060708090a0b0c0d0e0f10111213', |
| 43 |
'aes-cbc'); |
| 44 |
|
| 45 |
SELECT encrypt( |
| 46 |
'\x0011223344', |
| 47 |
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b', |
| 48 |
'aes-cbc'); |
| 49 |
|
| 50 |
-- empty data |
| 51 |
select encrypt('', 'foo', 'aes'); |
| 52 |
-- 10 bytes key |
| 53 |
select encrypt('foo', '0123456789', 'aes'); |
| 54 |
-- 22 bytes key |
| 55 |
select encrypt('foo', '0123456789012345678901', 'aes'); |
| 56 |
|
| 57 |
-- decrypt |
| 58 |
select encode(decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes'), 'escape'); |
| 59 |
-- data not multiple of block size |
| 60 |
select encode(decrypt(encrypt('foo', '0123456', 'aes') || '\x00'::bytea, '0123456', 'aes'), 'escape'); |
| 61 |
-- bad padding |
| 62 |
-- (The input value is the result of encrypt_iv('abcdefghijklmnopqrstuvwxyz', '0123456', 'abcd', 'aes') |
| 63 |
-- with the 16th byte changed (s/db/eb/) to corrupt the padding of the last block.) |
| 64 |
select encode(decrypt_iv('\xa21a9c15231465964e3396d32095e67eb52bab05f556a581621dee1b85385789', '0123456', 'abcd', 'aes'), 'escape'); |
| 65 |
|
| 66 |
-- iv |
| 67 |
select encrypt_iv('foo', '0123456', 'abcd', 'aes'); |
| 68 |
select encode(decrypt_iv('\x2c24cb7da91d6d5699801268b0f5adad', '0123456', 'abcd', 'aes'), 'escape'); |
| 69 |
|
| 70 |
-- long message |
| 71 |
select encrypt('Lets try a longer message.', '0123456789', 'aes'); |
| 72 |
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes'), '0123456789', 'aes'), 'escape'); |
| 73 |
|
| 74 |
-- cfb |
| 75 |
SELECT encrypt( |
| 76 |
'\x00112233445566778899aabbccddeeff', |
| 77 |
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', |
| 78 |
'aes-cfb/pad:none'); |
| 79 |
|
| 80 |
-- without padding, input not multiple of block size |
| 81 |
SELECT encrypt( |
| 82 |
'\x00112233445566778899aabbccddeeff00', |
| 83 |
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', |
| 84 |
'aes-cfb/pad:none'); |
| 85 |
|
| 86 |
-- key padding |
| 87 |
|
| 88 |
SELECT encrypt( |
| 89 |
'\x0011223344', |
| 90 |
'\x000102030405', |
| 91 |
'aes-cfb'); |
| 92 |
|
| 93 |
SELECT encrypt( |
| 94 |
'\x0011223344', |
| 95 |
'\x000102030405060708090a0b0c0d0e0f10111213', |
| 96 |
'aes-cfb'); |
| 97 |
|
| 98 |
SELECT encrypt( |
| 99 |
'\x0011223344', |
| 100 |
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b', |
| 101 |
'aes-cfb'); |
| 102 |
|
| 103 |
-- empty data |
| 104 |
select encrypt('', 'foo', 'aes-cfb'); |
| 105 |
-- 10 bytes key |
| 106 |
select encrypt('foo', '0123456789', 'aes-cfb'); |
| 107 |
-- 22 bytes key |
| 108 |
select encrypt('foo', '0123456789012345678901', 'aes-cfb'); |
| 109 |
|
| 110 |
-- decrypt |
| 111 |
select encode(decrypt(encrypt('foo', '0123456', 'aes-cfb'), '0123456', 'aes-cfb'), 'escape'); |
| 112 |
-- data not multiple of block size |
| 113 |
select encode(decrypt(encrypt('foo', '0123456', 'aes-cfb') || '\x00'::bytea, '0123456', 'aes-cfb'), 'escape'); |
| 114 |
-- bad padding |
| 115 |
-- (The input value is the result of encrypt_iv('abcdefghijklmnopqrstuvwxyz', '0123456', 'abcd', 'aes-cfb') |
| 116 |
-- with the 16th byte changed (s/c5/d5/) to corrupt the padding of the last block.) |
| 117 |
select encode(decrypt_iv('\xf9ad6817cb58d31dd9ba6571fbc4f55d56f65b631f0f437cb828', '0123456', 'abcd', 'aes-cfb'), 'escape'); |
| 118 |
|
| 119 |
-- iv |
| 120 |
select encrypt_iv('foo', '0123456', 'abcd', 'aes-cfb'); |
| 121 |
select encode(decrypt_iv('\xfea064', '0123456', 'abcd', 'aes-cfb'), 'escape'); |
| 122 |
|
| 123 |
-- long message |
| 124 |
select encrypt('Lets try a longer message.', '0123456789', 'aes-cfb'); |
| 125 |
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes-cfb'), '0123456789', 'aes-cfb'), 'escape'); |