Convert the key derivation function test to use the

same file for declaration and definitions, and ajust
the build system to match.

Also add CMake support.

svn path=/trunk/kdesupport/qca/; revision=594717
This commit is contained in:
Brad Hards 2006-10-12 03:17:19 +00:00
parent 70324484a2
commit e75cf4ef3a
4 changed files with 43 additions and 61 deletions

View File

@ -0,0 +1,8 @@
set( kdfunittest_bin_SRCS kdfunittest.cpp)
MY_AUTOMOC( kdfunittest_bin_SRCS )
add_executable( kdfunittest ${kdfunittest_bin_SRCS} )
target_link_libraries( kdfunittest qca ${QT_QTTEST_LIBRARY})

View File

@ -22,7 +22,28 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "kdfunittest.h"
#include <QtCrypto>
#include <QtTest>
class KDFUnitTest : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void pbkdf1md2Tests_data();
void pbkdf1md2Tests();
void pbkdf1sha1Tests_data();
void pbkdf1sha1Tests();
void pbkdf2Tests_data();
void pbkdf2Tests();
void pbkdf2extraTests();
private:
QCA::Initializer* m_init;
};
void KDFUnitTest::initTestCase()
{
@ -77,7 +98,7 @@ void KDFUnitTest::pbkdf1md2Tests()
// gcrypt doesn't do md2...
// providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QString, secret);
QFETCH(QString, output);
QFETCH(QString, salt);
@ -146,7 +167,7 @@ void KDFUnitTest::pbkdf1sha1Tests()
providersToTest.append("qca-openssl");
// providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QString, secret);
QFETCH(QString, output);
QFETCH(QString, salt);
@ -240,7 +261,7 @@ void KDFUnitTest::pbkdf2Tests()
// providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QString, secret);
QFETCH(QString, output);
QFETCH(QString, salt);
@ -271,7 +292,7 @@ void KDFUnitTest::pbkdf2extraTests()
// providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("pbkdf2(sha1)", provider))
QWARN(QString("PBKDF version 2 with SHA1 not supported for "+provider).toLocal8Bit());
@ -296,7 +317,7 @@ void KDFUnitTest::pbkdf2extraTests()
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "cdedb5281bb2f801565a1122b25635150ad1f7a04bb9f3a333ecc0e2e1f70837" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("ATHENA.MIT.EDUraeburn"));
@ -308,7 +329,7 @@ void KDFUnitTest::pbkdf2extraTests()
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "01dbee7f4a9e243e988b62c73cda935da05378b93244ec8f48a99e61ad799d86" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("ATHENA.MIT.EDUraeburn"));
@ -321,7 +342,7 @@ void KDFUnitTest::pbkdf2extraTests()
QString( "5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13" ) );
}
// RFC3211 and RFC3962, Appendix B
// RFC3211 and RFC3962, Appendix B
{
QCA::InitializationVector salt(QCA::hexToArray("1234567878563412"));
QSecureArray password("password");
@ -335,7 +356,7 @@ void KDFUnitTest::pbkdf2extraTests()
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "d1daa78615f287e6" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("pass phrase equals block size"));
@ -347,7 +368,7 @@ void KDFUnitTest::pbkdf2extraTests()
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1" ) );
}
// RFC3962, Appendix B
{
try {
@ -362,7 +383,7 @@ void KDFUnitTest::pbkdf2extraTests()
} catch(std::exception &) {
if (provider == "qca-botan")
qDebug() << "You should use a later version of Botan";
else
else
QFAIL("exception");
}
}
@ -383,3 +404,6 @@ void KDFUnitTest::pbkdf2extraTests()
}
QTEST_MAIN(KDFUnitTest)
#include "kdfunittest.moc"

View File

@ -1,49 +0,0 @@
/**
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KDFUNITTEST_H
#define KDFUNITTEST_H
#include <QtCrypto>
#include <QtTest>
class KDFUnitTest : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void pbkdf1md2Tests_data();
void pbkdf1md2Tests();
void pbkdf1sha1Tests_data();
void pbkdf1sha1Tests();
void pbkdf2Tests_data();
void pbkdf2Tests();
void pbkdf2extraTests();
private:
QCA::Initializer* m_init;
};
#endif

View File

@ -12,5 +12,4 @@ check.depends = kdfunittest
check.commands = ./kdfunittest
# Input
HEADERS += kdfunittest.h
SOURCES += kdfunittest.cpp