跳到主要内容
uencoder

Nonce

Nonce(number used once)是加密中仅使用一次的值,与 IV 类似但强调唯一性而非随机性,常用于流密码与 AEAD。

用途

确保同一密钥下每次加密产生不同密钥流,防止 two-time pad 攻击。

机制

Nonce 在密钥生命周期内必须唯一(不重复)。可为计数器(确定性)或随机值。CTR/GCM/ChaCha20 用 nonce 生成密钥流。GCM 96 位 nonce 最常见。nonce 重复会导致灾难性安全失效。

用例

  • AES-GCM 消息加密
  • ChaCha20-Poly1305 加密算法
  • TLS 记录序列号
  • WireGuard nonce 计数器

示例

  • 输入
    nonce=0,1,2... (counter)
    输出
    a unique nonce per message

    Deterministic and unique

常见错误

Nonce reuse replays the keystream and breaks authentication
Use a monotonic counter or a long enough random nonce

相关词条

相关工具

参考链接