Change qrand() to QRandomGenerator in the SSL backend

Change-Id: I631649b2ad8d9c2c766e99a12f7ff3a39c79cc7d
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Samuel Gaist 2017-06-12 23:23:48 +02:00
parent e22bf03e23
commit b6f6920654
2 changed files with 4 additions and 4 deletions

View File

@ -43,6 +43,7 @@
#include <QtCore/qdatastream.h>
#include <QtCore/qcryptographichash.h>
#include <QtCore/qrandom.h>
QT_USE_NAMESPACE
@ -286,10 +287,8 @@ QByteArray QSslKeyPrivate::toPem(const QByteArray &passPhrase) const
if (type == QSsl::PrivateKey && !passPhrase.isEmpty()) {
// ### use a cryptographically secure random number generator
QByteArray iv;
iv.resize(8);
for (int i = 0; i < iv.size(); ++i)
iv[i] = (qrand() & 0xff);
quint64 random = QRandomGenerator::generate64();
QByteArray iv = QByteArray::fromRawData(reinterpret_cast<const char *>(&random), sizeof(random));
Cipher cipher = DesEde3Cbc;
const QByteArray key = deriveKey(cipher, passPhrase, iv);

View File

@ -2486,6 +2486,7 @@ void tst_QSslSocket::writeBigChunk()
QByteArray data;
data.resize(1024*1024*10); // 10 MB
// init with garbage. needed so ssl cannot compress it in an efficient way.
// ### Qt 6: update to a random engine
for (size_t i = 0; i < data.size() / sizeof(int); i++) {
int r = qrand();
data.data()[i*sizeof(int)] = r;