{
  "id": "cryptographic-nonce",
  "title": "Cryptographic nonce",
  "lang": "en",
  "source_lang": "en",
  "summary": "A cryptographic nonce is a value used to distinguish operations or protocol exchanges, with uniqueness or unpredictability requirements determined by its application.",
  "category": "computer-science",
  "subcategory": "networks-security",
  "type": "concept",
  "aliases": [
    "Nonce",
    "Number used once"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/cryptographic-nonce/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/cryptographic-nonce/",
      "json": "https://aiwiki.page/zh/cryptographic-nonce.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A cryptographic nonce is a value used in cryptography to distinguish one operation, message, or protocol exchange from another. The term is commonly explained as “number used once,” but the relevant scope of “once” depends on the cryptographic construction: a nonce might need to be unique under a particular key, fresh for an authentication exchange, or unpredictable before it is issued. A nonce need not be random or secret. Counters, random bit strings, and structured combinations of identifiers and sequence numbers can all serve as nonces when they satisfy the applicable requirements."
    },
    {
      "heading": "Purpose and security properties",
      "text": "A cryptographic operation often needs more than a key and a message. Repeatedly processing messages under the same key can reveal relationships between them, while an attacker may record a legitimate protocol exchange and attempt to reuse it later. Nonces help distinguish these otherwise similar events.\n\nTheir security requirements fall into several categories:\n\n- Uniqueness: a value must not repeat within a specified scope, commonly all encryption operations under one key.\n- Freshness: a value must identify a current exchange rather than an old one.\n- Unpredictability: an attacker must not be able to predict the value before a particular point in the protocol.\n\nThese properties are distinct. A counter can guarantee uniqueness while being entirely predictable. A random value can be difficult to predict but still repeat by chance. A timestamp can indicate approximate recency while failing to distinguish operations occurring within the same clock interval.\n\nThe required properties follow from the threat model and the construction’s security analysis. Substituting an unpredictable value for a unique value, or vice versa, is not automatically safe."
    },
    {
      "heading": "Nonces in encryption",
      "text": "Stream ciphers and counter-based encryption\n\nIn a stream cipher, a key and nonce typically determine a pseudorandom keystream that is combined with the plaintext. A simplified representation is\n\n\\[C = P \\oplus S(K,N),\\]\n\nwhere \\(P\\) is the plaintext, \\(C\\) is the ciphertext, \\(K\\) is the secret key, \\(N\\) is the nonce, and \\(\\oplus\\) denotes bitwise exclusive OR.\n\nIf the same key and nonce generate the same keystream for two different plaintexts, then\n\n\\[C_1 \\oplus C_2 = P_1 \\oplus P_2.\\]\n\nThe keystream cancels, exposing a relationship between the plaintexts. Known or predictable portions of one message can reveal corresponding portions of the other. This resembles the failure caused by reusing a one-time pad.\n\nCounter mode, used with block ciphers such as the Advanced Encryption Standard, has a related requirement: the block-cipher inputs that generate the keystream must not repeat under the same key. The message nonce and the within-message block counter are therefore both relevant. Distinct message nonces do not prevent failure if a block counter wraps around or if input encodings overlap.\n\nAuthenticated encryption\n\nAuthenticated encryption protects confidentiality and detects unauthorized modification. Many widely used constructions accept a nonce alongside the key, plaintext, and any additional data that must be authenticated without being encrypted.\n\nFor conventional nonce-based constructions, nonce uniqueness is a critical condition of the security guarantee. In Galois/Counter Mode, or GCM, repeating a nonce under the same key can compromise confidentiality and undermine authentication, potentially enabling forged messages. The consequences are not limited to revealing that two messages are identical.\n\nSome constructions are designed to provide nonce-misuse resistance. For example, synthetic-IV designs can limit the damage caused by repeated nonces. Their guarantees remain construction-specific: repetition may still reveal equality of inputs, and misuse resistance does not imply protection against unlimited repetition or every implementation error.\n\nAn encryption nonce is normally public. It may be transmitted alongside the ciphertext or derived from protocol state. Its security role generally does not depend on keeping it secret."
    },
    {
      "heading": "Authentication and replay prevention",
      "text": "In authentication protocols, a nonce often acts as a challenge. A verifier generates a fresh challenge, and the other party returns a response that binds it to a secret key or private key, for example through a message authentication code or a digital signature.\n\nA recorded response to an earlier challenge should not authenticate a later exchange. This helps prevent a replay attack, in which an attacker retransmits previously valid traffic.\n\nA nonce alone does not provide replay protection. The protocol must authenticate its association with the exchange, and the verifier must enforce freshness—for example, by accepting only a currently outstanding challenge and consuming it after successful use. Depending on the protocol, identities, requested actions, and other contextual information also need to be bound to the response.\n\nUnpredictability is important when an attacker could obtain a valid response to a future challenge in advance. In other settings, authenticated sequence numbers and receiver-maintained state can provide replay protection without unpredictable challenges.\n\nTransport Layer Security illustrates the distinction between randomness and uniqueness. In TLS 1.3 record protection, the per-record nonce is derived from a connection-specific initialization value and the record sequence number rather than generated independently at random for each record."
    },
    {
      "heading": "Nonces in digital signatures",
      "text": "Some signature algorithms require a secret per-message value that is often called a nonce, although its requirements differ from those of a public encryption nonce.\n\nFor the Elliptic Curve Digital Signature Algorithm (ECDSA), signing uses a secret scalar \\(k\\). One signature component satisfies\n\n\\[s = k^{-1}(z + rd) \\pmod n,\\]\n\nwhere \\(d\\) is the private key, \\(z\\) represents the message hash, \\(r\\) is the other signature component, and \\(n\\) is the group order.\n\nReusing the same \\(k\\) for different message representatives can allow an observer to recover \\(k\\) and the private key from the signatures. Bias or partial leakage in these values can also compromise the key. Here, secrecy and resistance to prediction are essential, not merely non-repetition.\n\nDeterministic signing procedures derive the per-message value from the private key and message using a specified cryptographic process. This avoids dependence on fresh external randomness for each signature. Repeating the same message may then produce the same signature; this is different from reusing one signing nonce across distinct messages."
    },
    {
      "heading": "Generation and collision probability",
      "text": "Random generation\n\nRandom nonces are commonly generated using a cryptographically secure form of pseudorandom number generator. This avoids maintaining a counter across every operation, but it provides probabilistic rather than guaranteed uniqueness.\n\nFor \\(q\\) independently and uniformly sampled \\(n\\)-bit nonces, the probability of at least one collision is approximately\n\n\\[p \\approx 1-\\exp\\left(-\\frac{q(q-1)}{2^{n+1}}\\right).\\]\n\nWhen that probability is small,\n\n\\[p \\approx \\frac{q(q-1)}{2^{n+1}}.\\]\n\nThis is an instance of the birthday problem. The collision probability becomes substantial after a number of samples on the order of \\(2^{n/2}\\), rather than \\(2^n\\). Operational limits may be much lower because acceptable failure probabilities are small and the cryptographic construction can impose additional usage bounds.\n\nNonce width alone therefore does not establish safety. The generation method, number of operations per key, and construction-specific limits all matter.\n\nCounters and structured values\n\nA counter can ensure uniqueness if it never repeats within the relevant key scope. Its main difficulties concern state management:\n\n- preserving progress across crashes and restarts;\n- preventing counter exhaustion or wraparound;\n- avoiding duplicate allocation by concurrent processes;\n- separating values generated by different devices sharing a key;\n- preventing restored backups or virtual-machine snapshots from reusing earlier state.\n\nIn distributed computing, a nonce may combine a sender identifier with a local counter. This works only if identifiers are distinct within the shared-key scope and local counters do not repeat. Random prefixes reduce coordination requirements but introduce a collision probability of their own.\n\nTimestamps alone generally do not guarantee uniqueness: clocks can move backward, multiple operations can share a timestamp, and separate machines may produce identical values."
    },
    {
      "heading": "Related terms and other uses",
      "text": "An initialization vector (IV) is a parameter used to initialize a cryptographic operation. IVs and nonces overlap in practice, but the terms do not imply identical requirements. Some encryption modes require an unpredictable IV; others chiefly require uniqueness.\n\nA salt is another usually public parameter, commonly used in password hashing and key derivation. Its purpose is to distinguish otherwise identical inputs and impede reuse of precomputed work. Salt generation and reuse rules differ from nonce rules in encryption protocols.\n\nIn proof-of-work systems, a nonce is often a field varied while searching for a hash that meets a target condition. The security condition is successful verification of the work, not a universal requirement that the field never repeat across unrelated attempts.\n\nThese uses share the idea of distinguishing computations, but not a single universal security rule. The label “nonce” does not by itself specify whether a value must be secret, unpredictable, unique, or checked against stored state."
    }
  ],
  "links": [
    "cryptography",
    "one-time-pad",
    "advanced-encryption-standard",
    "authentication",
    "message-authentication-code",
    "digital-signature",
    "transport-layer-security",
    "pseudorandom-number-generator",
    "distributed-computing"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}