0

We have the need of saving encrypted data (general length 30-100 chars, unencrypted) into a database, this data will have to be read and decrypted in several different applications (PHP, python, ruby).

After doing a bit of research about it, and reaching libsodium, we have a few questions.

Between sodium_secretbox (sodium_crypto_box_xsalsa20poly1305) and sodium_​crypto_​aead_​xchacha20poly1305_​ietf which is nowadays recommended? Or do they fill different needs?

refs:

In the case of sodium_​crypto_​aead_​xchacha20poly1305_​ietf it seems to require additional data (https://github.com/jedisct1/libsodium/blob/master/src/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h#L40) which is "used in the verification of the authentication tag appended to the ciphertext, but it is not encrypted or stored in the ciphertext". (https://security.stackexchange.com/questions/179273/what-is-the-purpose-of-associated-authenticated-data-in-aead)

Since the authenticated data is optional, sodium_​crypto_​aead_​xchacha20poly1305 can be used like sodium_secretbox. But is it right (from a security perspective) to not add any authenticated data?

ateam
  • 137
  • 1
  • 11
  • The answer depends on whether you need AAD, see [What is the purpose of associated authenticated data in AEAD?](https://security.stackexchange.com/q/179273). If your use case does not require AAD, there is no reason not to use [*crypto_secretbox*](https://libsodium.gitbook.io/doc/secret-key_cryptography/secretbox), especially since it should have the highest interoperability (in Libsodium since version 0.1). – Topaco Mar 29 '23 at 11:57
  • If your use case requires AAD, one of the [AEAD algorithms](https://libsodium.gitbook.io/doc/secret-key_cryptography/aead) would have to be applied. The recommended one is *XChaCha20-Poly1305-IETF*, but it is supported in Libsodium only since 1.0.12 (there are others that are supported earlier and therefore should have a higher interoperability e.g. *ChaCha20-Poly1305-IETF* since 1.0.4, *ChaCha20-Poly1305* since 0.6.0). – Topaco Mar 29 '23 at 12:02

0 Answers0