# Salsa20

**Salsa20** 是由丹尼尔·J·伯恩斯坦（Daniel J. Bernstein）于2005年设计的一种流密码，为在软件实现中获得高性能而提交给 ECRYPT 流密码项目 eSTREAM<sup>[1](https://cr.yp.to/snuffle/salsafamily-20071225.pdf)</sup><sup> • </sup><sup>[2](https://datatracker.ietf.org/doc/draft-josefsson-salsa20-tls/01/)</sup>。它把一个256位密钥扩展为 2<sup>64</sup> 条可随机访问的流，每条流包含 2<sup>64</sup> 个可随机访问的64字节（512位）块<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup>。2008年，伯恩斯坦将其改进为 ChaCha 家族；两者之中，ChaCha 已成为标准化程度更高的那一个，而 Salsa20 仍通过 XSalsa20 部署在 NaCl 和 libsodium 库中<sup>[4](https://mojoauth.com/security-guides/chacha20-256-vs-salsa20-128)</sup>。

| 关键事实 | 详情 |
|---|---|
| 设计者与年份 | 丹尼尔·J·伯恩斯坦，2005年，提交至 eSTREAM<sup>[1](https://cr.yp.to/snuffle/salsafamily-20071225.pdf)</sup> |
| 密钥与 nonce | 256位密钥（也存在128位变体）；64位 nonce；XSalsa20 将 nonce 扩展至192位<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup><sup> • </sup><sup>[4](https://mojoauth.com/security-guides/chacha20-256-vs-salsa20-128)</sup> |
| 状态与块 | 由十六个32位字组成的512位内部状态；64字节输出块<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup> |
| 轮数 | 完整密码为20轮；存在减轮变体 Salsa20/12 和 Salsa20/8，eSTREAM 选择了12轮版本<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup><sup> • </sup><sup>[2](https://datatracker.ietf.org/doc/draft-josefsson-salsa20-tls/01/)</sup> |
| 软件速度 | 在2.4 GHz Core 2 Duo上，长消息约为每字节1.8个周期；相比之下，无硬件加速的软件 AES-128 为每字节15至20个周期<sup>[5](https://blog.lbenicio.dev/post/2024/12/09/the-performance-of-the-salsa20-stream-cipher-vs.-chacha20-in-modern-processors/)</sup> |
| 已知攻击 | 截至2013年初，最好的密码分析攻破了20轮中的8轮，使用 2<sup>31</sup> 对密钥流以 2<sup>251</sup> 次操作恢复256位密钥；尚无针对完整密码的已知实用攻击<sup>[2](https://datatracker.ietf.org/doc/draft-josefsson-salsa20-tls/01/)</sup><sup> • </sup><sup>[4](https://mojoauth.com/security-guides/chacha20-256-vs-salsa20-128)</sup> |
| 后继者 | ChaCha20（2008年）每轮扩散更快，是用于 TLS 1.3、SSH 和 WireGuard 的标准化变体<sup>[4](https://mojoauth.com/security-guides/chacha20-256-vs-salsa20-128)</sup> |

## 设计

Salsa20 遵循常见的流密码模型：由密钥和 nonce 生成密钥流，再通过异或与明文结合，因此加密和解密是同一操作<sup>[6](https://citeseerx.ist.psu.edu/document?doi=90ac5a4e1086b82d6cc248831419b0c71c2ea2a1&repid=rep1&type=pdf)</sup>。在内部，它的工作方式类似于以计数器模式使用的分组密码，并带有一个专用的64位块计数器，因此 nonce 不必对每个块都改变<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup>。

核心是一个4×4矩阵，由十六个32位字组成，存放常量、密钥、计数器和 nonce。基本的非线性运算是四分之一轮函数（quarterround），它仅使用模 2<sup>32</sup> 加法、旋转和异或来混合四个字，即 ARX（加-旋转-异或）风格<sup>[7](https://eprint.iacr.org/2015/217.pdf)</sup><sup> • </sup><sup>[8](https://www.researchgate.net/publication/220942416_On_the_Salsa20_Core_Function)</sup>。Salsa20 的一轮在奇数轮对列应用四分之一轮函数，在偶数轮对行应用四分之一轮函数，完整密码执行20个这样的轮<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup><sup> • </sup><sup>[16](https://www.iacr.org/archive/fse2008/50860479/50860479.pdf)</sup>。

**简洁性与常数时间行为。** 整个算法除初始化外大约只需20行 C 代码，密钥直接用于状态中，因此没有密钥扩展方案<sup>[5](https://blog.lbenicio.dev/post/2024/12/09/the-performance-of-the-salsa20-stream-cipher-vs.-chacha20-in-modern-processors/)</sup>。Salsa20 不使用查找表，从而消除了缓存时序攻击的可能性；其廉价运算使它适合多种架构<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup><sup> • </sup><sup>[2](https://datatracker.ietf.org/doc/draft-josefsson-salsa20-tls/01/)</sup>。

## 性能

Salsa20 是为软件中的速度而设计的。伯恩斯坦在2006年报告称，在2.4 GHz Core 2 Duo上，长消息约为每字节1.8个周期，比那个硬件时代软件 AES-128 典型的每字节15至20个周期快一个数量级，当时 AES 指令扩展尚未普及<sup>[5](https://blog.lbenicio.dev/post/2024/12/09/the-performance-of-the-salsa20-stream-cipher-vs.-chacha20-in-modern-processors/)</sup>。密钥设置开销极小，因为密钥直接进入状态，这也使短消息具有良好性能<sup>[5](https://blog.lbenicio.dev/post/2024/12/09/the-performance-of-the-salsa20-stream-cipher-vs.-chacha20-in-modern-processors/)</sup>。

在没有专用 AES 硬件的平台上，例如许多微控制器和较旧的手机，Salsa20 和 ChaCha20 仍然比基于表的软件 AES 更快<sup>[9](https://mojoauth.com/security-guides/aes-256-vs-salsa20-256)</sup>。在资源受限的物联网平台上的对比测量中，Salsa20 和 XChaCha20 表现出相似的软件性能特征，因为它们共享相同的 ARX 轮函数<sup>[10](https://pmc.ncbi.nlm.nih.gov/articles/PMC12473500/)</sup>。

## 安全性与密码分析

伯恩斯坦的设计分析认为，最少活跃S盒数量足够高，能在8轮后抵抗差分密码分析，从而使20轮版本具有宽裕的安全裕度<sup>[5](https://blog.lbenicio.dev/post/2024/12/09/the-performance-of-the-salsa20-stream-cipher-vs.-chacha20-in-modern-processors/)</sup>。Salsa 和 ChaCha 密码分析中最重要的一步，是奥马松（Aumasson）等人在 FSE 2008 上提出的概率中性位思想；2017年的一篇论文给出了一种构造此类位的新算法，并改进了现有的减轮攻击，对 Salsa 的运行速度约为乔杜里（Choudhuri）和迈特拉（Maitra）先前在 FSE 2017 被接收的工作的2.27倍，对 ChaCha 约为5.39倍<sup>[11](https://www.sciencedirect.com/science/article/pii/S0166218X1730224X)</sup>。

攻击记录进展缓慢。截至2013年初，最好的密码分析攻破了20轮中的8轮，使用 2<sup>31</sup> 对密钥流以 2<sup>251</sup> 次操作恢复256位密钥<sup>[2](https://datatracker.ietf.org/doc/draft-josefsson-salsa20-tls/01/)</sup>。后来的文献报告，针对 Salsa20/7 和 Salsa20/8 的安全性分别约为 2<sup>137</sup> 和 2<sup>244.9</sup> 量级<sup>[12](https://repositorio.unb.br/bitstream/10482/45865/1/2022_MuriloCoutinhoSilva.pdf)</sup>。尚无针对完整20轮 Salsa20 的已知实用攻击，伯恩斯坦建议使用256位密钥以获得更大的安全裕度<sup>[4](https://mojoauth.com/security-guides/chacha20-256-vs-salsa20-128)</sup>。

**轮数之争。** libsodium 文档指出，尽管针对 Salsa20/8 的已知最佳攻击并不实用，但完整轮版本提供了最高的安全裕度，同时对大多数用途仍足够快<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup>。

## Nonce 与 XSalsa20

标准 Salsa20 的 nonce 为64位，短到在密钥复用时绝不能随机选择；libsodium 建议在密钥复用时递增前一个 nonce，而不是生成新的随机 nonce<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup>。**XSalsa20** 将 nonce 扩展至192位，大到随机生成的 nonce 具有可忽略的碰撞概率，因此通常推荐使用它而非原始 Salsa20，因为它使安全的 nonce 生成更容易<sup>[13](https://ianix.com/pub/salsa20-deployment.html)</sup><sup> • </sup><sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup>。在 libsodium 中，XSalsa20-Poly1305 提供认证加密，原始流函数执行完整的20轮，而 Salsa20/12 和 Salsa20/8 可作为更快的减轮选项<sup>[3](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)</sup>。

## 与 ChaCha20 的关系

其目的是更快的扩散：按照伯恩斯坦的分析，ChaCha 状态在3轮后即充分混合，而 Salsa20 需要4轮，因此在相同安全裕度下，ChaCha 能承受更多轮的密码分析<sup>[5](https://blog.lbenicio.dev/post/2024/12/09/the-performance-of-the-salsa20-stream-cipher-vs.-chacha20-in-modern-processors/)</sup>。ChaCha20 成为标准化变体，在 RFC 8439 中为 IETF 协议定义，并用于 [TLS 1.3](https://www.edgepedia.org/zh/tls-1-3)、SSH 和 [WireGuard](https://www.edgepedia.org/zh/wireguard)；而 Salsa20 主要以 XSalsa20-Poly1305 的形式存在于 NaCl 和 libsodium 中<sup>[4](https://mojoauth.com/security-guides/chacha20-256-vs-salsa20-128)</sup><sup> • </sup><sup>[14](https://datatracker.ietf.org/doc/rfc8439/)</sup>。

## 部署

Salsa20 和 XSalsa20 已在多种协议和软件中实现。协议用途包括用于加密 DNS 的 DNSCurve 和 DNSCrypt v1，以及用于安全传输的 CurveCP<sup>[13](https://ianix.com/pub/salsa20-deployment.html)</sup>。库支持包括 NaCl 和 libsodium、PyPI 上 libsodium 实现的 Python 绑定，以及 C、Java 和 [JavaScript](https://www.edgepedia.org/zh/javascript) 中的独立实现<sup>[13](https://ianix.com/pub/salsa20-deployment.html)</sup><sup> • </sup><sup>[15](https://pypi.org/project/salsa20/)</sup>。2013年的一份互联网草案提出了用于 TLS 和 DTLS 的 Salsa20 密码套件，包含12轮和20轮变体，但它过期而未成为 RFC<sup>[2](https://datatracker.ietf.org/doc/draft-josefsson-salsa20-tls/01/)</sup>。

## References

1. [Daniel J. Bernstein (2005/2007). The Salsa20 family of stream ciphers. cr.yp.to](https://cr.yp.to/snuffle/salsafamily-20071225.pdf)
2. [Josefsson, Strombergson, Mavrogiannopoulos (2013). The Salsa20 Stream Cipher for TLS and DTLS, draft-josefsson-salsa20-tls-01, IETF Datatracker](https://datatracker.ietf.org/doc/draft-josefsson-salsa20-tls/01/)
3. [Salsa20, libsodium documentation](https://libsodium.gitbook.io/doc/advanced/stream_ciphers/salsa20)
4. [chacha20-256 vs salsa20-128:key differences | mojoauth security guides](https://mojoauth.com/security-guides/chacha20-256-vs-salsa20-128)
5. [Leonardo Benicio (2024). The Performance of the Salsa20 Stream Cipher vs. ChaCha20 in Modern Processors](https://blog.lbenicio.dev/post/2024/12/09/the-performance-of-the-salsa20-stream-cipher-vs.-chacha20-in-modern-processors/)
6. [Salsa20 specification, CiteSeerX](https://citeseerx.ist.psu.edu/document?doi=90ac5a4e1086b82d6cc248831419b0c71c2ea2a1&repid=rep1&type=pdf)
7. [Salsa20 Cryptanalysis: New Moves and Revisiting Old Styles, IACR ePrint 2015/217](https://eprint.iacr.org/2015/217.pdf)
8. [On the Salsa20 Core Function, ResearchGate](https://www.researchgate.net/publication/220942416_On_the_Salsa20_Core_Function)
9. [AES-256 vs Salsa20: Which Cipher to Use, MojoAuth Security Guides](https://mojoauth.com/security-guides/aes-256-vs-salsa20-256)
10. [Comparative Performance Analysis of Lightweight Cryptographic Algorithms on Resource-Constrained IoT Platforms, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC12473500/)
11. [Improved analysis for reduced round Salsa and Chacha, Discrete Applied Mathematics (2017)](https://www.sciencedirect.com/science/article/pii/S0166218X1730224X)
12. [Murilo Coutinho Silva (2022). Design, Diffusion, and Cryptanalysis of Symmetric Ciphers, Universidade de Brasília](https://repositorio.unb.br/bitstream/10482/45865/1/2022_MuriloCoutinhoSilva.pdf)
13. [Salsa20 Usage & Deployment, ianix.com](https://ianix.com/pub/salsa20-deployment.html)
14. [RFC 8439: ChaCha20 and Poly1305 for IETF Protocols, IETF Datatracker](https://datatracker.ietf.org/doc/rfc8439/)
15. [salsa20, PyPI](https://pypi.org/project/salsa20/)
16. [iacr.org](https://www.iacr.org/archive/fse2008/50860479/50860479.pdf)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Cryptographic algorithms and protocols

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/salsa20

English original: https://www.edgepedia.org/salsa20
