40 #include <QtNetwork/private/qssl_p.h>
45 #include "../shared/qwincrypt_p.h"
47 #include <QtNetwork/private/qtlsbackend_p.h>
48 #include <QtNetwork/private/qsslkey_p.h>
50 #include <QtNetwork/qsslkey.h>
52 #include <QtCore/qscopeguard.h>
53 #include <QtCore/qbytearray.h>
62 return BCRYPT_DES_ALGORITHM;
64 return BCRYPT_3DES_ALGORITHM;
66 return BCRYPT_RC2_ALGORITHM;
70 return BCRYPT_AES_ALGORITHM;
78 NTSTATUS status = BCryptOpenAlgorithmProvider(
85 qCWarning(lcTlsBackendSchannel,
"Failed to open algorithm handle (%ld)!", status);
95 BCRYPT_KEY_HANDLE keyHandle;
96 NTSTATUS status = BCryptGenerateSymmetricKey(
101 reinterpret_cast<unsigned char *
>(
const_cast<char *
>(
key.data())),
106 qCWarning(lcTlsBackendSchannel,
"Failed to generate symmetric key (%ld)!", status);
110 status = BCryptSetProperty(
112 BCRYPT_CHAINING_MODE,
113 reinterpret_cast<UCHAR *
>(
const_cast<wchar_t *
>(BCRYPT_CHAIN_MODE_CBC)),
114 ARRAYSIZE(BCRYPT_CHAIN_MODE_CBC),
118 BCryptDestroyKey(keyHandle);
119 qCWarning(lcTlsBackendSchannel,
"Failed to change the symmetric key's chaining mode (%ld)!",
133 BCryptCloseAlgorithmProvider(
handle, 0);
139 auto keyHandleDealloc =
qScopeGuard([&keyHandle]() {
140 BCryptDestroyKey(keyHandle);
145 ULONG sizeNeeded = 0;
147 auto cryptFunction = encrypt ? BCryptEncrypt : BCryptDecrypt;
148 for (
int i = 0;
i < 2;
i++) {
149 output.
resize(
int(sizeNeeded));
150 auto input =
reinterpret_cast<unsigned char *
>(
const_cast<char *
>(
data.data()));
152 NTSTATUS status = cryptFunction(
155 ULONG(
data.length()),
157 reinterpret_cast<unsigned char *
>(ivCopy.data()),
158 ULONG(ivCopy.length()),
159 sizeNeeded ? output.
data() :
nullptr,
165 qCWarning(lcTlsBackendSchannel,
"%s failed (%ld)!", encrypt ?
"Encrypt" :
"Decrypt",
small capitals from c petite p scientific i
[1]
The QByteArray class provides an array of bytes.
QByteArray decrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
QByteArray encrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
void resize(qsizetype sz)
const T * constData() const
const wchar_t * getName(QSslKeyPrivate::Cipher cipher)
QByteArray doCrypt(QSslKeyPrivate::Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv, bool encrypt)
BCRYPT_ALG_HANDLE getHandle(QSslKeyPrivate::Cipher cipher)
BCRYPT_KEY_HANDLE generateSymmetricKey(BCRYPT_ALG_HANDLE handle, const QByteArray &key)
QByteArray doCrypt(QSslKeyPrivate::Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv, bool enc)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define qCWarning(category,...)
GLuint64 GLenum void * handle
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLenum input
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]