1
0
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:
iphydf 2018-01-06 15:21:04 +00:00
parent fdcc695977
commit 398ba415ce
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
3 changed files with 40 additions and 16 deletions

View File

@ -112,11 +112,10 @@ search_dependency(TOXAV PACKAGE toxav OPTIONAL)
search_dependency(TOXENCRYPTSAVE PACKAGE toxencryptsave OPTIONAL)
# If not found, use automake toxcore libraries
if (NOT TOXCORE_FOUND OR
NOT TOXAV_FOUND OR
NOT TOXENCRYPTSAVE_FOUND)
search_dependency(TOXCORE PACKAGE libtoxcore)
search_dependency(TOXAV PACKAGE libtoxav)
# We only check for TOXCORE, because the other two are gone in 0.2.0.
if (NOT TOXCORE_FOUND)
search_dependency(TOXCORE PACKAGE libtoxcore)
search_dependency(TOXAV PACKAGE libtoxav)
endif()
search_dependency(OPENAL PACKAGE openal)

View File

@ -18,6 +18,7 @@
*/
#include "toxencrypt.h"
#include <tox/tox.h> // TOX_VERSION_IS_API_COMPATIBLE
#include <tox/toxencryptsave.h>
#include <QByteArray>
@ -155,11 +156,17 @@ QByteArray ToxEncrypt::decryptPass(const QString& password, const QByteArray& ci
*/
std::unique_ptr<ToxEncrypt> ToxEncrypt::makeToxEncrypt(const QString& password)
{
Tox_Pass_Key* passKey = tox_pass_key_new();
QByteArray pass = password.toUtf8();
const QByteArray pass = password.toUtf8();
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()),
static_cast<size_t>(pass.length()), &error);
#endif
if (error != TOX_ERR_KEY_DERIVATION_OK) {
tox_pass_key_free(passKey);
@ -195,11 +202,17 @@ std::unique_ptr<ToxEncrypt> ToxEncrypt::makeToxEncrypt(const QString& password,
return std::unique_ptr<ToxEncrypt>{};
}
Tox_Pass_Key* passKey = tox_pass_key_new();
QByteArray pass = password.toUtf8();
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()),
static_cast<size_t>(pass.length()), salt, &keyError);
#endif
if (keyError != TOX_ERR_KEY_DERIVATION_OK) {
tox_pass_key_free(passKey);

View File

@ -20,6 +20,7 @@
#include "rawdatabase.h"
#include <cassert>
#include <tox/tox.h> // TOX_VERSION_IS_API_COMPATIBLE
#include <tox/toxencryptsave.h>
#include <QCoreApplication>
@ -477,17 +478,22 @@ QString RawDatabase::deriveKey(const QString& password)
if (password.isEmpty())
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 const uint8_t expandConstant[TOX_PASS_SALT_LENGTH + 1] =
"L'ignorance est le pire des maux";
std::unique_ptr<Tox_Pass_Key, PassKeyDeleter> key(tox_pass_key_new());
tox_pass_key_derive_with_salt(key.get(), reinterpret_cast<uint8_t*>(passData.data()),
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
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);
#endif
return QByteArray(reinterpret_cast<char*>(key.get()) + 32, 32).toHex();
;
}
/**
@ -507,16 +513,22 @@ QString RawDatabase::deriveKey(const QString& password, const QByteArray& salt)
return {};
}
QByteArray passData = password.toUtf8();
const QByteArray passData = password.toUtf8();
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());
tox_pass_key_derive_with_salt(key.get(), reinterpret_cast<uint8_t*>(passData.data()),
#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0)
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()),
reinterpret_cast<const uint8_t*>(salt.constData()), nullptr);
#endif
return QByteArray(reinterpret_cast<char*>(key.get()) + 32, 32).toHex();
;
}
/**