1/**
2 * Copyright (C) 2004-2007 Brad Hards <bradh@frogmouth.net>
3 * Copyright (C) 2013-2016 Ivan Romanov <drizt@land.ru>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "cipherunittest.h"
28
29#include <QtCrypto>
30#include <QtTest/QtTest>
31
32#ifdef QT_STATICPLUGIN
33#include "import_plugins.h"
34#endif
35
36void CipherUnitTest::initTestCase()
37{
38 m_init = new QCA::Initializer;
39 const auto providers = QCA::providers();
40 for (QCA::Provider *provider : providers)
41 providersToTest << provider->name();
42}
43
44void CipherUnitTest::cleanupTestCase()
45{
46 delete m_init;
47}
48
49void CipherUnitTest::aes128_data()
50{
51 QTest::addColumn<QString>(name: "plainText");
52 QTest::addColumn<QString>(name: "cipherText");
53 QTest::addColumn<QString>(name: "keyText");
54
55 // Not sure where this came from...
56 QTest::newRow(dataTag: "mystery") << QStringLiteral("506812a45f08c889b97f5980038b8359")
57 << QStringLiteral("d8f532538289ef7d06b506a4fd5be9c9")
58 << QStringLiteral("00010203050607080a0b0c0d0f101112");
59
60 // From FIPS 197 Appendix C.1
61 QTest::newRow(dataTag: "FIPS197 App C.1") << QStringLiteral("00112233445566778899aabbccddeeff")
62 << QStringLiteral("69c4e0d86a7b0430d8cdb78070b4c55a")
63 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
64
65 // These are from the Botan test suite
66 QTest::newRow(dataTag: "1") << QStringLiteral("506812a45f08c889b97f5980038b8359")
67 << QStringLiteral("d8f532538289ef7d06b506a4fd5be9c9")
68 << QStringLiteral("00010203050607080a0b0c0d0f101112");
69 QTest::newRow(dataTag: "2") << QStringLiteral("5c6d71ca30de8b8b00549984d2ec7d4b")
70 << QStringLiteral("59ab30f4d4ee6e4ff9907ef65b1fb68c")
71 << QStringLiteral("14151617191a1b1c1e1f202123242526");
72 QTest::newRow(dataTag: "3") << QStringLiteral("53f3f4c64f8616e4e7c56199f48f21f6")
73 << QStringLiteral("bf1ed2fcb2af3fd41443b56d85025cb1")
74 << QStringLiteral("28292a2b2d2e2f30323334353738393a");
75 QTest::newRow(dataTag: "4") << QStringLiteral("a1eb65a3487165fb0f1c27ff9959f703")
76 << QStringLiteral("7316632d5c32233edcb0780560eae8b2")
77 << QStringLiteral("3c3d3e3f41424344464748494b4c4d4e");
78 QTest::newRow(dataTag: "5") << QStringLiteral("3553ecf0b1739558b08e350a98a39bfa")
79 << QStringLiteral("408c073e3e2538072b72625e68b8364b")
80 << QStringLiteral("50515253555657585a5b5c5d5f606162");
81 QTest::newRow(dataTag: "6") << QStringLiteral("67429969490b9711ae2b01dc497afde8")
82 << QStringLiteral("e1f94dfa776597beaca262f2f6366fea")
83 << QStringLiteral("64656667696a6b6c6e6f707173747576");
84 QTest::newRow(dataTag: "7") << QStringLiteral("93385c1f2aec8bed192f5a8e161dd508")
85 << QStringLiteral("f29e986c6a1c27d7b29ffd7ee92b75f1")
86 << QStringLiteral("78797a7b7d7e7f80828384858788898a");
87 QTest::newRow(dataTag: "8") << QStringLiteral("3e23b3bc065bcc152407e23896d77783")
88 << QStringLiteral("1959338344e945670678a5d432c90b93")
89 << QStringLiteral("54555657595a5b5c5e5f606163646566");
90 QTest::newRow(dataTag: "9") << QStringLiteral("79f0fba002be1744670e7e99290d8f52")
91 << QStringLiteral("e49bddd2369b83ee66e6c75a1161b394")
92 << QStringLiteral("68696a6b6d6e6f70727374757778797a");
93 QTest::newRow(dataTag: "10") << QStringLiteral("da23fe9d5bd63e1d72e3dafbe21a6c2a")
94 << QStringLiteral("d3388f19057ff704b70784164a74867d")
95 << QStringLiteral("7c7d7e7f81828384868788898b8c8d8e");
96 QTest::newRow(dataTag: "11") << QStringLiteral("e3f5698ba90b6a022efd7db2c7e6c823")
97 << QStringLiteral("23aa03e2d5e4cd24f3217e596480d1e1")
98 << QStringLiteral("a4a5a6a7a9aaabacaeafb0b1b3b4b5b6");
99 QTest::newRow(dataTag: "12") << QStringLiteral("bdc2691d4f1b73d2700679c3bcbf9c6e")
100 << QStringLiteral("c84113d68b666ab2a50a8bdb222e91b9")
101 << QStringLiteral("e0e1e2e3e5e6e7e8eaebecedeff0f1f2");
102 QTest::newRow(dataTag: "13") << QStringLiteral("ba74e02093217ee1ba1b42bd5624349a")
103 << QStringLiteral("ac02403981cd4340b507963db65cb7b6")
104 << QStringLiteral("08090a0b0d0e0f10121314151718191a");
105 QTest::newRow(dataTag: "14") << QStringLiteral("b5c593b5851c57fbf8b3f57715e8f680")
106 << QStringLiteral("8d1299236223359474011f6bf5088414")
107 << QStringLiteral("6c6d6e6f71727374767778797b7c7d7e");
108}
109
110void CipherUnitTest::aes128()
111{
112 bool anyProviderTested = false;
113 foreach (const QString provider, providersToTest) {
114 if (QCA::isSupported(features: "aes128-ecb", provider)) {
115 anyProviderTested = true;
116 QFETCH(QString, plainText);
117 QFETCH(QString, cipherText);
118 QFETCH(QString, keyText);
119
120 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
121 QCA::Cipher forwardCipher(QStringLiteral("aes128"),
122 QCA::Cipher::ECB,
123 QCA::Cipher::NoPadding,
124 QCA::Encode,
125 key,
126 QCA::InitializationVector(),
127 provider);
128
129 QCOMPARE(forwardCipher.blockSize(), 16);
130 QCOMPARE(forwardCipher.keyLength().minimum(), 16);
131 QCOMPARE(forwardCipher.keyLength().maximum(), 16);
132
133 QString afterEncodeText = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
134 QVERIFY(forwardCipher.ok());
135
136 afterEncodeText += QCA::arrayToHex(array: forwardCipher.final().toByteArray());
137 QVERIFY(forwardCipher.ok());
138
139 QCOMPARE(afterEncodeText, cipherText);
140
141 QCA::Cipher reverseCipher(QStringLiteral("aes128"),
142 QCA::Cipher::ECB,
143 QCA::Cipher::NoPadding,
144 QCA::Decode,
145 key,
146 QCA::InitializationVector(),
147 provider);
148
149 QCOMPARE(reverseCipher.blockSize(), 16);
150 QCOMPARE(reverseCipher.keyLength().minimum(), 16);
151 QCOMPARE(reverseCipher.keyLength().maximum(), 16);
152
153 QString afterDecodeText = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
154 QVERIFY(reverseCipher.ok());
155
156 afterDecodeText += QCA::arrayToHex(array: reverseCipher.final().toByteArray());
157 QVERIFY(reverseCipher.ok());
158
159 QCOMPARE(afterDecodeText, plainText);
160 }
161 }
162 if (!anyProviderTested)
163 qWarning() << "NONE of the providers supports AES128 ECB:" << providersToTest;
164}
165
166// This is from the Botan test suite
167void CipherUnitTest::aes128_cbc_data()
168{
169 QTest::addColumn<QString>(name: "plainText");
170 QTest::addColumn<QString>(name: "cipherText");
171 QTest::addColumn<QString>(name: "keyText");
172 QTest::addColumn<QString>(name: "ivText");
173
174 QTest::newRow(dataTag: "1") << QStringLiteral(
175 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
176 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
177 << QStringLiteral(
178 "7649abac8119b246cee98e9b12e9197d5086cb9b507219ee95db113a917678b273bed6b8e3c1743b7116e69e"
179 "222295163ff1caa1681fac09120eca307586e1a7")
180 << QStringLiteral("2b7e151628aed2a6abf7158809cf4f3c")
181 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
182}
183
184void CipherUnitTest::aes128_cbc()
185{
186 bool anyProviderTested = false;
187 foreach (const QString provider, providersToTest) {
188 if (QCA::isSupported(features: "aes128-cbc", provider)) {
189 anyProviderTested = true;
190 QFETCH(QString, plainText);
191 QFETCH(QString, cipherText);
192 QFETCH(QString, keyText);
193 QFETCH(QString, ivText);
194
195 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
196 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
197 QCA::Cipher forwardCipher(
198 QStringLiteral("aes128"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
199 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
200 QVERIFY(forwardCipher.ok());
201 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
202 QVERIFY(forwardCipher.ok());
203
204 QCA::Cipher reverseCipher(
205 QStringLiteral("aes128"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
206 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
207 QVERIFY(reverseCipher.ok());
208 QCOMPARE(update, plainText.left(update.size()));
209 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
210 QVERIFY(reverseCipher.ok());
211 }
212 }
213 if (!anyProviderTested)
214 qWarning() << "NONE of the providers supports AES128 CBC:" << providersToTest;
215}
216
217// These were generated using OpenSSL's enc command
218void CipherUnitTest::aes128_cbc_pkcs7_data()
219{
220 QTest::addColumn<QString>(name: "plainText");
221 QTest::addColumn<QString>(name: "cipherText");
222 QTest::addColumn<QString>(name: "keyText");
223 QTest::addColumn<QString>(name: "ivText");
224
225 QTest::newRow(dataTag: "1") << QString(QLatin1String("")) << QStringLiteral("18fe62efa4dc4b21a4127b225855b475")
226 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF")
227 << QStringLiteral("00001111222233334444555566667777");
228
229 QTest::newRow(dataTag: "2") << QStringLiteral("610a") << QStringLiteral("92823eab12924cd168f54d3f4baa9a4d")
230 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF")
231 << QStringLiteral("00001111222233334444555566667777");
232
233 QTest::newRow(dataTag: "3") << QStringLiteral("6162636465666768696a0a") << QStringLiteral("9d41b355abd61e3dfa482f3c1aeaae49")
234 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF")
235 << QStringLiteral("00001111222233334444555566667777");
236
237 QTest::newRow(dataTag: "block size - 1") << QStringLiteral("6162636465666768696a6b6c6d6e0a")
238 << QStringLiteral("c86b53850815cae7ae4a6e7529a87587")
239 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF")
240 << QStringLiteral("00001111222233334444555566667777");
241
242 QTest::newRow(dataTag: "block size") << QStringLiteral("6162636465666768696a6b6c6d6e310a")
243 << QStringLiteral("26fb0474b70d118f2b1d5b74e58c97bf3bb81bece1250509c5c68771ae23ceac")
244 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF")
245 << QStringLiteral("00001111222233334444555566667777");
246
247 QTest::newRow(dataTag: "block size+1") << QStringLiteral("6162636465666768696a6b6c6d6e6f310a")
248 << QStringLiteral("656f5c5693741967e059149e9239452fa286ac7c86ef653182d226d543d53013")
249 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF")
250 << QStringLiteral("00001111222233334444555566667777");
251}
252
253void CipherUnitTest::aes128_cbc_pkcs7()
254{
255 bool anyProviderTested = false;
256 foreach (const QString provider, providersToTest) {
257 if (QCA::isSupported(features: "aes128-cbc-pkcs7", provider)) {
258 anyProviderTested = true;
259 QFETCH(QString, plainText);
260 QFETCH(QString, cipherText);
261 QFETCH(QString, keyText);
262 QFETCH(QString, ivText);
263
264 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
265 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
266 QCA::Cipher forwardCipher(QStringLiteral("aes128"),
267 QCA::Cipher::CBC,
268 QCA::Cipher::DefaultPadding,
269 QCA::Encode,
270 key,
271 iv,
272 provider);
273 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
274 QVERIFY(forwardCipher.ok());
275 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
276 QVERIFY(forwardCipher.ok());
277
278 QCA::Cipher reverseCipher(QStringLiteral("aes128"),
279 QCA::Cipher::CBC,
280 QCA::Cipher::DefaultPadding,
281 QCA::Decode,
282 key,
283 iv,
284 provider);
285 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
286 QVERIFY(reverseCipher.ok());
287 QCOMPARE(update, plainText.left(update.size()));
288 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
289 QVERIFY(reverseCipher.ok());
290 }
291 }
292 if (!anyProviderTested)
293 qWarning() << "NONE of the providers supports AES128 CBC with PKCS7 padding:" << providersToTest;
294}
295
296// This is from the Botan test suite
297void CipherUnitTest::aes128_cfb_data()
298{
299 QTest::addColumn<QString>(name: "plainText");
300 QTest::addColumn<QString>(name: "cipherText");
301 QTest::addColumn<QString>(name: "keyText");
302 QTest::addColumn<QString>(name: "ivText");
303
304 QTest::newRow(dataTag: "1") << QStringLiteral(
305 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
306 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
307 << QStringLiteral(
308 "3b3fd92eb72dad20333449f8e83cfb4ac8a64537a0b3a93fcde3cdad9f1ce58b26751f67a3cbb140b1808cf1"
309 "87a4f4dfc04b05357c5d1c0eeac4c66f9ff7f2e6")
310 << QStringLiteral("2b7e151628aed2a6abf7158809cf4f3c")
311 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
312}
313
314void CipherUnitTest::aes128_cfb()
315{
316 bool anyProviderTested = false;
317 foreach (const QString provider, providersToTest) {
318 if (QCA::isSupported(features: "aes128-cfb", provider)) {
319 anyProviderTested = true;
320 QFETCH(QString, plainText);
321 QFETCH(QString, cipherText);
322 QFETCH(QString, keyText);
323 QFETCH(QString, ivText);
324
325 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
326 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
327 QCA::Cipher forwardCipher(
328 QStringLiteral("aes128"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
329 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
330 QVERIFY(forwardCipher.ok());
331 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
332 QVERIFY(forwardCipher.ok());
333
334 QCA::Cipher reverseCipher(
335 QStringLiteral("aes128"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
336 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
337 QVERIFY(reverseCipher.ok());
338 QCOMPARE(update, plainText.left(update.size()));
339 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
340 QVERIFY(reverseCipher.ok());
341 }
342 }
343 if (!anyProviderTested)
344 qWarning() << "NONE of the providers supports AES128 CFB:" << providersToTest;
345}
346
347// This is from the Botan test suite
348void CipherUnitTest::aes128_ofb_data()
349{
350 QTest::addColumn<QString>(name: "plainText");
351 QTest::addColumn<QString>(name: "cipherText");
352 QTest::addColumn<QString>(name: "keyText");
353 QTest::addColumn<QString>(name: "ivText");
354
355 QTest::newRow(dataTag: "1") << QStringLiteral(
356 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
357 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
358 << QStringLiteral(
359 "3b3fd92eb72dad20333449f8e83cfb4a7789508d16918f03f53c52dac54ed8259740051e9c5fecf64344f7a8"
360 "2260edcc304c6528f659c77866a510d9c1d6ae5e")
361 << QStringLiteral("2b7e151628aed2a6abf7158809cf4f3c")
362 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
363}
364
365void CipherUnitTest::aes128_ofb()
366{
367 bool anyProviderTested = false;
368 foreach (const QString provider, providersToTest) {
369 if (QCA::isSupported(features: "aes128-ofb", provider)) {
370 anyProviderTested = true;
371 QFETCH(QString, plainText);
372 QFETCH(QString, cipherText);
373 QFETCH(QString, keyText);
374 QFETCH(QString, ivText);
375
376 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
377 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
378 QCA::Cipher forwardCipher(
379 QStringLiteral("aes128"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
380 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
381 QVERIFY(forwardCipher.ok());
382 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
383 QVERIFY(forwardCipher.ok());
384
385 QCA::Cipher reverseCipher(
386 QStringLiteral("aes128"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
387 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
388 QVERIFY(reverseCipher.ok());
389 QCOMPARE(update, plainText.left(update.size()));
390 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
391 QVERIFY(reverseCipher.ok());
392 }
393 }
394 if (!anyProviderTested)
395 qWarning() << "NONE of the providers supports AES128 OFB:" << providersToTest;
396}
397
398void CipherUnitTest::aes128_ctr_data()
399{
400 QTest::addColumn<QString>(name: "plainText");
401 QTest::addColumn<QString>(name: "cipherText");
402 QTest::addColumn<QString>(name: "keyText");
403 QTest::addColumn<QString>(name: "ivText");
404
405 QTest::newRow(dataTag: "1") << QStringLiteral(
406 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
407 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
408 << QStringLiteral(
409 "3b3fd92eb72dad20333449f8e83cfb4a010c041999e03f36448624483e582d0ea62293cfa6df74535c354181"
410 "168774df2d55a54706273c50d7b4f8a8cddc6ed7")
411 << QStringLiteral("2b7e151628aed2a6abf7158809cf4f3c")
412 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
413}
414
415void CipherUnitTest::aes128_ctr()
416{
417 bool anyProviderTested = false;
418 foreach (const QString provider, providersToTest) {
419 if (QCA::isSupported(features: "aes128-ctr", provider)) {
420 anyProviderTested = true;
421 QFETCH(QString, plainText);
422 QFETCH(QString, cipherText);
423 QFETCH(QString, keyText);
424 QFETCH(QString, ivText);
425
426 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
427 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
428 QCA::Cipher forwardCipher(
429 QStringLiteral("aes128"), QCA::Cipher::CTR, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
430 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
431 QVERIFY(forwardCipher.ok());
432 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
433 QVERIFY(forwardCipher.ok());
434
435 QCA::Cipher reverseCipher(
436 QStringLiteral("aes128"), QCA::Cipher::CTR, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
437 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
438 QVERIFY(reverseCipher.ok());
439 QCOMPARE(update, plainText.left(update.size()));
440 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
441 QVERIFY(reverseCipher.ok());
442 }
443 }
444 if (!anyProviderTested)
445 qWarning() << "NONE of the providers supports AES128 CTR:" << providersToTest;
446}
447
448void CipherUnitTest::aes128_gcm_data()
449{
450 QTest::addColumn<QString>(name: "plainText");
451 QTest::addColumn<QString>(name: "payload");
452 QTest::addColumn<QString>(name: "tag");
453 QTest::addColumn<QString>(name: "keyText");
454 QTest::addColumn<QString>(name: "ivText");
455
456 QTest::newRow(dataTag: "short") << QStringLiteral("6f6820526f6d656d6f21") << QStringLiteral("a9f2558b9a74e6fc551f")
457 << QStringLiteral("f8ebf75f108c6f74e6fe49035d268d43")
458 << QStringLiteral("1f491f8ddf4856ae4bff9039d418175a")
459 << QStringLiteral("f85f8aad39164daf64a12ad9b3fc8a3a");
460
461 QTest::newRow(dataTag: "long") << QStringLiteral(
462 "54484520515549434b2042524f574e20464f58204a554d504544204f56455220544845204c415a5920444"
463 "f472753204241434b2031323334353637383930")
464 << QStringLiteral(
465 "04e321a8870b6b9cd6846239c27a63fb41d0a7b8994f1514c066f0427fa9ed6707ea6e3b4f161fdff0eb5"
466 "fc087ed3827b569cd72456c697b5a3a62c9e767")
467 << QStringLiteral("b0ad4aa545ea25fc3117cbed955ff155")
468 << QStringLiteral("56341f2b431d3b0dbad787db003f2215")
469 << QStringLiteral("bfcd3a7252f7f199bf788df8cf61032a");
470
471 QTest::newRow(dataTag: "wrongtag") << QStringLiteral("6f6820526f6d656d6f21") << QStringLiteral("a9f2558b9a74e6fc551f")
472 << QStringLiteral("f8ebf75f108c6f74e6fe49035d268d44")
473 << QStringLiteral("1f491f8ddf4856ae4bff9039d418175a")
474 << QStringLiteral("f85f8aad39164daf64a12ad9b3fc8a3a");
475}
476
477void CipherUnitTest::aes128_gcm()
478{
479 bool anyProviderTested = false;
480 foreach (const QString &provider, providersToTest) {
481 if (QCA::isSupported(features: "aes128-gcm", provider)) {
482 anyProviderTested = true;
483 QFETCH(QString, plainText);
484 QFETCH(QString, payload);
485 QFETCH(QString, tag);
486 QFETCH(QString, keyText);
487 QFETCH(QString, ivText);
488
489 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
490 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
491 QCA::AuthTag authTag(16);
492 QCA::Cipher forwardCipher(QStringLiteral("aes128"),
493 QCA::Cipher::GCM,
494 QCA::Cipher::NoPadding,
495 QCA::Encode,
496 key,
497 iv,
498 authTag,
499 provider);
500 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
501 QVERIFY(forwardCipher.ok());
502 update += QCA::arrayToHex(array: forwardCipher.final().toByteArray());
503 authTag = forwardCipher.tag();
504 QEXPECT_FAIL("wrongtag", "It's OK", Continue);
505 QCOMPARE(QCA::arrayToHex(authTag.toByteArray()), tag);
506 QCOMPARE(update, payload);
507 QVERIFY(forwardCipher.ok());
508
509 QCA::Cipher reverseCipher(QStringLiteral("aes128"),
510 QCA::Cipher::GCM,
511 QCA::Cipher::NoPadding,
512 QCA::Decode,
513 key,
514 iv,
515 QCA::AuthTag(QCA::hexToArray(hexString: tag)),
516 provider);
517
518 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: payload)).toByteArray());
519 QVERIFY(reverseCipher.ok());
520 QCOMPARE(update, plainText.left(update.size()));
521 update += QCA::arrayToHex(array: reverseCipher.final().toByteArray());
522 QEXPECT_FAIL("wrongtag", "It's OK", Continue);
523 QCOMPARE(update, plainText);
524 QEXPECT_FAIL("wrongtag", "It's OK", Continue);
525 QVERIFY(reverseCipher.ok());
526 }
527 }
528 if (!anyProviderTested)
529 qWarning() << "NONE of the providers supports AES128 GCM:" << providersToTest;
530}
531
532void CipherUnitTest::aes128_ccm_data()
533{
534}
535
536void CipherUnitTest::aes128_ccm()
537{
538 // For future implementation
539}
540
541void CipherUnitTest::aes192_data()
542{
543 QTest::addColumn<QString>(name: "plainText");
544 QTest::addColumn<QString>(name: "cipherText");
545 QTest::addColumn<QString>(name: "keyText");
546
547 // From FIPS 197 Appendix C.2
548 QTest::newRow(dataTag: "FIPS197 App C.2") << QStringLiteral("00112233445566778899aabbccddeeff")
549 << QStringLiteral("dda97ca4864cdfe06eaf70a0ec0d7191")
550 << QStringLiteral("000102030405060708090A0B0C0D0E0F1011121314151617");
551
552 // These are from the Botan test suite
553 QTest::newRow(dataTag: "1") << QStringLiteral("fec1c04f529bbd17d8cecfcc4718b17f")
554 << QStringLiteral("62564c738f3efe186e1a127a0c4d3c61")
555 << QStringLiteral("4a4b4c4d4f50515254555657595a5b5c5e5f606163646566");
556 QTest::newRow(dataTag: "2") << QStringLiteral("32df99b431ed5dc5acf8caf6dc6ce475")
557 << QStringLiteral("07805aa043986eb23693e23bef8f3438")
558 << QStringLiteral("68696a6b6d6e6f70727374757778797a7c7d7e7f81828384");
559 QTest::newRow(dataTag: "3") << QStringLiteral("7fdc2b746f3f665296943b83710d1f82")
560 << QStringLiteral("df0b4931038bade848dee3b4b85aa44b")
561 << QStringLiteral("868788898b8c8d8e90919293959697989a9b9c9d9fa0a1a2");
562 QTest::newRow(dataTag: "4") << QStringLiteral("8fba1510a3c5b87e2eaa3f7a91455ca2")
563 << QStringLiteral("592d5fded76582e4143c65099309477c")
564 << QStringLiteral("a4a5a6a7a9aaabacaeafb0b1b3b4b5b6b8b9babbbdbebfc0");
565 QTest::newRow(dataTag: "5") << QStringLiteral("2c9b468b1c2eed92578d41b0716b223b")
566 << QStringLiteral("c9b8d6545580d3dfbcdd09b954ed4e92")
567 << QStringLiteral("c2c3c4c5c7c8c9cacccdcecfd1d2d3d4d6d7d8d9dbdcddde");
568 QTest::newRow(dataTag: "6") << QStringLiteral("0a2bbf0efc6bc0034f8a03433fca1b1a")
569 << QStringLiteral("5dccd5d6eb7c1b42acb008201df707a0")
570 << QStringLiteral("e0e1e2e3e5e6e7e8eaebecedeff0f1f2f4f5f6f7f9fafbfc");
571 QTest::newRow(dataTag: "7") << QStringLiteral("25260e1f31f4104d387222e70632504b")
572 << QStringLiteral("a2a91682ffeb6ed1d34340946829e6f9")
573 << QStringLiteral("fefe01010304050608090a0b0d0e0f10121314151718191a");
574 QTest::newRow(dataTag: "8") << QStringLiteral("c527d25a49f08a5228d338642ae65137")
575 << QStringLiteral("e45d185b797000348d9267960a68435d")
576 << QStringLiteral("1c1d1e1f21222324262728292b2c2d2e3031323335363738");
577 QTest::newRow(dataTag: "9") << QStringLiteral("3b49fc081432f5890d0e3d87e884a69e")
578 << QStringLiteral("45e060dae5901cda8089e10d4f4c246b")
579 << QStringLiteral("3a3b3c3d3f40414244454647494a4b4c4e4f505153545556");
580 QTest::newRow(dataTag: "10") << QStringLiteral("d173f9ed1e57597e166931df2754a083")
581 << QStringLiteral("f6951afacc0079a369c71fdcff45df50")
582 << QStringLiteral("58595a5b5d5e5f60626364656768696a6c6d6e6f71727374");
583 QTest::newRow(dataTag: "11") << QStringLiteral("8c2b7cafa5afe7f13562daeae1adede0")
584 << QStringLiteral("9e95e00f351d5b3ac3d0e22e626ddad6")
585 << QStringLiteral("767778797b7c7d7e80818283858687888a8b8c8d8f909192");
586 QTest::newRow(dataTag: "12") << QStringLiteral("aaf4ec8c1a815aeb826cab741339532c")
587 << QStringLiteral("9cb566ff26d92dad083b51fdc18c173c")
588 << QStringLiteral("94959697999a9b9c9e9fa0a1a3a4a5a6a8a9aaabadaeafb0");
589 QTest::newRow(dataTag: "13") << QStringLiteral("40be8c5d9108e663f38f1a2395279ecf")
590 << QStringLiteral("c9c82766176a9b228eb9a974a010b4fb")
591 << QStringLiteral("d0d1d2d3d5d6d7d8dadbdcdddfe0e1e2e4e5e6e7e9eaebec");
592 QTest::newRow(dataTag: "14") << QStringLiteral("0c8ad9bc32d43e04716753aa4cfbe351")
593 << QStringLiteral("d8e26aa02945881d5137f1c1e1386e88")
594 << QStringLiteral("2a2b2c2d2f30313234353637393a3b3c3e3f404143444546");
595 QTest::newRow(dataTag: "15") << QStringLiteral("1407b1d5f87d63357c8dc7ebbaebbfee")
596 << QStringLiteral("c0e024ccd68ff5ffa4d139c355a77c55")
597 << QStringLiteral("48494a4b4d4e4f50525354555758595a5c5d5e5f61626364");
598}
599
600void CipherUnitTest::aes192()
601{
602 bool anyProviderTested = false;
603 foreach (const QString provider, providersToTest) {
604 if (QCA::isSupported(features: "aes192-ecb", provider)) {
605 anyProviderTested = true;
606 QFETCH(QString, plainText);
607 QFETCH(QString, cipherText);
608 QFETCH(QString, keyText);
609
610 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
611 QCA::Cipher forwardCipher(QStringLiteral("aes192"),
612 QCA::Cipher::ECB,
613 QCA::Cipher::NoPadding,
614 QCA::Encode,
615 key,
616 QCA::InitializationVector(),
617 provider);
618
619 QCOMPARE(forwardCipher.blockSize(), 16);
620 QCOMPARE(forwardCipher.keyLength().minimum(), 24);
621 QCOMPARE(forwardCipher.keyLength().maximum(), 24);
622
623 QString afterEncodeText = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
624 QVERIFY(forwardCipher.ok());
625
626 afterEncodeText += QCA::arrayToHex(array: forwardCipher.final().toByteArray());
627 QVERIFY(forwardCipher.ok());
628
629 QCOMPARE(afterEncodeText, cipherText);
630
631 QCA::Cipher reverseCipher(QStringLiteral("aes192"),
632 QCA::Cipher::ECB,
633 QCA::Cipher::NoPadding,
634 QCA::Decode,
635 key,
636 QCA::InitializationVector(),
637 provider);
638
639 QCOMPARE(reverseCipher.blockSize(), 16);
640 QCOMPARE(reverseCipher.keyLength().minimum(), 24);
641 QCOMPARE(reverseCipher.keyLength().maximum(), 24);
642
643 QString afterDecodeText = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
644 QVERIFY(reverseCipher.ok());
645
646 afterDecodeText += QCA::arrayToHex(array: reverseCipher.final().toByteArray());
647 QVERIFY(reverseCipher.ok());
648
649 QCOMPARE(afterDecodeText, plainText);
650 }
651 }
652 if (!anyProviderTested)
653 qWarning() << "NONE of the providers supports AES192 ECB:" << providersToTest;
654}
655
656// This is from the Botan test suite
657void CipherUnitTest::aes192_cbc_data()
658{
659 QTest::addColumn<QString>(name: "plainText");
660 QTest::addColumn<QString>(name: "cipherText");
661 QTest::addColumn<QString>(name: "keyText");
662 QTest::addColumn<QString>(name: "ivText");
663
664 QTest::newRow(dataTag: "1") << QStringLiteral(
665 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
666 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
667 << QStringLiteral(
668 "4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac"
669 "3df102e008b0e27988598881d920a9e64f5615cd")
670 << QStringLiteral("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b")
671 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
672}
673
674void CipherUnitTest::aes192_cbc()
675{
676 bool anyProviderTested = false;
677 foreach (const QString provider, providersToTest) {
678 if (QCA::isSupported(features: "aes192-cbc", provider)) {
679 anyProviderTested = true;
680 QFETCH(QString, plainText);
681 QFETCH(QString, cipherText);
682 QFETCH(QString, keyText);
683 QFETCH(QString, ivText);
684
685 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
686 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
687 QCA::Cipher forwardCipher(
688 QStringLiteral("aes192"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
689 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
690 QVERIFY(forwardCipher.ok());
691 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
692 QVERIFY(forwardCipher.ok());
693
694 QCA::Cipher reverseCipher(
695 QStringLiteral("aes192"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
696 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
697 QVERIFY(reverseCipher.ok());
698 QCOMPARE(update, plainText.left(update.size()));
699 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
700 QVERIFY(reverseCipher.ok());
701 }
702 }
703 if (!anyProviderTested)
704 qWarning() << "NONE of the providers supports AES192 CBC:" << providersToTest;
705}
706
707// These were generated using OpenSSL's enc command
708void CipherUnitTest::aes192_cbc_pkcs7_data()
709{
710 QTest::addColumn<QString>(name: "plainText");
711 QTest::addColumn<QString>(name: "cipherText");
712 QTest::addColumn<QString>(name: "keyText");
713 QTest::addColumn<QString>(name: "ivText");
714
715 QTest::newRow(dataTag: "1") << QString(QLatin1String("")) << QStringLiteral("49c1da70f461d1bb5147ded60f0f01ef")
716 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF0011223344556677")
717 << QStringLiteral("00001111222233334444555566667777");
718
719 QTest::newRow(dataTag: "2") << QStringLiteral("610a") << QStringLiteral("42e5a030df8b6bf896899853744e480c")
720 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF0011223344556677")
721 << QStringLiteral("00001111222233334444555566667777");
722
723 QTest::newRow(dataTag: "3") << QStringLiteral("6162636465666768696a0a") << QStringLiteral("160a3b6ff48d6850906ffa6b8291f511")
724 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF0011223344556677")
725 << QStringLiteral("00001111222233334444555566667777");
726
727 QTest::newRow(dataTag: "block size - 1") << QStringLiteral("6162636465666768696a6b6c6d6e0a")
728 << QStringLiteral("b113c5aec849e49dc8487f66ce29bab0")
729 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF0011223344556677")
730 << QStringLiteral("00001111222233334444555566667777");
731
732 QTest::newRow(dataTag: "block size") << QStringLiteral("6162636465666768696a6b6c6d6e310a")
733 << QStringLiteral("80c4a001f93c468b7dd3525cc46020b470e3ac39a13be57ab18c7903d121a266")
734 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF0011223344556677")
735 << QStringLiteral("00001111222233334444555566667777");
736
737 QTest::newRow(dataTag: "block size+1") << QStringLiteral("6162636465666768696a6b6c6d6e6f310a")
738 << QStringLiteral("f0f9982e4118287cda37062f5acfd7b2f27741ddac7bd3882c7b4e4872b81047")
739 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF0011223344556677")
740 << QStringLiteral("00001111222233334444555566667777");
741}
742
743void CipherUnitTest::aes192_cbc_pkcs7()
744{
745 bool anyProviderTested = false;
746 foreach (const QString provider, providersToTest) {
747 if (QCA::isSupported(features: "aes192-cbc-pkcs7", provider)) {
748 anyProviderTested = true;
749 QFETCH(QString, plainText);
750 QFETCH(QString, cipherText);
751 QFETCH(QString, keyText);
752 QFETCH(QString, ivText);
753
754 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
755 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
756 QCA::Cipher forwardCipher(QStringLiteral("aes192"),
757 QCA::Cipher::CBC,
758 QCA::Cipher::DefaultPadding,
759 QCA::Encode,
760 key,
761 iv,
762 provider);
763 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
764 QVERIFY(forwardCipher.ok());
765 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
766 QVERIFY(forwardCipher.ok());
767
768 QCA::Cipher reverseCipher(QStringLiteral("aes192"),
769 QCA::Cipher::CBC,
770 QCA::Cipher::DefaultPadding,
771 QCA::Decode,
772 key,
773 iv,
774 provider);
775 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
776 QVERIFY(reverseCipher.ok());
777 QCOMPARE(update, plainText.left(update.size()));
778 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
779 QVERIFY(reverseCipher.ok());
780 }
781 }
782 if (!anyProviderTested)
783 qWarning() << "NONE of the providers supports AES192 CBC with PKCS7 padding:" << providersToTest;
784}
785
786// This is from the Botan test suite
787void CipherUnitTest::aes192_cfb_data()
788{
789 QTest::addColumn<QString>(name: "plainText");
790 QTest::addColumn<QString>(name: "cipherText");
791 QTest::addColumn<QString>(name: "keyText");
792 QTest::addColumn<QString>(name: "ivText");
793
794 QTest::newRow(dataTag: "1") << QStringLiteral(
795 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
796 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
797 << QStringLiteral(
798 "cdc80d6fddf18cab34c25909c99a417467ce7f7f81173621961a2b70171d3d7a2e1e8a1dd59b88b1c8e60fed"
799 "1efac4c9c05f9f9ca9834fa042ae8fba584b09ff")
800 << QStringLiteral("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b")
801 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
802}
803
804void CipherUnitTest::aes192_cfb()
805{
806 bool anyProviderTested = false;
807 foreach (const QString provider, providersToTest) {
808 if (QCA::isSupported(features: "aes192-cfb", provider)) {
809 anyProviderTested = true;
810 QFETCH(QString, plainText);
811 QFETCH(QString, cipherText);
812 QFETCH(QString, keyText);
813 QFETCH(QString, ivText);
814
815 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
816 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
817 QCA::Cipher forwardCipher(
818 QStringLiteral("aes192"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
819 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
820 QVERIFY(forwardCipher.ok());
821 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
822 QVERIFY(forwardCipher.ok());
823
824 QCA::Cipher reverseCipher(
825 QStringLiteral("aes192"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
826 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
827 QVERIFY(reverseCipher.ok());
828 QCOMPARE(update, plainText.left(update.size()));
829 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
830 QVERIFY(reverseCipher.ok());
831 }
832 }
833 if (!anyProviderTested)
834 qWarning() << "NONE of the providers supports AES192 CFB:" << providersToTest;
835}
836
837// This is from the Botan test suite
838void CipherUnitTest::aes192_ofb_data()
839{
840 QTest::addColumn<QString>(name: "plainText");
841 QTest::addColumn<QString>(name: "cipherText");
842 QTest::addColumn<QString>(name: "keyText");
843 QTest::addColumn<QString>(name: "ivText");
844
845 QTest::newRow(dataTag: "1") << QStringLiteral(
846 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
847 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
848 << QStringLiteral(
849 "cdc80d6fddf18cab34c25909c99a4174fcc28b8d4c63837c09e81700c11004018d9a9aeac0f6596f559c6d4d"
850 "af59a5f26d9f200857ca6c3e9cac524bd9acc92a")
851 << QStringLiteral("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b")
852 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
853}
854
855void CipherUnitTest::aes192_ofb()
856{
857 bool anyProviderTested = false;
858 foreach (const QString provider, providersToTest) {
859 if (QCA::isSupported(features: "aes192-ofb", provider)) {
860 anyProviderTested = true;
861 QFETCH(QString, plainText);
862 QFETCH(QString, cipherText);
863 QFETCH(QString, keyText);
864 QFETCH(QString, ivText);
865
866 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
867 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
868 QCA::Cipher forwardCipher(
869 QStringLiteral("aes192"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
870 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
871 QVERIFY(forwardCipher.ok());
872 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
873 QVERIFY(forwardCipher.ok());
874
875 QCA::Cipher reverseCipher(
876 QStringLiteral("aes192"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
877 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
878 QVERIFY(reverseCipher.ok());
879 QCOMPARE(update, plainText.left(update.size()));
880 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
881 QVERIFY(reverseCipher.ok());
882 }
883 }
884 if (!anyProviderTested)
885 qWarning() << "NONE of the providers supports AES192 OFB:" << providersToTest;
886}
887
888void CipherUnitTest::aes192_ctr_data()
889{
890 QTest::addColumn<QString>(name: "plainText");
891 QTest::addColumn<QString>(name: "cipherText");
892 QTest::addColumn<QString>(name: "keyText");
893 QTest::addColumn<QString>(name: "ivText");
894
895 QTest::newRow(dataTag: "1") << QStringLiteral(
896 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
897 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
898 << QStringLiteral(
899 "cdc80d6fddf18cab34c25909c99a417437d8a639171fdcca63ebd17ce2d7321a79a0c96b53c7eeecd9ed7157"
900 "c444fc7a845c37b2f511697b0e89d5ed60c4d49e")
901 << QStringLiteral("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b")
902 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
903}
904
905void CipherUnitTest::aes192_ctr()
906{
907 bool anyProviderTested = false;
908 foreach (const QString provider, providersToTest) {
909 if (QCA::isSupported(features: "aes192-ctr", provider)) {
910 anyProviderTested = true;
911 QFETCH(QString, plainText);
912 QFETCH(QString, cipherText);
913 QFETCH(QString, keyText);
914 QFETCH(QString, ivText);
915
916 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
917 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
918 QCA::Cipher forwardCipher(
919 QStringLiteral("aes192"), QCA::Cipher::CTR, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
920 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
921 QVERIFY(forwardCipher.ok());
922 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
923 QVERIFY(forwardCipher.ok());
924
925 QCA::Cipher reverseCipher(
926 QStringLiteral("aes192"), QCA::Cipher::CTR, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
927 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
928 QVERIFY(reverseCipher.ok());
929 QCOMPARE(update, plainText.left(update.size()));
930 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
931 QVERIFY(reverseCipher.ok());
932 }
933 }
934 if (!anyProviderTested)
935 qWarning() << "NONE of the providers supports AES192 CTR:" << providersToTest;
936}
937
938void CipherUnitTest::aes192_gcm_data()
939{
940 QTest::addColumn<QString>(name: "plainText");
941 QTest::addColumn<QString>(name: "payload");
942 QTest::addColumn<QString>(name: "tag");
943 QTest::addColumn<QString>(name: "keyText");
944 QTest::addColumn<QString>(name: "ivText");
945
946 QTest::newRow(dataTag: "short") << QStringLiteral("6f6820526f6d656d6f21") << QStringLiteral("01ca25ff74121917f397")
947 << QStringLiteral("b90e97706d8eacbabc0be5e0a671b4e4")
948 << QStringLiteral("7ecb21a647fae54a0996ad281ab0c1a00cb905d9e2eb3b82")
949 << QStringLiteral("f85f8aad39164daf64a12ad9b3fc8a3a");
950
951 QTest::newRow(dataTag: "long") << QStringLiteral(
952 "54484520515549434b2042524f574e20464f58204a554d504544204f56455220544845204c415a5920444"
953 "f472753204241434b2031323334353637383930")
954 << QStringLiteral(
955 "4c1c5874877f0bee6efd450ec341b1c591e1e100da40bd4744e1035ed0ed0fb458f8efdb7c4b0b2101e29"
956 "c950c56dc2489c2febec2d7062da28b9a033173")
957 << QStringLiteral("af3ea1b7f275ea1e4d4e1fdce63f83fe")
958 << QStringLiteral("7ecb21a647fae54a0996ad281ab0c1a00cb905d9e2eb3b82")
959 << QStringLiteral("bfcd3a7252f7f199bf788df8cf61032a");
960
961 QTest::newRow(dataTag: "wrongtag") << QStringLiteral("6f6820526f6d656d6f21") << QStringLiteral("773c3d06b94727c04afc")
962 << QStringLiteral("c558aca7f19050db49d94d99119277af")
963 << QStringLiteral("7ecb21a647fae54a0996ad281ab0c1a00cb905d9e2eb3b82")
964 << QStringLiteral("bfcd3a7252f7f199bf788df8cf61032a");
965}
966
967void CipherUnitTest::aes192_gcm()
968{
969 bool anyProviderTested = false;
970 foreach (const QString &provider, providersToTest) {
971 if (QCA::isSupported(features: "aes192-gcm", provider)) {
972 anyProviderTested = true;
973 QFETCH(QString, plainText);
974 QFETCH(QString, payload);
975 QFETCH(QString, tag);
976 QFETCH(QString, keyText);
977 QFETCH(QString, ivText);
978
979 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
980 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
981 QCA::AuthTag authTag(16);
982 QCA::Cipher forwardCipher(QStringLiteral("aes192"),
983 QCA::Cipher::GCM,
984 QCA::Cipher::NoPadding,
985 QCA::Encode,
986 key,
987 iv,
988 authTag,
989 provider);
990 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
991 QVERIFY(forwardCipher.ok());
992 update += QCA::arrayToHex(array: forwardCipher.final().toByteArray());
993 authTag = forwardCipher.tag();
994 QEXPECT_FAIL("wrongtag", "It's OK", Continue);
995 QCOMPARE(QCA::arrayToHex(authTag.toByteArray()), tag);
996 QCOMPARE(update, payload);
997 QVERIFY(forwardCipher.ok());
998
999 QCA::Cipher reverseCipher(QStringLiteral("aes192"),
1000 QCA::Cipher::GCM,
1001 QCA::Cipher::NoPadding,
1002 QCA::Decode,
1003 key,
1004 iv,
1005 QCA::AuthTag(QCA::hexToArray(hexString: tag)),
1006 provider);
1007
1008 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: payload)).toByteArray());
1009 QVERIFY(reverseCipher.ok());
1010 QCOMPARE(update, plainText.left(update.size()));
1011 update += QCA::arrayToHex(array: reverseCipher.final().toByteArray());
1012 QEXPECT_FAIL("wrongtag", "It's OK", Continue);
1013 QCOMPARE(update, plainText);
1014 QEXPECT_FAIL("wrongtag", "It's OK", Continue);
1015 QVERIFY(reverseCipher.ok());
1016 }
1017 }
1018 if (!anyProviderTested)
1019 qWarning() << "NONE of the providers supports AES192 GCM:" << providersToTest;
1020}
1021
1022void CipherUnitTest::aes192_ccm_data()
1023{
1024}
1025
1026void CipherUnitTest::aes192_ccm()
1027{
1028 // For future implementation
1029}
1030
1031void CipherUnitTest::aes256_data()
1032{
1033 QTest::addColumn<QString>(name: "plainText");
1034 QTest::addColumn<QString>(name: "cipherText");
1035 QTest::addColumn<QString>(name: "keyText");
1036
1037 // From FIPS 197 Appendix C.3
1038 QTest::newRow(dataTag: "FIPS197 App C.3") << QStringLiteral("00112233445566778899aabbccddeeff")
1039 << QStringLiteral("8ea2b7ca516745bfeafc49904b496089")
1040 << QStringLiteral(
1041 "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
1042
1043 // These are from the Botan test suite
1044 QTest::newRow(dataTag: "1") << QStringLiteral("e51aa0b135dba566939c3b6359a980c5")
1045 << QStringLiteral("8cd9423dfc459e547155c5d1d522e540")
1046 << QStringLiteral("e0e1e2e3e5e6e7e8eaebecedeff0f1f2f4f5f6f7f9fafbfcfefe010103040506");
1047
1048 QTest::newRow(dataTag: "2") << QStringLiteral("069a007fc76a459f98baf917fedf9521")
1049 << QStringLiteral("080e9517eb1677719acf728086040ae3")
1050 << QStringLiteral("08090a0b0d0e0f10121314151718191a1c1d1e1f21222324262728292b2c2d2e");
1051
1052 QTest::newRow(dataTag: "3") << QStringLiteral("726165c1723fbcf6c026d7d00b091027")
1053 << QStringLiteral("7c1700211a3991fc0ecded0ab3e576b0")
1054 << QStringLiteral("30313233353637383a3b3c3d3f40414244454647494a4b4c4e4f505153545556");
1055
1056 QTest::newRow(dataTag: "4") << QStringLiteral("d7c544de91d55cfcde1f84ca382200ce")
1057 << QStringLiteral("dabcbcc855839251db51e224fbe87435")
1058 << QStringLiteral("58595a5b5d5e5f60626364656768696a6c6d6e6f71727374767778797b7c7d7e");
1059
1060 QTest::newRow(dataTag: "5") << QStringLiteral("fed3c9a161b9b5b2bd611b41dc9da357")
1061 << QStringLiteral("68d56fad0406947a4dd27a7448c10f1d")
1062 << QStringLiteral("80818283858687888a8b8c8d8f90919294959697999a9b9c9e9fa0a1a3a4a5a6");
1063
1064 QTest::newRow(dataTag: "6") << QStringLiteral("4f634cdc6551043409f30b635832cf82")
1065 << QStringLiteral("da9a11479844d1ffee24bbf3719a9925")
1066 << QStringLiteral("a8a9aaabadaeafb0b2b3b4b5b7b8b9babcbdbebfc1c2c3c4c6c7c8c9cbcccdce");
1067
1068 QTest::newRow(dataTag: "7") << QStringLiteral("109ce98db0dfb36734d9f3394711b4e6")
1069 << QStringLiteral("5e4ba572f8d23e738da9b05ba24b8d81")
1070 << QStringLiteral("d0d1d2d3d5d6d7d8dadbdcdddfe0e1e2e4e5e6e7e9eaebeceeeff0f1f3f4f5f6");
1071
1072 QTest::newRow(dataTag: "8") << QStringLiteral("4ea6dfaba2d8a02ffdffa89835987242")
1073 << QStringLiteral("a115a2065d667e3f0b883837a6e903f8")
1074 << QStringLiteral("70717273757677787a7b7c7d7f80818284858687898a8b8c8e8f909193949596");
1075
1076 QTest::newRow(dataTag: "9") << QStringLiteral("5ae094f54af58e6e3cdbf976dac6d9ef")
1077 << QStringLiteral("3e9e90dc33eac2437d86ad30b137e66e")
1078 << QStringLiteral("98999a9b9d9e9fa0a2a3a4a5a7a8a9aaacadaeafb1b2b3b4b6b7b8b9bbbcbdbe");
1079
1080 QTest::newRow(dataTag: "10") << QStringLiteral("764d8e8e0f29926dbe5122e66354fdbe")
1081 << QStringLiteral("01ce82d8fbcdae824cb3c48e495c3692")
1082 << QStringLiteral("c0c1c2c3c5c6c7c8cacbcccdcfd0d1d2d4d5d6d7d9dadbdcdedfe0e1e3e4e5e6");
1083
1084 QTest::newRow(dataTag: "11") << QStringLiteral("3f0418f888cdf29a982bf6b75410d6a9")
1085 << QStringLiteral("0c9cff163ce936faaf083cfd3dea3117")
1086 << QStringLiteral("e8e9eaebedeeeff0f2f3f4f5f7f8f9fafcfdfeff01020304060708090b0c0d0e");
1087
1088 QTest::newRow(dataTag: "12") << QStringLiteral("e4a3e7cb12cdd56aa4a75197a9530220")
1089 << QStringLiteral("5131ba9bd48f2bba85560680df504b52")
1090 << QStringLiteral("10111213151617181a1b1c1d1f20212224252627292a2b2c2e2f303133343536");
1091
1092 QTest::newRow(dataTag: "13") << QStringLiteral("211677684aac1ec1a160f44c4ebf3f26")
1093 << QStringLiteral("9dc503bbf09823aec8a977a5ad26ccb2")
1094 << QStringLiteral("38393a3b3d3e3f40424344454748494a4c4d4e4f51525354565758595b5c5d5e");
1095
1096 QTest::newRow(dataTag: "14") << QStringLiteral("d21e439ff749ac8f18d6d4b105e03895")
1097 << QStringLiteral("9a6db0c0862e506a9e397225884041d7")
1098 << QStringLiteral("60616263656667686a6b6c6d6f70717274757677797a7b7c7e7f808183848586");
1099
1100 QTest::newRow(dataTag: "15") << QStringLiteral("d9f6ff44646c4725bd4c0103ff5552a7")
1101 << QStringLiteral("430bf9570804185e1ab6365fc6a6860c")
1102 << QStringLiteral("88898a8b8d8e8f90929394959798999a9c9d9e9fa1a2a3a4a6a7a8a9abacadae");
1103
1104 QTest::newRow(dataTag: "16") << QStringLiteral("0b1256c2a00b976250cfc5b0c37ed382")
1105 << QStringLiteral("3525ebc02f4886e6a5a3762813e8ce8a")
1106 << QStringLiteral("b0b1b2b3b5b6b7b8babbbcbdbfc0c1c2c4c5c6c7c9cacbcccecfd0d1d3d4d5d6");
1107
1108 QTest::newRow(dataTag: "17") << QStringLiteral("b056447ffc6dc4523a36cc2e972a3a79")
1109 << QStringLiteral("07fa265c763779cce224c7bad671027b")
1110 << QStringLiteral("d8d9dadbdddedfe0e2e3e4e5e7e8e9eaecedeeeff1f2f3f4f6f7f8f9fbfcfdfe");
1111
1112 QTest::newRow(dataTag: "18") << QStringLiteral("5e25ca78f0de55802524d38da3fe4456")
1113 << QStringLiteral("e8b72b4e8be243438c9fff1f0e205872")
1114 << QStringLiteral("00010203050607080a0b0c0d0f10111214151617191a1b1c1e1f202123242526");
1115
1116 QTest::newRow(dataTag: "19") << QStringLiteral("a5bcf4728fa5eaad8567c0dc24675f83")
1117 << QStringLiteral("109d4f999a0e11ace1f05e6b22cbcb50")
1118 << QStringLiteral("28292a2b2d2e2f30323334353738393a3c3d3e3f41424344464748494b4c4d4e");
1119
1120 QTest::newRow(dataTag: "20") << QStringLiteral("814e59f97ed84646b78b2ca022e9ca43")
1121 << QStringLiteral("45a5e8d4c3ed58403ff08d68a0cc4029")
1122 << QStringLiteral("50515253555657585a5b5c5d5f60616264656667696a6b6c6e6f707173747576");
1123
1124 QTest::newRow(dataTag: "21") << QStringLiteral("15478beec58f4775c7a7f5d4395514d7")
1125 << QStringLiteral("196865964db3d417b6bd4d586bcb7634")
1126 << QStringLiteral("78797a7b7d7e7f80828384858788898a8c8d8e8f91929394969798999b9c9d9e");
1127}
1128
1129void CipherUnitTest::aes256()
1130{
1131 bool anyProviderTested = false;
1132 foreach (const QString provider, providersToTest) {
1133 if (QCA::isSupported(features: "aes256-ecb", provider)) {
1134 anyProviderTested = true;
1135 QFETCH(QString, plainText);
1136 QFETCH(QString, cipherText);
1137 QFETCH(QString, keyText);
1138
1139 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
1140 QCA::Cipher forwardCipher(QStringLiteral("aes256"),
1141 QCA::Cipher::ECB,
1142 QCA::Cipher::NoPadding,
1143 QCA::Encode,
1144 key,
1145 QCA::InitializationVector(),
1146 provider);
1147
1148 QCOMPARE(forwardCipher.blockSize(), 16);
1149 QCOMPARE(forwardCipher.keyLength().minimum(), 32);
1150 QCOMPARE(forwardCipher.keyLength().maximum(), 32);
1151
1152 QString afterEncodeText = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
1153 QVERIFY(forwardCipher.ok());
1154
1155 afterEncodeText += QCA::arrayToHex(array: forwardCipher.final().toByteArray());
1156 QVERIFY(forwardCipher.ok());
1157
1158 QCOMPARE(afterEncodeText, cipherText);
1159
1160 QCA::Cipher reverseCipher(QStringLiteral("aes256"),
1161 QCA::Cipher::ECB,
1162 QCA::Cipher::NoPadding,
1163 QCA::Decode,
1164 key,
1165 QCA::InitializationVector(),
1166 provider);
1167
1168 QCOMPARE(reverseCipher.blockSize(), 16);
1169 QCOMPARE(reverseCipher.keyLength().minimum(), 32);
1170 QCOMPARE(reverseCipher.keyLength().maximum(), 32);
1171
1172 QString afterDecodeText = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
1173 QVERIFY(reverseCipher.ok());
1174
1175 afterDecodeText += QCA::arrayToHex(array: reverseCipher.final().toByteArray());
1176 QVERIFY(reverseCipher.ok());
1177
1178 QCOMPARE(afterDecodeText, plainText);
1179 }
1180 }
1181 if (!anyProviderTested)
1182 qWarning() << "NONE of the providers supports AES256 ECB:" << providersToTest;
1183}
1184
1185// These are from the Botan test suite
1186void CipherUnitTest::aes256_cbc_data()
1187{
1188 QTest::addColumn<QString>(name: "plainText");
1189 QTest::addColumn<QString>(name: "cipherText");
1190 QTest::addColumn<QString>(name: "keyText");
1191 QTest::addColumn<QString>(name: "ivText");
1192
1193 QTest::newRow(dataTag: "1") << QStringLiteral(
1194 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
1195 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
1196 << QStringLiteral(
1197 "f58c4c04d6e5f1ba779eabfb5f7bfbd69cfc4e967edb808d679f777bc6702c7d39f23369a9d9bacfa530e263"
1198 "04231461b2eb05e2c39be9fcda6c19078c6a9d1b")
1199 << QStringLiteral("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")
1200 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
1201}
1202
1203void CipherUnitTest::aes256_cbc()
1204{
1205 bool anyProviderTested = false;
1206 foreach (const QString provider, providersToTest) {
1207 if (QCA::isSupported(features: "aes256-cbc", provider)) {
1208 anyProviderTested = true;
1209 QFETCH(QString, plainText);
1210 QFETCH(QString, cipherText);
1211 QFETCH(QString, keyText);
1212 QFETCH(QString, ivText);
1213
1214 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
1215 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
1216 QCA::Cipher forwardCipher(
1217 QStringLiteral("aes256"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
1218 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
1219 QVERIFY(forwardCipher.ok());
1220 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
1221 QVERIFY(forwardCipher.ok());
1222
1223 QCA::Cipher reverseCipher(
1224 QStringLiteral("aes256"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
1225
1226 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
1227 QVERIFY(reverseCipher.ok());
1228 QCOMPARE(update, plainText.left(update.size()));
1229 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
1230 QVERIFY(reverseCipher.ok());
1231 }
1232 }
1233 if (!anyProviderTested)
1234 qWarning() << "NONE of the providers supports AES256 CBC:" << providersToTest;
1235}
1236
1237// These were generated using OpenSSL's enc command
1238void CipherUnitTest::aes256_cbc_pkcs7_data()
1239{
1240 QTest::addColumn<QString>(name: "plainText");
1241 QTest::addColumn<QString>(name: "cipherText");
1242 QTest::addColumn<QString>(name: "keyText");
1243 QTest::addColumn<QString>(name: "ivText");
1244
1245 QTest::newRow(dataTag: "1") << QString(QLatin1String("")) << QStringLiteral("99fac653629ddb546d65ac699d7323ba")
1246 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF00112233445566778899AABBCCDDEEFF")
1247 << QStringLiteral("00001111222233334444555566667777");
1248
1249 QTest::newRow(dataTag: "2") << QStringLiteral("610a") << QStringLiteral("1dd0366efe719f6bf0e2c30e8cc168fd")
1250 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF00112233445566778899AABBCCDDEEFF")
1251 << QStringLiteral("00001111222233334444555566667777");
1252
1253 QTest::newRow(dataTag: "3") << QStringLiteral("6162636465666768696a0a") << QStringLiteral("a433fb0dc673093f726d748c8f76cf0d")
1254 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF00112233445566778899AABBCCDDEEFF")
1255 << QStringLiteral("00001111222233334444555566667777");
1256
1257 QTest::newRow(dataTag: "block size - 1") << QStringLiteral("6162636465666768696a6b6c6d6e0a")
1258 << QStringLiteral("b5cfa68d21ad91649eafc35dee06f007")
1259 << QStringLiteral(
1260 "0123456789ABCDEF0123456789ABCDEF00112233445566778899AABBCCDDEEFF")
1261 << QStringLiteral("00001111222233334444555566667777");
1262
1263 QTest::newRow(dataTag: "block size") << QStringLiteral("6162636465666768696a6b6c6d6e310a")
1264 << QStringLiteral("45c4b50e4d4433b011187983da5034fe14cf12c04cfc3bceb57a88c455491f46")
1265 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF00112233445566778899AABBCCDDEEFF")
1266 << QStringLiteral("00001111222233334444555566667777");
1267
1268 QTest::newRow(dataTag: "block size+1") << QStringLiteral("6162636465666768696a6b6c6d6e6f310a")
1269 << QStringLiteral("4ef5702f0c16bbfda9b57e6e98186763325c81c99b6cdd8e4bc34dcaa82d00e9")
1270 << QStringLiteral("0123456789ABCDEF0123456789ABCDEF00112233445566778899AABBCCDDEEFF")
1271 << QStringLiteral("00001111222233334444555566667777");
1272}
1273
1274void CipherUnitTest::aes256_cbc_pkcs7()
1275{
1276 bool anyProviderTested = false;
1277 foreach (const QString provider, providersToTest) {
1278 if (QCA::isSupported(features: "aes256-cbc-pkcs7", provider)) {
1279 anyProviderTested = true;
1280 QFETCH(QString, plainText);
1281 QFETCH(QString, cipherText);
1282 QFETCH(QString, keyText);
1283 QFETCH(QString, ivText);
1284
1285 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
1286 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
1287 QCA::Cipher forwardCipher(QStringLiteral("aes256"),
1288 QCA::Cipher::CBC,
1289 QCA::Cipher::DefaultPadding,
1290 QCA::Encode,
1291 key,
1292 iv,
1293 provider);
1294 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
1295 QVERIFY(forwardCipher.ok());
1296 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
1297 QVERIFY(forwardCipher.ok());
1298
1299 QCA::Cipher reverseCipher(QStringLiteral("aes256"),
1300 QCA::Cipher::CBC,
1301 QCA::Cipher::DefaultPadding,
1302 QCA::Decode,
1303 key,
1304 iv,
1305 provider);
1306 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
1307 QVERIFY(reverseCipher.ok());
1308 QCOMPARE(update, plainText.left(update.size()));
1309 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
1310 QVERIFY(reverseCipher.ok());
1311 }
1312 }
1313 if (!anyProviderTested)
1314 qWarning() << "NONE of the providers supports AES256 CBC with PKCS7 padding:" << providersToTest;
1315}
1316
1317// These are from the Botan test suite
1318void CipherUnitTest::aes256_cfb_data()
1319{
1320 QTest::addColumn<QString>(name: "plainText");
1321 QTest::addColumn<QString>(name: "cipherText");
1322 QTest::addColumn<QString>(name: "keyText");
1323 QTest::addColumn<QString>(name: "ivText");
1324
1325 QTest::newRow(dataTag: "1") << QStringLiteral(
1326 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
1327 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
1328 << QStringLiteral(
1329 "dc7e84bfda79164b7ecd8486985d386039ffed143b28b1c832113c6331e5407bdf10132415e54b92a13ed0a8"
1330 "267ae2f975a385741ab9cef82031623d55b1e471")
1331 << QStringLiteral("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")
1332 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
1333}
1334
1335void CipherUnitTest::aes256_cfb()
1336{
1337 bool anyProviderTested = false;
1338 foreach (const QString provider, providersToTest) {
1339 if (QCA::isSupported(features: "aes256-cfb", provider)) {
1340 anyProviderTested = true;
1341 QFETCH(QString, plainText);
1342 QFETCH(QString, cipherText);
1343 QFETCH(QString, keyText);
1344 QFETCH(QString, ivText);
1345
1346 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
1347 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
1348 QCA::Cipher forwardCipher(
1349 QStringLiteral("aes256"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
1350 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
1351 QVERIFY(forwardCipher.ok());
1352 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
1353 QVERIFY(forwardCipher.ok());
1354
1355 QCA::Cipher reverseCipher(
1356 QStringLiteral("aes256"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
1357
1358 QCOMPARE(QCA::arrayToHex(reverseCipher.update(QCA::hexToArray(cipherText)).toByteArray()), plainText);
1359 QVERIFY(reverseCipher.ok());
1360 QCOMPARE(QCA::arrayToHex(reverseCipher.final().toByteArray()), QLatin1String(""));
1361 QVERIFY(reverseCipher.ok());
1362 }
1363 }
1364 if (!anyProviderTested)
1365 qWarning() << "NONE of the providers supports AES256 CFB:" << providersToTest;
1366}
1367
1368void CipherUnitTest::aes256_ofb_data()
1369{
1370 QTest::addColumn<QString>(name: "plainText");
1371 QTest::addColumn<QString>(name: "cipherText");
1372 QTest::addColumn<QString>(name: "keyText");
1373 QTest::addColumn<QString>(name: "ivText");
1374
1375 QTest::newRow(dataTag: "1") << QStringLiteral(
1376 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
1377 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
1378 << QStringLiteral(
1379 "dc7e84bfda79164b7ecd8486985d38604febdc6740d20b3ac88f6ad82a4fb08d71ab47a086e86eedf39d1c5b"
1380 "ba97c4080126141d67f37be8538f5a8be740e484")
1381 << QStringLiteral("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")
1382 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
1383}
1384
1385void CipherUnitTest::aes256_ofb()
1386{
1387 bool anyProviderTested = false;
1388 foreach (const QString provider, providersToTest) {
1389 if (QCA::isSupported(features: "aes256-ofb", provider)) {
1390 anyProviderTested = true;
1391 QFETCH(QString, plainText);
1392 QFETCH(QString, cipherText);
1393 QFETCH(QString, keyText);
1394 QFETCH(QString, ivText);
1395
1396 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
1397 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
1398 QCA::Cipher forwardCipher(
1399 QStringLiteral("aes256"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
1400 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
1401 QVERIFY(forwardCipher.ok());
1402 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
1403 QVERIFY(forwardCipher.ok());
1404
1405 QCA::Cipher reverseCipher(
1406 QStringLiteral("aes256"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
1407
1408 QCOMPARE(QCA::arrayToHex(reverseCipher.update(QCA::hexToArray(cipherText)).toByteArray()), plainText);
1409 QVERIFY(reverseCipher.ok());
1410 QCOMPARE(QCA::arrayToHex(reverseCipher.final().toByteArray()), QLatin1String(""));
1411 QVERIFY(reverseCipher.ok());
1412 }
1413 }
1414 if (!anyProviderTested)
1415 qWarning() << "NONE of the providers supports AES256 OFB:" << providersToTest;
1416}
1417
1418void CipherUnitTest::aes256_ctr_data()
1419{
1420 QTest::addColumn<QString>(name: "plainText");
1421 QTest::addColumn<QString>(name: "cipherText");
1422 QTest::addColumn<QString>(name: "keyText");
1423 QTest::addColumn<QString>(name: "ivText");
1424
1425 QTest::newRow(dataTag: "1") << QStringLiteral(
1426 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc119"
1427 "1a0a52eff69f2445df4f9b17ad2b417be66c3710")
1428 << QStringLiteral(
1429 "dc7e84bfda79164b7ecd8486985d3860d577788b8d8a85745513a5d50f821f30ffe96d5cf54b238dcc8d6783"
1430 "a87f3beae9af546344cb9ca4d1e553ffc06bc73e")
1431 << QStringLiteral("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")
1432 << QStringLiteral("000102030405060708090a0b0c0d0e0f");
1433}
1434
1435void CipherUnitTest::aes256_ctr()
1436{
1437 bool anyProviderTested = false;
1438 foreach (const QString provider, providersToTest) {
1439 if (QCA::isSupported(features: "aes256-ctr", provider)) {
1440 anyProviderTested = true;
1441 QFETCH(QString, plainText);
1442 QFETCH(QString, cipherText);
1443 QFETCH(QString, keyText);
1444 QFETCH(QString, ivText);
1445
1446 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
1447 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
1448 QCA::Cipher forwardCipher(
1449 QStringLiteral("aes256"), QCA::Cipher::CTR, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
1450 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
1451 QVERIFY(forwardCipher.ok());
1452 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
1453 QVERIFY(forwardCipher.ok());
1454
1455 QCA::Cipher reverseCipher(
1456 QStringLiteral("aes256"), QCA::Cipher::CTR, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
1457
1458 QCOMPARE(QCA::arrayToHex(reverseCipher.update(QCA::hexToArray(cipherText)).toByteArray()), plainText);
1459 QVERIFY(reverseCipher.ok());
1460 QCOMPARE(QCA::arrayToHex(reverseCipher.final().toByteArray()), QLatin1String(""));
1461 QVERIFY(reverseCipher.ok());
1462 }
1463 }
1464 if (!anyProviderTested)
1465 qWarning() << "NONE of the providers supports AES256 CTR:" << providersToTest;
1466}
1467
1468void CipherUnitTest::aes256_gcm_data()
1469{
1470 QTest::addColumn<QString>(name: "plainText");
1471 QTest::addColumn<QString>(name: "payload");
1472 QTest::addColumn<QString>(name: "tag");
1473 QTest::addColumn<QString>(name: "keyText");
1474 QTest::addColumn<QString>(name: "ivText");
1475
1476 QTest::newRow(dataTag: "short") << QStringLiteral("6f6820526f6d656d6f21") << QStringLiteral("4ce2f4df041252820847")
1477 << QStringLiteral("1c570805832dfe7babc1b386c26bcd04")
1478 << QStringLiteral("3fa609690bf07a81a75839b0a4c0add774f54eb804d4f02df488691910298b04")
1479 << QStringLiteral("f85f8aad39164daf64a12ad9b3fc8a3a");
1480
1481 QTest::newRow(dataTag: "long") << QStringLiteral(
1482 "54484520515549434b2042524f574e20464f58204a554d504544204f56455220544845204c415a5920444"
1483 "f472753204241434b2031323334353637383930")
1484 << QStringLiteral(
1485 "e516c267146d6cfd3af3300e24aba7ac23ab3c5cb4765937a6c0156e454cae357e14f4c0dfb0def9624f4"
1486 "f70de90ad2bc9cd555171c4551c26b6346922ed")
1487 << QStringLiteral("f59aac31ab9dace3fcc693e114dd6610")
1488 << QStringLiteral("3fa609690bf07a81a75839b0a4c0add774f54eb804d4f02df488691910298b04")
1489 << QStringLiteral("bfcd3a7252f7f199bf788df8cf61032a");
1490
1491 QTest::newRow(dataTag: "wrongtag") << QStringLiteral("6f6820526f6d656d6f21") << QStringLiteral("4ce2f4df041252820847")
1492 << QStringLiteral("1c570805833dfe7babc1b386c26bcd04")
1493 << QStringLiteral("3fa609690bf07a81a75839b0a4c0add774f54eb804d4f02df488691910298b04")
1494 << QStringLiteral("f85f8aad39164daf64a12ad9b3fc8a3a");
1495}
1496
1497void CipherUnitTest::aes256_gcm()
1498{
1499 bool anyProviderTested = false;
1500 foreach (const QString &provider, providersToTest) {
1501 if (QCA::isSupported(features: "aes256-gcm", provider)) {
1502 anyProviderTested = true;
1503 QFETCH(QString, plainText);
1504 QFETCH(QString, payload);
1505 QFETCH(QString, tag);
1506 QFETCH(QString, keyText);
1507 QFETCH(QString, ivText);
1508
1509 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
1510 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
1511 QCA::AuthTag authTag(16);
1512 QCA::Cipher forwardCipher(QStringLiteral("aes256"),
1513 QCA::Cipher::GCM,
1514 QCA::Cipher::NoPadding,
1515 QCA::Encode,
1516 key,
1517 iv,
1518 authTag,
1519 provider);
1520 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
1521 QVERIFY(forwardCipher.ok());
1522 update += QCA::arrayToHex(array: forwardCipher.final().toByteArray());
1523 authTag = forwardCipher.tag();
1524 QEXPECT_FAIL("wrongtag", "It's OK", Continue);
1525 QCOMPARE(QCA::arrayToHex(authTag.toByteArray()), tag);
1526 QCOMPARE(update, payload);
1527 QVERIFY(forwardCipher.ok());
1528
1529 QCA::Cipher reverseCipher(QStringLiteral("aes256"),
1530 QCA::Cipher::GCM,
1531 QCA::Cipher::NoPadding,
1532 QCA::Decode,
1533 key,
1534 iv,
1535 QCA::AuthTag(QCA::hexToArray(hexString: tag)),
1536 provider);
1537
1538 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: payload)).toByteArray());
1539 QVERIFY(reverseCipher.ok());
1540 QCOMPARE(update, plainText.left(update.size()));
1541 update += QCA::arrayToHex(array: reverseCipher.final().toByteArray());
1542 QEXPECT_FAIL("wrongtag", "It's OK", Continue);
1543 QCOMPARE(update, plainText);
1544 QEXPECT_FAIL("wrongtag", "It's OK", Continue);
1545 QVERIFY(reverseCipher.ok());
1546 }
1547 }
1548 if (!anyProviderTested)
1549 qWarning() << "NONE of the providers supports AES256 GCM:" << providersToTest;
1550}
1551
1552void CipherUnitTest::aes256_ccm_data()
1553{
1554}
1555
1556void CipherUnitTest::aes256_ccm()
1557{
1558 // For future implementation
1559}
1560
1561void CipherUnitTest::tripleDES_data()
1562{
1563 QTest::addColumn<QString>(name: "plainText");
1564 QTest::addColumn<QString>(name: "cipherText");
1565 QTest::addColumn<QString>(name: "keyText");
1566
1567 QTest::newRow(dataTag: "1") << QStringLiteral("42fd443059577fa2") << QStringLiteral("af37fb421f8c4095")
1568 << QStringLiteral("04b915ba43feb5b604b915ba43feb5b604b915ba43feb5b6");
1569
1570 QTest::newRow(dataTag: "2") << QStringLiteral("736f6d6564617461") << QStringLiteral("18d748e563620572")
1571 << QStringLiteral("0123456789abcdef5555555555555555fedcba9876543210");
1572 QTest::newRow(dataTag: "3") << QStringLiteral("7371756967676c65") << QStringLiteral("c07d2a0fa566fa30")
1573 << QStringLiteral("0352020767208217860287665908219864056abdfea93457");
1574 QTest::newRow(dataTag: "4") << QStringLiteral("0123456789abcde7") << QStringLiteral("de0b7c06ae5e0ed5")
1575 << QStringLiteral("0123456789abcdeffedcba987654321089abcdef01234567");
1576 QTest::newRow(dataTag: "5") << QStringLiteral("0123456789abcde7") << QStringLiteral("7f1d0a77826b8aff")
1577 << QStringLiteral("0123456789abcdeffedcba98765432100123456789abcdef");
1578 QTest::newRow(dataTag: "6") << QStringLiteral("4115e551299a5c4b") << QStringLiteral("f7a0822fc310686c")
1579 << QStringLiteral("1ef743a68d629f68a5e3136c36ad7953a835cf849bb4ec3c");
1580 QTest::newRow(dataTag: "7") << QStringLiteral("d5ab44e0fe46e1b5") << QStringLiteral("02aed9bf72eca222")
1581 << QStringLiteral("b7d560be49c3936728ef0bf57b602d2eb7e5c631dd7f753e");
1582 QTest::newRow(dataTag: "8") << QStringLiteral("b4077dfdb721d88c") << QStringLiteral("f76aba838b1c4372")
1583 << QStringLiteral("d2d98706e9ab867647d244bdcdbcd5ef8b4dbc9cf4f35493");
1584 QTest::newRow(dataTag: "9") << QStringLiteral("890e98ab385fa1a1") << QStringLiteral("187087c77790c3b2")
1585 << QStringLiteral("153b963004101d12683e8f87116001b8c5526475510b5036");
1586 QTest::newRow(dataTag: "10") << QStringLiteral("02d5da6d5f247cd2") << QStringLiteral("89fc7df1e7913163")
1587 << QStringLiteral("45e4275dccc5d8b5a27993c16d9960ca939c023e2763216a");
1588 QTest::newRow(dataTag: "11") << QStringLiteral("5af9e5a3525e3f7d") << QStringLiteral("8fcc7a8bc337e484")
1589 << QStringLiteral("f6c2474b33934ea76e6c841d9b1e86e37189095a895a3e5a");
1590 QTest::newRow(dataTag: "12") << QStringLiteral("12864dde8e694bd1") << QStringLiteral("5b4dde8f000a5a9b")
1591 << QStringLiteral("5b4f6d3185efbae97d58ed9cc75e2bae655d2cefb2dd09cd");
1592 QTest::newRow(dataTag: "13") << QStringLiteral("0123456789abcde7") << QStringLiteral("c95744256a5ed31d")
1593 << QStringLiteral("0123456789abcdef0123456789abcdef0123456789abcdef");
1594 QTest::newRow(dataTag: "14") << QStringLiteral("68652074696d6520") << QStringLiteral("6a271787ab8883f9")
1595 << QStringLiteral("0123456789abcdef0123456789abcdef0123456789abcdef");
1596
1597 QTest::newRow(dataTag: "15") << QStringLiteral("4e6f772069732074") << QStringLiteral("3fa40e8a984d4815")
1598 << QStringLiteral("0123456789abcdef0123456789abcdef0123456789abcdef");
1599
1600 // These are from the Botan test suite
1601 QTest::newRow(dataTag: "16") << QStringLiteral("0123456789abcde7") << QStringLiteral("7f1d0a77826b8aff")
1602 << QStringLiteral("0123456789abcdeffedcba9876543210");
1603 QTest::newRow(dataTag: "17") << QStringLiteral("4e6f772069732074") << QStringLiteral("3fa40e8a984d4815")
1604 << QStringLiteral("0123456789abcdef0123456789abcdef");
1605 QTest::newRow(dataTag: "18") << QStringLiteral("42fd443059577fa2") << QStringLiteral("af37fb421f8c4095")
1606 << QStringLiteral("04b915ba43feb5b604b915ba43feb5b6");
1607 QTest::newRow(dataTag: "19") << QStringLiteral("afa4284fcceaa61a") << QStringLiteral("32527d5701d92b90")
1608 << QStringLiteral("4bc59e2c68aca60767a9a4b623bbbccc");
1609 QTest::newRow(dataTag: "20") << QStringLiteral("50b503a331d5b5cc") << QStringLiteral("e46a59e18b0c41e3")
1610 << QStringLiteral("b955bb7861fde77e7dc6418475457fe1");
1611 QTest::newRow(dataTag: "21") << QStringLiteral("3404435d5df2cb47") << QStringLiteral("644dd68ea73053ae")
1612 << QStringLiteral("c0557629eaa72abd4c102c5dc9ce8b47");
1613 QTest::newRow(dataTag: "22") << QStringLiteral("c7d80e955d1b6627") << QStringLiteral("9fe1c5a12cce6dd9")
1614 << QStringLiteral("9eaa94da916f30092e79dacdcdcc45c0");
1615 QTest::newRow(dataTag: "23") << QStringLiteral("bdcbe8929cd0e12f") << QStringLiteral("f2b6430450ab348b")
1616 << QStringLiteral("a55279671807d9b71fe62a77341249f8");
1617 QTest::newRow(dataTag: "24") << QStringLiteral("4b7a96b7051c64fc") << QStringLiteral("1555f08b2de690a0")
1618 << QStringLiteral("672e20826ad49c3df7579fab3752479e");
1619 QTest::newRow(dataTag: "25") << QStringLiteral("902f4edd44eaf3c1") << QStringLiteral("3ce357eba0fb3e26")
1620 << QStringLiteral("0ce61ede2659b413ab9f717ae4afad3e");
1621 QTest::newRow(dataTag: "26") << QStringLiteral("39c0f8e4c85cd70d") << QStringLiteral("882de9b6d0209a58")
1622 << QStringLiteral("e878020815ae517cd2808b6571eac2b4");
1623 QTest::newRow(dataTag: "27") << QStringLiteral("f77a1947a921b209") << QStringLiteral("e10dbee5615f312e")
1624 << QStringLiteral("d891ca20919f06a054ba3943c7daba16");
1625 QTest::newRow(dataTag: "28") << QStringLiteral("06d0416e0f0db7ce") << QStringLiteral("0cec5d1e59d7e347")
1626 << QStringLiteral("4909aed1f94eb77b6cacbcae2b25689a");
1627 QTest::newRow(dataTag: "29") << QStringLiteral("f7bb3a396d73d8a8") << QStringLiteral("f893b6b2a15d3fce")
1628 << QStringLiteral("8b9a5c13b0b118a1ee35eb912866ffa6");
1629 QTest::newRow(dataTag: "30") << QStringLiteral("bd35e3134b90ccbc") << QStringLiteral("12a7af172fd0ca7f")
1630 << QStringLiteral("fa7911d664326074b42e2f38e599b288");
1631 QTest::newRow(dataTag: "31") << QStringLiteral("e046b7f5707da4fc") << QStringLiteral("32b6a3fc72c7c480")
1632 << QStringLiteral("406903b340b8637928fde8058bdd6710");
1633 QTest::newRow(dataTag: "32") << QStringLiteral("58eb1dc16c482213") << QStringLiteral("a6c6234a8bbaa116")
1634 << QStringLiteral("37a2b53e2af8f6c9a73b39f919d969de");
1635 QTest::newRow(dataTag: "33") << QStringLiteral("4bd0f4854297fbde") << QStringLiteral("f4ab771861457dc6")
1636 << QStringLiteral("711f2cecdb92b2e201dfefa79fa7ba2f");
1637}
1638
1639// TODO: ECB-PKCS7
1640void CipherUnitTest::tripleDES()
1641{
1642 bool anyProviderTested = false;
1643 foreach (const QString provider, providersToTest) {
1644 if (QCA::isSupported(features: "tripledes-ecb", provider)) {
1645 anyProviderTested = true;
1646 QCA::Cipher cipherObj1(QStringLiteral("tripledes"),
1647 QCA::Cipher::ECB,
1648 QCA::Cipher::NoPadding,
1649 QCA::Encode,
1650 QCA::SymmetricKey(24),
1651 QCA::InitializationVector(),
1652 provider);
1653 // checking minimum is a bit hairy, because it depends on whether you are
1654 // doing 2 key or 3 key triple DES.
1655 QCOMPARE(cipherObj1.keyLength().minimum(), 16);
1656 QCOMPARE(cipherObj1.keyLength().maximum(), 24);
1657 QCOMPARE(cipherObj1.blockSize(), 8);
1658
1659 QFETCH(QString, plainText);
1660 QFETCH(QString, cipherText);
1661 QFETCH(QString, keyText);
1662
1663 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
1664 QCA::Cipher forwardCipher(QStringLiteral("tripledes"),
1665 QCA::Cipher::ECB,
1666 QCA::Cipher::NoPadding,
1667 QCA::Encode,
1668 key,
1669 QCA::InitializationVector(),
1670 provider);
1671
1672 QString afterEncodeText = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
1673 QVERIFY(forwardCipher.ok());
1674
1675 afterEncodeText += QCA::arrayToHex(array: forwardCipher.final().toByteArray());
1676 QVERIFY(forwardCipher.ok());
1677
1678 QCOMPARE(afterEncodeText, cipherText);
1679
1680 QCA::Cipher reverseCipher(QStringLiteral("tripledes"),
1681 QCA::Cipher::ECB,
1682 QCA::Cipher::NoPadding,
1683 QCA::Decode,
1684 key,
1685 QCA::InitializationVector(),
1686 provider);
1687
1688 QString afterDecodeText = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
1689 QVERIFY(reverseCipher.ok());
1690
1691 afterDecodeText += QCA::arrayToHex(array: reverseCipher.final().toByteArray());
1692 QVERIFY(reverseCipher.ok());
1693
1694 QCOMPARE(afterDecodeText, plainText);
1695 }
1696 }
1697 if (!anyProviderTested)
1698 qWarning() << "NONE of the providers supports Triple DES, ECB:" << providersToTest;
1699}
1700
1701// These are from the Botan test suite - its ECB mode, no padding
1702void CipherUnitTest::des_data()
1703{
1704 QTest::addColumn<QString>(name: "plainText");
1705 QTest::addColumn<QString>(name: "cipherText");
1706 QTest::addColumn<QString>(name: "keyText");
1707
1708 QTest::newRow(dataTag: "") << QStringLiteral("059b5e0851cf143a") << QStringLiteral("86a560f10ec6d85b")
1709 << QStringLiteral("0113b970fd34f2ce");
1710 QTest::newRow(dataTag: "") << QStringLiteral("4e6f772069732074") << QStringLiteral("3fa40e8a984d4815")
1711 << QStringLiteral("0123456789abcdef");
1712 QTest::newRow(dataTag: "") << QStringLiteral("666f7220616c6c20") << QStringLiteral("893d51ec4b563b53")
1713 << QStringLiteral("0123456789abcdef");
1714 QTest::newRow(dataTag: "") << QStringLiteral("68652074696d6520") << QStringLiteral("6a271787ab8883f9")
1715 << QStringLiteral("0123456789abcdef");
1716 QTest::newRow(dataTag: "") << QStringLiteral("5cd54ca83def57da") << QStringLiteral("7a389d10354bd271")
1717 << QStringLiteral("0131d9619dc1376e");
1718 QTest::newRow(dataTag: "") << QStringLiteral("0756d8e0774761d2") << QStringLiteral("0cd3da020021dc09")
1719 << QStringLiteral("0170f175468fb5e6");
1720 QTest::newRow(dataTag: "") << QStringLiteral("1d9d5c5018f728c2") << QStringLiteral("5f4c038ed12b2e41")
1721 << QStringLiteral("018310dc409b26d6");
1722 QTest::newRow(dataTag: "") << QStringLiteral("480d39006ee762f2") << QStringLiteral("a1f9915541020b56")
1723 << QStringLiteral("025816164629b007");
1724 QTest::newRow(dataTag: "") << QStringLiteral("26955f6835af609a") << QStringLiteral("5c513c9c4886c088")
1725 << QStringLiteral("04689104c2fd3b2f");
1726 QTest::newRow(dataTag: "") << QStringLiteral("42fd443059577fa2") << QStringLiteral("af37fb421f8c4095")
1727 << QStringLiteral("04b915ba43feb5b6");
1728 QTest::newRow(dataTag: "") << QStringLiteral("0248d43806f67172") << QStringLiteral("868ebb51cab4599a")
1729 << QStringLiteral("07a1133e4a0b2686");
1730 QTest::newRow(dataTag: "") << QStringLiteral("3bdd119049372802") << QStringLiteral("dfd64a815caf1a0f")
1731 << QStringLiteral("07a7137045da2a16");
1732 QTest::newRow(dataTag: "") << QStringLiteral("16393bcdd6560506") << QStringLiteral("9966adcfc53bf968")
1733 << QStringLiteral("0a3fddc8350aff39");
1734 QTest::newRow(dataTag: "") << QStringLiteral("dc7fc6cf0358ecc0") << QStringLiteral("a47a7485661f7085")
1735 << QStringLiteral("10dd6dcd5c89e151");
1736 QTest::newRow(dataTag: "") << QStringLiteral("305532286d6f295a") << QStringLiteral("63fac0d034d9f793")
1737 << QStringLiteral("1c587f1c13924fef");
1738 QTest::newRow(dataTag: "") << QStringLiteral("f786d02413c574fc") << QStringLiteral("54c160d369f62ae3")
1739 << QStringLiteral("1eb00767bdee584e");
1740 QTest::newRow(dataTag: "") << QStringLiteral("6b056e18759f5cca") << QStringLiteral("ef1bf03e5dfa575a")
1741 << QStringLiteral("1f08260d1ac2465e");
1742 QTest::newRow(dataTag: "") << QStringLiteral("905ea29aeea26e07") << QStringLiteral("2292e9aebee6a4b6")
1743 << QStringLiteral("28ee445d8a21c534");
1744 QTest::newRow(dataTag: "") << QStringLiteral("164d5e404f275232") << QStringLiteral("0a2aeeae3ff4ab77")
1745 << QStringLiteral("37d06bb516cb7546");
1746 QTest::newRow(dataTag: "") << QStringLiteral("51454b582ddf440a") << QStringLiteral("7178876e01f19b2a")
1747 << QStringLiteral("3849674c2602319e");
1748 QTest::newRow(dataTag: "") << QStringLiteral("68ff9d6068c71513") << QStringLiteral("84595f5b9d046132")
1749 << QStringLiteral("3cde816ef9ef8edb");
1750 QTest::newRow(dataTag: "") << QStringLiteral("762514b829bf486a") << QStringLiteral("ea676b2cb7db2b7a")
1751 << QStringLiteral("43297fad38e373fe");
1752 QTest::newRow(dataTag: "") << QStringLiteral("437540c8698f3cfa") << QStringLiteral("6fbf1cafcffd0556")
1753 << QStringLiteral("49793ebc79b3258f");
1754 QTest::newRow(dataTag: "") << QStringLiteral("02fe55778117f12a") << QStringLiteral("5a6b612cc26cce4a")
1755 << QStringLiteral("49e95d6d4ca229bf");
1756 QTest::newRow(dataTag: "") << QStringLiteral("1f508a50adb3d6e2") << QStringLiteral("470204969876604a")
1757 << QStringLiteral("4bb53ecfefb38dde");
1758 QTest::newRow(dataTag: "") << QStringLiteral("072d43a077075292") << QStringLiteral("2f22e49bab7ca1ac")
1759 << QStringLiteral("4fb05e1515ab73a7");
1760 QTest::newRow(dataTag: "") << QStringLiteral("004bd6ef09176062") << QStringLiteral("88bf0db6d70dee56")
1761 << QStringLiteral("584023641aba6176");
1762 QTest::newRow(dataTag: "") << QStringLiteral("5aa1d62806ae0ead") << QStringLiteral("6db0f280fef2b564")
1763 << QStringLiteral("5f2b51f59e781d9c");
1764 QTest::newRow(dataTag: "") << QStringLiteral("7e1b1c6776833772") << QStringLiteral("eb11cd3c72f7e90e")
1765 << QStringLiteral("699c920d7ce1e0b1");
1766 QTest::newRow(dataTag: "") << QStringLiteral("5dbfb47c5f471136") << QStringLiteral("9c8b904d4d772be7")
1767 << QStringLiteral("7ac2fdeee4c79746");
1768 QTest::newRow(dataTag: "") << QStringLiteral("01a1d6d039776742") << QStringLiteral("690f5b0d9a26939b")
1769 << QStringLiteral("7ca110454a1a6e57");
1770 QTest::newRow(dataTag: "") << QStringLiteral("4de2f0926cf598d7") << QStringLiteral("ba107655991df529")
1771 << QStringLiteral("7fc92c3098ecf14a");
1772 QTest::newRow(dataTag: "") << QStringLiteral("f45e6819e3108559") << QStringLiteral("f0c76ba556283b2f")
1773 << QStringLiteral("9ab645e268430854");
1774 QTest::newRow(dataTag: "") << QStringLiteral("51d4eaaac6d76553") << QStringLiteral("bf3c6e8fd15ba861")
1775 << QStringLiteral("a6b0ae88f980011a");
1776 QTest::newRow(dataTag: "") << QStringLiteral("6a89626ea8038511") << QStringLiteral("1067b36913cbcc47")
1777 << QStringLiteral("bafebafafeaeeaff");
1778 QTest::newRow(dataTag: "") << QStringLiteral("7b0313c0d3a866f9") << QStringLiteral("e49e15e4f46f10e9")
1779 << QStringLiteral("bb2420b5fee5a6a1");
1780 QTest::newRow(dataTag: "") << QStringLiteral("9d4a44aefce79965") << QStringLiteral("77b2ecc9278e9714")
1781 << QStringLiteral("bebafbeabaffeaaf");
1782 QTest::newRow(dataTag: "") << QStringLiteral("59bcdfc253424cb5") << QStringLiteral("0a50abbbcd07061a")
1783 << QStringLiteral("c38c6f20230d9ed5");
1784 QTest::newRow(dataTag: "") << QStringLiteral("d6c059a85ee2b13e") << QStringLiteral("25977533635beb5b")
1785 << QStringLiteral("c6f974504d954c7e");
1786 QTest::newRow(dataTag: "") << QStringLiteral("f9e4821dfcaa5466") << QStringLiteral("48ec3a79399e9a00")
1787 << QStringLiteral("cb959b7ffd94f734");
1788 QTest::newRow(dataTag: "") << QStringLiteral("35e8554bad60fb29") << QStringLiteral("993a3af0bc0d77a4")
1789 << QStringLiteral("cfb23034323cd19a");
1790 QTest::newRow(dataTag: "") << QStringLiteral("9f97210d75b7e6df") << QStringLiteral("4729e3396e57ae4e")
1791 << QStringLiteral("d4d861035745f2c8");
1792 QTest::newRow(dataTag: "") << QStringLiteral("ffffffffffffffff") << QStringLiteral("b5ce4f28fdeb21e8")
1793 << QStringLiteral("e36972fc4bec7587");
1794 QTest::newRow(dataTag: "") << QStringLiteral("323837024123c918") << QStringLiteral("7f28bf28adfa1cf0")
1795 << QStringLiteral("e91a71a7ed5eb0ef");
1796 QTest::newRow(dataTag: "") << QStringLiteral("37dfe527086af0a0") << QStringLiteral("5f53c6c87760256e")
1797 << QStringLiteral("ebbbbaebfbbefaba");
1798 QTest::newRow(dataTag: "") << QStringLiteral("20678f45b5b8ac00") << QStringLiteral("7cc8ecf2638cc808")
1799 << QStringLiteral("ebbeeeaebbbbffff");
1800 QTest::newRow(dataTag: "") << QStringLiteral("78481ed0c5a7c93e") << QStringLiteral("4ca3a08300ea6afc")
1801 << QStringLiteral("fbeaffeeffeeabab");
1802 QTest::newRow(dataTag: "") << QStringLiteral("e2ccd415ac25412a") << QStringLiteral("bd85b3b659ab7276")
1803 << QStringLiteral("fd8a675c0ed08301");
1804 // weak key
1805 QTest::newRow(dataTag: "") << QStringLiteral("cccc5bdfd9029507") << QStringLiteral("da57553d7d55775f")
1806 << QStringLiteral("ffffffffffffffff");
1807 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("23083a3ca70dd027")
1808 << QStringLiteral("d5d44ff720683d0d");
1809 QTest::newRow(dataTag: "") << QStringLiteral("0100000000000000") << QStringLiteral("6f353e3388abe2ef")
1810 << QStringLiteral("d5d44ff720683d0d");
1811 // weak keys till next comment.
1812 QTest::newRow(dataTag: "") << QStringLiteral("95f8a5e5dd31d900") << QStringLiteral("8000000000000000")
1813 << QStringLiteral("0101010101010101");
1814 QTest::newRow(dataTag: "") << QStringLiteral("95f8a5e5dd31d900") << QStringLiteral("8000000000000000")
1815 << QStringLiteral("0000000000000000");
1816 QTest::newRow(dataTag: "") << QStringLiteral("dd7f121ca5015619") << QStringLiteral("4000000000000000")
1817 << QStringLiteral("0101010101010101");
1818 QTest::newRow(dataTag: "") << QStringLiteral("2e8653104f3834ea") << QStringLiteral("2000000000000000")
1819 << QStringLiteral("0101010101010101");
1820 QTest::newRow(dataTag: "") << QStringLiteral("4bd388ff6cd81d4f") << QStringLiteral("1000000000000000")
1821 << QStringLiteral("0101010101010101");
1822 QTest::newRow(dataTag: "") << QStringLiteral("20b9e767b2fb1456") << QStringLiteral("0800000000000000")
1823 << QStringLiteral("0101010101010101");
1824 QTest::newRow(dataTag: "") << QStringLiteral("20b9e767b2fb1456") << QStringLiteral("0800000000000000")
1825 << QStringLiteral("0001010101010100");
1826 QTest::newRow(dataTag: "") << QStringLiteral("55579380d77138ef") << QStringLiteral("0400000000000000")
1827 << QStringLiteral("0101010101010101");
1828 QTest::newRow(dataTag: "") << QStringLiteral("6cc5defaaf04512f") << QStringLiteral("0200000000000000")
1829 << QStringLiteral("0101010101010101");
1830 QTest::newRow(dataTag: "") << QStringLiteral("0d9f279ba5d87260") << QStringLiteral("0100000000000000")
1831 << QStringLiteral("0101010101010101");
1832 QTest::newRow(dataTag: "") << QStringLiteral("d9031b0271bd5a0a") << QStringLiteral("0080000000000000")
1833 << QStringLiteral("0101010101010101");
1834 QTest::newRow(dataTag: "") << QStringLiteral("424250b37c3dd951") << QStringLiteral("0040000000000000")
1835 << QStringLiteral("0101010101010101");
1836 QTest::newRow(dataTag: "") << QStringLiteral("b8061b7ecd9a21e5") << QStringLiteral("0020000000000000")
1837 << QStringLiteral("0101010101010101");
1838 QTest::newRow(dataTag: "") << QStringLiteral("f15d0f286b65bd28") << QStringLiteral("0010000000000000")
1839 << QStringLiteral("0101010101010101");
1840 QTest::newRow(dataTag: "") << QStringLiteral("add0cc8d6e5deba1") << QStringLiteral("0008000000000000")
1841 << QStringLiteral("0101010101010101");
1842 QTest::newRow(dataTag: "") << QStringLiteral("e6d5f82752ad63d1") << QStringLiteral("0004000000000000")
1843 << QStringLiteral("0101010101010101");
1844 QTest::newRow(dataTag: "") << QStringLiteral("ecbfe3bd3f591a5e") << QStringLiteral("0002000000000000")
1845 << QStringLiteral("0101010101010101");
1846 QTest::newRow(dataTag: "") << QStringLiteral("f356834379d165cd") << QStringLiteral("0001000000000000")
1847 << QStringLiteral("0101010101010101");
1848 QTest::newRow(dataTag: "") << QStringLiteral("2b9f982f20037fa9") << QStringLiteral("0000800000000000")
1849 << QStringLiteral("0101010101010101");
1850 QTest::newRow(dataTag: "") << QStringLiteral("889de068a16f0be6") << QStringLiteral("0000400000000000")
1851 << QStringLiteral("0101010101010101");
1852 QTest::newRow(dataTag: "") << QStringLiteral("e19e275d846a1298") << QStringLiteral("0000200000000000")
1853 << QStringLiteral("0101010101010101");
1854 QTest::newRow(dataTag: "") << QStringLiteral("329a8ed523d71aec") << QStringLiteral("0000100000000000")
1855 << QStringLiteral("0101010101010101");
1856 QTest::newRow(dataTag: "") << QStringLiteral("e7fce22557d23c97") << QStringLiteral("0000080000000000")
1857 << QStringLiteral("0101010101010101");
1858 QTest::newRow(dataTag: "") << QStringLiteral("12a9f5817ff2d65d") << QStringLiteral("0000040000000000")
1859 << QStringLiteral("0101010101010101");
1860 QTest::newRow(dataTag: "") << QStringLiteral("a484c3ad38dc9c19") << QStringLiteral("0000020000000000")
1861 << QStringLiteral("0101010101010101");
1862 QTest::newRow(dataTag: "") << QStringLiteral("fbe00a8a1ef8ad72") << QStringLiteral("0000010000000000")
1863 << QStringLiteral("0101010101010101");
1864 QTest::newRow(dataTag: "") << QStringLiteral("750d079407521363") << QStringLiteral("0000008000000000")
1865 << QStringLiteral("0101010101010101");
1866 QTest::newRow(dataTag: "") << QStringLiteral("64feed9c724c2faf") << QStringLiteral("0000004000000000")
1867 << QStringLiteral("0101010101010101");
1868 QTest::newRow(dataTag: "") << QStringLiteral("f02b263b328e2b60") << QStringLiteral("0000002000000000")
1869 << QStringLiteral("0101010101010101");
1870 QTest::newRow(dataTag: "") << QStringLiteral("9d64555a9a10b852") << QStringLiteral("0000001000000000")
1871 << QStringLiteral("0101010101010101");
1872 QTest::newRow(dataTag: "") << QStringLiteral("d106ff0bed5255d7") << QStringLiteral("0000000800000000")
1873 << QStringLiteral("0101010101010101");
1874 QTest::newRow(dataTag: "") << QStringLiteral("e1652c6b138c64a5") << QStringLiteral("0000000400000000")
1875 << QStringLiteral("0101010101010101");
1876 QTest::newRow(dataTag: "") << QStringLiteral("e428581186ec8f46") << QStringLiteral("0000000200000000")
1877 << QStringLiteral("0101010101010101");
1878 QTest::newRow(dataTag: "") << QStringLiteral("aeb5f5ede22d1a36") << QStringLiteral("0000000100000000")
1879 << QStringLiteral("0101010101010101");
1880 QTest::newRow(dataTag: "") << QStringLiteral("e943d7568aec0c5c") << QStringLiteral("0000000080000000")
1881 << QStringLiteral("0101010101010101");
1882 QTest::newRow(dataTag: "") << QStringLiteral("df98c8276f54b04b") << QStringLiteral("0000000040000000")
1883 << QStringLiteral("0101010101010101");
1884 QTest::newRow(dataTag: "") << QStringLiteral("b160e4680f6c696f") << QStringLiteral("0000000020000000")
1885 << QStringLiteral("0101010101010101");
1886 QTest::newRow(dataTag: "") << QStringLiteral("fa0752b07d9c4ab8") << QStringLiteral("0000000010000000")
1887 << QStringLiteral("0101010101010101");
1888 QTest::newRow(dataTag: "") << QStringLiteral("ca3a2b036dbc8502") << QStringLiteral("0000000008000000")
1889 << QStringLiteral("0101010101010101");
1890 QTest::newRow(dataTag: "") << QStringLiteral("5e0905517bb59bcf") << QStringLiteral("0000000004000000")
1891 << QStringLiteral("0101010101010101");
1892 QTest::newRow(dataTag: "") << QStringLiteral("814eeb3b91d90726") << QStringLiteral("0000000002000000")
1893 << QStringLiteral("0101010101010101");
1894 QTest::newRow(dataTag: "") << QStringLiteral("4d49db1532919c9f") << QStringLiteral("0000000001000000")
1895 << QStringLiteral("0101010101010101");
1896 QTest::newRow(dataTag: "") << QStringLiteral("25eb5fc3f8cf0621") << QStringLiteral("0000000000800000")
1897 << QStringLiteral("0101010101010101");
1898 QTest::newRow(dataTag: "") << QStringLiteral("ab6a20c0620d1c6f") << QStringLiteral("0000000000400000")
1899 << QStringLiteral("0101010101010101");
1900 QTest::newRow(dataTag: "") << QStringLiteral("79e90dbc98f92cca") << QStringLiteral("0000000000200000")
1901 << QStringLiteral("0101010101010101");
1902 QTest::newRow(dataTag: "") << QStringLiteral("866ecedd8072bb0e") << QStringLiteral("0000000000100000")
1903 << QStringLiteral("0101010101010101");
1904 QTest::newRow(dataTag: "") << QStringLiteral("8b54536f2f3e64a8") << QStringLiteral("0000000000080000")
1905 << QStringLiteral("0101010101010101");
1906 QTest::newRow(dataTag: "") << QStringLiteral("ea51d3975595b86b") << QStringLiteral("0000000000040000")
1907 << QStringLiteral("0101010101010101");
1908 QTest::newRow(dataTag: "") << QStringLiteral("caffc6ac4542de31") << QStringLiteral("0000000000020000")
1909 << QStringLiteral("0101010101010101");
1910 QTest::newRow(dataTag: "") << QStringLiteral("8dd45a2ddf90796c") << QStringLiteral("0000000000010000")
1911 << QStringLiteral("0101010101010101");
1912 QTest::newRow(dataTag: "") << QStringLiteral("1029d55e880ec2d0") << QStringLiteral("0000000000008000")
1913 << QStringLiteral("0101010101010101");
1914 QTest::newRow(dataTag: "") << QStringLiteral("5d86cb23639dbea9") << QStringLiteral("0000000000004000")
1915 << QStringLiteral("0101010101010101");
1916 QTest::newRow(dataTag: "") << QStringLiteral("1d1ca853ae7c0c5f") << QStringLiteral("0000000000002000")
1917 << QStringLiteral("0101010101010101");
1918 QTest::newRow(dataTag: "") << QStringLiteral("ce332329248f3228") << QStringLiteral("0000000000001000")
1919 << QStringLiteral("0101010101010101");
1920 QTest::newRow(dataTag: "") << QStringLiteral("8405d1abe24fb942") << QStringLiteral("0000000000000800")
1921 << QStringLiteral("0101010101010101");
1922 QTest::newRow(dataTag: "") << QStringLiteral("e643d78090ca4207") << QStringLiteral("0000000000000400")
1923 << QStringLiteral("0101010101010101");
1924 QTest::newRow(dataTag: "") << QStringLiteral("48221b9937748a23") << QStringLiteral("0000000000000200")
1925 << QStringLiteral("0101010101010101");
1926 QTest::newRow(dataTag: "") << QStringLiteral("dd7c0bbd61fafd54") << QStringLiteral("0000000000000100")
1927 << QStringLiteral("0101010101010101");
1928 QTest::newRow(dataTag: "") << QStringLiteral("2fbc291a570db5c4") << QStringLiteral("0000000000000080")
1929 << QStringLiteral("0101010101010101");
1930 QTest::newRow(dataTag: "") << QStringLiteral("e07c30d7e4e26e12") << QStringLiteral("0000000000000040")
1931 << QStringLiteral("0101010101010101");
1932 QTest::newRow(dataTag: "") << QStringLiteral("0953e2258e8e90a1") << QStringLiteral("0000000000000020")
1933 << QStringLiteral("0101010101010101");
1934 QTest::newRow(dataTag: "") << QStringLiteral("5b711bc4ceebf2ee") << QStringLiteral("0000000000000010")
1935 << QStringLiteral("0101010101010101");
1936 QTest::newRow(dataTag: "") << QStringLiteral("cc083f1e6d9e85f6") << QStringLiteral("0000000000000008")
1937 << QStringLiteral("0101010101010101");
1938 QTest::newRow(dataTag: "") << QStringLiteral("d2fd8867d50d2dfe") << QStringLiteral("0000000000000004")
1939 << QStringLiteral("0101010101010101");
1940 QTest::newRow(dataTag: "") << QStringLiteral("06e7ea22ce92708f") << QStringLiteral("0000000000000002")
1941 << QStringLiteral("0101010101010101");
1942 QTest::newRow(dataTag: "") << QStringLiteral("166b40b44aba4bd6") << QStringLiteral("0000000000000001")
1943 << QStringLiteral("0101010101010101");
1944 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("95a8d72813daa94d")
1945 << QStringLiteral("8001010101010101");
1946 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("0eec1487dd8c26d5")
1947 << QStringLiteral("4001010101010101");
1948 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("7ad16ffb79c45926")
1949 << QStringLiteral("2001010101010101");
1950 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("d3746294ca6a6cf3")
1951 << QStringLiteral("1001010101010101");
1952 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("809f5f873c1fd761")
1953 << QStringLiteral("0801010101010101");
1954 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("c02faffec989d1fc")
1955 << QStringLiteral("0401010101010101");
1956 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("4615aa1d33e72f10")
1957 << QStringLiteral("0201010101010101");
1958 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("2055123350c00858")
1959 << QStringLiteral("0180010101010101");
1960 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("df3b99d6577397c8")
1961 << QStringLiteral("0140010101010101");
1962 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("31fe17369b5288c9")
1963 << QStringLiteral("0120010101010101");
1964 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("dfdd3cc64dae1642")
1965 << QStringLiteral("0110010101010101");
1966 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("178c83ce2b399d94")
1967 << QStringLiteral("0108010101010101");
1968 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("50f636324a9b7f80")
1969 << QStringLiteral("0104010101010101");
1970 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("a8468ee3bc18f06d")
1971 << QStringLiteral("0102010101010101");
1972 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("a2dc9e92fd3cde92")
1973 << QStringLiteral("0101800101010101");
1974 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("cac09f797d031287")
1975 << QStringLiteral("0101400101010101");
1976 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("90ba680b22aeb525")
1977 << QStringLiteral("0101200101010101");
1978 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("ce7a24f350e280b6")
1979 << QStringLiteral("0101100101010101");
1980 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("882bff0aa01a0b87")
1981 << QStringLiteral("0101080101010101");
1982 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("25610288924511c2")
1983 << QStringLiteral("0101040101010101");
1984 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("c71516c29c75d170")
1985 << QStringLiteral("0101020101010101");
1986 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("5199c29a52c9f059")
1987 << QStringLiteral("0101018001010101");
1988 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("c22f0a294a71f29f")
1989 << QStringLiteral("0101014001010101");
1990 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("ee371483714c02ea")
1991 << QStringLiteral("0101012001010101");
1992 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("a81fbd448f9e522f")
1993 << QStringLiteral("0101011001010101");
1994 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("4f644c92e192dfed")
1995 << QStringLiteral("0101010801010101");
1996 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("1afa9a66a6df92ae")
1997 << QStringLiteral("0101010401010101");
1998 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("b3c1cc715cb879d8")
1999 << QStringLiteral("0101010201010101");
2000 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("19d032e64ab0bd8b")
2001 << QStringLiteral("0101010180010101");
2002 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("3cfaa7a7dc8720dc")
2003 << QStringLiteral("0101010140010101");
2004 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("b7265f7f447ac6f3")
2005 << QStringLiteral("0101010120010101");
2006 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("9db73b3c0d163f54")
2007 << QStringLiteral("0101010110010101");
2008 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("8181b65babf4a975")
2009 << QStringLiteral("0101010108010101");
2010 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("93c9b64042eaa240")
2011 << QStringLiteral("0101010104010101");
2012 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("5570530829705592")
2013 << QStringLiteral("0101010102010101");
2014 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("8638809e878787a0")
2015 << QStringLiteral("0101010101800101");
2016 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("41b9a79af79ac208")
2017 << QStringLiteral("0101010101400101");
2018 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("7a9be42f2009a892")
2019 << QStringLiteral("0101010101200101");
2020 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("29038d56ba6d2745")
2021 << QStringLiteral("0101010101100101");
2022 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("5495c6abf1e5df51")
2023 << QStringLiteral("0101010101080101");
2024 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("ae13dbd561488933")
2025 << QStringLiteral("0101010101040101");
2026 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("024d1ffa8904e389")
2027 << QStringLiteral("0101010101020101");
2028 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("d1399712f99bf02e")
2029 << QStringLiteral("0101010101018001");
2030 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("14c1d7c1cffec79e")
2031 << QStringLiteral("0101010101014001");
2032 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("1de5279dae3bed6f")
2033 << QStringLiteral("0101010101012001");
2034 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("e941a33f85501303")
2035 << QStringLiteral("0101010101011001");
2036 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("da99dbbc9a03f379")
2037 << QStringLiteral("0101010101010801");
2038 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("b7fc92f91d8e92e9")
2039 << QStringLiteral("0101010101010401");
2040 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("ae8e5caa3ca04e85")
2041 << QStringLiteral("0101010101010201");
2042 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("9cc62df43b6eed74")
2043 << QStringLiteral("0101010101010180");
2044 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("d863dbb5c59a91a0")
2045 << QStringLiteral("0101010101010140");
2046 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("a1ab2190545b91d7")
2047 << QStringLiteral("0101010101010120");
2048 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("0875041e64c570f7")
2049 << QStringLiteral("0101010101010110");
2050 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("5a594528bebef1cc")
2051 << QStringLiteral("0101010101010108");
2052 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("fcdb3291de21f0c0")
2053 << QStringLiteral("0101010101010104");
2054 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("869efd7f9f265a09")
2055 << QStringLiteral("0101010101010102");
2056 // end of weak keys
2057 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("88d55e54f54c97b4")
2058 << QStringLiteral("1046913489980131");
2059 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("0c0cc00c83ea48fd")
2060 << QStringLiteral("1007103489988020");
2061 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("83bc8ef3a6570183")
2062 << QStringLiteral("10071034c8980120");
2063 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("df725dcad94ea2e9")
2064 << QStringLiteral("1046103489988020");
2065 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("e652b53b550be8b0")
2066 << QStringLiteral("1086911519190101");
2067 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("af527120c485cbb0")
2068 << QStringLiteral("1086911519580101");
2069 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("0f04ce393db926d5")
2070 << QStringLiteral("5107b01519580101");
2071 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("c9f00ffc74079067")
2072 << QStringLiteral("1007b01519190101");
2073 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("7cfd82a593252b4e")
2074 << QStringLiteral("3107915498080101");
2075 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("cb49a2f9e91363e3")
2076 << QStringLiteral("3107919498080101");
2077 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("00b588be70d23f56")
2078 << QStringLiteral("10079115b9080140");
2079 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("406a9a6ab43399ae")
2080 << QStringLiteral("3107911598090140");
2081 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("6cb773611dca9ada")
2082 << QStringLiteral("1007d01589980101");
2083 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("67fd21c17dbb5d70")
2084 << QStringLiteral("9107911589980101");
2085 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("9592cb4110430787")
2086 << QStringLiteral("9107d01589190101");
2087 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("a6b7ff68a318ddd3")
2088 << QStringLiteral("1007d01598980120");
2089 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("4d102196c914ca16")
2090 << QStringLiteral("1007940498190101");
2091 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("2dfa9f4573594965")
2092 << QStringLiteral("0107910491190401");
2093 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("b46604816c0e0774")
2094 << QStringLiteral("0107910491190101");
2095 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("6e7e6221a4f34e87")
2096 << QStringLiteral("0107940491190401");
2097 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("aa85e74643233199")
2098 << QStringLiteral("19079210981a0101");
2099 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("2e5a19db4d1962d6")
2100 << QStringLiteral("1007911998190801");
2101 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("23a866a809d30894")
2102 << QStringLiteral("10079119981a0801");
2103 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("d812d961f017d320")
2104 << QStringLiteral("1007921098190101");
2105 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("055605816e58608f")
2106 << QStringLiteral("100791159819010b");
2107 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("abd88e8b1b7716f1")
2108 << QStringLiteral("1004801598190101");
2109 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("537ac95be69da1e1")
2110 << QStringLiteral("1004801598190102");
2111 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("aed0f6ae3c25cdd8")
2112 << QStringLiteral("1004801598190108");
2113 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("b3e35a5ee53e7b8d")
2114 << QStringLiteral("1002911598100104");
2115 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("61c79c71921a2ef8")
2116 << QStringLiteral("1002911598190104");
2117 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("e2f5728f0995013c")
2118 << QStringLiteral("1002911598100201");
2119 QTest::newRow(dataTag: "") << QStringLiteral("0000000000000000") << QStringLiteral("1aeac39a61f0a464")
2120 << QStringLiteral("1002911698100101");
2121 QTest::newRow(dataTag: "") << QStringLiteral("059b5e0851cf143a") << QStringLiteral("86a560f10ec6d85b")
2122 << QStringLiteral("0113b970fd34f2ce");
2123 QTest::newRow(dataTag: "") << QStringLiteral("4e6f772069732074") << QStringLiteral("3fa40e8a984d4815")
2124 << QStringLiteral("0123456789abcdef");
2125}
2126
2127void CipherUnitTest::des()
2128{
2129 bool anyProviderTested = false;
2130 foreach (const QString provider, providersToTest) {
2131 if (QCA::isSupported(features: "des-ecb", provider)) {
2132 anyProviderTested = true;
2133 QFETCH(QString, plainText);
2134 QFETCH(QString, cipherText);
2135 QFETCH(QString, keyText);
2136
2137 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2138 QCA::Cipher forwardCipher(QStringLiteral("des"),
2139 QCA::Cipher::ECB,
2140 QCA::Cipher::NoPadding,
2141 QCA::Encode,
2142 key,
2143 QCA::InitializationVector(),
2144 provider);
2145
2146 QCOMPARE(forwardCipher.blockSize(), 8);
2147 QCOMPARE(forwardCipher.keyLength().minimum(), 8);
2148 QCOMPARE(forwardCipher.keyLength().maximum(), 8);
2149
2150 QString afterEncodeText = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2151 QVERIFY(forwardCipher.ok());
2152
2153 afterEncodeText += QCA::arrayToHex(array: forwardCipher.final().toByteArray());
2154 QVERIFY(forwardCipher.ok());
2155
2156 QCOMPARE(afterEncodeText, cipherText);
2157
2158 QCA::Cipher reverseCipher(QStringLiteral("des"),
2159 QCA::Cipher::ECB,
2160 QCA::Cipher::NoPadding,
2161 QCA::Decode,
2162 key,
2163 QCA::InitializationVector(),
2164 provider);
2165
2166 QCOMPARE(reverseCipher.blockSize(), 8);
2167 QCOMPARE(reverseCipher.keyLength().minimum(), 8);
2168 QCOMPARE(reverseCipher.keyLength().maximum(), 8);
2169
2170 QString afterDecodeText = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
2171 QVERIFY(reverseCipher.ok());
2172
2173 afterDecodeText += QCA::arrayToHex(array: reverseCipher.final().toByteArray());
2174 QVERIFY(reverseCipher.ok());
2175
2176 QCOMPARE(afterDecodeText, plainText);
2177 }
2178 }
2179 if (!anyProviderTested)
2180 qWarning() << "NONE of the providers supports DES ECB:" << providersToTest;
2181}
2182
2183// This is from the Botan test suite
2184void CipherUnitTest::des_cbc_data()
2185{
2186 QTest::addColumn<QString>(name: "plainText");
2187 QTest::addColumn<QString>(name: "cipherText");
2188 QTest::addColumn<QString>(name: "keyText");
2189 QTest::addColumn<QString>(name: "ivText");
2190
2191 QTest::newRow(dataTag: "1") << QStringLiteral("4e6f77206973207468652074696d6520666f7220616c6c20")
2192 << QStringLiteral("e5c7cdde872bf27c43e934008c389c0f683788499a7c05f6")
2193 << QStringLiteral("0123456789abcdef") << QStringLiteral("1234567890abcdef");
2194}
2195
2196void CipherUnitTest::des_cbc()
2197{
2198 bool anyProviderTested = false;
2199 foreach (const QString provider, providersToTest) {
2200 if (QCA::isSupported(features: "des-cbc", provider)) {
2201 anyProviderTested = true;
2202 QFETCH(QString, plainText);
2203 QFETCH(QString, cipherText);
2204 QFETCH(QString, keyText);
2205 QFETCH(QString, ivText);
2206
2207 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2208 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
2209 QCA::Cipher forwardCipher(
2210 QStringLiteral("des"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
2211 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2212 QVERIFY(forwardCipher.ok());
2213 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
2214 QVERIFY(forwardCipher.ok());
2215
2216 QCA::Cipher reverseCipher(
2217 QStringLiteral("des"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
2218 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
2219 QVERIFY(reverseCipher.ok());
2220 QCOMPARE(update, plainText.left(update.size()));
2221 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
2222 QVERIFY(reverseCipher.ok());
2223 }
2224 }
2225 if (!anyProviderTested)
2226 qWarning() << "NONE of the providers supports DES CBC:" << providersToTest;
2227}
2228
2229// This is from the Botan test suite
2230void CipherUnitTest::des_cfb_data()
2231{
2232 QTest::addColumn<QString>(name: "plainText");
2233 QTest::addColumn<QString>(name: "cipherText");
2234 QTest::addColumn<QString>(name: "keyText");
2235 QTest::addColumn<QString>(name: "ivText");
2236
2237 QTest::newRow(dataTag: "") << QStringLiteral("5eef8199471c2a7ef97509623cae32c35a90245b70a21ce36e")
2238 << QStringLiteral("658b25e25df23948847afa4c9ffdd5b3ddf35d801cbe945168")
2239 << QStringLiteral("add9ce7bcf48c44b") << QStringLiteral("0f90e78835ba3183");
2240 QTest::newRow(dataTag: "") << QStringLiteral("4e6f77206973207468652074696d6520666f7220616c6c20")
2241 << QStringLiteral("f3096249c7f46e51a69e839b1a92f78403467133898ea622")
2242 << QStringLiteral("0123456789abcdef") << QStringLiteral("1234567890abcdef");
2243 QTest::newRow(dataTag: "") << QStringLiteral("d14fd67a9b4d7b0f65b7ca3da91741603da446")
2244 << QStringLiteral("0cb8929a854e61ab3beb72ce0f13ba328ba73a") << QStringLiteral("7132d895529a7aff")
2245 << QStringLiteral("fa1fe8f921706c75");
2246 QTest::newRow(dataTag: "") << QStringLiteral("16") << QStringLiteral("e1") << QStringLiteral("f51cf13fd55f33b8")
2247 << QStringLiteral("10e61c7f8276132e");
2248 QTest::newRow(dataTag: "") << QStringLiteral("b8f7") << QStringLiteral("9f09") << QStringLiteral("6a2306397e6399af")
2249 << QStringLiteral("6791874e16642dd8");
2250 QTest::newRow(dataTag: "") << QStringLiteral("914aa4") << QStringLiteral("1cddad") << QStringLiteral("08d3b08cb02e2547")
2251 << QStringLiteral("b35072a53fa36190");
2252 QTest::newRow(dataTag: "") << QStringLiteral("252f0616") << QStringLiteral("e22a706a") << QStringLiteral("454a9aca108ad24c")
2253 << QStringLiteral("64dadb33ccf1debd");
2254 QTest::newRow(dataTag: "") << QStringLiteral("f06f376c6e") << QStringLiteral("c2f054e435")
2255 << QStringLiteral("087fc9f0b8be08f3") << QStringLiteral("5e511251c063b3c7");
2256 QTest::newRow(dataTag: "") << QStringLiteral("9a181afec04c") << QStringLiteral("c49218c8a25b")
2257 << QStringLiteral("fe1ea0f0ac5f2c02") << QStringLiteral("a247e69ced4a2bf1");
2258 QTest::newRow(dataTag: "") << QStringLiteral("ac465cbd745341") << QStringLiteral("768b6f5bfa9c24")
2259 << QStringLiteral("1e7c7274307edb90") << QStringLiteral("afb634941c366c1d");
2260 QTest::newRow(dataTag: "") << QStringLiteral("52bdfd51e3434e94") << QStringLiteral("c5d84483756ac360")
2261 << QStringLiteral("53e241e43aad03e7") << QStringLiteral("be0a4ae59056d8fe");
2262 QTest::newRow(dataTag: "") << QStringLiteral("a62c02059afe67cd7f") << QStringLiteral("032a99be4df6b63f97")
2263 << QStringLiteral("487c9fbd140ef278") << QStringLiteral("43f88de155e98523");
2264 QTest::newRow(dataTag: "") << QStringLiteral("32d3c8a283257f6276c3") << QStringLiteral("bcfa26efe2d93a4b1364")
2265 << QStringLiteral("8b068595d5b79177") << QStringLiteral("7129287761d94d9f");
2266 QTest::newRow(dataTag: "") << QStringLiteral("17cb11a60f880c16d6cc3a") << QStringLiteral("3dc099d927b8aa66b2a5c8")
2267 << QStringLiteral("750c87995afd65ee") << QStringLiteral("a61398fff559faad");
2268 QTest::newRow(dataTag: "") << QStringLiteral("eaa91cede4efc60f02b1e0ee") << QStringLiteral("75614ea2fd5474fdfe3a5612")
2269 << QStringLiteral("08a5f56200ac9300") << QStringLiteral("9f9ed0928b8cd2dd");
2270 QTest::newRow(dataTag: "") << QStringLiteral("68db8992e91d759256ab373748") << QStringLiteral("9d0e14f0b2be2d3b47103da75f")
2271 << QStringLiteral("b11dfa915ad86ff9") << QStringLiteral("3885ecf48a611dc5");
2272 QTest::newRow(dataTag: "") << QStringLiteral("d75acdd3e4040dfda924ce09e627")
2273 << QStringLiteral("a878ce766412a9c387ad61642fb7") << QStringLiteral("fbf9e6d9344b0f2c")
2274 << QStringLiteral("6917f8fe1ac12101");
2275 QTest::newRow(dataTag: "") << QStringLiteral("38b667a6e4458c8732aae6f4d0ac36")
2276 << QStringLiteral("5bcfd93d6b4b45d9d0d03162fa8fb9") << QStringLiteral("8616d2ea6e6106b3")
2277 << QStringLiteral("cfe4dfa7044f56ab");
2278 QTest::newRow(dataTag: "") << QStringLiteral("0b439a72a4430b3d15e234034ba2c066")
2279 << QStringLiteral("1adae0a4a0d582b70b60ed1c859a07b3") << QStringLiteral("e255e4a4c3606081")
2280 << QStringLiteral("3f160dff918c3f78");
2281 QTest::newRow(dataTag: "") << QStringLiteral("82e27182fc22cd8918dddbdb850034a4f2")
2282 << QStringLiteral("9767881b1909db5e146caaf5fc6a118814") << QStringLiteral("b9cdd5442e1c7fd7")
2283 << QStringLiteral("5d1b1eceb7335274");
2284}
2285
2286void CipherUnitTest::des_cfb()
2287{
2288 bool anyProviderTested = false;
2289 foreach (const QString provider, providersToTest) {
2290 if (QCA::isSupported(features: "des-cfb", provider)) {
2291 anyProviderTested = true;
2292 QFETCH(QString, plainText);
2293 QFETCH(QString, cipherText);
2294 QFETCH(QString, keyText);
2295 QFETCH(QString, ivText);
2296
2297 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2298 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
2299 QCA::Cipher forwardCipher(
2300 QStringLiteral("des"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
2301 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2302 QVERIFY(forwardCipher.ok());
2303 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
2304 QVERIFY(forwardCipher.ok());
2305
2306 QCA::Cipher reverseCipher(
2307 QStringLiteral("des"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
2308 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
2309 QVERIFY(reverseCipher.ok());
2310 QCOMPARE(update, plainText.left(update.size()));
2311 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
2312 QVERIFY(reverseCipher.ok());
2313 }
2314 }
2315 if (!anyProviderTested)
2316 qWarning() << "NONE of the providers supports DES CFB:" << providersToTest;
2317}
2318
2319// This is from the Botan test suite
2320void CipherUnitTest::des_ofb_data()
2321{
2322 QTest::addColumn<QString>(name: "plainText");
2323 QTest::addColumn<QString>(name: "cipherText");
2324 QTest::addColumn<QString>(name: "keyText");
2325 QTest::addColumn<QString>(name: "ivText");
2326
2327 QTest::newRow(dataTag: "1") << QStringLiteral("4e6f77206973207468652074696d6520666f7220616c6c20")
2328 << QStringLiteral("f3096249c7f46e5135f24a242eeb3d3f3d6d5be3255af8c3")
2329 << QStringLiteral("0123456789abcdef") << QStringLiteral("1234567890abcdef");
2330 QTest::newRow(dataTag: "2") << QStringLiteral("b25330d1cab11fddff278192aa2c935a9c7745733e6da8")
2331 << QStringLiteral("39b9bf284d6da6e639b8040b8da01e469dba4c6e50b1ab")
2332 << QStringLiteral("f871822c7fd1d6a3") << QStringLiteral("b311792c8bc02ee8");
2333 QTest::newRow(dataTag: "3") << QStringLiteral("73ad356623a1d6e0717e838b9344b4fff21bda")
2334 << QStringLiteral("0c06e63e9e81d9976e16d2009255f917797d51") << QStringLiteral("5860f4a413de6c68")
2335 << QStringLiteral("527a1e050a9d71f0");
2336 QTest::newRow(dataTag: "4") << QStringLiteral("08a6091fa2987fdc682a8199a6d6bd1f")
2337 << QStringLiteral("640b5033dcf26873fa8a34db644f2bf2") << QStringLiteral("3307042dc775035e")
2338 << QStringLiteral("99de32ff0351509b");
2339}
2340
2341void CipherUnitTest::des_ofb()
2342{
2343 bool anyProviderTested = false;
2344 foreach (const QString provider, providersToTest) {
2345 if (QCA::isSupported(features: "des-ofb", provider)) {
2346 anyProviderTested = true;
2347 QFETCH(QString, plainText);
2348 QFETCH(QString, cipherText);
2349 QFETCH(QString, keyText);
2350 QFETCH(QString, ivText);
2351
2352 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2353 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
2354 QCA::Cipher forwardCipher(
2355 QStringLiteral("des"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
2356 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2357 QVERIFY(forwardCipher.ok());
2358 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
2359 QVERIFY(forwardCipher.ok());
2360
2361 QCA::Cipher reverseCipher(
2362 QStringLiteral("des"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
2363 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
2364 QVERIFY(reverseCipher.ok());
2365 QCOMPARE(update, plainText.left(update.size()));
2366 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
2367 QVERIFY(reverseCipher.ok());
2368 }
2369 }
2370 if (!anyProviderTested)
2371 qWarning() << "NONE of the providers supports DES OFB:" << providersToTest;
2372}
2373
2374// These are from the Botan test suite
2375void CipherUnitTest::des_pkcs7_data()
2376{
2377 QTest::addColumn<QString>(name: "plainText");
2378 QTest::addColumn<QString>(name: "cipherText");
2379 QTest::addColumn<QString>(name: "keyText");
2380
2381 QTest::newRow(dataTag: "") << QString(QLatin1String("")) << QStringLiteral("705fdf4dc7abfbfc")
2382 << QStringLiteral("02d863a4885d417a");
2383 QTest::newRow(dataTag: "") << QStringLiteral("fa") << QStringLiteral("2281ac7cfa703ba9")
2384 << QStringLiteral("05add235b01bbda7");
2385 QTest::newRow(dataTag: "") << QStringLiteral("b895") << QStringLiteral("8c3bf9ab9d16c8cf")
2386 << QStringLiteral("93f04843afc3a191");
2387 QTest::newRow(dataTag: "") << QStringLiteral("8e97de") << QStringLiteral("be38bd2afe108d2a")
2388 << QStringLiteral("1f4e2c013314b55a");
2389 QTest::newRow(dataTag: "") << QStringLiteral("c1dae88e") << QStringLiteral("998341e8b0cce82e")
2390 << QStringLiteral("0f59c05186431e13");
2391 QTest::newRow(dataTag: "") << QStringLiteral("a6e0360e88") << QStringLiteral("f5e88fcc387b8883")
2392 << QStringLiteral("e68bf7b98d61fed0");
2393 QTest::newRow(dataTag: "") << QStringLiteral("55e67a79f043") << QStringLiteral("a868b107bd96f35c")
2394 << QStringLiteral("ae3ab00a0ba38be0");
2395 QTest::newRow(dataTag: "") << QStringLiteral("d77c93b63d6d5b") << QStringLiteral("19da07a34fa683c4")
2396 << QStringLiteral("9b661c7a536afc6d");
2397 QTest::newRow(dataTag: "") << QStringLiteral("328d09508e747ae1") << QStringLiteral("9c75845c6bff94438eb7e7e4c77342f0")
2398 << QStringLiteral("8e1c689280575f05");
2399 QTest::newRow(dataTag: "") << QStringLiteral("421d4bdc3869e59f07") << QStringLiteral("8df60dc27a2e2ee23360be31343fcbdb")
2400 << QStringLiteral("eb4a6b437572e1e7");
2401 QTest::newRow(dataTag: "") << QStringLiteral("160e525583c3e4fbc4fe") << QStringLiteral("9b649660dfe5b875cd81180ad627943f")
2402 << QStringLiteral("ffe58726b90c9f97");
2403 QTest::newRow(dataTag: "") << QStringLiteral("e873b3c2b31130719e6469") << QStringLiteral("6e33ae2af48cc39697800a3aa357cc5e")
2404 << QStringLiteral("560ee1ed2cc2bffb");
2405 QTest::newRow(dataTag: "") << QStringLiteral("405915adc0111eb8af225612")
2406 << QStringLiteral("569be1f2ae91785b0634f8dd4ec1dff2") << QStringLiteral("012a7de9cbfbd230");
2407 QTest::newRow(dataTag: "") << QStringLiteral("e923c535186730f309cdea6dea")
2408 << QStringLiteral("846d7314f76e00902054bd2b2ae1f580") << QStringLiteral("3d5d56ca2e8e359c");
2409 QTest::newRow(dataTag: "") << QStringLiteral("116053a5820f9d36650eef49a05b")
2410 << QStringLiteral("9bd56c43036485b648efe6d31e69f0c6") << QStringLiteral("2ad63a5312bf4259");
2411 QTest::newRow(dataTag: "") << QStringLiteral("b6dcd40077fe89138b5a2ed35e1b3d")
2412 << QStringLiteral("2fbe419bada6d4bf3f6c7bb2a1aac329") << QStringLiteral("7ff12d4d8a9ef138");
2413 QTest::newRow(dataTag: "") << QStringLiteral("08f0aa208f8a06c6292838a8cee9104e")
2414 << QStringLiteral("44bfca2722d274504af482e9261cdb7b16918be77a461b3b")
2415 << QStringLiteral("f71a3b1aabd660bd");
2416 QTest::newRow(dataTag: "") << QStringLiteral("878412f6255ff4360a22772711289fd351")
2417 << QStringLiteral("9c92fdde178d3b6c895aad1b8dc886176910b021d5b3aa77")
2418 << QStringLiteral("1ed8b08898872631");
2419 QTest::newRow(dataTag: "") << QStringLiteral("1399a0cd9f2778bcfba9c0f7e7c89ca069e3")
2420 << QStringLiteral("5972f89d8c161dd30a409bcdbf43b20bb104e8a293c48fdd")
2421 << QStringLiteral("0dcb3527035253a5");
2422 QTest::newRow(dataTag: "") << QStringLiteral("ea1cc272d3725e4c5dc56079fa3c9f26a1373a")
2423 << QStringLiteral("d1b2fcc83cbf11e022c058fcb988cbbbc3843517f5e9d900")
2424 << QStringLiteral("bf4b260909243b2f");
2425 QTest::newRow(dataTag: "") << QStringLiteral("098dd47ea5784d307c115824cfc3443983fdf58b")
2426 << QStringLiteral("77dfae7f46af6db0d0e5775859943e2875854a680b54b59b")
2427 << QStringLiteral("5d869f3486dfe1a1");
2428}
2429
2430// This is DES ECB, PKCS7 padding
2431void CipherUnitTest::des_pkcs7()
2432{
2433 bool anyProviderTested = false;
2434 foreach (const QString provider, providersToTest) {
2435 if (QCA::isSupported(features: "des-ecb-pkcs7", provider)) {
2436 anyProviderTested = true;
2437 QFETCH(QString, plainText);
2438 QFETCH(QString, cipherText);
2439 QFETCH(QString, keyText);
2440
2441 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2442 // just a filler
2443 QCA::InitializationVector iv;
2444 QCA::Cipher forwardCipher(
2445 QStringLiteral("des"), QCA::Cipher::ECB, QCA::Cipher::PKCS7, QCA::Encode, key, iv, provider);
2446
2447 QCOMPARE(forwardCipher.keyLength().minimum(), 8);
2448 QCOMPARE(forwardCipher.keyLength().maximum(), 8);
2449 QCOMPARE(forwardCipher.blockSize(), 8);
2450
2451 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2452 QVERIFY(forwardCipher.ok());
2453 QCOMPARE(update, cipherText.left(update.size()));
2454 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
2455 QVERIFY(forwardCipher.ok());
2456
2457 QCA::Cipher reverseCipher(
2458 QStringLiteral("des"), QCA::Cipher::ECB, QCA::Cipher::PKCS7, QCA::Decode, key, iv, provider);
2459
2460 QCOMPARE(reverseCipher.keyLength().minimum(), 8);
2461 QCOMPARE(reverseCipher.keyLength().maximum(), 8);
2462 QCOMPARE(reverseCipher.blockSize(), 8);
2463
2464 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
2465 QVERIFY(reverseCipher.ok());
2466 QCOMPARE(update, plainText.left(update.size()));
2467 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
2468 QVERIFY(reverseCipher.ok());
2469 }
2470 }
2471 if (!anyProviderTested)
2472 qWarning() << "NONE of the providers supports DES OFB with PKCS7 padding:" << providersToTest;
2473}
2474
2475// These are from the Botan test suite
2476void CipherUnitTest::des_cbc_pkcs7_data()
2477{
2478 QTest::addColumn<QString>(name: "plainText");
2479 QTest::addColumn<QString>(name: "cipherText");
2480 QTest::addColumn<QString>(name: "keyText");
2481 QTest::addColumn<QString>(name: "ivText");
2482
2483 QTest::newRow(dataTag: "1") << QStringLiteral("4e6f77206973207468652074696d6520666f7220616c6c20")
2484 << QStringLiteral("e5c7cdde872bf27c43e934008c389c0f683788499a7c05f662c16a27e4fcf277")
2485 << QStringLiteral("0123456789abcdef") << QStringLiteral("1234567890abcdef");
2486 QTest::newRow(dataTag: "2") << QString(QLatin1String("")) << QStringLiteral("ff4903e653af83c4")
2487 << QStringLiteral("46b534fbffdae457") << QStringLiteral("297873b948a44b5f");
2488 QTest::newRow(dataTag: "3") << QStringLiteral("69") << QStringLiteral("60fa7b46523aa51f")
2489 << QStringLiteral("d581a1d0c70f94a1") << QStringLiteral("c1ddd7447249ef80");
2490 QTest::newRow(dataTag: "4") << QStringLiteral("02b7") << QStringLiteral("63c1c1ef79555ed8")
2491 << QStringLiteral("a415b62e7e94caf2") << QStringLiteral("57fa9b2f95f57401");
2492 QTest::newRow(dataTag: "5") << QStringLiteral("568960") << QStringLiteral("d0321483090f524d")
2493 << QStringLiteral("5dcbe42db374090e") << QStringLiteral("b6215a095582763f");
2494 QTest::newRow(dataTag: "6") << QStringLiteral("b6eaf23c") << QStringLiteral("88e289e1de3e6451")
2495 << QStringLiteral("8fe92291c654ec9b") << QStringLiteral("0c054bbd31a9f623");
2496 QTest::newRow(dataTag: "7") << QStringLiteral("60a658cbbd") << QStringLiteral("89bffa9e36ff1780")
2497 << QStringLiteral("dbcee35e86088501") << QStringLiteral("11a8928bc6d0d117");
2498 QTest::newRow(dataTag: "8") << QStringLiteral("7e10cbd9e95c") << QStringLiteral("afc5cdf559abc6d3")
2499 << QStringLiteral("72338f946012ced5") << QStringLiteral("eaaa48b0c2ee2f3f");
2500 QTest::newRow(dataTag: "9") << QStringLiteral("d907ce88f077fa") << QStringLiteral("3476402272856ea8")
2501 << QStringLiteral("837fbb3167f0ccaa") << QStringLiteral("cd399dd3e402f8f2");
2502 QTest::newRow(dataTag: "10") << QStringLiteral("9476e85b198c9aee") << QStringLiteral("1af298a150514ca70d252f88271b3ca7")
2503 << QStringLiteral("308d1c02e7a4e09d") << QStringLiteral("6baa74f7f1a72e1f");
2504 QTest::newRow(dataTag: "11") << QStringLiteral("5c11285270e9606cdf") << QStringLiteral("78665abfe3def34f8bd55796825ee915")
2505 << QStringLiteral("126aff39882542ea") << QStringLiteral("51badb479de66a73");
2506 QTest::newRow(dataTag: "12") << QStringLiteral("d1d3d8675e42a4242fba") << QStringLiteral("e77bb4a24b4ee8c9ebda4971c2e60d10")
2507 << QStringLiteral("0ae8510bb0fb3994") << QStringLiteral("6c7293a8427bcb3b");
2508 QTest::newRow(dataTag: "13") << QStringLiteral("65026a8a41edc1d880f6c9")
2509 << QStringLiteral("45a6ef4acd49f9f1d892a808fa7b6f28") << QStringLiteral("0be9277b3504d524")
2510 << QStringLiteral("e47ec7a77db94755");
2511 QTest::newRow(dataTag: "14") << QStringLiteral("d72e81f4130107e396d5fb27")
2512 << QStringLiteral("a88eff91876a1b6958d52f99fe9b18fb") << QStringLiteral("2f03c36de4f78e13")
2513 << QStringLiteral("99fd2e8848f33fe7");
2514 QTest::newRow(dataTag: "15") << QStringLiteral("c8a3971efda18af1b18bfad98f")
2515 << QStringLiteral("54ff90bd90f6213d761f4b3ff89a8ded") << QStringLiteral("69329672e546c969")
2516 << QStringLiteral("294922cbe7e12341");
2517 QTest::newRow(dataTag: "16") << QStringLiteral("bb9a90f11551531de512dd48270e")
2518 << QStringLiteral("9ba7908e56edb1bef992faee40f5b1ca") << QStringLiteral("3007d71e86d8eaf2")
2519 << QStringLiteral("d7e300e168f60063");
2520 QTest::newRow(dataTag: "17") << QStringLiteral("77d6c182e4ddd444d614bcff98fb13")
2521 << QStringLiteral("cb50dec4728fc2f1a1a5dfb84fa1bd25") << QStringLiteral("f73c8c3355092eb6")
2522 << QStringLiteral("2e0db2552bb83ad3");
2523 QTest::newRow(dataTag: "18") << QStringLiteral("40aed22f93dcfcb1d734b7e4657dd31a")
2524 << QStringLiteral("66d17a6e9d5be3281e857b4c7e497988ca684524fd994882")
2525 << QStringLiteral("dd006f15e727cb62") << QStringLiteral("b256dc4fdb58451b");
2526 QTest::newRow(dataTag: "19") << QStringLiteral("bb25564c7ea1e5bd22016915805c27b51b")
2527 << QStringLiteral("b7ceb5f5ed2945f131064bbb9213694b19a04fbd1f138866")
2528 << QStringLiteral("df70ff987582ccfe") << QStringLiteral("88bb3b9bb2ea56d7");
2529 QTest::newRow(dataTag: "20") << QStringLiteral("49dab8d85ea753cf4ae2ece7a80f0784e42b")
2530 << QStringLiteral("d7fce9e5bed161ad7d950e453677e5bee422b7542afc0bd3")
2531 << QStringLiteral("747e09fa9ba257dc") << QStringLiteral("f1bbd406191de0d1");
2532 QTest::newRow(dataTag: "21") << QStringLiteral("dc13a6abaa35ceb3e6650f825a67942114af2e")
2533 << QStringLiteral("bafdb50e16c9ff4449bf336d410441d56e1e5335b54c9f11")
2534 << QStringLiteral("cdad411d0fa80e9d") << QStringLiteral("c83d55b1196958c4");
2535 QTest::newRow(dataTag: "22") << QStringLiteral("a8896d88907ad77ae790828c0a3384c1614e07d9")
2536 << QStringLiteral("70a9eb1c11bfd1b1d68c20a6b72c869dac5372a8ed46aa07")
2537 << QStringLiteral("642d12c591f6a4f4") << QStringLiteral("c17d0c69067af296");
2538 QTest::newRow(dataTag: "23") << QStringLiteral("b3fec4cc29dc1abbcf7d86f01d2c02c2a723e7c2f8")
2539 << QStringLiteral("48ed5583a04d333ffac9d6462fd96bf79222eeec70a6ae70")
2540 << QStringLiteral("62c62f54c426c59f") << QStringLiteral("cb6252ca271ff303");
2541 QTest::newRow(dataTag: "24") << QStringLiteral("ac0b4d5752d2009bdcd42314d9723716294146424542")
2542 << QStringLiteral("8a284713f8c9873ad5f558b995c5a67a66557a52601975d1")
2543 << QStringLiteral("386dcad5eae86830") << QStringLiteral("48153b966c8d686d");
2544 QTest::newRow(dataTag: "25") << QStringLiteral("ea331f6e518a8aeab2ef0a4e92e0d198df5dd0cc74369e")
2545 << QStringLiteral("6d3d7de9938935f9fb9af839e416ef6f842f2ed827334bfb")
2546 << QStringLiteral("782545ea65d89b01") << QStringLiteral("c2ce203020aabb0a");
2547 QTest::newRow(dataTag: "26") << QStringLiteral("b292d3a3fdc5d709709c87ef91122761847871f9b4e33426")
2548 << QStringLiteral("21dae17d157192146b52c49d90f898b25d0d1dfe677e8cd5b568814e9c6bb6a8")
2549 << QStringLiteral("ecc650e1ed1ce8a0") << QStringLiteral("aebc43ab811ab5f1");
2550 QTest::newRow(dataTag: "27") << QStringLiteral("65026a8a41edc1d880f6c90be9277b3504d524e47ec7a77db9")
2551 << QStringLiteral("a3b6404c4d87f72d5e0995d7cc20ece742d9705d48524cfa2820317087faf578")
2552 << QStringLiteral("4755b8639fd7c8a1") << QStringLiteral("4152e22f14baaf0a");
2553 QTest::newRow(dataTag: "28") << QStringLiteral("d1d3d8675e42a4242fba0ae8510bb0fb39946c7293a8427bcb3b")
2554 << QStringLiteral("db621f2fac9a924c83ed0b9e8acec9f1e23bf3ff2ad6efa814903f2ce293107b")
2555 << QStringLiteral("92a18b78a25c4b7a") << QStringLiteral("c3aabc68ceeb22d9");
2556 QTest::newRow(dataTag: "29") << QStringLiteral("c8a3971efda18af1b18bfad98f69329672e546c969294922cbe7e1")
2557 << QStringLiteral("940c610a41f04e7d9be0a74d5d00fe97a2647d3d16e9b76ff0db5bbdc197c82a")
2558 << QStringLiteral("2341239c09c73427") << QStringLiteral("c4d5b2b6863db060");
2559 QTest::newRow(dataTag: "30") << QStringLiteral("d72e81f4130107e396d5fb272f03c36de4f78e1399fd2e8848f33fe7")
2560 << QStringLiteral("7d495cba50c4127347e3ad29e3b8c098a3312782e3d45abfa1621f64bf8b8a06")
2561 << QStringLiteral("166ea8ed9d29e1b0") << QStringLiteral("2be993c1be8fe9ed");
2562 QTest::newRow(dataTag: "31") << QStringLiteral("77d6c182e4ddd444d614bcff98fb13f73c8c3355092eb62e0db2552bb8")
2563 << QStringLiteral("9d926142271e814ba4603509187c9020daa0d50f15af6e698e384644e9468c11")
2564 << QStringLiteral("3ad3301094b2f471") << QStringLiteral("8638489af44732f0");
2565 QTest::newRow(dataTag: "32") << QStringLiteral("bb9a90f11551531de512dd48270e3007d71e86d8eaf2d7e300e168f60063")
2566 << QStringLiteral("44858416f946c7fbdffd720282881630803803ab91ceab1af4f68f50e9c16dce")
2567 << QStringLiteral("04bbfd95ac12e6ff") << QStringLiteral("30cb120d13391c44");
2568 QTest::newRow(dataTag: "33") << QStringLiteral("8eb8faf49126ad5b8a0aa6df8b52dbe50dd5aed271641ef983bd650da69816")
2569 << QStringLiteral("5b4622f1c4faa817ee3ac181b969a7afed7117e23f68bc6017519a7d1399cfe9")
2570 << QStringLiteral("35501029e137d63d") << QStringLiteral("c1e0e3a06b357b51");
2571}
2572
2573void CipherUnitTest::des_cbc_pkcs7()
2574{
2575 bool anyProviderTested = false;
2576 foreach (const QString provider, providersToTest) {
2577 if (QCA::isSupported(features: "des-cbc-pkcs7", provider)) {
2578 anyProviderTested = true;
2579 QFETCH(QString, plainText);
2580 QFETCH(QString, cipherText);
2581 QFETCH(QString, keyText);
2582 QFETCH(QString, ivText);
2583
2584 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2585 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
2586 QCA::Cipher forwardCipher(
2587 QStringLiteral("des"), QCA::Cipher::CBC, QCA::Cipher::PKCS7, QCA::Encode, key, iv, provider);
2588
2589 QCOMPARE(forwardCipher.keyLength().minimum(), 8);
2590 QCOMPARE(forwardCipher.keyLength().maximum(), 8);
2591 QCOMPARE(forwardCipher.blockSize(), 8);
2592
2593 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2594 QVERIFY(forwardCipher.ok());
2595 QCOMPARE(update, cipherText.left(update.size()));
2596 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
2597 QVERIFY(forwardCipher.ok());
2598
2599 QCA::Cipher reverseCipher(
2600 QStringLiteral("des"), QCA::Cipher::CBC, QCA::Cipher::PKCS7, QCA::Decode, key, iv, provider);
2601
2602 QCOMPARE(reverseCipher.keyLength().minimum(), 8);
2603 QCOMPARE(reverseCipher.keyLength().maximum(), 8);
2604 QCOMPARE(reverseCipher.blockSize(), 8);
2605
2606 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
2607 QVERIFY(reverseCipher.ok());
2608 QCOMPARE(update, plainText.left(update.size()));
2609 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
2610 QVERIFY(reverseCipher.ok());
2611 }
2612 }
2613 if (!anyProviderTested)
2614 qWarning() << "NONE of the providers supports DES CBC with PKCS7 padding:" << providersToTest;
2615}
2616
2617#if 0
2618if (!QCA::isSupported("des-ecb-pkcs7") )
2619QWARN("DES, ECB mode with PKCS7 padding not supported!");
2620else {
2621QCA::Cipher cipherObj1( QStringLiteral( "des" ),
2622 QCA::Cipher::ECB,
2623 QCA::Cipher::PKCS7,
2624 QCA::Encode,
2625 QCA::SymmetricKey( 8 ) );
2626QCOMPARE( cipherObj1.keyLength().minimum(), 8 );
2627QCOMPARE( cipherObj1.keyLength().maximum(), 8 );
2628QCOMPARE( cipherObj1.blockSize(), 8 );
2629
2630for (int n = 0; (0 != desEcbPkcs7TestValues[n].plaintext); n++) {
2631 QCA::SymmetricKey key( QCA::hexToArray( desEcbPkcs7TestValues[n].key ) );
2632 QCA::DES forwardCipher( QCA::Cipher::ECB, QCA::Cipher::PKCS7, QCA::Encode, key);
2633 QCOMPARE( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( desEcbPkcs7TestValues[n].plaintext ) ).toByteArray() ),
2634 QString( desEcbPkcs7TestValues[n].ciphertext ) );
2635 QCOMPARE( forwardCipher.ok(), true );
2636 QCOMPARE( QCA::arrayToHex( forwardCipher.final().toByteArray() ), QLatin1String( "" ) );
2637 QCOMPARE( forwardCipher.ok(), true );
2638
2639 QCA::DES reverseCipher( QCA::Cipher::ECB, QCA::Cipher::PKCS7, QCA::Decode, key);
2640
2641 QCOMPARE( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( desEcbPkcs7TestValues[n].ciphertext ) ).toByteArray() ),
2642 QString( desEcbPkcs7TestValues[n].plaintext ) );
2643 QCOMPARE( reverseCipher.ok(), true );
2644 QCOMPARE( QCA::arrayToHex( reverseCipher.final().toByteArray() ), QLatin1String( "" ) );
2645 QCOMPARE( reverseCipher.ok(), true );
2646}
2647}
2648#endif
2649
2650// These are from the Botan test suite. They match the test vectors from Bruce's site
2651void CipherUnitTest::blowfish_data()
2652{
2653 QTest::addColumn<QString>(name: "plainText");
2654 QTest::addColumn<QString>(name: "cipherText");
2655 QTest::addColumn<QString>(name: "keyText");
2656
2657 QTest::newRow(dataTag: "1") << QStringLiteral("0000000000000000") << QStringLiteral("245946885754369a")
2658 << QStringLiteral("0123456789abcdef");
2659 QTest::newRow(dataTag: "2") << QStringLiteral("0000000000000000") << QStringLiteral("4ef997456198dd78")
2660 << QStringLiteral("0000000000000000");
2661 QTest::newRow(dataTag: "3") << QStringLiteral("0000000000000000") << QStringLiteral("f21e9a77b71c49bc")
2662 << QStringLiteral("ffffffffffffffff");
2663 QTest::newRow(dataTag: "4") << QStringLiteral("004bd6ef09176062") << QStringLiteral("452031c1e4fada8e")
2664 << QStringLiteral("584023641aba6176");
2665 QTest::newRow(dataTag: "5") << QStringLiteral("0123456789abcdef") << QStringLiteral("0aceab0fc6a0a28d")
2666 << QStringLiteral("fedcba9876543210");
2667 QTest::newRow(dataTag: "6") << QStringLiteral("0123456789abcdef") << QStringLiteral("7d0cc630afda1ec7")
2668 << QStringLiteral("1111111111111111");
2669 QTest::newRow(dataTag: "7") << QStringLiteral("0123456789abcdef") << QStringLiteral("a790795108ea3cae")
2670 << QStringLiteral("1f1f1f1f0e0e0e0e");
2671 QTest::newRow(dataTag: "8") << QStringLiteral("0123456789abcdef") << QStringLiteral("c39e072d9fac631d")
2672 << QStringLiteral("e0fee0fef1fef1fe");
2673 QTest::newRow(dataTag: "9") << QStringLiteral("0123456789abcdef") << QStringLiteral("fa34ec4847b268b2")
2674 << QStringLiteral("0101010101010101");
2675 QTest::newRow(dataTag: "10") << QStringLiteral("01a1d6d039776742") << QStringLiteral("59c68245eb05282b")
2676 << QStringLiteral("7ca110454a1a6e57");
2677 QTest::newRow(dataTag: "11") << QStringLiteral("0248d43806f67172") << QStringLiteral("1730e5778bea1da4")
2678 << QStringLiteral("07a1133e4a0b2686");
2679 QTest::newRow(dataTag: "12") << QStringLiteral("02fe55778117f12a") << QStringLiteral("cf9c5d7a4986adb5")
2680 << QStringLiteral("49e95d6d4ca229bf");
2681 QTest::newRow(dataTag: "13") << QStringLiteral("059b5e0851cf143a") << QStringLiteral("48f4d0884c379918")
2682 << QStringLiteral("0113b970fd34f2ce");
2683 QTest::newRow(dataTag: "14") << QStringLiteral("072d43a077075292") << QStringLiteral("7a8e7bfa937e89a3")
2684 << QStringLiteral("4fb05e1515ab73a7");
2685 QTest::newRow(dataTag: "15") << QStringLiteral("0756d8e0774761d2") << QStringLiteral("432193b78951fc98")
2686 << QStringLiteral("0170f175468fb5e6");
2687 QTest::newRow(dataTag: "16") << QStringLiteral("1000000000000001") << QStringLiteral("7d856f9a613063f2")
2688 << QStringLiteral("3000000000000000");
2689 QTest::newRow(dataTag: "17") << QStringLiteral("1111111111111111") << QStringLiteral("2466dd878b963c9d")
2690 << QStringLiteral("1111111111111111");
2691 QTest::newRow(dataTag: "18") << QStringLiteral("1111111111111111") << QStringLiteral("61f9c3802281b096")
2692 << QStringLiteral("0123456789abcdef");
2693 QTest::newRow(dataTag: "19") << QStringLiteral("164d5e404f275232") << QStringLiteral("5f99d04f5b163969")
2694 << QStringLiteral("37d06bb516cb7546");
2695 QTest::newRow(dataTag: "20") << QStringLiteral("1d9d5c5018f728c2") << QStringLiteral("d1abb290658bc778")
2696 << QStringLiteral("018310dc409b26d6");
2697 QTest::newRow(dataTag: "21") << QStringLiteral("26955f6835af609a") << QStringLiteral("d887e0393c2da6e3")
2698 << QStringLiteral("04689104c2fd3b2f");
2699 QTest::newRow(dataTag: "22") << QStringLiteral("305532286d6f295a") << QStringLiteral("55cb3774d13ef201")
2700 << QStringLiteral("1c587f1c13924fef");
2701 QTest::newRow(dataTag: "23") << QStringLiteral("3bdd119049372802") << QStringLiteral("2eedda93ffd39c79")
2702 << QStringLiteral("07a7137045da2a16");
2703 QTest::newRow(dataTag: "24") << QStringLiteral("42fd443059577fa2") << QStringLiteral("353882b109ce8f1a")
2704 << QStringLiteral("04b915ba43feb5b6");
2705 QTest::newRow(dataTag: "25") << QStringLiteral("437540c8698f3cfa") << QStringLiteral("53c55f9cb49fc019")
2706 << QStringLiteral("49793ebc79b3258f");
2707 QTest::newRow(dataTag: "26") << QStringLiteral("480d39006ee762f2") << QStringLiteral("7555ae39f59b87bd")
2708 << QStringLiteral("025816164629b007");
2709 QTest::newRow(dataTag: "27") << QStringLiteral("51454b582ddf440a") << QStringLiteral("a25e7856cf2651eb")
2710 << QStringLiteral("3849674c2602319e");
2711 QTest::newRow(dataTag: "28") << QStringLiteral("5cd54ca83def57da") << QStringLiteral("b1b8cc0b250f09a0")
2712 << QStringLiteral("0131d9619dc1376e");
2713 QTest::newRow(dataTag: "29") << QStringLiteral("6b056e18759f5cca") << QStringLiteral("4a057a3b24d3977b")
2714 << QStringLiteral("1f08260d1ac2465e");
2715 QTest::newRow(dataTag: "30") << QStringLiteral("762514b829bf486a") << QStringLiteral("13f04154d69d1ae5")
2716 << QStringLiteral("43297fad38e373fe");
2717 QTest::newRow(dataTag: "31") << QStringLiteral("ffffffffffffffff") << QStringLiteral("014933e0cdaff6e4")
2718 << QStringLiteral("0000000000000000");
2719 QTest::newRow(dataTag: "32") << QStringLiteral("ffffffffffffffff") << QStringLiteral("51866fd5b85ecb8a")
2720 << QStringLiteral("ffffffffffffffff");
2721 QTest::newRow(dataTag: "33") << QStringLiteral("ffffffffffffffff") << QStringLiteral("6b5c5a9c5d9e0a5a")
2722 << QStringLiteral("fedcba9876543210");
2723 QTest::newRow(dataTag: "34") << QStringLiteral("0123456789abcdef1111111111111111")
2724 << QStringLiteral("7d0cc630afda1ec72466dd878b963c9d") << QStringLiteral("1111111111111111");
2725 QTest::newRow(dataTag: "35") << QStringLiteral("fedcba9876543210") << QStringLiteral("cc91732b8022f684")
2726 << QStringLiteral("57686f206973204a6f686e2047616c743f");
2727 QTest::newRow(dataTag: "36") << QStringLiteral("424c4f5746495348") << QStringLiteral("324ed0fef413a203")
2728 << QStringLiteral("6162636465666768696a6b6c6d6e6f707172737475767778797a");
2729 QTest::newRow(dataTag: "37") << QStringLiteral("fedcba9876543210") << QStringLiteral("f9ad597c49db005e")
2730 << QStringLiteral("f0");
2731 QTest::newRow(dataTag: "38") << QStringLiteral("fedcba9876543210") << QStringLiteral("e91d21c1d961a6d6")
2732 << QStringLiteral("f0e1");
2733 QTest::newRow(dataTag: "39") << QStringLiteral("fedcba9876543210") << QStringLiteral("e9c2b70a1bc65cf3")
2734 << QStringLiteral("f0e1d2");
2735 QTest::newRow(dataTag: "40") << QStringLiteral("fedcba9876543210") << QStringLiteral("be1e639408640f05")
2736 << QStringLiteral("f0e1d2c3");
2737 QTest::newRow(dataTag: "41") << QStringLiteral("fedcba9876543210") << QStringLiteral("b39e44481bdb1e6e")
2738 << QStringLiteral("f0e1d2c3b4");
2739 QTest::newRow(dataTag: "42") << QStringLiteral("fedcba9876543210") << QStringLiteral("9457aa83b1928c0d")
2740 << QStringLiteral("f0e1d2c3b4a5");
2741 QTest::newRow(dataTag: "43") << QStringLiteral("fedcba9876543210") << QStringLiteral("8bb77032f960629d")
2742 << QStringLiteral("f0e1d2c3b4a596");
2743 QTest::newRow(dataTag: "44") << QStringLiteral("fedcba9876543210") << QStringLiteral("e87a244e2cc85e82")
2744 << QStringLiteral("f0e1d2c3b4a59687");
2745 QTest::newRow(dataTag: "45") << QStringLiteral("fedcba9876543210") << QStringLiteral("15750e7a4f4ec577")
2746 << QStringLiteral("f0e1d2c3b4a5968778");
2747 QTest::newRow(dataTag: "46") << QStringLiteral("fedcba9876543210") << QStringLiteral("122ba70b3ab64ae0")
2748 << QStringLiteral("f0e1d2c3b4a596877869");
2749 QTest::newRow(dataTag: "47") << QStringLiteral("fedcba9876543210") << QStringLiteral("3a833c9affc537f6")
2750 << QStringLiteral("f0e1d2c3b4a5968778695a");
2751 QTest::newRow(dataTag: "48") << QStringLiteral("fedcba9876543210") << QStringLiteral("9409da87a90f6bf2")
2752 << QStringLiteral("f0e1d2c3b4a5968778695a4b");
2753 QTest::newRow(dataTag: "49") << QStringLiteral("fedcba9876543210") << QStringLiteral("884f80625060b8b4")
2754 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c");
2755 QTest::newRow(dataTag: "50") << QStringLiteral("fedcba9876543210") << QStringLiteral("1f85031c19e11968")
2756 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d");
2757 QTest::newRow(dataTag: "51") << QStringLiteral("fedcba9876543210") << QStringLiteral("79d9373a714ca34f")
2758 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e");
2759 QTest::newRow(dataTag: "52") << QStringLiteral("fedcba9876543210") << QStringLiteral("93142887ee3be15c")
2760 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e0f");
2761 QTest::newRow(dataTag: "53") << QStringLiteral("fedcba9876543210") << QStringLiteral("03429e838ce2d14b")
2762 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e0f00");
2763 QTest::newRow(dataTag: "54") << QStringLiteral("fedcba9876543210") << QStringLiteral("a4299e27469ff67b")
2764 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e0f0011");
2765 QTest::newRow(dataTag: "55") << QStringLiteral("fedcba9876543210") << QStringLiteral("afd5aed1c1bc96a8")
2766 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e0f001122");
2767 QTest::newRow(dataTag: "56") << QStringLiteral("fedcba9876543210") << QStringLiteral("10851c0e3858da9f")
2768 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e0f00112233");
2769 QTest::newRow(dataTag: "57") << QStringLiteral("fedcba9876543210") << QStringLiteral("e6f51ed79b9db21f")
2770 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344");
2771 QTest::newRow(dataTag: "58") << QStringLiteral("fedcba9876543210") << QStringLiteral("64a6e14afd36b46f")
2772 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455");
2773 QTest::newRow(dataTag: "59") << QStringLiteral("fedcba9876543210") << QStringLiteral("80c7d7d45a5479ad")
2774 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566");
2775 QTest::newRow(dataTag: "60") << QStringLiteral("fedcba9876543210") << QStringLiteral("05044b62fa52d080")
2776 << QStringLiteral("f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344556677");
2777}
2778
2779void CipherUnitTest::blowfish()
2780{
2781 bool anyProviderTested = false;
2782 foreach (const QString provider, providersToTest) {
2783 if (QCA::isSupported(features: "blowfish-ecb", provider)) {
2784 anyProviderTested = true;
2785 QCA::Cipher cipherObj1(QStringLiteral("blowfish"),
2786 QCA::Cipher::ECB,
2787 QCA::Cipher::NoPadding,
2788 QCA::Encode,
2789 QCA::SymmetricKey(16),
2790 QCA::InitializationVector(),
2791 provider);
2792
2793 // TODO: add some test for min and max keysizes
2794 QCOMPARE(cipherObj1.blockSize(), 8);
2795
2796 QFETCH(QString, plainText);
2797 QFETCH(QString, cipherText);
2798 QFETCH(QString, keyText);
2799
2800 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2801 QCA::Cipher forwardCipher(QStringLiteral("blowfish"),
2802 QCA::Cipher::ECB,
2803 QCA::Cipher::NoPadding,
2804 QCA::Encode,
2805 key,
2806 QCA::InitializationVector(),
2807 provider);
2808
2809 QString afterEncodeText = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2810 QVERIFY(forwardCipher.ok());
2811
2812 afterEncodeText += QCA::arrayToHex(array: forwardCipher.final().toByteArray());
2813 QVERIFY(forwardCipher.ok());
2814
2815 QCOMPARE(afterEncodeText, cipherText);
2816
2817 QCA::Cipher reverseCipher(QStringLiteral("blowfish"),
2818 QCA::Cipher::ECB,
2819 QCA::Cipher::NoPadding,
2820 QCA::Decode,
2821 key,
2822 QCA::InitializationVector(),
2823 provider);
2824 QString afterDecodeText = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
2825 QVERIFY(reverseCipher.ok());
2826
2827 afterDecodeText += QCA::arrayToHex(array: reverseCipher.final().toByteArray());
2828 QVERIFY(reverseCipher.ok());
2829
2830 QCOMPARE(afterDecodeText, plainText);
2831 }
2832 }
2833 if (!anyProviderTested)
2834 qWarning() << "NONE of the providers supports Blowfish ECB:" << providersToTest;
2835}
2836
2837// From the Eric Young test vectors on Bruce's site. I modified
2838// them to remove the incomplete block.
2839void CipherUnitTest::blowfish_cbc_data()
2840{
2841 QTest::addColumn<QString>(name: "plainText");
2842 QTest::addColumn<QString>(name: "cipherText");
2843 QTest::addColumn<QString>(name: "keyText");
2844 QTest::addColumn<QString>(name: "ivText");
2845
2846 QTest::newRow(dataTag: "1") << QStringLiteral("37363534333231204e6f77206973207468652074696d6520")
2847 << QStringLiteral("6b77b4d63006dee605b156e27403979358deb9e7154616d9")
2848 << QStringLiteral("0123456789abcdeff0e1d2c3b4a59687") << QStringLiteral("fedcba9876543210");
2849 QTest::newRow(dataTag: "pkcs7") << QStringLiteral("37363534333231204e6f77206973207468652074696d6520666f722000030303")
2850 << QStringLiteral("6b77b4d63006dee605b156e27403979358deb9e7154616d9749decbec05d264b")
2851 << QStringLiteral("0123456789abcdeff0e1d2c3b4a59687") << QStringLiteral("fedcba9876543210");
2852}
2853
2854void CipherUnitTest::blowfish_cbc()
2855{
2856 bool anyProviderTested = false;
2857 foreach (const QString provider, providersToTest) {
2858 if (QCA::isSupported(features: "blowfish-cbc", provider)) {
2859 anyProviderTested = true;
2860 QFETCH(QString, plainText);
2861 QFETCH(QString, cipherText);
2862 QFETCH(QString, keyText);
2863 QFETCH(QString, ivText);
2864
2865 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2866 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
2867 QCA::Cipher forwardCipher(
2868 QStringLiteral("blowfish"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
2869 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2870 QVERIFY(forwardCipher.ok());
2871 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
2872 QVERIFY(forwardCipher.ok());
2873
2874 QCA::Cipher reverseCipher(
2875 QStringLiteral("blowfish"), QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
2876 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
2877 QVERIFY(reverseCipher.ok());
2878 QCOMPARE(update, plainText.left(update.size()));
2879 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
2880 QVERIFY(reverseCipher.ok());
2881 }
2882 }
2883 if (!anyProviderTested)
2884 qWarning() << "NONE of the providers supports Blowfish CBC:" << providersToTest;
2885}
2886
2887// I can't find any independent test vectors. I used the no padding case, with hand padding added,
2888// as a poor check.
2889void CipherUnitTest::blowfish_cbc_pkcs7_data()
2890{
2891 QTest::addColumn<QString>(name: "plainText");
2892 QTest::addColumn<QString>(name: "cipherText");
2893 QTest::addColumn<QString>(name: "keyText");
2894 QTest::addColumn<QString>(name: "ivText");
2895
2896 QTest::newRow(dataTag: "1") << QStringLiteral("37363534333231204e6f77206973207468652074696d6520666f722000")
2897 << QStringLiteral("6b77b4d63006dee605b156e27403979358deb9e7154616d9749decbec05d264b")
2898 << QStringLiteral("0123456789abcdeff0e1d2c3b4a59687") << QStringLiteral("fedcba9876543210");
2899}
2900
2901void CipherUnitTest::blowfish_cbc_pkcs7()
2902{
2903 bool anyProviderTested = false;
2904 foreach (const QString provider, providersToTest) {
2905 if (QCA::isSupported(features: "blowfish-cbc-pkcs7", provider)) {
2906 anyProviderTested = true;
2907 QFETCH(QString, plainText);
2908 QFETCH(QString, cipherText);
2909 QFETCH(QString, keyText);
2910 QFETCH(QString, ivText);
2911
2912 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2913 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
2914 QCA::Cipher forwardCipher(
2915 QStringLiteral("blowfish"), QCA::Cipher::CBC, QCA::Cipher::PKCS7, QCA::Encode, key, iv, provider);
2916 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2917 QVERIFY(forwardCipher.ok());
2918 QCOMPARE(update, cipherText.left(update.size()));
2919 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
2920 QVERIFY(forwardCipher.ok());
2921
2922 QCA::Cipher reverseCipher(
2923 QStringLiteral("blowfish"), QCA::Cipher::CBC, QCA::Cipher::PKCS7, QCA::Decode, key, iv, provider);
2924 update = QCA::arrayToHex(array: reverseCipher.update(a: QCA::hexToArray(hexString: cipherText)).toByteArray());
2925 QVERIFY(reverseCipher.ok());
2926 QCOMPARE(update, plainText.left(update.size()));
2927 QCOMPARE(QString(update + QCA::arrayToHex(reverseCipher.final().toByteArray())), plainText);
2928 QVERIFY(reverseCipher.ok());
2929 }
2930 }
2931 if (!anyProviderTested)
2932 qWarning() << "NONE of the providers supports Blowfish CBC with PKCS7 padding:" << providersToTest;
2933}
2934
2935// From the Eric Young test vectors on Bruce's site:
2936void CipherUnitTest::blowfish_cfb_data()
2937{
2938 QTest::addColumn<QString>(name: "plainText");
2939 QTest::addColumn<QString>(name: "cipherText");
2940 QTest::addColumn<QString>(name: "keyText");
2941 QTest::addColumn<QString>(name: "ivText");
2942
2943 QTest::newRow(dataTag: "1") << QStringLiteral("37363534333231204e6f77206973207468652074696d6520666f722000")
2944 << QStringLiteral("e73214a2822139caf26ecf6d2eb9e76e3da3de04d1517200519d57a6c3")
2945 << QStringLiteral("0123456789abcdeff0e1d2c3b4a59687") << QStringLiteral("fedcba9876543210");
2946}
2947
2948void CipherUnitTest::blowfish_cfb()
2949{
2950 bool anyProviderTested = false;
2951 foreach (const QString provider, providersToTest) {
2952 if (QCA::isSupported(features: "blowfish-cfb", provider)) {
2953 anyProviderTested = true;
2954 QFETCH(QString, plainText);
2955 QFETCH(QString, cipherText);
2956 QFETCH(QString, keyText);
2957 QFETCH(QString, ivText);
2958
2959 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
2960 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
2961 QCA::Cipher forwardCipher(
2962 QStringLiteral("blowfish"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
2963 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
2964 QVERIFY(forwardCipher.ok());
2965 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
2966 QVERIFY(forwardCipher.ok());
2967
2968 QCA::Cipher reverseCipher(
2969 QStringLiteral("blowfish"), QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
2970 QCOMPARE(QCA::arrayToHex(reverseCipher.update(QCA::hexToArray(cipherText)).toByteArray()), plainText);
2971 QVERIFY(reverseCipher.ok());
2972 QCOMPARE(QCA::arrayToHex(reverseCipher.final().toByteArray()), QLatin1String(""));
2973 QVERIFY(reverseCipher.ok());
2974 }
2975 }
2976 if (!anyProviderTested)
2977 qWarning() << "NONE of the providers supports Blowfish CFB:" << providersToTest;
2978}
2979
2980// From the Eric Young test vectors on Bruce's site:
2981void CipherUnitTest::blowfish_ofb_data()
2982{
2983 QTest::addColumn<QString>(name: "plainText");
2984 QTest::addColumn<QString>(name: "cipherText");
2985 QTest::addColumn<QString>(name: "keyText");
2986 QTest::addColumn<QString>(name: "ivText");
2987
2988 QTest::newRow(dataTag: "1") << QStringLiteral("37363534333231204e6f77206973207468652074696d6520666f722000")
2989 << QStringLiteral("e73214a2822139ca62b343cc5b65587310dd908d0c241b2263c2cf80da")
2990 << QStringLiteral("0123456789abcdeff0e1d2c3b4a59687") << QStringLiteral("fedcba9876543210");
2991}
2992
2993void CipherUnitTest::blowfish_ofb()
2994{
2995 bool anyProviderTested = false;
2996 foreach (const QString provider, providersToTest) {
2997 if (QCA::isSupported(features: "blowfish-ofb", provider)) {
2998 anyProviderTested = true;
2999 QFETCH(QString, plainText);
3000 QFETCH(QString, cipherText);
3001 QFETCH(QString, keyText);
3002 QFETCH(QString, ivText);
3003
3004 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
3005 QCA::InitializationVector iv(QCA::hexToArray(hexString: ivText));
3006 QCA::Cipher forwardCipher(
3007 QStringLiteral("blowfish"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
3008 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
3009 QVERIFY(forwardCipher.ok());
3010 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
3011 QVERIFY(forwardCipher.ok());
3012
3013 QCA::Cipher reverseCipher(
3014 QStringLiteral("blowfish"), QCA::Cipher::OFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
3015
3016 QCOMPARE(QCA::arrayToHex(reverseCipher.update(QCA::hexToArray(cipherText)).toByteArray()), plainText);
3017 QVERIFY(reverseCipher.ok());
3018 QCOMPARE(QCA::arrayToHex(reverseCipher.final().toByteArray()), QLatin1String(""));
3019 QVERIFY(reverseCipher.ok());
3020 }
3021 }
3022 if (!anyProviderTested)
3023 qWarning() << "NONE of the providers supports Blowfish OFB:" << providersToTest;
3024}
3025
3026// From RFC2144 Appendix B
3027void CipherUnitTest::cast5_data()
3028{
3029 QTest::addColumn<QString>(name: "plainText");
3030 QTest::addColumn<QString>(name: "cipherText");
3031 QTest::addColumn<QString>(name: "keyText");
3032
3033 QTest::newRow(dataTag: "128-bit") << QStringLiteral("0123456789abcdef") << QStringLiteral("238b4fe5847e44b2")
3034 << QStringLiteral("0123456712345678234567893456789A");
3035
3036 QTest::newRow(dataTag: "80-bit") << QStringLiteral("0123456789abcdef") << QStringLiteral("eb6a711a2c02271b")
3037 << QStringLiteral("01234567123456782345");
3038
3039 QTest::newRow(dataTag: "40-bit") << QStringLiteral("0123456789abcdef") << QStringLiteral("7ac816d16e9b302e")
3040 << QStringLiteral("0123456712");
3041}
3042
3043void CipherUnitTest::cast5()
3044{
3045 bool anyProviderTested = false;
3046 foreach (const QString provider, providersToTest) {
3047 if (QCA::isSupported(features: "cast5-ecb", provider)) {
3048 anyProviderTested = true;
3049 QFETCH(QString, plainText);
3050 QFETCH(QString, cipherText);
3051 QFETCH(QString, keyText);
3052
3053 QCA::SymmetricKey key(QCA::hexToArray(hexString: keyText));
3054 QCA::InitializationVector iv;
3055 QCA::Cipher forwardCipher(
3056 QStringLiteral("cast5"), QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key, iv, provider);
3057 QString update = QCA::arrayToHex(array: forwardCipher.update(a: QCA::hexToArray(hexString: plainText)).toByteArray());
3058 QVERIFY(forwardCipher.ok());
3059 QCOMPARE(QString(update + QCA::arrayToHex(forwardCipher.final().toByteArray())), cipherText);
3060 QVERIFY(forwardCipher.ok());
3061
3062 QCA::Cipher reverseCipher(
3063 QStringLiteral("cast5"), QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key, iv, provider);
3064
3065 QCOMPARE(QCA::arrayToHex(reverseCipher.update(QCA::hexToArray(cipherText)).toByteArray()), plainText);
3066 QVERIFY(reverseCipher.ok());
3067 QCOMPARE(QCA::arrayToHex(reverseCipher.final().toByteArray()), QLatin1String(""));
3068 QVERIFY(reverseCipher.ok());
3069 }
3070 }
3071 if (!anyProviderTested)
3072 qWarning() << "NONE of the providers supports CAST5:" << providersToTest;
3073}
3074
3075QTEST_MAIN(CipherUnitTest)
3076

source code of qca/unittest/cipherunittest/cipherunittest.cpp