2

When encrypting a string through the Libsodium secret box feature, the ciphertext is 48 bytes longer than the plain text message ...

I am wondering why this is ... since the nonce is only 24 bytes.

abc
  • 331
  • 3
  • 8
  • There should be a 16 byte MAC as well. – CodesInChaos Mar 17 '18 at 13:01
  • @CodesInChaos Thanks, I guess that answers it. Many thanks and my apologies for this n00b question ;) ... However 24 + 16 <> 48 .... Am I missing something else? – abc Mar 17 '18 at 13:02

2 Answers2

5

Notice that $\operatorname{secretbox}$ has a $16$-byte MAC too. For reference, I've included $\operatorname{box}$ too.

$$ \operatorname{secretbox} : \text{24 nonce} + \text{0 xsalsa} + \text{16 poly1305}\\ \operatorname{box} : \text{32 curve25519} + \text{24 nonce} + \text{0 xsalsa} + \text{16 poly1305} $$

However, the nonce is user-controlled and normally not included in the ciphertext overhead as it is usually never sent, often a protocol-level counter.

You say "secret box" but you mean the normal "box" which uses a public key. Your ciphertext is expanded with your $32$-byte ephemeral public key and the $16$-byte MAC.

cypherfox
  • 1,422
  • 7
  • 16
1

Sealed boxes: public key (32 bytes) + MAC (16 bytes).

The nonce is deterministic, as a new key pair is created for every message.

Frank Denis
  • 2,964
  • 15
  • 17