Questions tagged [nonce]

A "nonce" is an arbitrary number or string used only once within the context of a specific cryptographic scheme. Nonces are used e.g. in authentication protocols to prevent replay attacks, as well as in stream ciphers (including CTR mode) to avoid keystream reuse.

A nonce is an arbitrary number or string used in a cryptographic scheme. The defining feature of a nonce is that it must be used only once within a particular context.

Nonces are used in various areas of cryptography. For example, they may be used in challenge–response authentication protocols as part of the challenge to prevent replay attacks. In stream ciphers (including streaming block cipher modes of operation, such as CTR) nonces are used to modify the keystream generation in order to avoid reusing the same keystream for multiple messages, which would significantly compromise security.

One common method of nonce generation is to simply use a counter value, such as a message number, that is known to be unique within the appropriate context (e.g. among messages encrypted with the same key). This method is simple and fast, but typically requires retaining some state (the counter value) between operation, and may be vulnerable to implementation mistakes (e.g. two parties using overlapping ranges of counter values).

An alternative method of generating nonces is to use random numbers of sufficient length (e.g. 96 bits or more) that the probability of collision is negligible. (Due to the birthday paradox, this generally requires at least $2n$ bits for an expected number of up to $2^n$ uses.) This method is more robust against some implementation mistakes, and can be implemented without any persistent state, but does require a source of cryptographically secure random numbers.

See also:

201 questions
24
votes
4 answers

What are the requirements of a nonce?

Sometimes I read that a nonce has to be a random number but I disagree. A nonce just can't repeat itself. You could increase in by 1 every time if you are sure it would never repeat.
Smit Johnth
  • 1,681
  • 4
  • 17
  • 27
12
votes
1 answer

Why does the crypto_box functionality in NaCl library expose the nonce to the programmer?

The idea of crypto_box API in NaCl library is to shield the programmer away from the technical details and provide easy to use functions for encrypting and encrypting messages. Given what I've just written, I do not understand why the idea of nonce…
user7610
  • 283
  • 4
  • 10
5
votes
3 answers

How to prevent accidental nonce reuse with AEAD cipher

I'm trying to correctly implement ChaCha20-Poly1305 in my node.js app (...crypto is hard). I understand that the cipher requires a unique key/nonce pair for each message or the security breaks down. The nonce doesn't have to be random or…
Dominic P
  • 153
  • 6
3
votes
1 answer

As a cryptographic primitive, what does a nonce provide?

As a cryptographic primitive, what does a nonce provide? It seems like, at least in my understanding of it, a nonce by itself would not provide any sort of cryptographic usefulness, compared with primitives such as digital signatures or symmetric…
tpm900
  • 203
  • 2
  • 5
2
votes
0 answers

What happens when a nonce is reused (WPA2)

I am trying to understand the KRACK on WPA2. But in their paper (PDF) it just simply states that By forcing nonce reuse in this manner, the encryption protocol can be attacked. But I cannot find an explanation WHY this is possible. I.e. what…
Tafel
  • 121
  • 1
2
votes
2 answers

I don't care about replay attacks. What should I do with the nonce in nacl?

My system forwards encrypted and/or signed messages on a gossip network. Replay is part of the design. What should I do with the nonce? I'm tempted to just set it to the same number always. Is this a bad idea?
Jehan
  • 374
  • 1
  • 6
2
votes
1 answer

NaCL - should I keep track of expired nonces

I store the ciphertext and the nonce in a SQL database. If I decrypt the ciphertext change it and encrypt it again I generate a new nonce, so that I do not encrypt two different plaintexts with the same nonce. After encrypting the updated plaintext…
user109145
0
votes
1 answer

JavaScript PKCE Code Verifier (random string nonce) alternatives

I'm creating a PKCE Code Verifier (a random string). Solution 1 from a StackOverflow answer. (You can copy/paste these code examples into a browser's inspector.) (function generateCodeVerifier() { function dec2hex(dec) { return ("0" +…
Larry K
  • 103
  • 4