git-svn-id: svn://db.shs.com.ru/pip@349 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -28,8 +28,7 @@ const char hash_def_key[] = "_picrypt_";
|
||||
|
||||
PICrypt::PICrypt() {
|
||||
#ifdef PIP_CRYPT
|
||||
int ret;
|
||||
ret = sodium_init();
|
||||
sodium_init();
|
||||
nonce_.resize(crypto_secretbox_NONCEBYTES);
|
||||
key_.resize(crypto_secretbox_KEYBYTES);
|
||||
randombytes_buf(key_.data(), key_.size());
|
||||
@@ -78,8 +77,7 @@ PIByteArray PICrypt::crypt(const PIByteArray & data, PIByteArray key) {
|
||||
if (key.size() != crypto_secretbox_KEYBYTES)
|
||||
key.resize(crypto_secretbox_KEYBYTES, ' ');
|
||||
//return PIByteArray();
|
||||
int ret;
|
||||
ret = sodium_init();
|
||||
sodium_init();
|
||||
PIByteArray n;
|
||||
retba.resize(data.size() + crypto_secretbox_MACBYTES);
|
||||
n.resize(crypto_secretbox_NONCEBYTES);
|
||||
@@ -125,8 +123,7 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo
|
||||
if (ok) *ok = false;
|
||||
return PIByteArray();
|
||||
}
|
||||
int ret;
|
||||
ret = sodium_init();
|
||||
sodium_init();
|
||||
PIByteArray n;
|
||||
n.resize(crypto_secretbox_NONCEBYTES);
|
||||
retba.resize(crypt_data.size() - n.size() - crypto_secretbox_MACBYTES);
|
||||
@@ -147,8 +144,7 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo
|
||||
PIByteArray PICrypt::hash(const PIString & secret) {
|
||||
PIByteArray hash;
|
||||
#ifdef PIP_CRYPT
|
||||
int ret;
|
||||
ret = sodium_init();
|
||||
sodium_init();
|
||||
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, sizeof(hash_def_key) - 1);
|
||||
@@ -163,8 +159,7 @@ ullong PICrypt::shorthash(const PIString& s, PIByteArray key) {
|
||||
ullong hash = 0;
|
||||
#ifdef PIP_CRYPT
|
||||
if (crypto_shorthash_BYTES != sizeof(hash)) piCout << "[PICrypt]" << "internal error: bad hash size";
|
||||
int ret;
|
||||
ret = sodium_init();
|
||||
sodium_init();
|
||||
if (key.size() != crypto_shorthash_KEYBYTES) {
|
||||
piCout << "[PICrypt]" << "invalid key size" << key.size() << ", shoud be" << crypto_shorthash_KEYBYTES << ", filled zeros";
|
||||
key.resize(crypto_shorthash_KEYBYTES, 0);
|
||||
@@ -181,8 +176,7 @@ ullong PICrypt::shorthash(const PIString& s, PIByteArray key) {
|
||||
PIByteArray PICrypt::generateKey() {
|
||||
PIByteArray hash;
|
||||
#ifdef PIP_CRYPT
|
||||
int ret;
|
||||
ret = sodium_init();
|
||||
sodium_init();
|
||||
hash.resize(crypto_secretbox_KEYBYTES);
|
||||
randombytes_buf(hash.data(), hash.size());
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user