]> git.stg.codes - stg.git/blob - tests/test_crypto.cpp
Add missing include to conffiles.h.
[stg.git] / tests / test_crypto.cpp
1 #define BOOST_TEST_MODULE STGCrypto
2
3 #include "stg/blowfish.h"
4
5 #pragma GCC diagnostic push
6 #pragma GCC diagnostic ignored "-Wold-style-cast"
7 #pragma GCC diagnostic ignored "-Wunused-parameter"
8 #pragma GCC diagnostic ignored "-Wsign-compare"
9 #pragma GCC diagnostic ignored "-Wparentheses"
10 #include <boost/test/unit_test.hpp>
11 #pragma GCC diagnostic pop
12
13 #include <string>
14 #include <vector>
15 #include <array>
16
17 namespace
18 {
19
20 bool equalCtx(const BLOWFISH_CTX& a, const BLOWFISH_CTX& b)
21 {
22     for (size_t i = 0; i < 18; ++i)
23         if (a.P[i] != b.P[i])
24         {
25             printf("Failed for P at %ld: 0x%x != 0x%x\n", i, a.P[i], b.P[i]);
26             return false;
27         }
28     for (size_t i = 0; i < 4; ++i)
29         for (size_t j = 0; j < 256; ++j)
30             if (a.S[i][j] != b.S[i][j])
31             {
32                 printf("Failed for S at %ld, %ld: 0x%x != 0x%x\n", i, j, a.S[i][j], b.S[i][j]);
33                 return false;
34             }
35     return true;
36 }
37
38 bool equalString(const char* a, const char* b, size_t length)
39 {
40     for (size_t i = 0; i < length; ++i)
41         if (a[i] != b[i])
42         {
43             //printf("Failed at pos %d: %hhu != %hhu\n", i, a[i], b[i]);
44             return false;
45         }
46     return true;
47 }
48
49 const BLOWFISH_CTX testCtx =
50 {
51     {
52         0x84ddf841, 0xbbdc17f,
53         0x3dd821af, 0x66fdf0c,
54         0x426a2fff, 0x30223f2c,
55         0x8325f1a3, 0xf5c99ab9,
56         0x417ce6da, 0xba4c9637,
57         0xd226c646, 0xe50ea3b5,
58         0x3860f82c, 0x1565ecc8,
59         0xf4461621, 0x68058dd4,
60         0x217da3bb, 0xd6cd3ddc,
61     },
62     {
63         {
64             0x72f9dc5c, 0xf701a2e4, 0xf30e3ec3, 0x2f1c9683,
65             0x985b9801, 0xfb28c4f5, 0xf6f5c777, 0xfa7b5b24,
66             0xd761c693, 0xf53e1484, 0x8622da13, 0xb240d1b4,
67             0xd1bc58f8, 0x43f462ef, 0x6a4e97a3, 0xb0619beb,
68             0xff07b462, 0xd390c3b9, 0xe91f2840, 0x869566ae,
69             0xfebd249c, 0x567002c1, 0x342e0e8e, 0x31b01687,
70             0xd7e3a5bd, 0xa933de2e, 0xb4ef05f2, 0x33e4919f,
71             0x724e8b3e, 0xc6b9d44f, 0x849b1674, 0x90758946,
72             0x295986fa, 0xa2e11855, 0xf2099a4e, 0x42ed46f9,
73             0x597cbb6d, 0xc3691952, 0x408f873e, 0xdee0d6cf,
74             0x6570a45d, 0xc6a24b81, 0x2d3a1c24, 0x4a2edda4,
75             0x443dcfa5, 0x5971a9a5, 0xfd2258c0, 0x72c36b37,
76             0xf8696ce, 0xf2e84f7, 0xc543bf6d, 0x352818c5,
77             0xdc01f156, 0xc67bfce5, 0xdadf0cbf, 0x6194b6a9,
78             0xdb3cc22f, 0xc7873bcb, 0x9b9e622c, 0xa7869810,
79             0xcb1ba91, 0x137b1bf5, 0x3e71252b, 0x5229f33e,
80             0x30ded88f, 0x5763ef1f, 0xee7f01b8, 0xdac73dee,
81             0x2f4d1efb, 0x5f518b97, 0xe7c7d61e, 0x9d5ca3f3,
82             0xa196c020, 0x74634a7b, 0xdd1d0042, 0x454268aa,
83             0x5c610ac8, 0x277e8d2c, 0x4a8b4ee8, 0xf959f5a8,
84             0xc0c63a7e, 0xea9f2ed7, 0xaab4a699, 0x6f872358,
85             0x3927189a, 0x23ae56ac, 0xcfa5b09c, 0x9751e84,
86             0x7ec68c4b, 0x99f9502b, 0x886e764, 0x957c89a4,
87             0x48c5ddb0, 0x9f4d5b7e, 0xa84d5c52, 0xf2ae7bde,
88             0x75e6ddaf, 0xc2b45798, 0x5f846059, 0x5bf85e2a,
89             0x5f6c4382, 0xb621465a, 0x5bf2977c, 0x2c1eb17a,
90             0xbf3e5b18, 0x5f0bdcb7, 0xd6195c47, 0x2c61ec83,
91             0x2315c2da, 0x95195c86, 0x4c4f9855, 0xc5e3787d,
92             0xe5014918, 0x714dd230, 0xd2abd926, 0x9229a99e,
93             0x8306695a, 0x66f7bb54, 0x544affdc, 0x84aa830c,
94             0xad8c8db6, 0x48b29b2, 0xcf33d204, 0xc78ac51d,
95             0xacb18e60, 0x49b516ac, 0x614e2887, 0xe39e1a7c,
96             0xdb1f9652, 0x8c8378a3, 0x8cbe2070, 0x773fe7f,
97             0x899e1922, 0x12dd7b8b, 0xccf8198d, 0xcc48faff,
98             0x30ca9cab, 0x9ebd7129, 0xf254b601, 0x8ac97b38,
99             0x504804d1, 0x3568fbbe, 0x9a40bc99, 0x9c23761b,
100             0x28e26904, 0xe396e583, 0x2f2c4053, 0xa45caf19,
101             0xb7996794, 0x4c825669, 0x3f07f001, 0xf24a084b,
102             0x884888fd, 0xa7fc71f4, 0x21abeff4, 0x719ecba6,
103             0x90104162, 0x50c2b5f1, 0x86135070, 0xc9523fc,
104             0x9c219eca, 0xc12ef7f0, 0x6b3f6b8c, 0x288ee9ef,
105             0xe722f758, 0x229c0bac, 0x3d934d09, 0x4a5cf131,
106             0x14189fc9, 0x10c8aa2e, 0x74e9fe96, 0xcfc110d4,
107             0x35202bfb, 0x90bc66f1, 0x5d4c6616, 0x498927ea,
108             0x581934cc, 0x43e712a, 0x5f095b3c, 0xea0e1406,
109             0xa4921c29, 0xe8a306f0, 0xfec369ef, 0x992921c1,
110             0xcdc5abb6, 0x3ebd83fa, 0x8a7f16e9, 0xfaf73bb3,
111             0x3e8181, 0x34fc47c9, 0xdb92d725, 0x8b40795,
112             0x14273fa0, 0xd704e4f8, 0xd3435939, 0x3450c0a8,
113             0xce721627, 0x10d4a466, 0x7bc1a724, 0x5efc63b,
114             0x153ae5ef, 0xa0aa6945, 0xe5a3b8c9, 0xf0bec5ba,
115             0xde02619e, 0xd155e989, 0xf5e3a551, 0x951d9d74,
116             0x41544875, 0x6aa455e8, 0xda28a584, 0x72d17a11,
117             0x417c066c, 0xe6f82546, 0xbd258cd0, 0x8a3979b4,
118             0xe896e0d9, 0x76871921, 0x709842f1, 0x5dd3756b,
119             0x2ebe8dfb, 0x81ab8b0d, 0x4c9d635, 0x3fd75cf2,
120             0x37876ef8, 0x1c5a806f, 0x96de1b30, 0x2a8e971a,
121             0x89ac843a, 0x96c23371, 0x95ee2343, 0xffb1614f,
122             0x1116003c, 0x25b45917, 0xad0783c2, 0x4662ce95,
123             0xfc751ade, 0xa13e75ae, 0xc75010c3, 0x9170a859,
124             0x86ca62d6, 0x3acb094f, 0x87349773, 0x2765ba9b,
125             0xaaebd756, 0x7b3d6693, 0x92193a80, 0x765f4eb8,
126             0x42f88c21, 0x27ff9f9b, 0x9db88664, 0xe302e6d9,
127             0x2e8fb36e, 0xfc58b9bc, 0x3a649297, 0x76876ce1
128         },
129         {
130             0x8e3ea6e4, 0x1dd37803, 0xffd051c0, 0xec395f57,
131             0x2eae16f7, 0x821505b4, 0x7ab81f78, 0xf2c88c63,
132             0xa7655b7c, 0xc436644, 0x18e67d7c, 0xa5c8e283,
133             0x6e44a66e, 0xe7547024, 0x280ce7d0, 0x8ec06da2,
134             0x93683af4, 0x5e39165c, 0x77721743, 0x7b9d837e,
135             0x32fed2ef, 0x9726079b, 0x98a579a, 0xc51b8dc5,
136             0xedd45d61, 0xbf70e897, 0x5c8187f8, 0x83909156,
137             0x469c6dc2, 0xf6fb34f5, 0xf14e0646, 0x5e988165,
138             0x3dea4f92, 0x51b2d53c, 0xb543c4e, 0xae450075,
139             0xf9aaffee, 0x4bee49e7, 0x60ffe4f6, 0x395318e3,
140             0x8acb2b46, 0x6df56797, 0x52c9d67, 0x1ffd024a,
141             0x2499d763, 0x951c8244, 0x560ceb0, 0x5d0490a2,
142             0x7208da46, 0xfe40f9d7, 0xd2b96165, 0x696f3072,
143             0x2ba20225, 0x8758c6b4, 0x71f59b60, 0xd84d9bd3,
144             0x8bc05ab, 0xa09fa33, 0xd14769cf, 0x238c630a,
145             0x5635a041, 0x9af1f0bc, 0xa347515, 0xa90ac427,
146             0xdbcbc880, 0x9434490c, 0xcb041e0f, 0x4101f58,
147             0xcb057a30, 0x721e4a62, 0x8d59b73, 0x76d1c883,
148             0x724d675, 0x57833e73, 0xf65e3cc7, 0x4025c165,
149             0x61caa9fa, 0xecf3ffad, 0xc9ccba59, 0xbf1e78c0,
150             0xe7c9f808, 0x5f3ae0ad, 0xe338467, 0x5baf328,
151             0x77ea9442, 0x232d063c, 0x44c1f91f, 0xcfaaa06,
152             0xcd95c059, 0xf92f3f43, 0xd105984a, 0x4ea4eac2,
153             0xdb17fb06, 0xed567697, 0x896b421d, 0x40c3b884,
154             0xf3258ace, 0xbdb93689, 0xb75abba5, 0xc69f182c,
155             0x5798ae31, 0xff3ba2e7, 0x1ef383b4, 0xc689850c,
156             0xa0e850e, 0x7478b55d, 0xf0cd99e7, 0x78128b44,
157             0x99139a31, 0x191a4f69, 0x4dcb9de1, 0x80d9512c,
158             0x6dd3001a, 0xcb6f465e, 0xaa760561, 0x19cc07b3,
159             0x383c9dc4, 0x620f19d8, 0xbc621d05, 0x888061f0,
160             0x549fb42, 0xd21c5ac2, 0x4e37b133, 0xda38e932,
161             0x66ac40ae, 0x855de0db, 0x29c32890, 0xfc79f537,
162             0xea0bc017, 0xb30fd396, 0x9f6e65d0, 0x1fbd8e56,
163             0xa6a79b7b, 0x63871bcf, 0x977361fe, 0x572fc22e,
164             0xcac4d530, 0xee9631a1, 0xd66ca305, 0xd8648a0b,
165             0xa0fa4f44, 0x1b49d414, 0xb9b89101, 0xbb3dc53b,
166             0x9267697d, 0x998ee205, 0xca1a4a0b, 0x16e0c5d3,
167             0xb099860c, 0x3ec1b23b, 0x5d11b6a5, 0x78daf576,
168             0xd58d0926, 0x7e77c453, 0x42a2daf5, 0x6465314c,
169             0xa25d7243, 0x33eb1745, 0x9d662159, 0x61e86fcb,
170             0xedca8ac0, 0xc4afdc42, 0x866e5492, 0x9e72fe28,
171             0x9e5b7096, 0xb3121ab3, 0x9eafbc0d, 0xb03b48,
172             0x3a29c9d, 0x517d9ea7, 0xd12dd262, 0x8965c881,
173             0x3f1575bf, 0x811afeb2, 0xb8699338, 0xa49b7870,
174             0x8b72b9aa, 0xa56dbc23, 0xbdc66113, 0xc80baa85,
175             0x2f6e2fe2, 0xe2f32eaa, 0x4942b340, 0x3782424d,
176             0xc7f3fd93, 0x29c6dbac, 0x181c1bc1, 0x7db26d5e,
177             0x49ecc6f6, 0x7f600a7f, 0xf73b236a, 0x264d7fd1,
178             0x68bac57f, 0xd276c9e, 0x1784d004, 0xb98b5fc7,
179             0xd03f81ca, 0xd44d46a1, 0xcfbea6d1, 0x5c06d9d0,
180             0xbec1bad1, 0xa3bacc94, 0xaacc518c, 0xf8e20ef9,
181             0x8749c85a, 0xe4f865cd, 0x819fdb8a, 0x3c9924f6,
182             0xcb96ac1, 0x3a2bc069, 0x34b28508, 0xdb02aaf2,
183             0x231dccd0, 0xe088dc6a, 0x4d54c84, 0x9096e29f,
184             0x92db735a, 0x44ebca10, 0x8bbe55f2, 0x17287085,
185             0xf782f3b5, 0xc98a9a13, 0x117c0991, 0x69d34986,
186             0xa53303c9, 0x786c1b84, 0x5c174525, 0x4887510b,
187             0xaaf68a8e, 0xff4cba8f, 0xb6b66cc7, 0x1d5de8ea,
188             0xb98783a8, 0x82525dd6, 0x41200306, 0xaf354785,
189             0xb3479dc5, 0x508c2a19, 0x61a3104e, 0x5688a9f2,
190             0xca4bee32, 0x45df7f55, 0x2d2caedd, 0xdfdffc59,
191             0x911454c1, 0xd9dd2d80, 0x4e328041, 0x582ebac0,
192             0xbda7aab2, 0x10c52f26, 0x472690d0, 0x258304cf,
193             0x54e2e210, 0xd4482bf8, 0x22086561, 0x98407334
194         },
195         {
196             0x900aa5b7, 0x4e649e1f, 0xc9d635c9, 0x69ffda97,
197             0xdce34ccd, 0xf08ff29b, 0xee9360d3, 0xd9c59300,
198             0x7190589d, 0x69d75cc1, 0x9e3c3dc1, 0x45541e71,
199             0x6f1bccc2, 0x46f39b64, 0xc2622672, 0xfacf3cca,
200             0x867a7957, 0xd14995f, 0xfaa6011d, 0xaeaa8c37,
201             0x3d911958, 0x5f672f3a, 0x80ffb57, 0x7c27f22d,
202             0x295fd1f, 0x55f3a836, 0x55476bd5, 0x1d717b6b,
203             0x99b01c2, 0xf7a4359a, 0xfbf0d88f, 0x90f0a4fd,
204             0xdd1bed5d, 0x395e2267, 0x84473b44, 0x216d1700,
205             0xd91466b6, 0xf6723abc, 0xb58917f7, 0xe4055634,
206             0x5e5c94a9, 0x371a7adc, 0xa9444660, 0x9cd864c7,
207             0x942160f8, 0xfa57e367, 0x3ac900aa, 0xfed09d6c,
208             0xab1e8ce6, 0x1c3440b2, 0x2921f7ef, 0xcbc8aad9,
209             0xaee21a52, 0xb65bac8c, 0x4e24db59, 0xa0afe727,
210             0xd6a6a2ce, 0xcda6dc7c, 0xde7b8be, 0xac98135d,
211             0x61ebab33, 0xd6c91e9a, 0x42afb446, 0x5ffdebdd,
212             0x22d4df79, 0xd19e8fe7, 0xbc6b9029, 0x597ff071,
213             0xa4f6f069, 0xa41ed335, 0xa933f4c8, 0x3a4b5456,
214             0xca3df8d6, 0x91915bbd, 0x7c656515, 0x6ae7e70d,
215             0x517118c, 0x2a9565e0, 0x3046470a, 0x4d0b8c6,
216             0x788182c, 0x3bf3c684, 0x1e7a37f5, 0x45507790,
217             0xb9ab569e, 0x1d3927fe, 0x2aac516d, 0x8eb519e0,
218             0xc7563e93, 0x8572cdd1, 0xcfe62ded, 0x78eeb7d6,
219             0x152032bb, 0x5f480f75, 0xa1d06607, 0x51da64b0,
220             0xbc666eb1, 0x34ea7eec, 0x6ccff8b1, 0xd952ba,
221             0x32d16b6, 0xcbfe265e, 0x9daab452, 0xb12f4349,
222             0xceac2beb, 0x4b9787f9, 0x85719171, 0xf0b9c027,
223             0x7feeaa15, 0x990aebcc, 0x767bf1a9, 0xcd56802d,
224             0xe718ab1e, 0x661ef622, 0x3e217d8f, 0x8604b297,
225             0x712d7706, 0xff2a8240, 0xe149f2cd, 0x49c36be2,
226             0x3ac40571, 0xa041a748, 0xaa1580cb, 0x7a9a3e62,
227             0x9def968d, 0x908f3347, 0x40dddf27, 0xfd078597,
228             0x30b9d025, 0xd40d138, 0xde35af82, 0x5718e93,
229             0x529cd4ac, 0x41632ca0, 0x169c0ff3, 0xbac5b27a,
230             0x771b0fa7, 0xdcdf8bd, 0x4faf140e, 0x5aec8617,
231             0x24597031, 0x6407c4a6, 0x70fc5d31, 0x9085ff31,
232             0x8b1397d8, 0x99633b58, 0x91d5b56f, 0xfb451a1a,
233             0xe379e1fc, 0xe6ba2f3f, 0x462cb5c1, 0x1dd06ff4,
234             0x2cf546ba, 0x70800782, 0xdc27b1eb, 0x7965ad5d,
235             0x39ffac7a, 0x862ffce9, 0x569e938e, 0xd42c7cc3,
236             0x614f729b, 0x842ba8d5, 0xc4c56289, 0x77df9d86,
237             0xf51eb421, 0xec140c11, 0x2b891d79, 0x58b98151,
238             0x49955e, 0x6d2ae4cb, 0xdb9bd16f, 0x816ed489,
239             0x5187b66a, 0xe2428c32, 0x340ca67c, 0x6002c78f,
240             0xe7479dfd, 0xcc924e44, 0xc73ec342, 0xf17cfd8d,
241             0x8942a89b, 0x75d34569, 0xac22e545, 0x8375e876,
242             0x8395884a, 0x586698a6, 0x3f3d8f12, 0xdc5943d3,
243             0x66d1996b, 0xd06a5896, 0x6a8afde7, 0xb4d9accb,
244             0x17289e6a, 0xff9b64ef, 0x47c3dab, 0xfa2e58,
245             0x26790980, 0x5163e6f6, 0x65e17492, 0x62e55e79,
246             0x8af1b5a0, 0x2c72e6ba, 0x47da4a0a, 0x8a20bab4,
247             0xf3bcbd52, 0x16d2a483, 0xe5877bcf, 0x3cade4ba,
248             0xf65721a2, 0xb5815461, 0xb3fb53b5, 0xf74508db,
249             0x5c5c1af, 0x3b53868, 0xd9c6825d, 0x4a55bb36,
250             0x785ce186, 0xd5732f60, 0xd94fadb0, 0x1676d0cf,
251             0x1090d57f, 0x7bd7a227, 0xac20c78c, 0x2c68e495,
252             0xcd6478d2, 0xc7f4641c, 0x5ed5d389, 0x2cdc09ca,
253             0xff6d94d2, 0x47d4921c, 0xc3da6fc4, 0x6231f4c6,
254             0x28643ecd, 0x9367f303, 0x2319a3a2, 0x2f86fd8e,
255             0x7f13a567, 0x785e871a, 0xf88564cf, 0x27203f51,
256             0x7f7fe69a, 0xf0bbc1f4, 0x6ac32b0, 0xfa87113a,
257             0x1533dab5, 0x9e168c28, 0x621b244d, 0xc26cdca8,
258             0xe2b12ff1, 0xb1fb41d, 0x74abc0bf, 0x6faf66ed,
259             0x7f96eef7, 0x8dd96699, 0xe0afd88c, 0x5666ae1e
260         },
261         {
262             0x429f8c4d, 0x7a6f751a, 0xe1f9f104, 0x8f3352a2,
263             0xee11c98f, 0xd3e00903, 0x834b9614, 0x1ca1cd5f,
264             0xc5da95e5, 0x48aa87f9, 0xf3e28f3a, 0xb3d2f1cd,
265             0x11a99c75, 0x6fc626d4, 0x75c5dbf4, 0x9a055ab0,
266             0x878bd7d0, 0x797cb4fe, 0xb56af6f2, 0xd8dad771,
267             0xd79d651f, 0xecc885c2, 0xe36ba61b, 0x3af46b8b,
268             0xd4c4dec7, 0x1ef69803, 0x24c094f2, 0x4796f5ca,
269             0xd0b4f1a4, 0x35b71a50, 0xc93bda59, 0x88744ee4,
270             0xe435da7e, 0xc2add479, 0xf89eba5b, 0xeb7b3be7,
271             0x25abda16, 0x31bc2a9, 0xd46c3697, 0xbdab88a5,
272             0xaf765372, 0x776715c1, 0x91f39946, 0x5a46fca5,
273             0xb7345689, 0xe5ccffc6, 0x83094686, 0xd29b145,
274             0x947c5b14, 0xee6a48b9, 0xf80bcf7e, 0x80364978,
275             0x28785457, 0x7f01f829, 0x2480cb12, 0x1c4e853d,
276             0x9c5be553, 0xbc234906, 0xf48c6576, 0x20d7163e,
277             0xd13fb6aa, 0x7911e4f2, 0x74a4c545, 0xcd37db61,
278             0x923daabd, 0x3671e21f, 0x474b7b1, 0xd6c142a8,
279             0xfd74fe19, 0x967d3c94, 0x76507cd3, 0x1860dcdf,
280             0x40511fa8, 0x19feec2b, 0xa624cb9, 0x3125d93b,
281             0xc4bed3ba, 0xaa215b42, 0xa44f7c85, 0x63065ae5,
282             0xde95bfe, 0x6b6e92e8, 0xf3e516d1, 0x8bc680c8,
283             0x5fdc0cad, 0x6e7281d4, 0x1a4a5a56, 0x5edb95a3,
284             0xb91324c1, 0xbbfbce4c, 0x9e90028c, 0x4825c43d,
285             0xe5f599a4, 0xcacc8db0, 0xf1fd746b, 0x2d7baad9,
286             0xcc3148c4, 0xffefb22f, 0x9ec43aee, 0x7556ebfc,
287             0x7ce98693, 0x19eb04dd, 0xc5c3d0e2, 0x5d0c1bea,
288             0x801fe923, 0xcb47549d, 0xada4ca94, 0x953a3ff6,
289             0x92d8bc7e, 0x1a8b21fa, 0x7e7d47ca, 0x345de887,
290             0x668fc1d5, 0xb191b107, 0x29f30bbd, 0x669cdc3a,
291             0x907fad0c, 0xa8432d5d, 0x8125844d, 0x6f8ee014,
292             0x96fe6488, 0x6b812b55, 0x96e27fb5, 0xb68e0b09,
293             0x6d28e784, 0x370fff6c, 0x65c77431, 0xa6ba0fe6,
294             0x85ede90f, 0x6ebc916e, 0xd2927076, 0x8f7f7b17,
295             0x690c30f5, 0x88c8404e, 0x76b88278, 0x27eb857b,
296             0xfd20c71d, 0x53b63cc4, 0x93fb6326, 0xca3a6e63,
297             0x879e4bc7, 0x7e75fa05, 0x2dc60e82, 0xc4b2b95,
298             0xe6e17a43, 0x6e6c53a7, 0xe6baa075, 0x7b50f168,
299             0xf95e02a8, 0x3422dd2d, 0x4eb38261, 0xd17615c8,
300             0x238c1d99, 0x24def9f8, 0x250a45d1, 0xaeb97793,
301             0xd6bf65e6, 0xf4080ae1, 0x90814d9e, 0x2d9d8436,
302             0x2d742949, 0xa9afb64c, 0xdd4d18f8, 0x8855711e,
303             0x856bf7df, 0xbeb28a6b, 0xff5d789b, 0xd1e24c20,
304             0x92581004, 0xf9ee25e5, 0xdd445cff, 0xb5bc99cd,
305             0x2e90fb9d, 0x86e95fa6, 0x3ce3fc89, 0x2ccff4c9,
306             0x42b6541c, 0xf2cdb401, 0x76b6cd96, 0x5cbc0f31,
307             0x5d988c8e, 0x5535eb69, 0x1354397b, 0x5f105b42,
308             0x70359c13, 0x8053d6a9, 0x43ee0e25, 0x7279a17b,
309             0x23b44313, 0x99dbf710, 0x3671f4f1, 0x212fb10a,
310             0xd61b85ef, 0x5370eec8, 0xb03ac259, 0x53068883,
311             0x10325203, 0x2550b3b5, 0x3afa6580, 0x5945266f,
312             0xf8f21594, 0x1f2feef2, 0xcaebbffc, 0xcc55f93a,
313             0x21f277bf, 0x4e1c1b9c, 0xdd74f5a4, 0x34e84677,
314             0xb85d1834, 0xf9fdccaa, 0x5f13cc3, 0x8d1a00d9,
315             0xd3b7f623, 0x2d8886bf, 0x1505627e, 0x476ea29b,
316             0x7758fa96, 0xc59274f8, 0x5d6cd56, 0xf892f3ce,
317             0xc26a482c, 0xe00f252c, 0x38c981c3, 0x223869ac,
318             0xaa8bc73f, 0xe8ca1111, 0xed51fdd6, 0xeb0724d4,
319             0x61b05512, 0x290876c2, 0x50b855d1, 0x20cf2267,
320             0x894a6a06, 0xd87f0ab4, 0x5961c4f5, 0xdd7781a,
321             0x8f898f63, 0xe5bcfae8, 0x2ab999c3, 0x6d25c711,
322             0x11b0621c, 0x7a097422, 0xa7f23f1, 0x9fbfb450,
323             0xd5e5019b, 0xbe3427a9, 0x70967c5c, 0x18f65981,
324             0x2c9bde6b, 0xfe6f03c4, 0xc754ef9a, 0x637d1ff5,
325             0x9749ef7a, 0xae0c1da6, 0x4e05c89c, 0x87e4150a
326         }
327     }
328 };
329
330 const unsigned char testString[] = { 68, 100, 2, 115, 6, 54, 226, 228 };
331
332 } // namespace anonymous
333
334 BOOST_AUTO_TEST_SUITE(Crypto)
335
336 BOOST_AUTO_TEST_CASE(ContextCreation)
337 {
338     BLOWFISH_CTX ctx;
339     InitContext("pr7Hhen", 7, &ctx);
340     BOOST_CHECK(equalCtx(ctx, testCtx));
341 }
342
343 BOOST_AUTO_TEST_CASE(Encryption)
344 {
345     BLOWFISH_CTX ctx;
346     InitContext("pr7Hhen", 7, &ctx);
347     uint32_t a = 0x12345678;
348     uint32_t b = 0x87654321;
349     Blowfish_Encrypt(&ctx, &a, &b);
350
351     BOOST_CHECK_EQUAL(a, 0xd3988cd);
352     BOOST_CHECK_EQUAL(b, 0x7996c6d6);
353 }
354
355 BOOST_AUTO_TEST_CASE(Decryption)
356 {
357     BLOWFISH_CTX ctx;
358     InitContext("pr7Hhen", 7, &ctx);
359     uint32_t a = 0xd3988cd;
360     uint32_t b = 0x7996c6d6;
361     Blowfish_Decrypt(&ctx, &a, &b);
362
363     BOOST_CHECK_EQUAL(a, 0x12345678);
364     BOOST_CHECK_EQUAL(b, 0x87654321);
365 }
366
367 BOOST_AUTO_TEST_CASE(BlockEncryption)
368 {
369     BLOWFISH_CTX ctx;
370     InitContext("pr7Hhen", 7, &ctx);
371     uint32_t block[2] = {0x12345678, 0x87654321};
372     EncryptBlock(&block, &block, &ctx);
373
374     BOOST_CHECK_EQUAL(block[0], 0xd3988cd);
375     BOOST_CHECK_EQUAL(block[1], 0x7996c6d6);
376 }
377
378 BOOST_AUTO_TEST_CASE(BlockDecryption)
379 {
380     BLOWFISH_CTX ctx;
381     InitContext("pr7Hhen", 7, &ctx);
382     uint32_t block[2] = {0xd3988cd, 0x7996c6d6};
383     DecryptBlock(&block, &block, &ctx);
384
385     BOOST_CHECK_EQUAL(block[0], 0x12345678);
386     BOOST_CHECK_EQUAL(block[1], 0x87654321);
387 }
388
389 BOOST_AUTO_TEST_CASE(StringEncryption)
390 {
391     BLOWFISH_CTX ctx;
392     InitContext("pr7Hhen", 7, &ctx);
393     char res[8];
394     EncryptString(res, "testtest", 8, &ctx);
395
396     BOOST_CHECK(equalString(res, reinterpret_cast<const char*>(testString), 8));
397 }
398
399 BOOST_AUTO_TEST_CASE(LongStringEncryption)
400 {
401     BLOWFISH_CTX ctx;
402     InitContext("pr7Hhen", 7, &ctx);
403     const std::string source("abcdefghijklmnopqrstuvwxyz 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ");
404     std::vector<char> longTest(source.length() + 8);
405     EncryptString(longTest.data(), source.c_str(), source.length() + 1, &ctx);
406     DecryptString(longTest.data(), longTest.data(), longTest.size(), &ctx);
407
408     BOOST_CHECK_EQUAL(source, std::string(longTest.data()));
409 }
410
411 BOOST_AUTO_TEST_CASE(OldStringEncryption)
412 {
413     BLOWFISH_CTX ctx;
414     InitContext("123456", 7, &ctx);
415     const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39,
416                                     0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb,
417                                     0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb,
418                                     0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb};
419     std::array<char, 32> res{};
420     DecryptString(res.data(), source, res.size(), &ctx);
421
422     BOOST_CHECK_EQUAL(std::string(res.data()), "admin");
423 }
424
425 BOOST_AUTO_TEST_CASE(NewStringEncryption)
426 {
427     BLOWFISH_CTX ctx;
428     InitContext("123456", 7, &ctx);
429     const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39,
430                                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
431                                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
432                                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
433     std::array<char, 32> res{};
434     DecryptString(res.data(), source, 32, &ctx);
435
436     BOOST_CHECK_EQUAL(std::string(res.data()), "admin");
437 }
438
439 BOOST_AUTO_TEST_SUITE_END()