|
1 | 1 | -- |
2 | 2 | -- Blowfish cipher |
3 | 3 | -- |
4 | | --- ensure consistent test output regardless of the default bytea format |
5 | | -SET bytea_output TO escape; |
6 | 4 | -- some standard Blowfish testvalues |
7 | | -SELECT encode(encrypt( |
8 | | -decode('0000000000000000', 'hex'), |
9 | | -decode('0000000000000000', 'hex'), |
10 | | -'bf-ecb/pad:none'), 'hex'); |
11 | | - encode |
12 | | ------------------- |
13 | | - 4ef997456198dd78 |
14 | | -(1 row) |
15 | | - |
16 | | -SELECT encode(encrypt( |
17 | | -decode('ffffffffffffffff', 'hex'), |
18 | | -decode('ffffffffffffffff', 'hex'), |
19 | | -'bf-ecb/pad:none'), 'hex'); |
20 | | - encode |
21 | | ------------------- |
22 | | - 51866fd5b85ecb8a |
23 | | -(1 row) |
24 | | - |
25 | | -SELECT encode(encrypt( |
26 | | -decode('1000000000000001', 'hex'), |
27 | | -decode('3000000000000000', 'hex'), |
28 | | -'bf-ecb/pad:none'), 'hex'); |
29 | | - encode |
30 | | ------------------- |
31 | | - 7d856f9a613063f2 |
32 | | -(1 row) |
33 | | - |
34 | | -SELECT encode(encrypt( |
35 | | -decode('1111111111111111', 'hex'), |
36 | | -decode('1111111111111111', 'hex'), |
37 | | -'bf-ecb/pad:none'), 'hex'); |
38 | | - encode |
39 | | ------------------- |
40 | | - 2466dd878b963c9d |
41 | | -(1 row) |
42 | | - |
43 | | -SELECT encode(encrypt( |
44 | | -decode('0123456789abcdef', 'hex'), |
45 | | -decode('fedcba9876543210', 'hex'), |
46 | | -'bf-ecb/pad:none'), 'hex'); |
47 | | - encode |
48 | | ------------------- |
49 | | - 0aceab0fc6a0a28d |
50 | | -(1 row) |
51 | | - |
52 | | -SELECT encode(encrypt( |
53 | | -decode('01a1d6d039776742', 'hex'), |
54 | | -decode('fedcba9876543210', 'hex'), |
55 | | -'bf-ecb/pad:none'), 'hex'); |
56 | | - encode |
57 | | ------------------- |
58 | | - 3273b8badc9e9e15 |
59 | | -(1 row) |
60 | | - |
61 | | -SELECT encode(encrypt( |
62 | | -decode('ffffffffffffffff', 'hex'), |
63 | | -decode('0000000000000000', 'hex'), |
64 | | -'bf-ecb/pad:none'), 'hex'); |
65 | | - encode |
66 | | ------------------- |
67 | | - 014933e0cdaff6e4 |
| 5 | +SELECT encrypt('\x0000000000000000', '\x0000000000000000', 'bf-ecb/pad:none'); |
| 6 | + encrypt |
| 7 | +-------------------- |
| 8 | + \x4ef997456198dd78 |
| 9 | +(1 row) |
| 10 | + |
| 11 | +SELECT encrypt('\xffffffffffffffff', '\xffffffffffffffff', 'bf-ecb/pad:none'); |
| 12 | + encrypt |
| 13 | +-------------------- |
| 14 | + \x51866fd5b85ecb8a |
| 15 | +(1 row) |
| 16 | + |
| 17 | +SELECT encrypt('\x1000000000000001', '\x3000000000000000', 'bf-ecb/pad:none'); |
| 18 | + encrypt |
| 19 | +-------------------- |
| 20 | + \x7d856f9a613063f2 |
| 21 | +(1 row) |
| 22 | + |
| 23 | +SELECT encrypt('\x1111111111111111', '\x1111111111111111', 'bf-ecb/pad:none'); |
| 24 | + encrypt |
| 25 | +-------------------- |
| 26 | + \x2466dd878b963c9d |
| 27 | +(1 row) |
| 28 | + |
| 29 | +SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'bf-ecb/pad:none'); |
| 30 | + encrypt |
| 31 | +-------------------- |
| 32 | + \x0aceab0fc6a0a28d |
| 33 | +(1 row) |
| 34 | + |
| 35 | +SELECT encrypt('\x01a1d6d039776742', '\xfedcba9876543210', 'bf-ecb/pad:none'); |
| 36 | + encrypt |
| 37 | +-------------------- |
| 38 | + \x3273b8badc9e9e15 |
| 39 | +(1 row) |
| 40 | + |
| 41 | +SELECT encrypt('\xffffffffffffffff', '\x0000000000000000', 'bf-ecb/pad:none'); |
| 42 | + encrypt |
| 43 | +-------------------- |
| 44 | + \x014933e0cdaff6e4 |
68 | 45 | (1 row) |
69 | 46 |
|
70 | 47 | -- setkey |
71 | | -SELECT encode(encrypt( |
72 | | -decode('fedcba9876543210', 'hex'), |
73 | | -decode('f0e1d2c3b4a5968778695a4b3c2d1e0f', 'hex'), |
74 | | -'bf-ecb/pad:none'), 'hex'); |
75 | | - encode |
76 | | ------------------- |
77 | | - 93142887ee3be15c |
| 48 | +SELECT encrypt('\xfedcba9876543210', '\xf0e1d2c3b4a5968778695a4b3c2d1e0f', 'bf-ecb/pad:none'); |
| 49 | + encrypt |
| 50 | +-------------------- |
| 51 | + \x93142887ee3be15c |
78 | 52 | (1 row) |
79 | 53 |
|
80 | 54 | -- with padding |
81 | | -SELECT encode(encrypt( |
82 | | -decode('01234567890123456789', 'hex'), |
83 | | -decode('33443344334433443344334433443344', 'hex'), |
84 | | -'bf-ecb'), 'hex'); |
85 | | - encode |
86 | | ----------------------------------- |
87 | | - 0d04a43a20456dee5ede6ed9e4dcaaa6 |
| 55 | +SELECT encrypt('\x01234567890123456789', '\x33443344334433443344334433443344', 'bf-ecb'); |
| 56 | + encrypt |
| 57 | +------------------------------------ |
| 58 | + \x0d04a43a20456dee5ede6ed9e4dcaaa6 |
88 | 59 | (1 row) |
89 | 60 |
|
90 | 61 | -- cbc |
91 | 62 | -- 28 bytes key |
92 | | -SELECT encode(encrypt( |
93 | | -decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', 'hex'), |
94 | | -decode('37363534333231204e6f77206973207468652074696d6520666f7220', 'hex'), |
95 | | -'bf-cbc'), 'hex'); |
96 | | - encode |
97 | | ------------------------------------------------------------------- |
98 | | - 4f2beb748c4f689ec755edb9dc252a41b93a3786850b4c75d6a702b6a8e48825 |
| 63 | +SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', |
| 64 | + '\x37363534333231204e6f77206973207468652074696d6520666f7220', |
| 65 | + 'bf-cbc'); |
| 66 | + encrypt |
| 67 | +-------------------------------------------------------------------- |
| 68 | + \x4f2beb748c4f689ec755edb9dc252a41b93a3786850b4c75d6a702b6a8e48825 |
99 | 69 | (1 row) |
100 | 70 |
|
101 | 71 | -- 29 bytes key |
102 | | -SELECT encode(encrypt( |
103 | | -decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', 'hex'), |
104 | | -decode('37363534333231204e6f77206973207468652074696d6520666f722000', 'hex'), |
105 | | -'bf-cbc'), 'hex'); |
106 | | - encode |
107 | | ----------------------------------------------------------------------------------- |
108 | | - 3ea6357a0ee7fad6d0c4b63464f2aafa40c2e91b4b7e1bba8114932fd92b5c8f111e7e50e7b2e541 |
| 72 | +SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', |
| 73 | + '\x37363534333231204e6f77206973207468652074696d6520666f722000', |
| 74 | + 'bf-cbc'); |
| 75 | + encrypt |
| 76 | +------------------------------------------------------------------------------------ |
| 77 | + \x3ea6357a0ee7fad6d0c4b63464f2aafa40c2e91b4b7e1bba8114932fd92b5c8f111e7e50e7b2e541 |
109 | 78 | (1 row) |
110 | 79 |
|
111 | 80 | -- blowfish-448 |
112 | | -SELECT encode(encrypt( |
113 | | -decode('fedcba9876543210', 'hex'), |
114 | | -decode('f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', 'hex'), |
115 | | -'bf-ecb/pad:none'), 'hex'); |
116 | | - encode |
117 | | ------------------- |
118 | | - c04504012e4e1f53 |
| 81 | +SELECT encrypt('\xfedcba9876543210', |
| 82 | + '\xf0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', |
| 83 | + 'bf-ecb/pad:none'); |
| 84 | + encrypt |
| 85 | +-------------------- |
| 86 | + \xc04504012e4e1f53 |
119 | 87 | (1 row) |
120 | 88 |
|
121 | | --- result: c04504012e4e1f53 |
122 | 89 | -- empty data |
123 | | -select encode(encrypt('', 'foo', 'bf'), 'hex'); |
124 | | - encode |
125 | | ------------------- |
126 | | - 1871949bb2311c8e |
| 90 | +select encrypt('', 'foo', 'bf'); |
| 91 | + encrypt |
| 92 | +-------------------- |
| 93 | + \x1871949bb2311c8e |
127 | 94 | (1 row) |
128 | 95 |
|
129 | 96 | -- 10 bytes key |
130 | | -select encode(encrypt('foo', '0123456789', 'bf'), 'hex'); |
131 | | - encode |
132 | | ------------------- |
133 | | - 42f58af3b2c03f46 |
| 97 | +select encrypt('foo', '0123456789', 'bf'); |
| 98 | + encrypt |
| 99 | +-------------------- |
| 100 | + \x42f58af3b2c03f46 |
134 | 101 | (1 row) |
135 | 102 |
|
136 | 103 | -- 22 bytes key |
137 | | -select encode(encrypt('foo', '0123456789012345678901', 'bf'), 'hex'); |
138 | | - encode |
139 | | ------------------- |
140 | | - 86ab6f0bc72b5f22 |
| 104 | +select encrypt('foo', '0123456789012345678901', 'bf'); |
| 105 | + encrypt |
| 106 | +-------------------- |
| 107 | + \x86ab6f0bc72b5f22 |
141 | 108 | (1 row) |
142 | 109 |
|
143 | 110 | -- decrypt |
144 | | -select decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf'); |
145 | | - decrypt |
146 | | ---------- |
| 111 | +select encode(decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf'), 'escape'); |
| 112 | + encode |
| 113 | +-------- |
147 | 114 | foo |
148 | 115 | (1 row) |
149 | 116 |
|
150 | 117 | -- iv |
151 | | -select encode(encrypt_iv('foo', '0123456', 'abcd', 'bf'), 'hex'); |
152 | | - encode |
153 | | ------------------- |
154 | | - 95c7e89322525d59 |
| 118 | +select encrypt_iv('foo', '0123456', 'abcd', 'bf'); |
| 119 | + encrypt_iv |
| 120 | +-------------------- |
| 121 | + \x95c7e89322525d59 |
155 | 122 | (1 row) |
156 | 123 |
|
157 | | -select decrypt_iv(decode('95c7e89322525d59', 'hex'), '0123456', 'abcd', 'bf'); |
158 | | - decrypt_iv |
159 | | ------------- |
| 124 | +select encode(decrypt_iv('\x95c7e89322525d59', '0123456', 'abcd', 'bf'), 'escape'); |
| 125 | + encode |
| 126 | +-------- |
160 | 127 | foo |
161 | 128 | (1 row) |
162 | 129 |
|
163 | 130 | -- long message |
164 | | -select encode(encrypt('Lets try a longer message.', '0123456789', 'bf'), 'hex'); |
165 | | - encode |
166 | | ------------------------------------------------------------------- |
167 | | - a76059f7a1b627b5b84080d9beb337714c7a7f8b70300023e5feb6dfa6813536 |
| 131 | +select encrypt('Lets try a longer message.', '0123456789', 'bf'); |
| 132 | + encrypt |
| 133 | +-------------------------------------------------------------------- |
| 134 | + \xa76059f7a1b627b5b84080d9beb337714c7a7f8b70300023e5feb6dfa6813536 |
168 | 135 | (1 row) |
169 | 136 |
|
170 | | -select decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf'); |
171 | | - decrypt |
| 137 | +select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf'), 'escape'); |
| 138 | + encode |
172 | 139 | ---------------------------- |
173 | 140 | Lets try a longer message. |
174 | 141 | (1 row) |
|
0 commit comments