fix picrypt and remove crypt_frag from PIStreamPacker
This commit is contained in:
@@ -50,15 +50,9 @@ bool PICrypt::setKey(const PIByteArray & _key) {
|
||||
}
|
||||
|
||||
|
||||
bool PICrypt::setKey(const PIString & secret) {
|
||||
PIByteArray hash;
|
||||
hash.resize(crypto_generichash_BYTES);
|
||||
PIByteArray s(secret.data(), secret.size());
|
||||
crypto_generichash(hash.data(), hash.size(), s.data(), s.size(), (const uchar *)hash_def_key, hash_def_key_size);
|
||||
hash.resize(key_.size());
|
||||
key_ = std::move(hash);
|
||||
secret.deleteData();
|
||||
return true;
|
||||
bool PICrypt::setKey(const PIString & secret) {;
|
||||
key_ = hash(secret);
|
||||
return key_.isNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -145,23 +139,23 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PICrypt::hash(const PIString & secret) {
|
||||
PIByteArray hash;
|
||||
if (!init()) return hash;
|
||||
hash.resize(crypto_generichash_BYTES);
|
||||
PIByteArray s(secret.data(), secret.size());
|
||||
crypto_generichash(hash.data(), hash.size(), s.data(), s.size(), (const uchar *)hash_def_key, hash_def_key_size);
|
||||
secret.deleteData();
|
||||
return hash;
|
||||
PIByteArray PICrypt::hash(PIString secret) {
|
||||
if (!init()) return {};
|
||||
PIByteArray s = secret.toUTF8();
|
||||
PIByteArray h = hash(s);
|
||||
memset(const_cast<char *>(secret.data()), 0, s.size());
|
||||
secret.fill('\0');
|
||||
s.fill(0);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PICrypt::hash(const PIByteArray & data) {
|
||||
PIByteArray hash;
|
||||
if (!init()) return hash;
|
||||
hash.resize(crypto_generichash_BYTES);
|
||||
crypto_generichash(hash.data(), hash.size(), data.data(), data.size(), (const uchar *)hash_def_key, hash_def_key_size);
|
||||
return hash;
|
||||
if (!init()) return {};
|
||||
PIByteArray h;
|
||||
h.resize(crypto_generichash_BYTES);
|
||||
crypto_generichash(h.data(), h.size(), data.data(), data.size(), (const uchar *)hash_def_key, hash_def_key_size);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
@@ -336,7 +330,7 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, const PIByteArray &
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PICrypt::passwordHash(const PIString & password, const PIByteArray & seed) {
|
||||
PIByteArray PICrypt::passwordHash(PIString password, const PIByteArray & seed) {
|
||||
#ifdef crypto_pwhash_ALG_ARGON2I13
|
||||
PIByteArray pass = password.toUTF8();
|
||||
PIByteArray n = hash(seed);
|
||||
@@ -352,7 +346,8 @@ PIByteArray PICrypt::passwordHash(const PIString & password, const PIByteArray &
|
||||
crypto_pwhash_argon2i_memlimit_moderate(),
|
||||
crypto_pwhash_ALG_ARGON2I13);
|
||||
pass.fill(0);
|
||||
password.deleteData();
|
||||
memset(const_cast<char *>(password.data()), 0, pass.size());
|
||||
password.fill('\0');
|
||||
if (r != 0) return PIByteArray();
|
||||
return ph;
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user