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:
Diffstat (limited to 'src/crypto/Crypto.cpp')
-rw-r--r--src/crypto/Crypto.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/crypto/Crypto.cpp b/src/crypto/Crypto.cpp
index d00be720b..7ba78a6b3 100644
--- a/src/crypto/Crypto.cpp
+++ b/src/crypto/Crypto.cpp
@@ -95,18 +95,28 @@ bool Crypto::checkAlgorithms()
qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr));
return false;
}
+ if (gcry_cipher_algo_info(GCRY_CIPHER_CHACHA20, GCRYCTL_TEST_ALGO, nullptr, nullptr) != 0) {
+ m_errorStr = "GCRY_CIPHER_CHACHA20 not found.";
+ qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr));
+ return false;
+ }
if (gcry_md_test_algo(GCRY_MD_SHA256) != 0) {
m_errorStr = "GCRY_MD_SHA256 not found.";
qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr));
return false;
}
+ if (gcry_md_test_algo(GCRY_MD_SHA512) != 0) {
+ m_errorStr = "GCRY_MD_SHA512 not found.";
+ qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr));
+ return false;
+ }
return true;
}
bool Crypto::selfTest()
{
- return testSha256() && testAes256Cbc() && testAes256Ecb() && testTwofish() && testSalsa20();
+ return testSha256() && testSha512() && testAes256Cbc() && testAes256Ecb() && testTwofish() && testSalsa20() && testChaCha20();
}
void Crypto::raiseError(const QString& str)
@@ -128,6 +138,19 @@ bool Crypto::testSha256()
return true;
}
+bool Crypto::testSha512()
+{
+ QByteArray sha512Test = CryptoHash::hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ CryptoHash::Sha512);
+
+ if (sha512Test != QByteArray::fromHex("204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445")) {
+ raiseError("SHA-512 mismatch.");
+ return false;
+ }
+
+ return true;
+}
+
bool Crypto::testAes256Cbc()
{
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
@@ -285,3 +308,30 @@ bool Crypto::testSalsa20()
return true;
}
+
+bool Crypto::testChaCha20() {
+ QByteArray chacha20Key = QByteArray::fromHex("0000000000000000000000000000000000000000000000000000000000000000");
+ QByteArray chacha20iv = QByteArray::fromHex("0000000000000000");
+ QByteArray chacha20Plain = QByteArray::fromHex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
+ QByteArray chacha20Cipher = QByteArray::fromHex("76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee6586");
+ bool ok;
+
+ SymmetricCipher chacha20Stream(SymmetricCipher::ChaCha20, SymmetricCipher::Stream,
+ SymmetricCipher::Encrypt);
+ if (!chacha20Stream.init(chacha20Key, chacha20iv)) {
+ raiseError(chacha20Stream.errorString());
+ return false;
+ }
+
+ QByteArray chacha20Processed = chacha20Stream.process(chacha20Plain, &ok);
+ if (!ok) {
+ raiseError(chacha20Stream.errorString());
+ return false;
+ }
+ if (chacha20Processed != chacha20Cipher) {
+ raiseError("ChaCha20 stream cipher mismatch.");
+ return false;
+ }
+
+ return true;
+} \ No newline at end of file