mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
chore: Update to immutable TES API and one-big-lib change.
This commit is contained in:
parent
fdcc695977
commit
398ba415ce
|
@ -112,9 +112,8 @@ search_dependency(TOXAV PACKAGE toxav OPTIONAL)
|
||||||
search_dependency(TOXENCRYPTSAVE PACKAGE toxencryptsave OPTIONAL)
|
search_dependency(TOXENCRYPTSAVE PACKAGE toxencryptsave OPTIONAL)
|
||||||
|
|
||||||
# If not found, use automake toxcore libraries
|
# If not found, use automake toxcore libraries
|
||||||
if (NOT TOXCORE_FOUND OR
|
# We only check for TOXCORE, because the other two are gone in 0.2.0.
|
||||||
NOT TOXAV_FOUND OR
|
if (NOT TOXCORE_FOUND)
|
||||||
NOT TOXENCRYPTSAVE_FOUND)
|
|
||||||
search_dependency(TOXCORE PACKAGE libtoxcore)
|
search_dependency(TOXCORE PACKAGE libtoxcore)
|
||||||
search_dependency(TOXAV PACKAGE libtoxav)
|
search_dependency(TOXAV PACKAGE libtoxav)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "toxencrypt.h"
|
#include "toxencrypt.h"
|
||||||
|
#include <tox/tox.h> // TOX_VERSION_IS_API_COMPATIBLE
|
||||||
#include <tox/toxencryptsave.h>
|
#include <tox/toxencryptsave.h>
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
@ -155,11 +156,17 @@ QByteArray ToxEncrypt::decryptPass(const QString& password, const QByteArray& ci
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<ToxEncrypt> ToxEncrypt::makeToxEncrypt(const QString& password)
|
std::unique_ptr<ToxEncrypt> ToxEncrypt::makeToxEncrypt(const QString& password)
|
||||||
{
|
{
|
||||||
Tox_Pass_Key* passKey = tox_pass_key_new();
|
const QByteArray pass = password.toUtf8();
|
||||||
QByteArray pass = password.toUtf8();
|
|
||||||
TOX_ERR_KEY_DERIVATION error;
|
TOX_ERR_KEY_DERIVATION error;
|
||||||
|
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
|
||||||
|
Tox_Pass_Key* const passKey = tox_pass_key_derive(
|
||||||
|
reinterpret_cast<const uint8_t*>(pass.constData()),
|
||||||
|
static_cast<size_t>(pass.length()), &error);
|
||||||
|
#else
|
||||||
|
Tox_Pass_Key* const passKey = tox_pass_key_new();
|
||||||
tox_pass_key_derive(passKey, reinterpret_cast<const uint8_t*>(pass.constData()),
|
tox_pass_key_derive(passKey, reinterpret_cast<const uint8_t*>(pass.constData()),
|
||||||
static_cast<size_t>(pass.length()), &error);
|
static_cast<size_t>(pass.length()), &error);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (error != TOX_ERR_KEY_DERIVATION_OK) {
|
if (error != TOX_ERR_KEY_DERIVATION_OK) {
|
||||||
tox_pass_key_free(passKey);
|
tox_pass_key_free(passKey);
|
||||||
|
@ -195,11 +202,17 @@ std::unique_ptr<ToxEncrypt> ToxEncrypt::makeToxEncrypt(const QString& password,
|
||||||
return std::unique_ptr<ToxEncrypt>{};
|
return std::unique_ptr<ToxEncrypt>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
Tox_Pass_Key* passKey = tox_pass_key_new();
|
|
||||||
QByteArray pass = password.toUtf8();
|
QByteArray pass = password.toUtf8();
|
||||||
TOX_ERR_KEY_DERIVATION keyError;
|
TOX_ERR_KEY_DERIVATION keyError;
|
||||||
|
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
|
||||||
|
Tox_Pass_Key* const passKey = tox_pass_key_derive_with_salt(
|
||||||
|
reinterpret_cast<const uint8_t*>(pass.constData()),
|
||||||
|
static_cast<size_t>(pass.length()), salt, &keyError);
|
||||||
|
#else
|
||||||
|
Tox_Pass_Key* const passKey = tox_pass_key_new();
|
||||||
tox_pass_key_derive_with_salt(passKey, reinterpret_cast<const uint8_t*>(pass.constData()),
|
tox_pass_key_derive_with_salt(passKey, reinterpret_cast<const uint8_t*>(pass.constData()),
|
||||||
static_cast<size_t>(pass.length()), salt, &keyError);
|
static_cast<size_t>(pass.length()), salt, &keyError);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (keyError != TOX_ERR_KEY_DERIVATION_OK) {
|
if (keyError != TOX_ERR_KEY_DERIVATION_OK) {
|
||||||
tox_pass_key_free(passKey);
|
tox_pass_key_free(passKey);
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "rawdatabase.h"
|
#include "rawdatabase.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <tox/tox.h> // TOX_VERSION_IS_API_COMPATIBLE
|
||||||
#include <tox/toxencryptsave.h>
|
#include <tox/toxencryptsave.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
@ -477,17 +478,22 @@ QString RawDatabase::deriveKey(const QString& password)
|
||||||
if (password.isEmpty())
|
if (password.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
QByteArray passData = password.toUtf8();
|
const QByteArray passData = password.toUtf8();
|
||||||
|
|
||||||
static_assert(TOX_PASS_KEY_LENGTH >= 32, "toxcore must provide 256bit or longer keys");
|
static_assert(TOX_PASS_KEY_LENGTH >= 32, "toxcore must provide 256bit or longer keys");
|
||||||
|
|
||||||
static const uint8_t expandConstant[TOX_PASS_SALT_LENGTH + 1] =
|
static const uint8_t expandConstant[TOX_PASS_SALT_LENGTH + 1] =
|
||||||
"L'ignorance est le pire des maux";
|
"L'ignorance est le pire des maux";
|
||||||
std::unique_ptr<Tox_Pass_Key, PassKeyDeleter> key(tox_pass_key_new());
|
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
|
||||||
tox_pass_key_derive_with_salt(key.get(), reinterpret_cast<uint8_t*>(passData.data()),
|
const std::unique_ptr<Tox_Pass_Key, PassKeyDeleter> key(tox_pass_key_derive_with_salt(
|
||||||
|
reinterpret_cast<const uint8_t*>(passData.data()),
|
||||||
|
static_cast<std::size_t>(passData.size()), expandConstant, nullptr));
|
||||||
|
#else
|
||||||
|
const std::unique_ptr<Tox_Pass_Key, PassKeyDeleter> key(tox_pass_key_new());
|
||||||
|
tox_pass_key_derive_with_salt(key.get(), reinterpret_cast<const uint8_t*>(passData.data()),
|
||||||
static_cast<std::size_t>(passData.size()), expandConstant, nullptr);
|
static_cast<std::size_t>(passData.size()), expandConstant, nullptr);
|
||||||
|
#endif
|
||||||
return QByteArray(reinterpret_cast<char*>(key.get()) + 32, 32).toHex();
|
return QByteArray(reinterpret_cast<char*>(key.get()) + 32, 32).toHex();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -507,16 +513,22 @@ QString RawDatabase::deriveKey(const QString& password, const QByteArray& salt)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray passData = password.toUtf8();
|
const QByteArray passData = password.toUtf8();
|
||||||
|
|
||||||
static_assert(TOX_PASS_KEY_LENGTH >= 32, "toxcore must provide 256bit or longer keys");
|
static_assert(TOX_PASS_KEY_LENGTH >= 32, "toxcore must provide 256bit or longer keys");
|
||||||
|
|
||||||
std::unique_ptr<Tox_Pass_Key, PassKeyDeleter> key(tox_pass_key_new());
|
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
|
||||||
tox_pass_key_derive_with_salt(key.get(), reinterpret_cast<uint8_t*>(passData.data()),
|
const std::unique_ptr<Tox_Pass_Key, PassKeyDeleter> key(tox_pass_key_derive_with_salt(
|
||||||
|
reinterpret_cast<const uint8_t*>(passData.data()),
|
||||||
|
static_cast<std::size_t>(passData.size()),
|
||||||
|
reinterpret_cast<const uint8_t*>(salt.constData()), nullptr));
|
||||||
|
#else
|
||||||
|
const std::unique_ptr<Tox_Pass_Key, PassKeyDeleter> key(tox_pass_key_new());
|
||||||
|
tox_pass_key_derive_with_salt(key.get(), reinterpret_cast<const uint8_t*>(passData.data()),
|
||||||
static_cast<std::size_t>(passData.size()),
|
static_cast<std::size_t>(passData.size()),
|
||||||
reinterpret_cast<const uint8_t*>(salt.constData()), nullptr);
|
reinterpret_cast<const uint8_t*>(salt.constData()), nullptr);
|
||||||
|
#endif
|
||||||
return QByteArray(reinterpret_cast<char*>(key.get()) + 32, 32).toHex();
|
return QByteArray(reinterpret_cast<char*>(key.get()) + 32, 32).toHex();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user