Change qrand() to QRandomGenerator in the SSL backend
Change-Id: I631649b2ad8d9c2c766e99a12f7ff3a39c79cc7d Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
e22bf03e23
commit
b6f6920654
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user