Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
3349d033
Commit
3349d033
authored
10 years ago
by
Brian Warner
Browse files
Options
Downloads
Patches
Plain Diff
docs/secret.rst: update text about nonces
parent
b8ead559
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/secret.rst
+22
-13
22 additions, 13 deletions
docs/secret.rst
with
22 additions
and
13 deletions
docs/secret.rst
+
22
−
13
View file @
3349d033
...
@@ -56,19 +56,28 @@ decrypt the data, or encrypt new data.
...
@@ -56,19 +56,28 @@ decrypt the data, or encrypt new data.
Nonce
Nonce
~~~~~
~~~~~
The 24 bytes nonce (`Number used once <https://en.wikipedia.org/wiki/Cryptographic_nonce>`_)
The 24-byte nonce (`Number used once <https://en.wikipedia.org/wiki/Cryptographic_nonce>`_)
given to :meth:`~nacl.secret.SecretBox.encrypt` and :meth:`~nacl.secret.SecretBox.decrypt`
given to :meth:`~nacl.secret.SecretBox.encrypt` and
must **NEVER** be reused for a particular key. Reusing the nonce means an
:meth:`~nacl.secret.SecretBox.decrypt` must **NEVER** be reused for a
attacker will have enough information to recover your secret key and encrypt or
particular key. Reusing a nonce may give an attacker enough information to
decrypt arbitrary messages. A nonce is not considered secret and may be freely
decrypt or forge other messages. A nonce is not considered secret and may be
transmitted or stored in plaintext alongside the ciphertext.
freely transmitted or stored in plaintext alongside the ciphertext.
A nonce does not need to be random, nor does the method of generating them need
A nonce does not need to be random or unpredictable, nor does the method of
to be secret. A nonce could simply be a counter incremented with each message
generating them need to be secret. A nonce could simply be a counter
encrypted.
incremented with each message encrypted, which can be useful in
connection-oriented protocols to reject duplicate messages ("replay
The nonce is long enough that using random bytes from ``nacl.utils.random(24)``
attacks"). A bidirectional connection could use the same key for both
suffices. A birthday attack would require octillions of nonces before collision.
directions, as long as their nonces never overlap (e.g. one direction always
sets the high bit to "1", the other always sets it to "0").
If you use a counter-based nonce along with a key that is persisted from one
session to another (e.g. saved to disk), you must store the counter along
with the key, to avoid accidental nonce reuse on the next session. For this
reason, many protocols derive a new key for each session, reset the counter
to zero with each new key, and never store the derived key or the counter.
You can safely generate random nonces by calling ``nacl.utils.random(SecretBox.NONCE_SIZE)``.
Reference
Reference
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment