In a PHP project in which fool-proof encryption is fundamental, I'm using the Libsodium library.
Hope you guys can shine some light on the following questions.
For all of the following functions, it looks like the length of the encrypted message is directly proportional to the length of the unencrypted message:
- sodium_crypto_secretbox
- sodium_crypto_box
- sodium_crypto_box_seal
It looks like no padding is used by default, correct ? This means that if within my setup I use different types of messages which each have a different length, an attacker can easily derive what kind of message it's about (without however knowing the content of the message), right ?
To mitigate this risk, I want to implement padding and I am looking for some advise on how to do this.
Is appending a random length random content (using random_bytes) message to the unencrypted message a good idea ? Does it make a difference whether I append it to the end of the message, at the beginning of the message or somewhere in the middle (or a combination of all) ? Are there more efficient ways to do this ?
If part(s) of the unencrypted messages are known, is it possible for an attacker to crack the encryption ? Or does it somehow becomes easier to do so ?
Example: if each encrypted message contains data delimited by for example "," or if each message starts/ends with a certain string or contains a certain string somewhere in the message, does this make attacks easier ? I mean, even when using padding an attacker might still know for sure part of the message's content.
I previously asked a question about how safe the encryption is (How safe are Libsodium Crypto Boxes?). Someone replied that 2^128 tries would be required to crack it. Does the amount of tries decrease if part of the message is known ? If yes by how much does it decrease ? What if someone knows the entire unencrypted message (for example the receiver) ? How easy/hard would it be for him to crack the senders' secret key ?
What about signed messages in Libsodium ? I know that signing does not encrypt the message but only appends a signature to it. How easy/hard is it to crack a SK based on a signature ? Could the receiver of a signed message potentially create a valid signature for a message not created by the sender ?
I read that nonces can be public without a problem. Nonetheless, does the fact that an attacker is in the possession of the nonce of a message decrease the cracking difficulty ?
Is it a good idea to change keypairs periodically to increase security ? Or doesn't this make sense ?
Does multi layer encryption make sense ? For example putting a crypto box inside another crypto box (with different keypairs off course). Or is this a bad idea ?
What about timing attacks ? I read that the time needed to decrypt/encrypt a message might give some clues about the SK. If Bob wants to crack Alices' SK, can he do so by analyzing how long it takes him to decrypt her message ? Or does it at least decrease the difficulty to do so ? If yes by how much ?