Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2015-05-09 20:47:53 +0300
committerFelix Geyer <debfx@fobos.de>2015-05-10 00:21:44 +0300
commita762cef0a93661fe6563c89da8f0cdfca713cdbb (patch)
tree9de727fe5dcb16eba41a7596390b81a2133e6ee9 /tests/TestSymmetricCipher.cpp
parenta7f4e2d0cddba53167dc4ae02a28a7971f4b4e2f (diff)
Catch and handle all errors from libgcrypt.
Diffstat (limited to 'tests/TestSymmetricCipher.cpp')
-rw-r--r--tests/TestSymmetricCipher.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/tests/TestSymmetricCipher.cpp b/tests/TestSymmetricCipher.cpp
index 6d4e94f6f..ec9badd90 100644
--- a/tests/TestSymmetricCipher.cpp
+++ b/tests/TestSymmetricCipher.cpp
@@ -42,17 +42,20 @@ void TestSymmetricCipher::testAes256CbcEncryption()
plainText.append(QByteArray::fromHex("ae2d8a571e03ac9c9eb76fac45af8e51"));
QByteArray cipherText = QByteArray::fromHex("f58c4c04d6e5f1ba779eabfb5f7bfbd6");
cipherText.append(QByteArray::fromHex("9cfc4e967edb808d679f777bc6702c7d"));
+ bool ok;
- SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt,
- key, iv);
+ SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt);
+ QVERIFY(cipher.init(key, iv));
QCOMPARE(cipher.blockSize(), 16);
- QCOMPARE(cipher.process(plainText),
+ QCOMPARE(cipher.process(plainText, &ok),
cipherText);
+ QVERIFY(ok);
QBuffer buffer;
SymmetricCipherStream stream(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
- SymmetricCipher::Encrypt, key, iv);
+ SymmetricCipher::Encrypt);
+ QVERIFY(stream.init(key, iv));
buffer.open(QIODevice::WriteOnly);
stream.open(QIODevice::WriteOnly);
QVERIFY(stream.reset());
@@ -86,18 +89,22 @@ void TestSymmetricCipher::testAes256CbcDecryption()
cipherText.append(QByteArray::fromHex("9cfc4e967edb808d679f777bc6702c7d"));
QByteArray plainText = QByteArray::fromHex("6bc1bee22e409f96e93d7e117393172a");
plainText.append(QByteArray::fromHex("ae2d8a571e03ac9c9eb76fac45af8e51"));
+ bool ok;
- SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Decrypt, key, iv);
+ SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Decrypt);
+ QVERIFY(cipher.init(key, iv));
QCOMPARE(cipher.blockSize(), 16);
- QCOMPARE(cipher.process(cipherText),
+ QCOMPARE(cipher.process(cipherText, &ok),
plainText);
+ QVERIFY(ok);
// padded with 16 0x16 bytes
QByteArray cipherTextPadded = cipherText + QByteArray::fromHex("3a3aa5e0213db1a9901f9036cf5102d2");
QBuffer buffer(&cipherTextPadded);
SymmetricCipherStream stream(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
- SymmetricCipher::Decrypt, key, iv);
+ SymmetricCipher::Decrypt);
+ QVERIFY(stream.init(key, iv));
buffer.open(QIODevice::ReadOnly);
stream.open(QIODevice::ReadOnly);
@@ -123,16 +130,20 @@ void TestSymmetricCipher::testSalsa20()
QByteArray key = QByteArray::fromHex("F3F4F5F6F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E0F101112");
QByteArray iv = QByteArray::fromHex("0000000000000000");
+ bool ok;
- SymmetricCipher cipher(SymmetricCipher::Salsa20, SymmetricCipher::Stream, SymmetricCipher::Encrypt, key, iv);
+ SymmetricCipher cipher(SymmetricCipher::Salsa20, SymmetricCipher::Stream, SymmetricCipher::Encrypt);
+ QVERIFY(cipher.init(key, iv));
QByteArray cipherTextA;
for (int i = 0; i < 8; i++) {
- cipherTextA.append(cipher.process(QByteArray(64, '\0')));
+ cipherTextA.append(cipher.process(QByteArray(64, '\0'), &ok));
+ QVERIFY(ok);
}
cipher.reset();
- QByteArray cipherTextB = cipher.process(QByteArray(512, '\0'));
+ QByteArray cipherTextB = cipher.process(QByteArray(512, '\0'), &ok);
+ QVERIFY(ok);
cipher.reset();
QByteArray expectedCipherText1;
@@ -180,7 +191,8 @@ void TestSymmetricCipher::testPadding()
buffer.open(QIODevice::ReadWrite);
SymmetricCipherStream streamEnc(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
- SymmetricCipher::Encrypt, key, iv);
+ SymmetricCipher::Encrypt);
+ QVERIFY(streamEnc.init(key, iv));
streamEnc.open(QIODevice::WriteOnly);
streamEnc.write(plainText);
streamEnc.close();
@@ -189,7 +201,8 @@ void TestSymmetricCipher::testPadding()
QCOMPARE(buffer.buffer().size(), 16);
SymmetricCipherStream streamDec(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
- SymmetricCipher::Decrypt, key, iv);
+ SymmetricCipher::Decrypt);
+ QVERIFY(streamDec.init(key, iv));
streamDec.open(QIODevice::ReadOnly);
QByteArray decrypted = streamDec.readAll();
QCOMPARE(decrypted, plainText);