add startup check for encryption, encrypt if sdl close
This commit is contained in:
@@ -8,19 +8,9 @@ void PASSWD::show_hex_buff(unsigned char buf[])
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
const unsigned char* PASSWD::hash(QString password)
|
||||
const unsigned char* PASSWD::key(QString password)
|
||||
{
|
||||
/*std::string data = password.toStdString();
|
||||
|
||||
unsigned char hash[crypto_generichash_BYTES];
|
||||
|
||||
crypto_generichash(hash, sizeof hash,
|
||||
(const unsigned char*)data.c_str(), data.size(),
|
||||
NULL, 0);
|
||||
|
||||
//qDebug() << PASSWD::convertToHexString(hash);
|
||||
return (const unsigned char*)hash;*/
|
||||
|
||||
|
||||
int length = password.length();
|
||||
|
||||
char *sequence = NULL;
|
||||
@@ -29,24 +19,42 @@ const unsigned char* PASSWD::hash(QString password)
|
||||
|
||||
#define MESSAGE ((const unsigned char *) sequence)
|
||||
#define MESSAGE_LEN length
|
||||
|
||||
unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES];
|
||||
|
||||
crypto_hash_sha256(hash, MESSAGE, MESSAGE_LEN);
|
||||
|
||||
qDebug()<<"Generating SaltHash from password: " <<sequence;
|
||||
|
||||
|
||||
/////////we use the Hash of the Password as Salt, not perfect but still a good solution.
|
||||
|
||||
#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 */
|
||||
}
|
||||
|
||||
qDebug()<<"Generating cryptographic key from password: " <<sequence;
|
||||
unsigned char * sha256hash = new unsigned char[crypto_hash_sha256_BYTES];
|
||||
unsigned char * blacke2hash = new unsigned char[crypto_generichash_KEYBYTES];
|
||||
unsigned char * hash = new unsigned char[crypto_secretstream_xchacha20poly1305_KEYBYTES];
|
||||
|
||||
crypto_hash_sha256(sha256hash, MESSAGE, MESSAGE_LEN);
|
||||
crypto_generichash(blacke2hash, sizeof hash, MESSAGE, MESSAGE_LEN, NULL, 0);
|
||||
|
||||
// crypto_generichash(blacke2hash, sizeof hash, MESSAGE, MESSAGE_LEN, NULL, 0);
|
||||
|
||||
for(uint8_t i = 0; i < crypto_secretstream_xchacha20poly1305_KEYBYTES/2; i++)
|
||||
hash[i] = blacke2hash[i];
|
||||
//for(uint8_t i = 0; i < crypto_secretstream_xchacha20poly1305_KEYBYTES/2; i++)
|
||||
// hash[i] = blacke2hash[i];
|
||||
|
||||
for(uint8_t i = crypto_secretstream_xchacha20poly1305_KEYBYTES/2; i < crypto_secretstream_xchacha20poly1305_KEYBYTES; i++)
|
||||
hash[i] = sha256hash[i];
|
||||
// for(uint8_t i = crypto_secretstream_xchacha20poly1305_KEYBYTES/2; i < crypto_secretstream_xchacha20poly1305_KEYBYTES; i++)
|
||||
// hash[i] = sha256hash[i];
|
||||
|
||||
delete[] sha256hash;
|
||||
delete[] blacke2hash;
|
||||
// delete[] sha256hash;
|
||||
//delete[] blacke2hash;
|
||||
qDebug()<<"secret key generated:\n";
|
||||
PASSWD::show_hex_buff(hash);
|
||||
return hash;
|
||||
PASSWD::show_hex_buff(key);
|
||||
return key;
|
||||
}
|
||||
Reference in New Issue
Block a user