Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random nonces are not secure #76

Open
alcore opened this issue Jun 14, 2021 · 1 comment
Open

Random nonces are not secure #76

alcore opened this issue Jun 14, 2021 · 1 comment
Labels
new feature New feature or request security

Comments

@alcore
Copy link

alcore commented Jun 14, 2021

Via

let nonce = generate_nonce();

While the probability can be astronomically low given a large enough nonce, the probability that a nonce will be reused still exists when it is random. Reusing a nonce under ciphers like ChaCha20-Poly1305 or AES-GCM effectively means revealing the encryption secret to an attacker that can observe both of the messages encrypted with the same nonce.

It's for that reason that protocols like TLS use sequential nonces and require implementations to change secrets when the sequence is about to overflow. The point is to guarantee that a reused nonce will never be observed.

Due to the nature of this library and lack of control over how and how many objects get serialized-and-encrypted, nor how they are transported or stored, it effectively means that this library is currently not secure.

I wanted to raise this issue to raise awareness - but do not see an easy fix given the current API, considering maintaining a sequence requires maintaining additional state on a per-key basis and defeats the convenience-centric aim of this library.

@laysakura
Copy link
Owner

laysakura commented Jun 14, 2021

@alcore Thank you.

I thought XChaCha20 nonce is large enough so that;

the probability can be astronomically low

but

The point is to guarantee that a reused nonce will never be observed.

is quite true and very important point.

I already created issue about incremental nonce feature but close it since this report is more informative.


I will do the following. What do you think?

  • Adds new API to use incremental nonce (state control is sender/receiver's responsibility)
  • Documents about danger of random nonce (like @alcore writes here)

@laysakura laysakura added the new feature New feature or request label Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request security
Projects
None yet
Development

No branches or pull requests

2 participants