androidencryptiontink

Google / Tink: XChaCha20Poly1305 encryption with custom non-random nonce


I would like to use Tink in order to replace Sodium-JNI on Android. Tink seems to be great and really easy to use. But I have one problem. In my use case I have to exchange XChaCha20Poly1305 encrypted messages with other peers and the peers only send certain parts of the nonce, not the whole 24 bytes. This shortened nonce is then used to recover/derive the complete 24 nonce bytes. That's why I would need full control over the used nonce and to set a custom nonce for encryption instead of using encryption with random nonces chosen by Tink. Is there an easy way to use my custom nonces with XChaCha20Poly1305 in Tink?

Thanks in advance and regards Bruno


Solution

  • Using a shortened nonce is not recommended. The shorter then nonces the less security you'd get from encryption.

    This is one of the reasons we don't want users to use their own nonces. Another reason is if you reuse nonces, you'd leak plaintext.

    Hope that helps, Thai.