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:

221 questions
29
votes
2 answers

How bad it is using the same IV twice with AES/GCM?

I understand that initialization vectors (IV) should not be used twice when using AES/GCM. I am using a counter as an initialization vector. Every time I send out a new packet (I am developing an UDP based protocol that needs packet encryption) I…
Matteo Monti
  • 1,477
  • 2
  • 14
  • 19
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,731
  • 4
  • 18
  • 27
14
votes
3 answers

Difference between a nonce and IV

I know the generic difference between a nonce and an IV. I am specifically looking for a clarification on these terms as used in the "Evaluation of Some Blockcipher Modes of Operation" by Phil Rogaway. In that when describing the block cipher modes…
user220201
  • 881
  • 4
  • 9
  • 15
13
votes
1 answer

AES-SIV security

I am invesigating the AES-SIV (rfc 5297) based block cipher. The construction of the S2V is lying on the AES-CMAC and dbl and XOR operation. Given a AAD the size of L and in the 128bit block operation, I have some concern that if the L<16bytes, the…
13
votes
1 answer

Why do stream ciphers use a nonce?

My question maybe will be stupid, but my problem is that I do not understand why stream ciphers need a key and also a nonce. As far as I understand, the keystream is generated with the nonce. The same key can be reused with a different…
robert
  • 273
  • 2
  • 10
13
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
  • 291
  • 5
  • 11
13
votes
3 answers

How much security is gained from hiding the nonce?

Public nonces can be problematic for privacy when they can be considered metadata. They can also be troublesome for security if you do things like using a hash of the message as the nonce. PASETO now derives the nonce alongside the key using HKDF on…
10
votes
0 answers

Are there any weak nonce-misuse resistant encryption scheme?

Nonce-misuse resistance seems to have two standard notions: The stronger notion: this reveals nothing unless the exact same nonce is used to encrypt the exact same message twice. In this case, the only information that is revealed is that the same…
kelalaka
  • 49,797
  • 12
  • 123
  • 211
10
votes
1 answer

Unique GCM/CCM initial counters without recipient side message counters

I am implementing the encryption layer for a communication protocol. The bulk encryption method used is either AES-CCM or AES-GCM. Due to implementation details, encryption of packets is usually, but not necessarily, performed by the sender in the…
Henrick Hellström
  • 10,556
  • 1
  • 32
  • 59
10
votes
2 answers

Is CBC mode with a fixed IV secure, if a counter is prepended to the plaintext?

In this answer to an earlier, related question I noted that encrypting a nonce, such as a sequential counter, using the same block cipher and key as used for the message encryption itself is one of the recommended ways described in NIST SP 800-38A,…
9
votes
3 answers

Can a zero nonce be safely used with AES-GCM if the key is random and never used again?

I could generate a random nonce and prepend it to the ciphertext, but storage space is at a premium and the only constraint AES-GCM has on the nonce (if I'm reading correctly) is that the same nonce must never be paired with the same key for a…
jnm2
  • 582
  • 5
  • 11
9
votes
3 answers

Why does TLS 1.3 use random-looking nonces for AEAD?

In TLS 1.3, it seems that nonces for AEAD are constructed by XORing the recorded sequence number with the server/client_write_IV (which is generated during the handshake). Thus, nonces are random-looking and cannot be reused as the sequence number…
Raoul722
  • 3,003
  • 3
  • 23
  • 42
9
votes
3 answers

Why is it good to split a CTR-mode counter into nonce and counter?

When discussing the CTR mode of block ciphers, Wikipedia says the following: Simply adding or XORing the nonce and counter into a single value would completely break the security under a chosen-plaintext attack. I don't understand the difference…
Myria
  • 2,635
  • 15
  • 26
9
votes
2 answers

nonce of AES-GCM in SSL

It seems that the nonce of AES-GCM in SSL has 3 parts: salt, 4 bytes, generated in handshake, not changed in whole session nonce_explicit, 8 bytes, chosen by the sender and carried in each SSL record inner_counter, 4 bytes, used in AES-GCM…
wub
  • 223
  • 2
  • 5
8
votes
1 answer

Deterministic Encryption with AES GCM - how to choose the IV (nonce)

I have not a very large background in cryptography so I hope these questions are not very dumb. I don't want to reinvent the wheel, I'm just looking for advise on the best practices about how to build the following. I've seeking and reading for…
1
2 3
14 15