1
$\begingroup$

I have read the following questions and answers:

However, neither of these discuss an important detail that caught my attention while reading the libsodium documentation on the padding API:

Most modern cryptographic constructions disclose message lengths. The ciphertext for a given message will always have the same length, or add a constant number of bytes to it. For most applications, this is not an issue. But in some specific situations, such as interactive remote shells, hiding the length may be desirable.

As far as I can tell, this also applies to boxes, because they use a stream cipher, XSalsa20, under the hood. However, the docs for the Box API claim that:

The _easy and _detached APIs are faster and improve usability by not requiring padding, copying or tricky pointer arithmetic.

I've also read in various places that unpadded symmetric key cryptography is not secure for several reasons (e.g. malleability caused by determinism). However, in the Box implementation, the asymmetric keys are not used for encrypting the plaintext itself, but for deriving the shared secret key for the XSalsa20 symmetric cipher.

Overall, this made me wonder whether the problem of padding is still relevant, and whether I should manually pad my messages before passing them to crypto_box_easy (and obviously, unpad them when they are returned from crypto_box_easy_open) for better security? I can't quite connect the dots, and I don't want to uselessly complicate the crypto code I'm writing either (because that in itself could grow the security attack surface).

$\endgroup$
1
$\begingroup$

The _easy and _detached APIs are faster and improve usability by not requiring padding, copying or tricky pointer arithmetic.

This refers to the way the original NaCl API worked. You had to add some zeros before the message, and remove them after decryption. But this is just how the functions had to be used. It made the primitive implementation easier, but usage trickier. It didn't add any actual padding to the messages.

(e.g. malleability caused by determinism)

Irrelevant here. The nonce ensures that the same message encrypted twice produces different ciphertexts.

Padding should be added only if you consider that an attacker may learn something relevant from the length of the messages. If you are sending encrypted passwords, this will reveal the length of the passwords, which may not be desirable. If the only messages that can be exchanged are "yes" and "no", the attacker will not require to decrypt anything to guess the message. Here, padding would be useful.

But for most applications, it is useless.

$\endgroup$
  • $\begingroup$ Thanks for your answer! I do have some answer payloads that constitute some simple true/false fields, JSON encoded. So in this case I think it could be useful to apply padding. $\endgroup$ – notacryptographer Dec 4 '17 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.