# 小步大步法

小步大步法（baby-step giant-step，BSGS）是丹尼尔·尚克斯（Daniel Shanks）提出的一种确定性方法，用于在有限循环群中以约群阶平方根的时间计算离散对数，代价是需要存储大致相同数量的群元素。尚克斯在1971年的论文《类数、因子分解理论与种》（《纯粹数学研讨会论文集》第20卷，第415–440页）中引入了这一方法，最初是作为计算阿贝尔群阶的工具，特别是虚二次域的类群。<sup>[1](https://pub.math.leidenuniv.nl/~stevenhagenp/ANTproc/11carl.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 解决的问题 | 给定群 \( G \) 中的 \( g, h \)，求 \( a \) 使得 \( h = g^{a} \)（离散对数问题）<sup>[2](https://www.math.auckland.ac.nz/~sgal018/crypto-book/main.pdf)</sup> |
| 时间复杂度 | \( O(\sqrt{|G|}) \) 次群运算，确定性<sup>[3](https://www.cur.ac.rw/mis/main/library/documents/book_file/2010_Book_UnderstandingCryptography.pdf)</sup> |
| 空间复杂度 | \( O(\sqrt{|G|}) \) 个群元素的存储，这是其核心权衡<sup>[3](https://www.cur.ac.rw/mis/main/library/documents/book_file/2010_Book_UnderstandingCryptography.pdf)</sup> |
| 起源 | 丹尼尔·尚克斯，1971年，源于类群计算的背景<sup>[1](https://pub.math.leidenuniv.nl/~stevenhagenp/ANTproc/11carl.pdf)</sup> |
| 主要对手 | 波拉德rho算法，期望时间同为 \( O(\sqrt{|G|}) \) 但空间为 \( O(1) \)，随机化<sup>[4](https://andrea.corbellini.name/2015/06/08/elliptic-curve-cryptography-breaking-security-and-a-comparison-with-rsa/)</sup> |
| 区间变体 | 已知 \( x \in [a,b] \) 时，BSGS至多需要 \( 2\sqrt{b-a} \) 次群运算，平均 \( 3\sqrt{b-a}/2 \) 次<sup>[5](https://doi.org/10.1016%2FS0166-218X%2802%2900590-5)</sup> |

## 算法原理

该方法是一种中间相遇攻击。它将未知指数改写为两位表示。将离散对数写作 \( x = \log_{\alpha} \beta \)，选取 \( m = \lceil \sqrt{|G|} \rceil \) 并分解

\[ x = x_{g} \cdot m + x_{b}, \qquad 0 \le x_{g},\, x_{b} < m. \]

代入 \( \beta = \alpha^{x} \) 并整理得

\[ \beta \cdot (\alpha^{-m})^{x_{g}} = \alpha^{x_{b}}. \]

两个未知量 \( x_{b} \) 和 \( x_{g} \) 现在可以分别搜索。在小步阶段，算法计算并存储所有 \( \alpha^{x_{b}} \)（\( 0 \le x_{b} < m \)），约需 \( \sqrt{|G|} \) 次群运算，并存储大致相同数量的群元素。在大步阶段，对每个 \( x_{g} \)（\( 0 \le x_{g} < m \)）检查 \( \beta \cdot (\alpha^{-m})^{x_{g}} \) 是否与已存储的小步匹配。一旦匹配，直接得到 \( x = x_{g} \cdot m + x_{b} \)。<sup>[3](https://www.cur.ac.rw/mis/main/library/documents/book_file/2010_Book_UnderstandingCryptography.pdf)</sup> 在椭圆曲线情形下，同样的思想写作 \( Q - [a_{1}]([M]P) = [a_{0}]P \)，其中 \( M = \lceil \sqrt{\ell} \rceil \)，存储小步 \( [a_{0}]P \) 并对列表计算大步。<sup>[6](https://www.cryptrec.go.jp/exreport/cryptrec-ex-3003-2020.pdf)</sup>

实现细节对常数因子有影响。小步通常存放在哈希表中，或存放在排序列表中以便用二分查找，以获得快速查询；大步乘数 \( \alpha^{-m} \) 只计算一次，此后每个大步只需一次群运算。平均而言，在首次匹配之前只需约一半的大步。若群阶 \( n \) 未知，算法仍可用任意 \( m \ge \sqrt{n} \) 工作：从小 \( m \) 开始，失败则以 \( 2m \) 重试，总代价保持为 \( O(\sqrt{n} \log n) \)。小步列表还可复用于计算多个目标的对数。<sup>[1](https://pub.math.leidenuniv.nl/~stevenhagenp/ANTproc/11carl.pdf)</sup>

## 时间-内存权衡

平方根级的运行时间相比暴力搜索的 \( O(|G|) \) 步是巨大改进，但同等的存储需求在实践中才是真正的约束。对于阶为 \( 2^{80} \) 的群，攻击者需要约 \( 2^{40} \) 次计算和同样数量的内存单元，这在普通硬件上即可实现，因此群至少需要有 \( 2^{160} \) 个元素才能使攻击代价达到 \( 2^{80} \)。<sup>[3](https://www.cur.ac.rw/mis/main/library/documents/book_file/2010_Book_UnderstandingCryptography.pdf)</sup> 在密码学规模下，存储占据主导地位：攻击阶为 \( 2^{128} \) 的群意味着存储 \( 2^{64} \) 个条目，远超任何现有存储能力，因此仅凭时间界会低估实际难度。<sup>[7](https://www.kevos.com/engineering/the-baby-step-giant-step-method)</sup>

一条具体的标准化曲线能让数字更直观。对于曲线 prime192v1（secp192r1），其阶 \( n \) 是一个192位二进制数，\( \sqrt{n} \approx 7.9228 \times 10^{28} \)。以每点32字节存储 \( \sqrt{n} \) 个点需要约 \( 2.5 \times 10^{30} \) 字节，比估计的全球总存储容量约一泽字节（\( 10^{21} \) 字节）高出约十个数量级。<sup>[4](https://andrea.corbellini.name/2015/06/08/elliptic-curve-cryptography-breaking-security-and-a-comparison-with-rsa/)</sup>

将内存计入成本的模型使BSGS显得更差。迈克尔·维纳（Michael Wiener）主张分析算法时必须计入存储成本和内存访问，在这种设定下小步大步法的复杂度超过平方根，而带区分点的波拉德rho算法可在任意固定存储界内实现。在AT度量（芯片面积与运行时间的乘积）下，即使允许预计算和非均匀算法，也没有已知算法能超越波拉德rho。<sup>[6](https://www.cryptrec.go.jp/exreport/cryptrec-ex-3003-2020.pdf)</sup>

## 与其他离散对数算法的比较

| 方法 | 时间 | 内存 | 确定性 |
|---|---|---|---|
| 暴力搜索 | \( O(q) \) | \( O(1) \) | 是 |
| 小步大步法 | \( O(\sqrt{q}) \) | \( O(\sqrt{q}) \) | 是 |
| 波拉德rho | \( O(\sqrt{q}) \) | \( O(1) \) | 否 |
| 带区分点的并行rho | \( P \) 个处理器上 \( O(\sqrt{q}/P) \) | 适中 | 否 |

波拉德rho通过检测伪随机游走中的循环而非存储表格，以常数内存达到相同的平方根时间；代价是它是随机化的。带区分点的并行rho变体才是大规模分布式计算实际采用的方案，因为它几乎完美并行化且内存需求适中。<sup>[7](https://www.kevos.com/engineering/the-baby-step-giant-step-method)</sup> 因此，在一般群中椭圆曲线离散对数问题上，rho而非BSGS被视为已知最佳攻击，只有当曲线小到微不足道时才会用BSGS攻击真实曲线。<sup>[4](https://andrea.corbellini.name/2015/06/08/elliptic-curve-cryptography-breaking-security-and-a-comparison-with-rsa/)</sup>

小规模实验显示了预期的排序。在阶为10331的玩具椭圆曲线上，计算所有对数时暴力搜索平均耗时2分31秒、5193步（接近群阶的一半），小步大步法平均6秒、152步，波拉德rho平均21秒、138步；两种平方根方法的步数都接近 \( \sqrt{10331} \approx 101.64 \)。BSGS是两者中较快的，而rho使用的内存少得多。<sup>[4](https://andrea.corbellini.name/2015/06/08/elliptic-curve-cryptography-breaking-security-and-a-comparison-with-rsa/)</sup> 2025年一项在阶约为 \( 2^{19} \) 的椭圆曲线上的比较研究同样发现BSGS在暴力搜索、波拉德rho和BSGS中最快，但将结果外推到阶约为 \( 2^{160} \) 的曲线时，波拉德rho被证明最为高效。<sup>[8](https://www.sciencedirect.com/science/article/pii/S1877050925027437)</sup>

BSGS可与波利格-赫尔曼算法结合，后者将合数群阶上的离散对数归约为素数阶子群中的对数，每个子群再用BSGS或rho求解。这就是为什么一个要提供 \( 2^{128} \) 抗离散对数攻击工作量的群，需要大于 \( 2^{256} \) 的素数阶子群。<sup>[9](https://www.cur.ac.rw/mis/main/library/documents/book_file/2016_Book_CryptographyMadeSimple.pdf)</sup> 在 \( \mathbb{Z}_p^{*} \) 中情况不同：数域筛法以约 \( \exp((\log p)^{1/3}(\log \log p)^{2/3}) \) 的时间求解离散对数，属于亚指数级，远快于任何平方根方法，这就是此类群需要比椭圆曲线群大得多的参数的原因。<sup>[10](https://securitybook.eecs.berkeley.edu/chapters/lec10.html)</sup>

## 变体与改进

**交错执行与平均情形分析。** 波拉德提出交错执行小步和大步计算以改善平均性能，对素数阶 \( \ell \) 的群给出平均运行时间为 \( \frac{4}{3}\sqrt{\ell} \) 次群运算的算法。<sup>[6](https://www.cryptrec.go.jp/exreport/cryptrec-ex-3003-2020.pdf)</sup> 伯恩斯坦和兰格的成功概率分析发现，在无快速取负的阶为 \( l \) 的群中经过 \( (1.5 + o(1))\sqrt{l} \) 次加法后，小步大步法以概率 \( 0.5625 + o(1) \) 找到均匀随机离散对数，低于真正随机游走的 \( 0.6753 \) 以及他们新提出的“两个脾气暴躁的巨人和一个婴儿”方法的 \( 0.71875 \)。<sup>[11](https://research.tue.nl/en/publications/two-grumpy-giants-and-a-baby-2/)</sup> 加尔布雷斯、王和张后来结合取负映射与批量求逆来加速椭圆曲线上的BSGS，结论是在完全优化的设定下，交错BSGS和脾气暴躁巨人算法在平均运行时间上都优于波拉德rho，且对于已知区间内的对数，交错BSGS比波拉德袋鼠法或高德里-肖斯特法快得多。<sup>[12](https://www.aimsciences.org/article/doi/10.3934/amc.2017038?viewType=HTML)</sup>

**区间目标。** 当已知对数位于区间 \( [a,b] \) 时，BSGS充分利用这一信息，至多 \( 2\sqrt{b-a} \) 次群运算、平均 \( 3\sqrt{b-a}/2 \) 次即可算出，与袋鼠法以可忽略内存达到的复杂度增长阶相同。<sup>[5](https://doi.org/10.1016%2FS0166-218X%2802%2900590-5)</sup>

**群阶计算。** 尚克斯最初的用途是确定元素或群的阶。在椭圆曲线上绍夫式点计数中，小步大步法在哈塞区间内搜索满足 \( MP = 0 \) 的整数 \( M \)；选取 \( r \approx s \approx 2q^{1/4} \) 个小步和大步，结合批量域求逆，以期望时间 \( O(q^{1/4} M(\log q)) \) 计算 \( \#E(\mathbb{F}_q) \)。<sup>[13](https://math.mit.edu/classes/18.783/2017/LectureNotes8.pdf)</sup>

**软件。** SageMath 提供了完全通用的 `bsgs` 函数，可在任何指定了运算的群中求解给定界内的 \( na = b \)，在界区间上具有软 \( O(\sqrt{n}) \) 时间和空间；其通用 `discrete_log` 例程将BSGS作为默认验证算法，与波利格-赫尔曼、波拉德rho和波拉德lambda并列。<sup>[14](https://doc.sagemath.org/html/en/reference/groups/sage/groups/generic.html)</sup>

## 对密钥长度的意义

由于每个通用离散对数算法（包括BSGS）在素数阶 \( \ell \) 的群中至少需要 \( \sqrt{\ell} \) 次群运算，标准惯例是当 \( 2^{2\lambda} < \ell < 2^{2\lambda+2} \) 时该问题提供 \( \lambda \) 比特安全性；标准猜想是在一般曲线上，在同时计入运算和内存访问成本的度量下，没有ECDLP算法能达到 \( t/\varepsilon \le 2^{\lambda} \)。<sup>[6](https://www.cryptrec.go.jp/exreport/cryptrec-ex-3003-2020.pdf)</sup> 平方根界也有相应的通用下界匹配：纽约大学计算机科学教授、《数论与代数的计算导论》（剑桥大学出版社，2005年）的作者维克托·舒普（Victor Shoup）证明了通用离散对数算法的下界，而BSGS与该界相差一个常数因子。<sup>[15](https://cs355.stanford.edu/schedule/cryptanalysis/lecture-6/)</sup><sup> • </sup><sup>[7](https://www.kevos.com/engineering/the-baby-step-giant-step-method)</sup>

## References

1. [Carl Pomerance. The baby steps giant steps method, in Algorithmic Number Theory (ANTS proceedings).](https://pub.math.leidenuniv.nl/~stevenhagenp/ANTproc/11carl.pdf)
2. [Steven Galbraith. Basic Discrete Logarithm Algorithms, Mathematics of Public Key Cryptography, Ch. 13.](https://www.math.auckland.ac.nz/~sgal018/crypto-book/main.pdf)
3. [Understanding Cryptography, Ch. 8.3, The Discrete Logarithm Problem.](https://www.cur.ac.rw/mis/main/library/documents/book_file/2010_Book_UnderstandingCryptography.pdf)
4. [Andrea Corbellini (2015). Elliptic Curve Cryptography: breaking security and a comparison with RSA.](https://andrea.corbellini.name/2015/06/08/elliptic-curve-cryptography-breaking-security-and-a-comparison-with-rsa/)
5. [Pollard's kangaroo method paper, Theory of Computing Systems / Discrete Applied Mathematics (2002).](https://doi.org/10.1016%2FS0166-218X%2802%2900590-5)
6. [CRYPTREC Technical Report EX-3003-2020: security levels for the ECDLP.](https://www.cryptrec.go.jp/exreport/cryptrec-ex-3003-2020.pdf)
7. [KEVOS Engineering. The Baby Step/Giant Step Method.](https://www.kevos.com/engineering/the-baby-step-giant-step-method)
8. [Tanujaya, Thendito, Faisal (2025). Comparative Efficiency of Algorithms for Solving the Elliptic Curve Discrete Log Problem. Procedia Computer Science 269, 1348–1357.](https://www.sciencedirect.com/science/article/pii/S1877050925027437)
9. [Cryptography Made Simple, Ch. 3: Discrete Logarithms.](https://www.cur.ac.rw/mis/main/library/documents/book_file/2016_Book_CryptographyMadeSimple.pdf)
10. [UC Berkeley, The Structure of Secure Systems, Lecture 10: Key Exchange and Public-key Encryption.](https://securitybook.eecs.berkeley.edu/chapters/lec10.html)
11. [D. J. Bernstein, T. Lange (2013). Two grumpy giants and a baby. ANTS X, The Open Book Series 1, 87–111.](https://research.tue.nl/en/publications/two-grumpy-giants-and-a-baby-2/)
12. [S. D. Galbraith, P. Wang, F. Zhang (2017). Computing elliptic curve discrete logarithms with improved baby-step giant-step algorithm. Advances in Mathematics of Communications.](https://www.aimsciences.org/article/doi/10.3934/amc.2017038?viewType=HTML)
13. [MIT 18.783 Elliptic Curves, Spring 2017, Lecture 8 notes.](https://math.mit.edu/classes/18.783/2017/LectureNotes8.pdf)
14. [SageMath documentation, sage.groups.generic.](https://doc.sagemath.org/html/en/reference/groups/sage/groups/generic.html)
15. [Stanford CS 355, Lecture 6: Attacks on Groups.](https://cs355.stanford.edu/schedule/cryptanalysis/lecture-6/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026; Oct 25, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Number theory › Computational and probabilistic number theory › Discrete logarithm and cyclic-group algorithms

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/baby-step-giant-step

English original: https://www.edgepedia.org/baby-step-giant-step
