fix(picrypt): use crypto_box_* constants for public-key decrypt
The decrypt() function for crypto_box (public-key) used crypto_secretbox_NONCEBYTES and crypto_secretbox_MACBYTES (secret-key constants) instead of crypto_box_* constants. These happen to be equal in libsodium but are semantically different APIs. Fix ensures consistency with the encrypt() counterpart.
This commit is contained in:
@@ -317,10 +317,10 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, const PIByteArray &
|
||||
return PIByteArray();
|
||||
}
|
||||
PIByteArray n;
|
||||
n.resize(crypto_secretbox_NONCEBYTES);
|
||||
n.resize(crypto_box_NONCEBYTES);
|
||||
const ullong data_size = crypt_data.size() - n.size();
|
||||
PIByteArray ret;
|
||||
ret.resize(data_size - crypto_secretbox_MACBYTES);
|
||||
ret.resize(data_size - crypto_box_MACBYTES);
|
||||
memcpy(n.data(), crypt_data.data(data_size), n.size());
|
||||
if (crypto_box_open_easy(ret.data(), crypt_data.data(), data_size, n.data(), public_key.data(), secret_key.data()) != 0) {
|
||||
// Bad key
|
||||
|
||||
Reference in New Issue
Block a user