git-svn-id: svn://db.shs.com.ru/pip@294 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2016-12-03 23:43:42 +00:00
parent eb1e413929
commit 71a178c870
2 changed files with 23 additions and 9 deletions

View File

@@ -84,6 +84,8 @@ PIByteArray PICrypt::crypt(const PIByteArray & data, PIByteArray key) {
randombytes_buf(n.data(), n.size());
crypto_secretbox_easy(ret.data(), data.data(), data.size(), n.data(), key.data());
ret.append(n);
#else
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
#endif
return ret;
}
@@ -131,6 +133,8 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo
// piCout << "[PICrypt]" << "bad key_";
return PIByteArray();
}
#else
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
#endif
if (ok) *ok = true;
return ret;
@@ -144,22 +148,26 @@ PIByteArray PICrypt::hash(const PIString & secret) {
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);
#else
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
#endif
return hash;
}
ullong PICrypt::shorthash(const PIString& s, PIByteArray key) {
ullong hash;
ullong hash = 0;
#ifdef PIP_CRYPT
if (crypto_shorthash_BYTES != sizeof(hash)) piCout << "[PICrypt]" << "internal error: bad hash size";
sodium_init();
if (key.size() != crypto_shorthash_KEYBYTES) {
key.resize(crypto_shorthash_KEYBYTES);
randombytes_buf(key.data(), key.size());
piCout << "[PICrypt]" << "invalid key size" << key.size() << ", shoud be" << crypto_shorthash_KEYBYTES << ", filled zeros";
key.resize(crypto_shorthash_KEYBYTES, 0);
}
PIByteArray in(s.data(), s.size());
crypto_shorthash((uchar *)&hash, in.data(), in.size(), key.data());
#else
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
#endif
return hash;
}
@@ -171,6 +179,8 @@ PIByteArray PICrypt::generateKey() {
sodium_init();
hash.resize(crypto_secretbox_KEYBYTES);
randombytes_buf(hash.data(), hash.size());
#else
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
#endif
return hash;
}
@@ -179,6 +189,8 @@ PIByteArray PICrypt::generateKey() {
int PICrypt::sizeKey() {
#ifdef PIP_CRYPT
return crypto_secretbox_KEYBYTES;
#else
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
#endif
return 0;
}
@@ -187,6 +199,8 @@ int PICrypt::sizeKey() {
int PICrypt::sizeCrypt() {
#ifdef PIP_CRYPT
return crypto_secretbox_MACBYTES + crypto_secretbox_NONCEBYTES;
#else
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
#endif
return 0;
}