add shorthash to PICrypt

git-svn-id: svn://db.shs.com.ru/pip@130 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-05-15 12:19:14 +00:00
parent b2c9023deb
commit a4fadea95f
2 changed files with 19 additions and 0 deletions

View File

@@ -146,6 +146,22 @@ PIByteArray PICrypt::hash(const PIString & secret) {
}
ullong PICrypt::shorthash(const PIString& s, PIByteArray key) {
ullong hash;
#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());
}
PIByteArray in(s.data(), s.size());
crypto_shorthash((uchar *)&hash, in.data(), in.size(), key.data());
#endif
return hash;
}
PIByteArray PICrypt::generateKey() {
PIByteArray hash;
#ifdef PIP_CRYPT