| 标准 | RFC 8439 |
|---|---|
| 密钥 / nonce | 256 位 / 96 位(协议层) |
| 计数器 | 32 位 |
| 轮数 | 20 轮(10 个双轮) |
Python 使用示例
Python 使用示例
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms
import os
key, nonce = os.urandom(32), os.urandom(16)
enc = Cipher(algorithms.ChaCha20(key, nonce), mode=None).encryptor()
ct = enc.update(b"data") + enc.finalize()裸 ChaCha20 无完整性保护;协议中应使用 ChaCha20-Poly1305(AEAD),并保证同一密钥下 nonce 不重复。