2004-11-09 09:00:22 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2004 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.
|
|
|
|
*/
|
|
|
|
#include "randomunittest.h"
|
2005-01-01 05:11:34 +00:00
|
|
|
#include <QtCrypto>
|
2004-11-09 09:00:22 +00:00
|
|
|
|
|
|
|
RandomUnitTest::RandomUnitTest()
|
|
|
|
: Tester()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void RandomUnitTest::allTests()
|
|
|
|
{
|
2005-03-28 07:49:05 +00:00
|
|
|
QCA::Initializer init;
|
|
|
|
|
2005-01-01 04:20:34 +00:00
|
|
|
QCA::Random rng = QCA::globalRNG( );
|
|
|
|
CHECK( rng.provider()->name(), QString( "qca-botan" ) );
|
|
|
|
|
|
|
|
QCA::setGlobalRNG( "default" );
|
|
|
|
rng = QCA::globalRNG( );
|
2004-11-24 07:37:57 +00:00
|
|
|
CHECK( rng.provider()->name(), QString( "default" ) );
|
2004-11-10 10:05:55 +00:00
|
|
|
|
2004-11-24 07:37:57 +00:00
|
|
|
{
|
2005-01-01 04:20:34 +00:00
|
|
|
QCA::Random randObject ("default");
|
2004-11-24 07:37:57 +00:00
|
|
|
CHECK( randObject.nextByte() == randObject.nextByte(), false );
|
|
|
|
CHECK( QCA::Random().nextByte() == QCA::Random().nextByte(), false );
|
|
|
|
CHECK( randObject.nextBytes(4) == randObject.nextBytes(4), false );
|
|
|
|
CHECK( randObject.nextBytes(100) == randObject.nextBytes(100), false );
|
|
|
|
CHECK( randObject.randomChar() == randObject.randomChar(), false );
|
|
|
|
CHECK( QCA::Random().randomChar() == QCA::Random().randomChar(), false );
|
|
|
|
CHECK( QCA::Random::randomChar() == QCA::Random::randomChar(), false );
|
|
|
|
CHECK( QCA::Random().randomInt() == QCA::Random().randomInt(), false );
|
|
|
|
CHECK( QCA::Random::randomInt() == QCA::Random::randomInt(), false );
|
|
|
|
CHECK( QCA::Random().randomArray(3) == QCA::Random().randomArray(3), false );
|
|
|
|
CHECK( QCA::Random::randomArray(3) == QCA::Random::randomArray(3), false );
|
2004-11-09 09:00:22 +00:00
|
|
|
|
2004-11-24 07:37:57 +00:00
|
|
|
CHECK( randObject.nextByte(QCA::Random::Nonce) == randObject.nextByte(QCA::Random::SessionKey), false );
|
|
|
|
CHECK( QCA::Random().nextByte(QCA::Random::PublicValue) == QCA::Random().nextByte(), false );
|
|
|
|
CHECK( randObject.nextBytes(4) == randObject.nextBytes(4, QCA::Random::Nonce), false );
|
|
|
|
CHECK( randObject.randomChar(QCA::Random::LongTermKey) == randObject.randomChar(), false );
|
|
|
|
CHECK( QCA::Random().randomChar() == QCA::Random().randomChar(QCA::Random::PublicValue), false );
|
|
|
|
CHECK( QCA::Random::randomChar(QCA::Random::PublicValue) == QCA::Random::randomChar(QCA::Random::Nonce), false );
|
|
|
|
CHECK( QCA::Random().randomInt(QCA::Random::Nonce) == QCA::Random().randomInt(), false );
|
|
|
|
CHECK( QCA::Random::randomInt(QCA::Random::Nonce) == QCA::Random::randomInt(QCA::Random::Nonce), false );
|
|
|
|
CHECK( QCA::Random().randomArray(3, QCA::Random::Nonce) == QCA::Random().randomArray(3), false );
|
|
|
|
CHECK( QCA::Random::randomArray(3, QCA::Random::SessionKey) == QCA::Random::randomArray(3, QCA::Random::PublicValue), false );
|
|
|
|
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
for (int len = 1; len <= 1024; len*=2 ) {
|
2004-11-24 07:37:57 +00:00
|
|
|
CHECK( QCA::globalRNG().nextBytes(len, QCA::Random::SessionKey).size(), len );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QCA::setGlobalRNG( "qca-botan" );
|
|
|
|
QCA::Random rng1 = QCA::globalRNG();
|
|
|
|
CHECK( rng1.provider()->name(), QString( "qca-botan" ) );
|
|
|
|
|
|
|
|
{
|
2005-01-01 04:20:34 +00:00
|
|
|
QCA::Random randObject ( "qca-botan" );
|
2004-11-24 07:37:57 +00:00
|
|
|
CHECK( randObject.nextByte() == randObject.nextByte(), false );
|
|
|
|
CHECK( QCA::Random().nextByte() == QCA::Random().nextByte(), false );
|
|
|
|
CHECK( randObject.nextBytes(4) == randObject.nextBytes(4), false );
|
|
|
|
CHECK( randObject.nextBytes(100) == randObject.nextBytes(100), false );
|
|
|
|
CHECK( randObject.randomChar() == randObject.randomChar(), false );
|
|
|
|
CHECK( QCA::Random().randomChar() == QCA::Random().randomChar(), false );
|
|
|
|
CHECK( QCA::Random::randomChar() == QCA::Random::randomChar(), false );
|
|
|
|
CHECK( QCA::Random().randomInt() == QCA::Random().randomInt(), false );
|
|
|
|
CHECK( QCA::Random::randomInt() == QCA::Random::randomInt(), false );
|
|
|
|
CHECK( QCA::Random().randomArray(3) == QCA::Random().randomArray(3), false );
|
|
|
|
CHECK( QCA::Random::randomArray(3) == QCA::Random::randomArray(3), false );
|
|
|
|
|
|
|
|
CHECK( randObject.nextByte(QCA::Random::Nonce) == randObject.nextByte(QCA::Random::SessionKey), false );
|
|
|
|
CHECK( QCA::Random().nextByte(QCA::Random::PublicValue) == QCA::Random().nextByte(), false );
|
|
|
|
CHECK( randObject.nextBytes(4) == randObject.nextBytes(4, QCA::Random::Nonce), false );
|
|
|
|
CHECK( randObject.randomChar(QCA::Random::LongTermKey) == randObject.randomChar(), false );
|
|
|
|
CHECK( QCA::Random().randomChar() == QCA::Random().randomChar(QCA::Random::PublicValue), false );
|
|
|
|
CHECK( QCA::Random::randomChar(QCA::Random::PublicValue) == QCA::Random::randomChar(QCA::Random::Nonce), false );
|
|
|
|
CHECK( QCA::Random().randomInt(QCA::Random::Nonce) == QCA::Random().randomInt(), false );
|
|
|
|
CHECK( QCA::Random::randomInt(QCA::Random::Nonce) == QCA::Random::randomInt(QCA::Random::Nonce), false );
|
|
|
|
CHECK( QCA::Random().randomArray(3, QCA::Random::Nonce) == QCA::Random().randomArray(3), false );
|
|
|
|
CHECK( QCA::Random::randomArray(3, QCA::Random::SessionKey) == QCA::Random::randomArray(3, QCA::Random::PublicValue), false );
|
|
|
|
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
for (int len = 1; len <= 1024; len*=2 ) {
|
2004-11-24 07:37:57 +00:00
|
|
|
CHECK( QCA::globalRNG().nextBytes(len, QCA::Random::SessionKey).size(), len );
|
|
|
|
}
|
|
|
|
|
|
|
|
QCA::SymmetricKey testkey;
|
|
|
|
testkey = QCA::globalRNG().nextBytes(10, QCA::Random::SessionKey);
|
|
|
|
}
|
|
|
|
|
2005-01-01 04:20:34 +00:00
|
|
|
#if 0
|
|
|
|
QCA::setGlobalRNG( "qca-egads" );
|
|
|
|
QCA::Random rng2 = QCA::globalRNG();
|
|
|
|
CHECK( rng2.provider()->name(), QString( "qca-egads" ) );
|
|
|
|
|
|
|
|
{
|
|
|
|
QCA::Random randObject ( "qca-egads" );
|
|
|
|
CHECK( randObject.nextByte() == randObject.nextByte(), false );
|
|
|
|
CHECK( QCA::Random("qca-egads").nextByte() == QCA::Random("qca-egads").nextByte(), false );
|
|
|
|
CHECK( randObject.nextBytes(4) == randObject.nextBytes(4), false );
|
|
|
|
CHECK( randObject.nextBytes(100) == randObject.nextBytes(100), false );
|
|
|
|
CHECK( randObject.randomChar() == randObject.randomChar(), false );
|
|
|
|
CHECK( QCA::Random("qca-egads").randomChar() == QCA::Random("qca-egads").randomChar(), false );
|
|
|
|
CHECK( QCA::Random::randomChar() == QCA::Random::randomChar(), false );
|
|
|
|
CHECK( QCA::Random("qca-egads").randomInt() == QCA::Random().randomInt(), false );
|
|
|
|
CHECK( QCA::Random::randomInt() == QCA::Random::randomInt(), false );
|
|
|
|
CHECK( QCA::Random().randomArray(3) == QCA::Random().randomArray(3), false );
|
|
|
|
CHECK( QCA::Random::randomArray(3) == QCA::Random::randomArray(3), false );
|
|
|
|
|
|
|
|
CHECK( randObject.nextByte(QCA::Random::Nonce) == randObject.nextByte(QCA::Random::SessionKey), false );
|
|
|
|
CHECK( QCA::Random().nextByte(QCA::Random::PublicValue) == QCA::Random().nextByte(), false );
|
|
|
|
CHECK( randObject.nextBytes(4) == randObject.nextBytes(4, QCA::Random::Nonce), false );
|
|
|
|
CHECK( randObject.randomChar(QCA::Random::LongTermKey) == randObject.randomChar(), false );
|
|
|
|
CHECK( QCA::Random().randomChar() == QCA::Random().randomChar(QCA::Random::PublicValue), false );
|
|
|
|
CHECK( QCA::Random::randomChar(QCA::Random::PublicValue) == QCA::Random::randomChar(QCA::Random::Nonce), false );
|
|
|
|
CHECK( QCA::Random().randomInt(QCA::Random::Nonce) == QCA::Random().randomInt(), false );
|
|
|
|
CHECK( QCA::Random::randomInt(QCA::Random::Nonce) == QCA::Random::randomInt(QCA::Random::Nonce), false );
|
|
|
|
CHECK( QCA::Random().randomArray(3, QCA::Random::Nonce) == QCA::Random().randomArray(3), false );
|
|
|
|
CHECK( QCA::Random::randomArray(3, QCA::Random::SessionKey) == QCA::Random::randomArray(3, QCA::Random::PublicValue), false );
|
|
|
|
|
|
|
|
for (unsigned int len = 1; len <= 1024; len*=2 ) {
|
|
|
|
CHECK( QCA::globalRNG().nextBytes(len, QCA::Random::SessionKey).size(), len );
|
|
|
|
}
|
|
|
|
|
|
|
|
QCA::SymmetricKey testkey;
|
|
|
|
testkey = QCA::globalRNG().nextBytes(10, QCA::Random::SessionKey);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-11-09 09:00:22 +00:00
|
|
|
}
|
|
|
|
|