XChaCha20 - nonce size restrictions
Closed this issue · 4 comments
Hi there!
Thanks for your great library.
I have a question: why nonce size in XChaCha20 is strictly 32 in bytes, or NONCE_SIZE == 24.
In my case i need NONCE_SIZE to be eqal to 12.
Encryption with 12 value works fine, but decryption in method hChaCha20 fails with crash.
upd: encryption doesn't work too, unfortunately.
@antailyaqwer I referenced Tink's implementation of XChaCha20
. Currently it only supports NONCE_SIZE
= 24 and KEY_SIZE
= 32, if you want to support NONCE_SIZE = 12, PR welcome. 🍺
KEY_SIZE: InsecureNonceChaCha20Base.java#L43C36-L43C53
NONCE_SIZE: InsecureNonceXChaCha20.java#L34C27-L34C46
If anyones wondering: I found java-only realization with custom nonce size. Converted with android studio utility and copied required files (5 files copied) - works fine.
@antailyaqwer Reference here, bcgit/bc-java#957