use blake3 for salt and pwhash for passphrase hash
This commit is contained in:
@@ -318,13 +318,16 @@ void MainWindow::closeEvent(QCloseEvent* event) {
|
||||
|
||||
#define PASSWORD sequence
|
||||
#define KEY_LEN crypto_box_SEEDBYTES
|
||||
|
||||
const QByteArray ba = QByteArray::fromHex(passphraseHash.toLatin1());
|
||||
const unsigned char *encryptedMemo1 = reinterpret_cast<const unsigned char *>(ba.constData());
|
||||
|
||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||
QString sourceWallet_file = dirwallet;
|
||||
QString target_encWallet_file = dirwalletenc;
|
||||
|
||||
// FileEncryption::encrypt(target_enc_file, source_file, key);
|
||||
FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, PassphraseHashEnd);
|
||||
FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, encryptedMemo1);
|
||||
|
||||
QFile wallet(dirwallet);
|
||||
wallet.remove();
|
||||
@@ -375,7 +378,8 @@ void MainWindow::encryptWallet() {
|
||||
if (d.exec() == QDialog::Accepted)
|
||||
{
|
||||
|
||||
QString passphrase = ed.txtPassword->text(); // data comes from user inputs
|
||||
QString passphraseBlank = ed.txtPassword->text(); // data comes from user inputs
|
||||
QString passphrase = QString("HUSH3") + passphraseBlank + QString("SDL");
|
||||
int length = passphrase.length();
|
||||
|
||||
|
||||
@@ -390,18 +394,30 @@ void MainWindow::encryptWallet() {
|
||||
sequence1 = new char[length+1];
|
||||
strncpy(sequence1, passphraseHash.toUtf8(), length+1);
|
||||
|
||||
#define MESSAGE1 ((const unsigned char *) sequence1)
|
||||
#define MESSAGE ((const unsigned char *) sequence)
|
||||
#define MESSAGE_LEN length
|
||||
#define hash ((const unsigned char *) sequence1)
|
||||
|
||||
#define PASSWORD sequence
|
||||
#define KEY_LEN crypto_box_SEEDBYTES
|
||||
|
||||
unsigned char key[KEY_LEN];
|
||||
|
||||
if (crypto_pwhash
|
||||
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
|
||||
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
|
||||
crypto_pwhash_ALG_DEFAULT) != 0) {
|
||||
/* out of memory */
|
||||
}
|
||||
QString passphraseHash1 = QByteArray(reinterpret_cast<const char*>(key), KEY_LEN).toHex();
|
||||
DataStore::getChatDataStore()->setPassword(passphraseHash1);
|
||||
|
||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||
QString sourceWallet_file = dirwallet;
|
||||
QString target_encWallet_file = dirwalletenc;
|
||||
|
||||
FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, MESSAGE1);
|
||||
FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key);
|
||||
|
||||
QFile wallet(dirwallet);
|
||||
wallet.rename(dirwalletbackup);
|
||||
@@ -445,7 +461,10 @@ void MainWindow::removeWalletEncryption() {
|
||||
|
||||
if (d.exec() == QDialog::Accepted)
|
||||
{
|
||||
QString passphrase = ed.txtPassword->text(); // data comes from user inputs
|
||||
QString passphraseBlank = ed.txtPassword->text(); // data comes from user inputs
|
||||
|
||||
QString passphrase = QString("HUSH3") + passphraseBlank + QString("SDL");
|
||||
|
||||
int length = passphrase.length();
|
||||
|
||||
char *sequence = NULL;
|
||||
@@ -458,20 +477,27 @@ void MainWindow::removeWalletEncryption() {
|
||||
sequence1 = new char[length+1];
|
||||
strncpy(sequence1, passphraseHash.toUtf8(), length+1);
|
||||
|
||||
#define MESSAGE3 ((const unsigned char *) sequence1)
|
||||
#define MESSAGE3_LEN length
|
||||
|
||||
#define hash ((const unsigned char *) sequence1)
|
||||
|
||||
#define PASSWORD sequence
|
||||
#define KEY_LEN crypto_box_SEEDBYTES
|
||||
|
||||
unsigned char key[KEY_LEN];
|
||||
|
||||
if (crypto_pwhash
|
||||
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
|
||||
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
|
||||
crypto_pwhash_ALG_DEFAULT) != 0) {
|
||||
/* out of memory */
|
||||
}
|
||||
|
||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||
QString target_encwallet_file = dirwalletenc;
|
||||
QString target_decwallet_file = dirwallet;
|
||||
|
||||
FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, MESSAGE3);
|
||||
FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key);
|
||||
|
||||
|
||||
QFile filencrypted(dirwalletenc);
|
||||
@@ -507,7 +533,9 @@ void MainWindow::removeWalletEncryptionStartUp() {
|
||||
|
||||
if (d.exec() == QDialog::Accepted)
|
||||
{
|
||||
QString passphrase = ed.txtPassword->text(); // data comes from user inputs
|
||||
QString passphraseBlank = ed.txtPassword->text(); // data comes from user inputs
|
||||
|
||||
QString passphrase = QString("HUSH3") + passphraseBlank + QString("SDL");
|
||||
int length = passphrase.length();
|
||||
|
||||
char *sequence = NULL;
|
||||
@@ -515,7 +543,7 @@ void MainWindow::removeWalletEncryptionStartUp() {
|
||||
strncpy(sequence, passphrase.toUtf8(), length +1);
|
||||
|
||||
QString passphraseHash = blake3_PW(sequence);
|
||||
DataStore::getChatDataStore()->setPassword(passphraseHash);
|
||||
|
||||
|
||||
char *sequence1 = NULL;
|
||||
sequence1 = new char[length+1];
|
||||
@@ -527,16 +555,26 @@ void MainWindow::removeWalletEncryptionStartUp() {
|
||||
|
||||
#define PASSWORD sequence
|
||||
#define KEY_LEN crypto_box_SEEDBYTES
|
||||
|
||||
{
|
||||
|
||||
unsigned char key[KEY_LEN];
|
||||
|
||||
if (crypto_pwhash
|
||||
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
|
||||
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
|
||||
crypto_pwhash_ALG_DEFAULT) != 0) {
|
||||
/* out of memory */
|
||||
}
|
||||
QString passphraseHash1 = QByteArray(reinterpret_cast<const char*>(key), KEY_LEN).toHex();
|
||||
DataStore::getChatDataStore()->setPassword(passphraseHash1);
|
||||
|
||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||
|
||||
QString target_encwallet_file = dirwalletenc;
|
||||
QString target_decwallet_file = dirwallet;
|
||||
|
||||
FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, hash);
|
||||
FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key);
|
||||
|
||||
}
|
||||
|
||||
|
||||
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||
QFile wallet(dirwallet);
|
||||
|
||||
Reference in New Issue
Block a user