Skip to content
Snippets Groups Projects
Commit b8ead559 authored by Jan Varho's avatar Jan Varho Committed by Brian Warner
Browse files

Remove the FUD about random nonces

Now it's consistent with the documentation for public key encryption.

The NaCL pages also say random nonces are fine:
http://nacl.cr.yp.to/stream.html
parent 67afb6b6
No related branches found
No related tags found
No related merge requests found
...@@ -67,20 +67,8 @@ A nonce does not need to be random, nor does the method of generating them need ...@@ -67,20 +67,8 @@ A nonce does not need to be random, nor does the method of generating them need
to be secret. A nonce could simply be a counter incremented with each message to be secret. A nonce could simply be a counter incremented with each message
encrypted. encrypted.
Both the sender and the receiver should record every nonce both that they've The nonce is long enough that using random bytes from ``nacl.utils.random(24)``
used and they've received from the other. They should reject any message which suffices. A birthday attack would require octillions of nonces before collision.
reuses a nonce and they should make absolutely sure never to reuse a nonce. It
is not enough to simply use a random value and hope that it's not being reused
(simply generating random values would open up the system to a
`Birthday Attack <https://en.wikipedia.org/wiki/Birthday_attack>`_).
One good method of generating nonces is for each person to pick a unique prefix,
for example ``b"p1"`` and ``b"p2"``. When each person generates a nonce they
prefix it, so instead of ``nacl.utils.random(24)`` you'd do
``b"p1" + nacl.utils.random(22)``. This prefix serves as a guarantee that no
two messages from different people will inadvertently overlap nonces while in
transit. They should still record every nonce they've personally used and every
nonce they've received to prevent reuse or replays.
Reference Reference
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment