diff --git a/src/core/Global.h b/src/core/Global.h index 0b1ed2140..914c7b412 100644 --- a/src/core/Global.h +++ b/src/core/Global.h @@ -128,4 +128,8 @@ template <> class QStaticAssertFailure {}; # define KEEPASSX_EXPORT Q_DECL_EXPORT #endif +#ifndef QUINT32_MAX +#define QUINT32_MAX 4294967295U +#endif + #endif // KEEPASSX_GLOBAL_H diff --git a/src/crypto/Random.cpp b/src/crypto/Random.cpp index a3e14272e..2a375f3b1 100644 --- a/src/crypto/Random.cpp +++ b/src/crypto/Random.cpp @@ -21,10 +21,6 @@ #include "crypto/Crypto.h" -#ifndef QUINT32_MAX -#define QUINT32_MAX 4294967295U -#endif - class RandomBackendGcrypt : public RandomBackend { public: diff --git a/tests/TestRandom.cpp b/tests/TestRandom.cpp index 313cd19c1..8ac570e1c 100644 --- a/tests/TestRandom.cpp +++ b/tests/TestRandom.cpp @@ -46,18 +46,18 @@ void TestRandom::testUInt() QCOMPARE(randomGen()->randomUInt(1), 0U); nextBytes.clear(); - nextBytes.append(Endian::int32ToBytes(4294967295U, QSysInfo::ByteOrder)); - nextBytes.append(Endian::int32ToBytes(4294897295U, QSysInfo::ByteOrder)); + nextBytes.append(Endian::int32ToBytes(QUINT32_MAX, QSysInfo::ByteOrder)); + nextBytes.append(Endian::int32ToBytes(QUINT32_MAX - 70000U, QSysInfo::ByteOrder)); m_backend->setNextBytes(nextBytes); - QCOMPARE(randomGen()->randomUInt(100000U), 97295U); + QCOMPARE(randomGen()->randomUInt(100000U), (QUINT32_MAX - 70000U) % 100000U); nextBytes.clear(); for (int i = 0; i < 10000; i++) { - nextBytes.append(Endian::int32ToBytes(2147483648U + i, QSysInfo::ByteOrder)); + nextBytes.append(Endian::int32ToBytes((QUINT32_MAX / 2U) + 1U + i, QSysInfo::ByteOrder)); } - nextBytes.append(Endian::int32ToBytes(2147483647U, QSysInfo::ByteOrder)); + nextBytes.append(Endian::int32ToBytes(QUINT32_MAX / 2U, QSysInfo::ByteOrder)); m_backend->setNextBytes(nextBytes); - QCOMPARE(randomGen()->randomUInt(2147483648U), 2147483647U); + QCOMPARE(randomGen()->randomUInt((QUINT32_MAX / 2U) + 1U), QUINT32_MAX / 2U); } void TestRandom::testUIntRange()