<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>ecc on codestack</title>
    <link>https://chenquan.me/tags/ecc/</link>
    <description>Recent content in ecc on codestack</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-cn</language>
    <lastBuildDate>Thu, 15 Jun 2017 00:00:00 +0000</lastBuildDate><atom:link href="https://chenquan.me/tags/ecc/index.xml" rel="self" type="application/rss+xml" />
    <item>
            <title>Elliptic Curve Cryptography: a gentle introduction (4)</title>
            <link>https://chenquan.me/posts/elliptic-curve-cryptography_a-gentle-introduction_4/</link>
            <pubDate>Thu, 15 Jun 2017 00:00:00 +0000</pubDate>
            <guid>https://chenquan.me/posts/elliptic-curve-cryptography_a-gentle-introduction_4/</guid>
            <description>&lt;h1 id=&#34;椭圆曲线加密安全性以及rsa对比&#34;&gt;&lt;a href=&#34;#%e6%a4%ad%e5%9c%86%e6%9b%b2%e7%ba%bf%e5%8a%a0%e5%af%86%e5%ae%89%e5%85%a8%e6%80%a7%e4%bb%a5%e5%8f%8arsa%e5%af%b9%e6%af%94&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;椭圆曲线加密：安全性以及RSA对比&#xA;&lt;/h1&gt;&#xA;    &lt;blockquote&gt;&#xA;        &lt;p&gt;原标题：Elliptic Curve Cryptography: breaking security and a comparison with RSA&lt;/p&gt;&#xA;&#xA;    &lt;/blockquote&gt;&#xA;&lt;p&gt;这篇文章是ECC：优雅入门系列的第四篇文章，我们已经在前面的文章中知道了一个椭圆曲线上的离散对数离散对数问题是如何在保障加密安全的过程中扮演重要角色的。但是，如果你还记得的话，我们曾经提到说目前还没有严格的&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/23/elliptic-curve-cryptography-finite-fields-and-discrete-logarithms/#discrete-logarithm&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;数学证明&lt;/a&gt;来证明计算离散对数的复杂性:我们相信这件事情是“困难”的，但是我们并不确定。在这篇文章的开篇，我们将尝试去解释在目前的技术能力下，完成这件事情是多么地“困难”。&#xA;然后，在这篇文章的第二部分，我们将尝试去回答这样的问题，为什么我们需要椭圆曲线？RSA（或者其他基于模运算的加密系统）不是也挺好的吗？&lt;/p&gt;&#xA;&lt;h2 id=&#34;攻破离散对数问题&#34;&gt;&lt;a href=&#34;#%e6%94%bb%e7%a0%b4%e7%a6%bb%e6%95%a3%e5%af%b9%e6%95%b0%e9%97%ae%e9%a2%98&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;攻破离散对数问题&#xA;&lt;/h2&gt;&lt;p&gt;我们将会在下文中看到两个最为有效的用来计算椭圆曲线上的离散对数的算法：baby-step,giant-step算法，以及Pollard&amp;rsquo;s方法。&lt;/p&gt;&#xA;&lt;p&gt;在开始之前，我还是简单提醒一下，所谓的离散对数问题就是&lt;strong&gt;给定两个点P和Q，找到这样的证书x使得满足式子 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q = xP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;。其中的点是椭圆曲线子群中的点，这个椭圆曲线应该拥有基点G和阶n。&lt;/p&gt;&#xA;&lt;h3 id=&#34;baby-stepgiant-step&#34;&gt;&lt;a href=&#34;#baby-stepgiant-step&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Baby-step,giant-step&#xA;&lt;/h3&gt;&lt;p&gt;在描述这个算法的细节之前，我们先快速地看一下这个问题：我们始终能够写出这样的整数x使得&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;x = am+b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，其中a,m,b是三个任意整数。举例来说，我们可以写出 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;10&lt;/mn&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo&gt;⋅&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;10 = 2\cdot 3+4&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。&lt;/p&gt;&#xA;&lt;p&gt;根据上面的规则，我们可以给出如下的等式来描述离散对数问题：&lt;/p&gt;&#xA;&lt;div class=&#34;article-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;&#xA;Q = xP \ Q = (am +b)P \ Q = amP + bP \ Q - amp = bP&#xA;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;“baby-step,giant-step”其实是一个二分算法。不同于暴力破解( brute-force attack)(通过枚举所有有可能的点xP得到我们需要的Q)，我们可以&amp;quot;稍微&amp;quot;地减少计算量，通过计算bP和Q-amP直到我们找到相似值。这个算法的具体步骤如下：&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;计算 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;⌈&lt;/mo&gt;&lt;msqrt&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msqrt&gt;&lt;mo stretchy=&#34;false&#34;&gt;⌉&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;m = \lceil \sqrt{n} \rceil&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;对于所有的&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;属于&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;0,…,m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;计算&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;bP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;并将结果存储到hash表中.&lt;/li&gt;&#xA;&lt;li&gt;对于所有的&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;a&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;属于&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;0,…,m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;:&lt;/li&gt;&#xA;&lt;li&gt;计算&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;amP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;计算&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q - amP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;检查这个hash表并观察是否存在这样的点使得&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q - amP = bP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;如果这样的点存在，那么我们就找到了这样的x 满足&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;x = am +b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;就像你看到的一样，我们计算点&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;bP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的时候步进非常小，就像baby走路一样，系数b慢慢增加(&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;1P,2P,3P,…&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;)。然后，在这个算法的第二部分，我们计算&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;amP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的时候步进又很大，因为系数am的变化规律是(&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;1mP,2mP,3mP,…&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，其中m是一个大整数)。&#xA;&lt;img alt=&#34;baby-step-giant-step&#34; class=&#34;gallery-image&#34; data-flex-basis=&#34;215px&#34; data-flex-grow=&#34;89&#34; height=&#34;346&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 850px) calc(100vw - 32px), 724px&#34; src=&#34;https://chenquan.me/blog-assets/elliptic-curve-cryptography_a-gentle-introduction_4-1.gif&#34; width=&#34;310&#34;&gt;&lt;/p&gt;&#xA;&#xA;    &lt;blockquote&gt;&#xA;        &lt;p&gt;&lt;code&gt;baby-step,giant-step&lt;/code&gt;算法：通过小步进初始化一些点在hashmap中进行存储，然后我们计算大步进并比较新的点是否在hashmap中能够被找到，计算离散对数相当于是一个重新排序的事情。&lt;/p&gt;&#xA;&#xA;    &lt;/blockquote&gt;&#xA;&lt;p&gt;为了能够理解这个算法是怎么工作的，首先我们先忘记点&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;bP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是如何缓存的，而是考虑等式 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q = amP + bP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。看看如下的步骤：&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;当&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;a=0&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的时候我们看看&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是否等于&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;bP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，其中&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;0&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;之间的某个整数。那么在实际上我们就是在比较&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;0P&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;mP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;之间是否相等。&lt;/li&gt;&#xA;&lt;li&gt;当&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;a = 1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; 时，我们检查&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是否等于&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;mP + bP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。其中这里的&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;就相当于同 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;mP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;2mP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;之间的值比较。&lt;/li&gt;&#xA;&lt;li&gt;当&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;a=2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;我们需要比较&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;2mP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;3mP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;之间的点。&lt;/li&gt;&#xA;&lt;li&gt;&amp;hellip;&lt;/li&gt;&#xA;&lt;li&gt;当 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;a = m-1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;,我们其实在比较Q同&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;(n-1)mP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;m^2P = nP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;之间的点。&#xA;所以终上所述，我们其实是在检查所有的从&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;0P&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;变化到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;nP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的点。（这么多就足够了，这已经是所有的可能情况了）这需要我们计算至多&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;2m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;次加法和乘法（包括&lt;code&gt;baby-step&lt;/code&gt;中的m和&lt;code&gt;giant-step&lt;/code&gt;中的）。&#xA;当然我们知道在hash表中找一个元素需要花费&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(1)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的复杂度，所以我们可以轻易地知道，这个算法需要花费的时间和空间复杂度都是&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msqrt&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msqrt&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(\sqrt{n})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;(或者是&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msup&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mfrac&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/mfrac&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(2^{\frac{k}{2}})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;)，虽然这还是需要很多时间，但是比穷举是好多了。&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;baby-stepgiant-step实战&#34;&gt;&lt;a href=&#34;#baby-stepgiant-step%e5%ae%9e%e6%88%98&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;&lt;code&gt;Baby-step,giant-step&lt;/code&gt;实战&#xA;&lt;/h3&gt;&lt;p&gt;为了能够说明&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msqrt&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msqrt&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(\sqrt{n})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是有意义的，我们以标准曲线为例子:&lt;code&gt;prime192v1&lt;/code&gt;(也叫做&lt;code&gt;secp192r1&lt;/code&gt;,&lt;code&gt;ansiX9p192r1&lt;/code&gt;),这个曲线拥有阶数&lt;code&gt;n = 0xffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831&lt;/code&gt;。这个数的开根号大约是&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;7.922816251426434&lt;/mn&gt;&lt;mo&gt;⋅&lt;/mo&gt;&lt;msup&gt;&lt;mn&gt;10&lt;/mn&gt;&lt;mn&gt;28&lt;/mn&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;7.922816251426434 \cdot 10^{28}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。&#xA;想象一下为了在hash表中存储&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msqrt&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msqrt&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;\sqrt{n}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;个点，假设每个点需要32byte,&lt;strong&gt;我们的hash表大约需要&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;2.5&lt;/mn&gt;&lt;mo&gt;⋅&lt;/mo&gt;&lt;msup&gt;&lt;mn&gt;10&lt;/mn&gt;&lt;mn&gt;30&lt;/mn&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;2.5\cdot 10^{30}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;byte的内存&lt;/strong&gt;，&lt;a class=&#34;link&#34; href=&#34;http://www.csc.com/big_data/flxwd/83638-big_data_just_beginning_to_explode_interactive_infographic&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;网上查了一下&lt;/a&gt;，将全世界的存储能力加起来以zettabyte（&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mn&gt;10&lt;/mn&gt;&lt;mn&gt;21&lt;/mn&gt;&lt;/msup&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;10^{21} byte&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;）为单位来衡量，我们的hash表需要的存储空间这里还是大约相差10倍左右。就算我们的一个点只需要存储1 byte，还是无法存储这些点。&lt;/p&gt;&#xA;&lt;p&gt;这非常的令人惊讶，但是更加令人惊讶的是，曲线&lt;code&gt;prime192v1&lt;/code&gt;几乎是所有曲线中阶数最小的了。&lt;code&gt;secp521r1&lt;/code&gt;(另一个NIST中规定的标准曲线)阶数大约是&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;6.9&lt;/mn&gt;&lt;mo&gt;⋅&lt;/mo&gt;&lt;msup&gt;&lt;mn&gt;10&lt;/mn&gt;&lt;mn&gt;156&lt;/mn&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;6.9 \cdot 10^{156}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。&lt;/p&gt;&#xA;&lt;h3 id=&#34;亲自动手实践baby-stepgiant-step&#34;&gt;&lt;a href=&#34;#%e4%ba%b2%e8%87%aa%e5%8a%a8%e6%89%8b%e5%ae%9e%e8%b7%b5baby-stepgiant-step&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;亲自动手实践&lt;code&gt;baby-step，giant-step&lt;/code&gt;&#xA;&lt;/h3&gt;&lt;p&gt;安装惯例，我写了一个python程序利用&lt;code&gt;baby-step,giant step&lt;/code&gt;算法计算离散对数。明显这个脚本只对低阶的椭圆曲线有效，如果你想用曲线&lt;code&gt;secp521r1&lt;/code&gt;那你就等着收到一个&lt;code&gt;MemoryError&lt;/code&gt;吧。&#xA;脚本的输出结果应该如下:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Curve: y^2 = (x^3 + 1x - 1) mod 10177&#xA;Curve order: 10331&#xA;p = (0x1, 0x1)&#xA;q = (0x1a28, 0x8fb)&#xA;325 * p = q&#xA;log(p, q) = 325&#xA;Took 105 steps&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;pollards&#34;&gt;&lt;a href=&#34;#pollards&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Pollard&amp;rsquo;s &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;ρ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;\rho&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&#xA;&lt;/h3&gt;&lt;p&gt;Pollard&amp;rsquo;s &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;ρ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;\rho&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是另一个计算离散对数的算法。这个算法和&lt;code&gt;babe-step,giant-step&lt;/code&gt;算法有相同的复杂度&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msqrt&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msqrt&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(\sqrt{n})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，但是它的空间复杂度只有&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(1)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;.如果&lt;code&gt;baby-step,giant-step&lt;/code&gt;算法因为内存空间限制无法解决的问题，Pollard算法是否能解决呢？&lt;/p&gt;&#xA;&lt;p&gt;在Pollard算法中，我们将会去解决稍稍不同的问题，给定&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;P&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，找到这样的整数&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;a&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;满足&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;aP+bQ = AP + BQ&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。&#xA;一旦这四个整数都被找到了，我们可以用等式&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q = xP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;来找到这个x:&lt;/p&gt;&#xA;&lt;div class=&#34;article-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;&#xA;aP +bQ = AP + BQ \ aP+bxP = AP + BxP \ (a + bx)P = (A+Bx)P \ (a - A)P = (B - b)xP&#xA;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;限制我们可以得到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;P&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的值，但是在计算它的值之前，我们需要重新说明一下，我们的子群是循环的并且具有阶n因此，在计算的时候需要加上模n作为系数：&lt;/p&gt;&#xA;&lt;div class=&#34;article-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mo&gt;≡&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;1em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;1em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;&#xA;a -A \equiv (B-b)x (\mod n) \ x = (a-A)(B - b)^{-1} \mod n&#xA;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;Pollard’s &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;ρ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;\rho&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;算法的理论其实很简单，我们定义一个**(a,b)的伪随机序列**，这个序列产生的值可以用于产生点&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;aP + bQ&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，因为&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;P&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;都是同一个循环子群中的元素，所以&lt;strong&gt;产生的一系列点&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;aP+bQ&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;也是循环的&lt;/strong&gt;。&lt;/p&gt;&#xA;&lt;p&gt;上面的说明的意思就是只要我们遍历我们的伪随机序列&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;(a,b)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，早晚我们就会发现这是一个换，所以我们可以肯定一定存在这样的值对&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mtext&gt;，&lt;/mtext&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;(A，B)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;使得等式&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;aP+bQ = AP+BQ&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。&#xA;不同的值对代表同一个点，这点就在我们计算对数的时候起到作用。&#xA;问题是：我们如何高效地得到这样的环？&lt;/p&gt;&#xA;&lt;h3 id=&#34;tortoise-and-hare龟兔赛跑&#34;&gt;&lt;a href=&#34;#tortoise-and-hare%e9%be%9f%e5%85%94%e8%b5%9b%e8%b7%91&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Tortoise and Hare(龟兔赛跑)&#xA;&lt;/h3&gt;&lt;p&gt;为了能够找出我们的换，我们可以尝试所的a和b的可能值，通过&lt;a class=&#34;link&#34; href=&#34;http://en.wikipedia.org/wiki/Pairing_function&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;pairing funciton&lt;/a&gt;,但是这里却有&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;n^2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;个可能的值对，那么我们的算法的复杂度就会是 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(n^2)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，比暴力穷举的复杂度还搞。&#xA;但是这里还是有稍微快点的算法的：龟兔算法（tortoise and hare algorithm）也叫Floyd&amp;rsquo;s cycle-finding algorithm。下面的图片展示了这个算法是怎么工作的，这就是Pollard&amp;rsquo;s rho算法的核心部分了。&#xA;&lt;img alt=&#34;tortoise-hare&#34; class=&#34;gallery-image&#34; data-flex-basis=&#34;1544px&#34; data-flex-grow=&#34;643&#34; height=&#34;101&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 850px) calc(100vw - 32px), 724px&#34; src=&#34;https://chenquan.me/blog-assets/elliptic-curve-cryptography_a-gentle-introduction_4-2.gif&#34; width=&#34;650&#34;&gt;&lt;/p&gt;&#xA;&#xA;    &lt;blockquote&gt;&#xA;        &lt;p&gt;我们现在用曲线&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo&gt;≡&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;/msup&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mn&gt;97&lt;/mn&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;y^2 \equiv x^3 + 2x+3 (\mod 97)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;以及点&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mn&gt;6&lt;/mn&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;P = (3,6)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mn&gt;80&lt;/mn&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mn&gt;87&lt;/mn&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q = (80,87)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，这两个点都是属于这个5阶子群的。&#xA;我们用不同的速度遍历这个值对序列知道我们找到两个不同的值对(a,b)和(A,B)能够得出相同的但。在这个例子我们相同的值对是(3,3)和(2,0)，通过这两个点我们可以算出&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mn&gt;5&lt;/mn&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;x = (3-2)(0-3)^{-1} \mod 5 =3&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;,而且这确实是正确的 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt; Q = 3P &lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;    &lt;/blockquote&gt;&#xA;&lt;p&gt;基本地，我们将我们的随机数生成序列得到(a,b)值对，然后计算得到相应的点序列&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;aP+bQ&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。这个值对序列可能是也可能不是循环的，但是点序列确实循环的，因为&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;P&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;Q&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;都是由相同的基点产生的，从子群理论中我们知道仅仅在其上用加法和乘法我们是无法“逃出”子群的。&lt;/p&gt;&#xA;&lt;p&gt;现在我们用两个小动物来做比喻，乌龟和兔子，乌龟和兔子将会找到两个相同的点，但是却是由不同的系数对产生的。更加详细地，乌龟将会找到值对(a,b)而兔子将会找到值对(A,B)，最后会满足&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt; aP+bQ = AP+BQ &lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;如果你的随机数序列是由某种算法（或者就是固定存储的），那么我们就可以简单地退出这个龟兔理论所需要的空间复杂度为 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;log&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(\log n)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，然而计算时间复杂度却没有那么简单，但是我们可以通过计算概率的方式得到&lt;strong&gt;时间复杂度就和我们前面说的一样是&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msqrt&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msqrt&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(\sqrt{n})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;。&lt;/p&gt;&#xA;&lt;h3 id=&#34;与pollards-亲密接触&#34;&gt;&lt;a href=&#34;#%e4%b8%8epollards-%e4%ba%b2%e5%af%86%e6%8e%a5%e8%a7%a6&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;与Pollard&amp;rsquo;s &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;ρ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;\rho&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;亲密接触&#xA;&lt;/h3&gt;&lt;p&gt;我已经写了一个用于计算Pollard&amp;rsquo;s rho的&lt;a class=&#34;link&#34; href=&#34;https://github.com/andreacorbellini/ecc/blob/master/logs/pollardsrho.py&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;python&lt;/a&gt;脚本，虽然这个脚本没有完整地实现Pollard&amp;rsquo;s rho算法，但是就是有稍稍的改进（我用了更加高效的随机数生成算法生成值对序列）。这个脚本包含了一些非常有用的注水，如果你对这个算法感兴趣的话，去阅读这些注释吧。&#xA;这个脚本和&lt;code&gt;baby-step, giant step&lt;/code&gt;一样都只能工作在小规模的曲线上，而且和上面的输出结果是一样的。&lt;/p&gt;&#xA;&lt;h3 id=&#34;与pollards-实战&#34;&gt;&lt;a href=&#34;#%e4%b8%8epollards-%e5%ae%9e%e6%88%98&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;与Pollard&amp;rsquo;s &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;ρ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;\rho&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;实战&#xA;&lt;/h3&gt;&lt;p&gt;我们前面说到&lt;code&gt;baby-step, giant step&lt;/code&gt;算法无法应用到实际当中，因为它需要巨大的内存空间，然而Pollard&amp;rsquo;s rho却不需要那么大的内存空间，那么实际上呢？&lt;/p&gt;&#xA;&lt;p&gt;Certicom在1988年发起了一项&lt;a class=&#34;link&#34; href=&#34;https://www.certicom.com/index.php/the-certicom-ecc-challenge&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;挑战&lt;/a&gt;，计算比特位数为109到359的椭圆曲线的离散对数。到今天为止，也只有&lt;strong&gt;109bit长度的曲线&lt;/strong&gt;被成功攻破，这次尝试是在2004年发起的，在&lt;a class=&#34;link&#34; href=&#34;http://en.wikipedia.org/wiki/Discrete_logarithm_records&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;维基百科&lt;/a&gt;上的评论是：&lt;/p&gt;&#xA;&#xA;    &lt;blockquote&gt;&#xA;        &lt;p&gt;he prize was awarded on 8 April 2004 to a group of about 2600 people represented by Chris Monico. They also used a version of a parallelized Pollard rho method, taking 17 months of calendar time.&lt;/p&gt;&#xA;&#xA;    &lt;/blockquote&gt;&#xA;&lt;p&gt;我们已经说过了，&lt;code&gt;prime192v1&lt;/code&gt;是目前来说“最小”的椭圆曲线了，我们也说过Pollard&amp;rsquo;s rho 的时间复杂度是&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msqrt&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msqrt&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(\sqrt{n})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;,如果我们用Chris Monico相同的技术(相同的算法，在相同的硬件和相同的机器上)，我们需要花多久来计算一次在&lt;code&gt;prime192v1&lt;/code&gt;上的离散对数呢？&lt;/p&gt;&#xA;&lt;div class=&#34;article-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;17&lt;/mn&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mi&gt;h&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo&gt;×&lt;/mo&gt;&lt;mfrac&gt;&lt;msqrt&gt;&lt;msup&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mn&gt;192&lt;/mn&gt;&lt;/msup&gt;&lt;/msqrt&gt;&lt;msqrt&gt;&lt;msup&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mn&gt;109&lt;/mn&gt;&lt;/msup&gt;&lt;/msqrt&gt;&lt;/mfrac&gt;&lt;mo&gt;≈&lt;/mo&gt;&lt;mn&gt;5&lt;/mn&gt;&lt;mo&gt;⋅&lt;/mo&gt;&lt;msup&gt;&lt;mn&gt;10&lt;/mn&gt;&lt;mn&gt;13&lt;/mn&gt;&lt;/msup&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mi&gt;h&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;&#xA;17\ months \times \frac{\sqrt{2^{192}}}{\sqrt{2^{109}}} \approx 5\cdot 10^{13} \  months&#xA;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;这个数字足以在某种程度上说明破解离散对数问题在目前的技术能力上的难度了。&lt;/p&gt;&#xA;&lt;h3 id=&#34;对比一下pollards-rho-和baby-step-giant-step算法&#34;&gt;&lt;a href=&#34;#%e5%af%b9%e6%af%94%e4%b8%80%e4%b8%8bpollards-rho-%e5%92%8cbaby-step-giant-step%e7%ae%97%e6%b3%95&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;对比一下Pollard&amp;rsquo;s rho 和Baby-step giant step算法&#xA;&lt;/h3&gt;&lt;p&gt;我决定将&lt;a class=&#34;link&#34; href=&#34;ttps://github.com/andreacorbellini/ecc/blob/master/logs/babygiantstep.py&#34; &gt;baby-step giant-step&lt;/a&gt;和&lt;a class=&#34;link&#34; href=&#34;https://github.com/andreacorbellini/ecc/blob/master/logs/pollardsrho.py&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;Pollard&amp;rsquo;s rho&lt;/a&gt;一起同&lt;a class=&#34;link&#34; href=&#34;https://github.com/andreacorbellini/ecc/blob/master/logs/bruteforce.py&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;暴力穷举算法&lt;/a&gt;合在一起放到第[四个脚本](fourth script)中做一个比较，看看它们之间的性能。&#xA;第四个脚本会在“小型”曲线上用不同的算法计算所有的点，并报告一共耗时多少：&lt;/p&gt;&#xA;&#xA;    &lt;blockquote&gt;&#xA;        &lt;p&gt;Curve order: 10331&#xA;Using bruteforce&#xA;Computing all logarithms: 100.00% done&#xA;Took 2m 31s (5193 steps on average)&#xA;Using babygiantstep&#xA;Computing all logarithms: 100.00% done&#xA;Took 0m 6s (152 steps on average)&#xA;Using pollardsrho&#xA;Computing all logarithms: 100.00% done&#xA;Took 0m 21s (138 steps on average)&lt;/p&gt;&#xA;&#xA;    &lt;/blockquote&gt;&#xA;&lt;p&gt;正如我们所期待的，暴力穷举同其它两个算法相比就非常地慢，Baby-step giant step算法是最快的，而Pollard&amp;rsquo;s rho算法比Baby-step giant step算法慢三倍（虽然看上去它用的内存空间最小且步数最小）。&lt;/p&gt;&#xA;&lt;p&gt;当然我们在看看计算步数，暴力穷举平均花费了5193步，非常接近10331/2（曲线阶数的一半），Baby-step和Pollard’s rho花费了152步和138步两个步数都很接近10331的平方根(101.64)。&lt;/p&gt;&#xA;&lt;h3 id=&#34;最终结论&#34;&gt;&lt;a href=&#34;#%e6%9c%80%e7%bb%88%e7%bb%93%e8%ae%ba&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;最终结论&#xA;&lt;/h3&gt;&lt;p&gt;我们讨论了很多算法，同时也给出了相当的数据。但是我们一直都有一个问题，就是：算法能够在很多方面加以提升，比如硬件，特殊针对于计算离散对数的硬件也会出现。&lt;/p&gt;&#xA;&lt;p&gt;&lt;img alt=&#34;同一群阶下的工作量尺度。逐一枚举，随群阶近似线性增长。通用平方根算法，随群阶的平方根增长。&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 850px) calc(100vw - 32px), 724px&#34; src=&#34;https://chenquan.me/diagrams/elliptic-curve-cryptography_a-gentle-introduction_4-detail-1.svg&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;实际上在今天提升硬件的方法看上去是不实际的，并不是说这个方法不可行，而是我们又更加好的办法（记住，现在还没有严谨的证明离散对数的复杂性）。&lt;/p&gt;&#xA;&lt;p&gt;##Shor’s algorithm&#xA;如果现在的技术不可行，那么未来的技术呢？好吧，现在有些事变得有些令人担忧：实际上存在一种&lt;a class=&#34;link&#34; href=&#34;https://en.wikipedia.org/wiki/Quantum_algorithm&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;量子算法&lt;/a&gt;&lt;strong&gt;能够在多项式时间内解出离散对数问题&lt;/strong&gt;，这个算法的时间复杂度是O((log_n)^3)，空间复杂度是&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;l&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;g&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(log_n)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。&lt;/p&gt;&#xA;&lt;p&gt;之所以量子算法能够有这么高的效率，得益于它的状态叠加。在传统的计算机中，内存单元（例如bit）只有两种状态1或者0，没有中间状态。但是相对的，量子计算机的内存单位（被称为qubit）的状态却是无法被确定的，这同薛定谔的猫理论类似，只要在其被测量的时候才能知道其具体状态，状态叠加并不是说这个qubit可以同时为0和1,而是我们可能发现0也可能发现1。而量子算法就是基于每个qubit的可能性构建的。&lt;/p&gt;&#xA;&lt;p&gt;其实这隐含了一个qubit的特性，就是我们可以在同一时刻输入多个可能的输入值。举例来说我们可以告诉量子计算机这里有一个数x均匀地分布在0到n-1之间，这仅仅需要&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;log&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;\log n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;个quebit而不是&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;log&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;n\log n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;个bit。然后我们可以让量子计算机计算标量乘法得到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;xP&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。结果会在我们给定的0P到(n-1)P之间叠加——也就是说，我们如果现在测量我们的qubit们我们将会得到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;0P&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;(n-1)P&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;之间的某个值，而概率是1/n。&lt;/p&gt;&#xA;&lt;p&gt;上面的只是让你知道状态叠加的强大力量，，但是Shor’s算法目前还是没有办法实现的，实际上其实更加复杂。其中比较复杂的一点是，当我们能够“模拟”同时有n种状态的时候，我们需要输出的是一个答案而不是一堆答案（即，我们需要知道单一的对数，而不是一堆可能错误的对数）。&lt;/p&gt;&#xA;&lt;h2 id=&#34;ecc-和rsa&#34;&gt;&lt;a href=&#34;#ecc-%e5%92%8crsa&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;ECC 和RSA&#xA;&lt;/h2&gt;&lt;p&gt;现在让我们忘了该死的量子计算，这个问题目前还不能作为一个严重的问题，现在我们需要讨论的问题是&lt;strong&gt;在RSA还不错的情况下，为什么要用椭圆曲线呢？&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;img alt=&#34;两类公钥系统依赖的数学问题。椭圆曲线，已知公钥点，求对应的私有标量。RSA 模数，将大合数分解为其素因子。&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 850px) calc(100vw - 32px), 724px&#34; src=&#34;https://chenquan.me/diagrams/elliptic-curve-cryptography_a-gentle-introduction_4-detail-2.svg&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;一个由NIST给出的快速答案，它给出了一个&lt;a class=&#34;link&#34; href=&#34;https://www.nsa.gov/business/programs/elliptic_curve.shtml&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;同等安全等级下的密钥大小对比表&lt;/a&gt;：&lt;/p&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;RSA Key size (bits)&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;ECC key size (bits)&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1024&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;160&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2048&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;224&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3072&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;256&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;7680&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;384&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;15360&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;521&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;p&gt;需要注意的是，RSA的key大小和ECC的key大小并没有相应的线性关系（换句话说，如果我们将RSA的密钥大小加倍，并不能相应地得到双倍的ECC的密钥）。这个表告诉我们ECC不仅仅需要较小的内存，而且公钥的生成和签名更快。&#xA;但是为什么是这样的呢？这是因为在椭圆曲线上的计算离散对数的最快的方法就是 Pollard&amp;rsquo;s rho and baby-step giant-step但是在RSA体系下我们却有更加快的算法。一个较为实用的算法是： &lt;a class=&#34;link&#34; href=&#34;https://en.wikipedia.org/wiki/General_number_field_sieve&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;general number field sieve&lt;/a&gt;,一个通过因式分解计算离散对数的算法。general number field sieve是目前整数因式分解最快的算法。&lt;/p&gt;&#xA;&lt;p&gt;所有基于模运算的加密系统都有相同的问题，包括DSA, D-H 和ElGamal。&lt;/p&gt;&#xA;&lt;h2 id=&#34;nsa的隐藏威胁&#34;&gt;&lt;a href=&#34;#nsa%e7%9a%84%e9%9a%90%e8%97%8f%e5%a8%81%e8%83%81&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;NSA的隐藏威胁&#xA;&lt;/h2&gt;&lt;p&gt;现在我们需要讨论一下更加难的部分。目前我们已经讨论了算法和数学的部分，现在我们讨论一下复杂的人和事。&lt;/p&gt;&#xA;&lt;p&gt;如果你还记得的话，上一篇文章我们说到有一些椭圆曲线是很脆弱的，为了解决来着可疑来源的曲线的可信任问题，我们加入了一个随机种子到主要参数当中。而且我们可以看到那些NIST的标准曲线都是可验证的随机的。&lt;/p&gt;&#xA;&lt;p&gt;如果我们阅读维基百科&lt;a class=&#34;link&#34; href=&#34;http://en.wikipedia.org/wiki/Nothi%e7%9a%84ng_up_my_sleeve_number&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;“nothing up my sleeve”&lt;/a&gt;我们可以看到如下内容：&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;MD5的随机数是从正弦整数中产生的&lt;/li&gt;&#xA;&lt;li&gt;Blowfish的随机数是从&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;π&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;\pi&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的第一个数字产生的&lt;/li&gt;&#xA;&lt;li&gt;RC5的随机数是从&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;e&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和黄金比例中产生的&#xA;这些数字都是随机的因为这些数字都是非均匀分布的。这些都是毋庸置疑的，因为这些都是公开的。&#xA;但是现在的问题是：**NIST曲线的随机数是从哪里来的呢？**答案是我们不知道，而且这些随机种子也没有公开。&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;是否存在这样的可能:**NIST已经发现了一类“足够大的”弱椭圆曲线，并尝试了一些可能的随机种子直到生成一个脆弱的曲线？**我无法回答这个问题，但是这是一个正当的且重要的问题。我们知道NIST成功地规范化了一个&lt;a class=&#34;link&#34; href=&#34;http://en.wikipedia.org/wiki/Dual_EC_DRBG&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;&amp;quot; vulnerable random number generator “&lt;/a&gt;(一个奇怪的基于椭圆曲线的若随机数生成器)。可能他们也成功地规范化了一组弱椭圆曲线，但是是不是这样我们无从得知。&lt;/p&gt;&#xA;&lt;p&gt;理解“可信随机”和“安全”是两码事，这个和对数问题的困难程度或者我们的密钥长度无关，如果我们的算法被攻破了，我们几乎什么都做不了。&lt;/p&gt;&#xA;&lt;p&gt;考虑到这些，RSA是成功的，因为它不需要任何特殊的领域参数，而且这些领域参数也不会被篡改。RSA(和其他的模运算加密系统一样)在我们无法自己生成领域参数且无法信任授权方时，是一个很好的选择。值得一提的是，TLS用的也是椭圆曲线算法，它基于ECDHE和ECDSA算法，证书基于&lt;code&gt;prime256v1&lt;/code&gt;（也称&lt;code&gt;secp256p1&lt;/code&gt;）上。&lt;/p&gt;&#xA;&lt;h2 id=&#34;thats-all&#34;&gt;&lt;a href=&#34;#thats-all&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;That&amp;rsquo;s all&#xA;&lt;/h2&gt;&lt;p&gt;我希望你能够喜欢这个系列的文章。我的目标是让你能够对椭圆曲线加密系统有一个基本的了解，知道其术语代表的都是什么意思。如果我达成了我的目标，那么目前依旧能够理解现在的基于ECC的加密系统是怎么工作的，同时你也能够通过阅读一些“不怎么优雅”的文献来加深对这些知识的理解。当我在完成这个系列的文章的时候我跳过了很多细节，用了最简单的术语和知识为了是你能够快速理解。但是我比较担心的是你无法理解网络上的一些较为复杂的术语，我认为这系列的文章能够在简单性和完整性上做到了较好的均衡。&lt;/p&gt;&#xA;&lt;p&gt;一定要注意仅仅阅读了这系列的文章并不能让你实现一个安全的ECC加密系统：这需要了解很多安全方面的重要细节。还记得&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/30/elliptic-curve-cryptography-ecdh-and-ecdsa/#random-curves&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;requirements for Smart’s attack&lt;/a&gt;和&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/30/elliptic-curve-cryptography-ecdh-and-ecdsa/#ecdsa-k&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;Sony’s mistake&lt;/a&gt;——这些例子都告诉我们产生一个不安全的算法是多么简单，以及攻破这些算法是多么容易。&lt;/p&gt;&#xA;&lt;p&gt;所以，如果你对ECC有着更深层次的兴趣，应该去看些什么呢？&lt;/p&gt;&#xA;&lt;p&gt;首先，我们已经看到了素数域上的Weierstrass curves，但是你必须要知道其他的域和曲线，典型的有：&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Koblitz curves over binary fields. 这些曲线定义在&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;/msup&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;msup&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;y^2 + xy = x^3 ax^2 +1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;()其中a 是0或1),它的有限域包括了&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;2^m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;个元素（其中&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是一个素数），这个曲线能够明显地提高加法和乘法的效率，标准的Koblitz曲线有&lt;code&gt;nistk163&lt;/code&gt;, &lt;code&gt;nistk283&lt;/code&gt; 和&lt;code&gt;nistk571&lt;/code&gt; (三个曲线分别定义在 163, 283 和 571 位的域上)。&lt;/li&gt;&#xA;&lt;li&gt;Binary curves. 这个曲线和 Koblitz curves 很相似，形如 and are in the form &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;63&lt;/mn&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;x^2+xy=x63+x^2+b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; (其中&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; 是一个从随机数). 正如其名，binary curves 被限制到二进制域中。主要的标准曲线有 &lt;code&gt;nistb163&lt;/code&gt;,&lt;code&gt;nistb283&lt;/code&gt; 和 &lt;code&gt;nistb571&lt;/code&gt;。目前有观点认为 Koblitz 和 Binary curves不像 prime curves那么安全。&lt;/li&gt;&#xA;&lt;li&gt;Edwards curves, 形如&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;msup&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;x^2+y^2=1+dx^2y^2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; (其中 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;d&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; 可以是 0 或 1). 它的特点除了其加法和标量乘法的速度都很快之外，还有它点加的公式都是相同的，在某些情况下可以描述为 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo mathvariant=&#34;normal&#34;&gt;≠&lt;/mo&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;Q&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;.&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;.&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;.&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;(P≠Q,P=Q, P=−Q, ...)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。这个特点能够抵御side-channel攻击，这个攻击通过零标量乘法的时间来猜测标量因子。( This feature leverages the possibility of side-channel attacks, where you measure the time used for scalar multiplication and try to guess the scalar coefficient based on the time it took to compute.) Edwards curves 相对来说比较新 ( 2007被发表) 目前还没有权威机构类似于Certicom 或者 NIST对其进行标准化。&lt;/li&gt;&#xA;&lt;li&gt;Curve25519 and Ed25519 are two particular elliptic curves 是分别为ECDH和ECDSA专门设计的曲线，就像Edwards curves, 这两个曲线非常地快速，并能够抵御side-channel 攻击。 并且正如 Edwards curves,这两个曲线还没有被正式标准化，我们还不能够在典型的引用中找到他们的身影（除了OpenSSL，它在2014年支持了Ed25519曲线）。&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;如果你对ECC的实现细节比较感兴趣，我建议你去阅读以下OpenSSL和GnuTLs的源代码。&lt;/p&gt;&#xA;&lt;p&gt;最后如果你对ECC背后的数学细节感兴趣，而不是安全高效的算法，你需要知道如下知识：&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Elliptic curves are algebraic varieties with genus one.&lt;/li&gt;&#xA;&lt;li&gt;Points at infinity are studied in &lt;em&gt;projective geometry&lt;/em&gt; and can be represented using &lt;em&gt;homogeneous coordinates&lt;/em&gt; (although most of the features of projective geometry are not needed for elliptic curve cryptography).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;以及不要忘记学习&lt;strong&gt;finite fields&lt;/strong&gt; 和 &lt;strong&gt;field theory&lt;/strong&gt;。&lt;/p&gt;&#xA;&lt;p&gt;这些就是你需要查询或者你会感兴趣的全部主题了。&lt;/p&gt;&#xA;&lt;p&gt;现在，这个系列已经官方完结了。&lt;/p&gt;&#xA;</description>
        </item>
    <item>
            <title>Elliptic Curve Cryptography: a gentle introduction (3)</title>
            <link>https://chenquan.me/posts/elliptic-curve-cryptography_a-gentle-introduction_3/</link>
            <pubDate>Thu, 15 Jun 2017 00:00:00 +0000</pubDate>
            <guid>https://chenquan.me/posts/elliptic-curve-cryptography_a-gentle-introduction_3/</guid>
            <description>&lt;p&gt;这篇文章是系列文章ECC：优雅入门中的第三篇文章。&lt;/p&gt;&#xA;&lt;p&gt;在之前的文章中我们知道了&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/17/elliptic-curve-cryptography-a-gentle-introduction/#elliptic-curves&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;什么是椭圆曲线&lt;/a&gt;以及我们定义了一些&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/17/elliptic-curve-cryptography-a-gentle-introduction/#group-law&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;群律&lt;/a&gt;为了能够在椭圆曲线上做一些数学运算。然后我们将椭圆曲线重新在一个素数的有限模整数域中进行描述。在这次重新描述过程中，我们知道了椭圆曲线是如何生成一个循环子群的，以及我们介绍了一些基本的概念：&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/23/elliptic-curve-cryptography-finite-fields-and-discrete-logarithms/#base-point&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;基点(base point)&lt;/a&gt;，&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/23/elliptic-curve-cryptography-finite-fields-and-discrete-logarithms/#subgroup-order&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;阶(order)&lt;/a&gt;和&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/23/elliptic-curve-cryptography-finite-fields-and-discrete-logarithms/#cofactor&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;辅因子(cofactor)&lt;/a&gt;。&lt;/p&gt;&#xA;&lt;p&gt;最后，我们了解了&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/23/elliptic-curve-cryptography-finite-fields-and-discrete-logarithms/#scalar-multiplication&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;在有限域上的标量乘法&lt;/a&gt;是一个“简单”的问题，但是反过来的离散对数问题却是一个“困难”的问题。现在我们一起看看这些东西是如何应用到加密算法中的。&lt;/p&gt;&#xA;&lt;h2 id=&#34;主要参数domain-parameters&#34;&gt;&lt;a href=&#34;#%e4%b8%bb%e8%a6%81%e5%8f%82%e6%95%b0domain-parameters&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;主要参数(Domain parameters)&#xA;&lt;/h2&gt;&lt;p&gt;我们的椭圆曲线算法将会在一个定义在有限域上的的椭圆曲线的子群中运行。因此我们需要如下的几个参数：&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;素数&lt;/strong&gt;P 描述了有限域的大小。&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;系数&lt;/strong&gt;a和b 用于描述椭圆曲线的方程。&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;基点&lt;/strong&gt;G用于生成我们的子群&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;阶&lt;/strong&gt;n ，子群的阶&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;辅因子&lt;/strong&gt;h ，子群的辅因子&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;一言以蔽之，我们算法中所需要的主要参数是一个6元组(p,a,b,G,n,h)。&lt;/p&gt;&#xA;&lt;h2 id=&#34;随机曲线&#34;&gt;&lt;a href=&#34;#%e9%9a%8f%e6%9c%ba%e6%9b%b2%e7%ba%bf&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;随机曲线&#xA;&lt;/h2&gt;&lt;p&gt;当我们说离散对数问题是一个“困难的问题”时，其实并不完全正确。&lt;strong&gt;这里有一些椭圆曲线是非常脆弱的&lt;/strong&gt;，这些椭圆曲线能够被一些具有特殊目的的算法快速解决。例如，所有的曲线满足 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;h&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;p = hn&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; (这种曲线的有限域的阶和椭圆曲线的阶相同)能够被&lt;a class=&#34;link&#34; href=&#34;http://interact.sagemath.org/edu/2010/414/projects/novotney.pdf&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;Smart&amp;rsquo;s attack&lt;/a&gt;轻而易举地攻破,这个攻击方式能够在多项式时间内将离散对数问题解决。&lt;/p&gt;&#xA;&lt;p&gt;现在，假设我给你一些曲线的主要参数。这里就会存在一个问题，就是可能我已经发现了一些脆弱的能够被轻而易举地攻破的曲线，但是没有其它人知道，而且我能够建立一个“”快速”的算法，很快地得到我刚刚给你的离散对数的答案。那么我该如何说服你相信我，或者说我并不知道任何的弱点呢？也就是说我该如何证明，这个&lt;strong&gt;曲线&lt;/strong&gt;是安全的（在某种意义上说，这不能被我以特殊的目的攻击）？&lt;/p&gt;&#xA;&lt;p&gt;为了能够解决这类问题，我们常常会增加一个主要参数：&lt;strong&gt;种子S（seed S）&lt;/strong&gt;。这是一个随机数用来生成系数a和b，或者是基点&lt;strong&gt;G&lt;/strong&gt;，或者两者。这些参数通过对S计算hash生成。Hash，众所周知，非常容易计算，但是逆运算是非常&amp;quot;困难&amp;quot;的。&#xA;&lt;img alt=&#34;random-parameters-generation&#34; class=&#34;gallery-image&#34; data-flex-basis=&#34;1621px&#34; data-flex-grow=&#34;675&#34; height=&#34;74&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 850px) calc(100vw - 32px), 724px&#34; src=&#34;https://chenquan.me/blog-assets/elliptic-curve-cryptography_a-gentle-introduction_3-1.png&#34; width=&#34;500&#34;&gt;&lt;/p&gt;&#xA;&#xA;    &lt;blockquote&gt;&#xA;        &lt;p&gt;通过种子生成一个随机曲线的示意图：一个随机数的hash是用来计算曲线的不同参数的。&#xA;&lt;img alt=&#34;seed-inversion&#34; class=&#34;gallery-image&#34; data-flex-basis=&#34;1133px&#34; data-flex-grow=&#34;472&#34; height=&#34;76&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 850px) calc(100vw - 32px), 724px&#34; src=&#34;https://chenquan.me/blog-assets/elliptic-curve-cryptography_a-gentle-introduction_3-2.png&#34; width=&#34;359&#34;&gt;&#xA;如果我们想要作弊，通过主要参数中得到随机种子，我们需要解决一个&amp;quot;hard&amp;quot;问题：hash逆推&#xA;一个通过种子生成的曲线被称为&lt;strong&gt;通过随机验证&lt;/strong&gt;。这个利用hash生成参数的理论被称为&amp;quot;&lt;a class=&#34;link&#34; href=&#34;http://en.wikipedia.org/wiki/Nothing_up_my_sleeve_number&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;nothing up mu sleeve&lt;/a&gt;&amp;quot;,这个理论被广泛应用在密码学中。&lt;/p&gt;&#xA;&#xA;    &lt;/blockquote&gt;&#xA;&lt;p&gt;这个技巧能够提供一些保障，保证这个&lt;strong&gt;曲线不是被作者精心设计的隐藏的脆弱的&lt;/strong&gt;。实际上，如果我给你一个曲线和以和种子，它就意味着我不能够任意地选择参数a和b,而你也相对的可以肯定这个曲线不能够被我利用特定的目的攻击。而这个“相对的”的原因我将在下一篇文章中进行解释。&lt;/p&gt;&#xA;&lt;p&gt;一个用于生成和检查随机曲线的标准算法已经在ANSI X.9.62中进行描述，这个算法是基于&lt;a class=&#34;link&#34; href=&#34;https://en.wikipedia.org/wiki/SHA-1&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;SHA-1&lt;/a&gt;。如果你对这个感兴趣，你可以阅读&lt;a class=&#34;link&#34; href=&#34;http://www.secg.org/sec1-v2.pdf&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;a specification by SECG&lt;/a&gt;了解生成可信的随机曲线算法（搜索 “Verifiably Random Curves and Base Point Generators”）。&lt;/p&gt;&#xA;&lt;p&gt;我写了一个简单的&lt;a class=&#34;link&#34; href=&#34;https://github.com/andreacorbellini/ecc/blob/master/scripts/verifyrandom.py&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;python脚本&lt;/a&gt;用于验证所有的随机曲线，这个脚本是基于&lt;a class=&#34;link&#34; href=&#34;https://github.com/openssl/openssl/blob/81fc390/crypto/ec/ec_curve.c&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;OpenSSL&lt;/a&gt;的。我非常建议你去看看。&lt;/p&gt;&#xA;&lt;h2 id=&#34;椭圆曲线加密elliptic-curve-cryptography&#34;&gt;&lt;a href=&#34;#%e6%a4%ad%e5%9c%86%e6%9b%b2%e7%ba%bf%e5%8a%a0%e5%af%86elliptic-curve-cryptography&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;椭圆曲线加密(Elliptic Curve Cryptography)&#xA;&lt;/h2&gt;&lt;p&gt;我们在前面花了很多时间，但是最后我们还是到这一节了！废话不多说，简单粗暴：&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;私钥&lt;/strong&gt;是一个随机的整数，从&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;.&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;.&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;.&lt;/mi&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;{1,...,n-1}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;中选择(其中n 是子群的阶)。&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;公钥&lt;/strong&gt;是一个点H满足条件H = dG(其中G是这个子群的基点)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;看到了嘛？如果我们知道d和G（以及其他的主要参数），找到最终的H是很&amp;quot;简单&amp;quot;的。但是如果我们知道H和G，&lt;strong&gt;找到私钥d是困难的，因为这需要我们解决一个离散对数问题&lt;/strong&gt;。&lt;/p&gt;&#xA;&lt;p&gt;现在我们将介绍两个基于上述条件的公钥加密算法：ECDH(Elliptic curve Diffie-Hellman)用于加密，另一个是ECDSA(Elliptic Curve Digital Signature Algorithm)用于数字签名。&lt;/p&gt;&#xA;&lt;h2 id=&#34;利用ecdh加密&#34;&gt;&lt;a href=&#34;#%e5%88%a9%e7%94%a8ecdh%e5%8a%a0%e5%af%86&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;利用ECDH加密&#xA;&lt;/h2&gt;&lt;p&gt;ECDH 是&lt;a class=&#34;link&#34; href=&#34;https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;Diffie-Hellman算法&lt;/a&gt;。这实际上是一个&lt;a class=&#34;link&#34; href=&#34;https://en.wikipedia.org/wiki/Key-agreement_protocol&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;密钥交换协议&lt;/a&gt;,而不仅仅是一个加密算法。简而言之，ECDH定义了密钥应该如何生成，以及在双方之间如何交换。至于如何用这个密钥加密数据由我们自己决定。&lt;/p&gt;&#xA;&lt;p&gt;那么我们简单地描述一下这个如何解决这个问题的过程（通常我们用&lt;a class=&#34;link&#34; href=&#34;http://en.wikipedia.org/wiki/Alice_and_Bob&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;Alice and Bob&lt;/a&gt;描述）。当Alice和Bob之间需要安全地交换信息，但是&lt;a class=&#34;link&#34; href=&#34;http://en.wikipedia.org/wiki/Man-in-the-middle_attack&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;第三者(中间人)&lt;/a&gt;威胁到他们，他可能截获消息，但是无法解密这些信息。这是TLS底层的一个基本理论，这里仅仅给你一个例子：&lt;/p&gt;&#xA;&lt;p&gt;这里是整个密钥交换的过程：&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;首先,&lt;strong&gt;Alice和Bob生成他们各自的公钥和私钥&lt;/strong&gt;，我们假设私钥&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;d_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和公钥&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_A = d_AG&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是Alice的，以及私钥&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;d_B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和公钥&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_B = d_BG&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是Bob的。需要说明的是，Alice和Bob都使用相同的主要参数，在相同的有限域上的相同椭圆曲线的相同基点G。&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Alice 和Bob再不安全的网络上交换各自的公钥H_A 和H_B&lt;/strong&gt;，中间人将会截获&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，但是无法得到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;d_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;d_B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，除非它能够解决离散对数问题。&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Alice 计算&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;⋅&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;S=d_A\cdot H_B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;(用她自己的私钥和Bob的公钥)，然后Bob计算&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;⋅&lt;/mo&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;S = d_B\cdot HA&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;(用他自己的私钥和Alice的公钥)&lt;/strong&gt;，这里需要说明的是Alice和Bob来说都是算出来的&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;S&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;都是相同的，因为：&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;article-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;&#xA;S = d_AH_B = d_A(d_BG) = d_B(d_AG) = d_BH_A&#xA;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;中间人虽然知道&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;（当然也可能知道所有的主要参数），但是仍然无法得到共享密钥&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;S&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，这被称为 Diffie-Hellman问题，它可以被如下问题描述：&lt;/p&gt;&#xA;&#xA;    &lt;blockquote&gt;&#xA;        &lt;p&gt;给定三个点 P , aP 和bP, abP的答案是什么？&#xA;或者等价的：&#xA;给定三个整数&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;,&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k^x&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;,&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k^y&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k^{xy}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的答案是什么？&#xA;（后面的这个问题是在原始的Diffie-Hellman算法中被采用，基于模运算）&#xA;&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/images/ecdh.png&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;ecdh&lt;/a&gt;&#xA;Diffie-Hellman密钥交换，Alice和Bob能够“轻易”地计算出共享密钥，但是中间人需要解决一个“困难”的问题。&#xA;在Diffie-Hellman问题背后的理论在可汗学院有一个超棒的介绍，但这个仅仅是在模运算的体系上的介绍，(而不是在椭圆曲线上的介绍)。&lt;/p&gt;&#xA;&#xA;    &lt;/blockquote&gt;&#xA;&lt;p&gt;椭圆曲线上的Diffie-Hellman问题被认为是一个&amp;quot;hard&amp;quot;的问题，他被认为其难度和离散对数相同，尽管没有有效的证明。我们知道的是这个问题没有办法&amp;quot;harder&amp;quot;了，因为解决这个问题相当于解决Diffie-Hellman问题。&lt;/p&gt;&#xA;&lt;p&gt;现在，Alice和Bob已经得到对称密钥的，他们可以通过对称加密交换密钥了。&lt;/p&gt;&#xA;&lt;p&gt;举例来说，他们可以用S的x坐标值作为AES或者3DES对称加密的密钥。这就和TLS的做法差不多，区别是TLS将x坐标加上了一些连接的标识码并做了一次hash。&lt;/p&gt;&#xA;&lt;h3 id=&#34;接触一下ecdh&#34;&gt;&lt;a href=&#34;#%e6%8e%a5%e8%a7%a6%e4%b8%80%e4%b8%8becdh&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;接触一下ECDH&#xA;&lt;/h3&gt;&lt;p&gt;我写了另一个&lt;a class=&#34;link&#34; href=&#34;https://github.com/andreacorbellini/ecc/blob/master/scripts/ecdhe.py&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;简单的pyhton脚本&lt;/a&gt;用来计算椭圆曲线上的公/私钥对和共享密钥。&lt;/p&gt;&#xA;&lt;p&gt;不同于我们之前提到的任何例子，这和脚本用了一个标准的曲线，而不是我们前面用的在很小的域中的简单曲线。这个曲线是 &lt;em&gt;secp256k1&lt;/em&gt;，来自&lt;a class=&#34;link&#34; href=&#34;http://www.secg.org/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;SECG&lt;/a&gt;(the “Standards for Efficient Cryptography Group”, founded by &lt;a class=&#34;link&#34; href=&#34;https://www.certicom.com/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;Certicom&lt;/a&gt;)，这和&lt;a class=&#34;link&#34; href=&#34;https://en.bitcoin.it/wiki/Secp256k1&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;比特币数字签名用的曲线&lt;/a&gt;是同一个，这里是这个曲线的一些主要参数：&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;p = 0xffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;a = 0&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;7&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;b = 7&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;79&lt;/mn&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mn&gt;667&lt;/mn&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mn&gt;9&lt;/mn&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mn&gt;55&lt;/mn&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mn&gt;06295&lt;/mn&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mn&gt;870&lt;/mn&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mn&gt;07029&lt;/mn&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mn&gt;28&lt;/mn&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mn&gt;959&lt;/mn&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mn&gt;2815&lt;/mn&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mn&gt;16&lt;/mn&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mn&gt;81798&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;x_G = 0x79be667e f9dcbbac 55a06295 ce870b07 029bfcdb 2dce28d9 59f2815b 16f81798&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;483&lt;/mn&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mn&gt;7726&lt;/mn&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mn&gt;4655&lt;/mn&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mn&gt;1108&lt;/mn&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mn&gt;8&lt;/mn&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mn&gt;17&lt;/mn&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mn&gt;448&lt;/mn&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mn&gt;68554199&lt;/mn&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mn&gt;47&lt;/mn&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mn&gt;08&lt;/mn&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mn&gt;10&lt;/mn&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mn&gt;8&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;y_G = 0x483ada77 26a3c465 5da4fbfc 0e1108a8 fd17b448 a6855419 9c47d08f fb10d4b8&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mn&gt;6&lt;/mn&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mn&gt;48&lt;/mn&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mn&gt;03&lt;/mn&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mn&gt;25&lt;/mn&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mn&gt;8&lt;/mn&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mn&gt;0364141&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;n = 0xffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;h&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;h = 1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&#xA;(这些值是我从OpenSSL 的源代码中找到的)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;当然，你可以随意地修改脚本，改成你需要的曲线和相应的参数，但需要记住曲线需要满足素数域，和非尖锐(Weierstrass normal form)的形式，否则这个脚本将不会工作。&lt;/p&gt;&#xA;&lt;p&gt;这个脚本虽然简单，但是却包含了所有我们前面提到的算法：点加(point addition ), double and add,ECDH，我推荐你阅读并且运行它，运行结果将如下形式：&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Curve: secp256k1&#xA;Alice&amp;#39;s private key: 0xe32868331fa8ef0138de0de85478346aec5e3912b6029ae71691c384237a3eeb&#xA;Alice&amp;#39;s public key: (0x86b1aa5120f079594348c67647679e7ac4c365b2c01330db782b0ba611c1d677, 0x5f4376a23eed633657a90f385ba21068ed7e29859a7fab09e953cc5b3e89beba)&#xA;Bob&amp;#39;s private key: 0xcef147652aa90162e1fff9cf07f2605ea05529ca215a04350a98ecc24aa34342&#xA;Bob&amp;#39;s public key: (0x4034127647bb7fdab7f1526c7d10be8b28174e2bba35b06ffd8a26fc2c20134a, 0x9e773199edc1ea792b150270ea3317689286c9fe239dd5b9c5cfd9e81b4b632)&#xA;Shared secret: (0x3e2ffbc3aa8a2836c1689e55cd169ba638b58a3a18803fcf7de153525b28c3cd, 0x43ca148c92af58ebdb525542488a4fe6397809200fe8c61b41a105449507083)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;短暂ecdh-ephemeral-ecdh&#34;&gt;&lt;a href=&#34;#%e7%9f%ad%e6%9a%82ecdh-ephemeral-ecdh&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;短暂ECDH (Ephemeral ECDH)&#xA;&lt;/h3&gt;&lt;p&gt;你可能在有些地方看到ECDHE而不是ECDH，这里在ECDHE中的&amp;quot;E&amp;quot;代表&amp;quot;Ephemeral&amp;quot;，表示这次&lt;strong&gt;密钥交换是临时的&lt;/strong&gt;而不是永久的。&lt;/p&gt;&#xA;&lt;p&gt;ECDHE在实际中的应用也很广泛。在TLS中，客户端和服务器在连接建立的时候快速生成公私钥对。这些密钥都是经过TLS证书签名（为了授权）的，然后在双方交换。&lt;/p&gt;&#xA;&lt;p&gt;##用ECDSA签名(Signing with ECDSA)&#xA;我们现在又有一个新的剧本：&lt;strong&gt;Alice 需要用她的私钥(&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;d_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;)签名一个消息，然后Bob需要用Alice的公钥(&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;)验证这个消息是否真实&lt;/strong&gt;。除了Alice没有人能够创建一个合法的签名，但是所有的人都能够验证这个消息的真实性。&lt;/p&gt;&#xA;&lt;p&gt;再一次地，Alice和Bob利用相同的主要参数，现在我们来研究新的算法——ECDSA,利用椭圆曲线实现的一种&lt;a class=&#34;link&#34; href=&#34;https://en.wikipedia.org/wiki/Digital_Signature_Algorithm&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;数字签名算法&lt;/a&gt;的变体。&lt;/p&gt;&#xA;&lt;p&gt;ECDSA利用消息的hash工作，而不是消息本身。hash算法的选择取决于我们自身，但是明显地，我们需要选择一个&lt;a class=&#34;link&#34; href=&#34;http://en.wikipedia.org/wiki/Cryptographic_hash_function&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;密码学安全的hash算法&lt;/a&gt;。&lt;strong&gt;消息的hash应该缩短到其bit位数和n(子群的阶)的bit位数相同,被缩短之后的hash应该是一个整数，我们用&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;z&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;来表示&lt;/strong&gt;。&lt;/p&gt;&#xA;&lt;p&gt;对Alice来说这个算法主要有以下几步：&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;选择一个&lt;strong&gt;随机整数k&lt;/strong&gt;，这个整数&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;从&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;{1,…,n - 1 }&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;中选择(其中 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是子群的阶)&lt;/li&gt;&#xA;&lt;li&gt;计算点&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;P = kG&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;(其中&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;G&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是子群的基点)&lt;/li&gt;&#xA;&lt;li&gt;计算数&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/msub&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;r = x_p \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; 其中&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;x_p&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是点P的横坐标。&lt;/li&gt;&#xA;&lt;li&gt;如果&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;r=0&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，从新选择一个k然后再试验一次。&lt;/li&gt;&#xA;&lt;li&gt;计算 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;s = k^{-1}(z + rd_A) mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; 其中&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;d_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是Alice的私钥同时&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;/msup&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k^-1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;是k模nd的相反幂(where &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;d_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; is Alice’s private key and &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k^{−1}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; is the multiplicative inverse of &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; modulo &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;)&lt;/li&gt;&#xA;&lt;li&gt;如果&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;s = 0&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;,选择一个新的k然后再试一次。&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;这里的**(r,s)**对就是签名了。&lt;/p&gt;&#xA;&lt;p&gt;&lt;img alt=&#34;ecdsa&#34; class=&#34;gallery-image&#34; data-flex-basis=&#34;483px&#34; data-flex-grow=&#34;201&#34; height=&#34;255&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 850px) calc(100vw - 32px), 724px&#34; src=&#34;https://chenquan.me/blog-assets/elliptic-curve-cryptography_a-gentle-introduction_3-3.png&#34; width=&#34;514&#34;&gt;&lt;/p&gt;&#xA;&#xA;    &lt;blockquote&gt;&#xA;        &lt;p&gt;Alice 用自己的私钥&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;d_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和一个随机数&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;对hash进行签名。Bob利用Alice的公钥&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;验证消息的合法性。&#xA;需要强调的是，可以通过(r,s)对得到公钥。&lt;/p&gt;&#xA;&#xA;    &lt;/blockquote&gt;&#xA;&lt;p&gt;用简洁明了的话总结，这个算法首先生成了一个密钥(k)。这个密钥隐藏到r当中了，这点是利用点乘得到的（我们知道点乘是&amp;quot;easy&amp;quot;的，但是反过来却是&amp;quot;困难&amp;quot;的）。r 通过公式&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;s = k^{-1}(z + rd_A) \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;同消息的摘要绑定到一起了。&lt;/p&gt;&#xA;&lt;p&gt;再说明一下，为了计算s,我们需要计算 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的相反幂，我们在&lt;a class=&#34;link&#34; href=&#34;http://andrea.corbellini.name/2015/05/23/elliptic-curve-cryptography-finite-fields-and-discrete-logarithms/#p-must-be-prime&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;前面的文章中&lt;/a&gt;有做解释,只有当n是素数的时候才能够奏效。&lt;strong&gt;如果子群拥有一个非素数阶,ECDSA算法将不可用&lt;/strong&gt;。几乎所有的标准曲线拥有素数阶并不是偶然，而是因为非素数阶的曲线不能够适用于ECSDA算法。&lt;/p&gt;&#xA;&lt;h3 id=&#34;验证签名verifying-signatures&#34;&gt;&lt;a href=&#34;#%e9%aa%8c%e8%af%81%e7%ad%be%e5%90%8dverifying-signatures&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;验证签名(Verifying signatures)&#xA;&lt;/h3&gt;&lt;p&gt;为了验证签名，我们需要Alice的公钥&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;,hash(被缩短)&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;z&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和签名(r,s)。&lt;/p&gt;&#xA;&lt;p&gt;&lt;img alt=&#34;签名与验签各自持有什么。签名方，消息、私钥和每次签名的随机数。验签方，消息、公钥和签名。&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 850px) calc(100vw - 32px), 724px&#34; src=&#34;https://chenquan.me/diagrams/elliptic-curve-cryptography_a-gentle-introduction_3-detail-1.svg&#34;&gt;&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;计算第一个整数&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;u_1 = s^{-1}z \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;计算第二个整数&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;u_2 = s^{-1}r \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;计算点 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;⋅&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;P= u_1G + u_2\cdot H_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;如果式子&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/msub&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;r = x_P \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;成立，则验签通过&lt;/p&gt;&#xA;&lt;h2 id=&#34;算法的正确性&#34;&gt;&lt;a href=&#34;#%e7%ae%97%e6%b3%95%e7%9a%84%e6%ad%a3%e7%a1%ae%e6%80%a7&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;算法的正确性&#xA;&lt;/h2&gt;&lt;p&gt;第一眼我们没有办法看出这个算法的正确性，所以我们把所有的等式重新分析一下，将会豁然开朗。&lt;/p&gt;&#xA;&lt;p&gt;让我们从&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;P = u_1G + u_2H_A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;开始，从公钥的定义可知，&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mtext&gt;其中&lt;/mtext&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;H_A = d_AG(其中 &lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;d_A&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;是私钥&lt;/mtext&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;是 私钥)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;。我们可以得到：&lt;/p&gt;&#xA;&lt;div class=&#34;article-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;&#xA;P = u_1G + u_2G \ = u_1G  + u2d_AG \ = (u_1 + u_2d_A)G&#xA;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;利用&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;u_1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;u_2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;的定义，我们可以得到：&lt;/p&gt;&#xA;&lt;div class=&#34;article-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;u&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;&#xA;P = (u_1 + u_2d_A)G \ = (s^{-1}z + s^{-1}rd_A)G \ = s^{-1}(z +rd_A)G&#xA;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;这里为了简洁起见我们忽略了 “mod n”,因为G生成的循环子群都拥有阶n，因此“mod n”是多余的。&lt;/p&gt;&#xA;&lt;p&gt;之前我们定义&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;s = k^{-1}(z + rd_A) \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;.两边都乘以一个&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;并除以一个&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;s&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;,我们可以得到一个新的等式 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k = s^{-1}(z+rd_A) \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;.将这个结果替换到我们先前得到P的等式中，我们得到：&lt;/p&gt;&#xA;&lt;div class=&#34;article-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;&#xA;P = s^{-1}(z + rd_A)G \ =kG&#xA;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;** 这个结果同我们在步骤2中生成签名的算法一样！&lt;strong&gt;当生成签名并且验证它们之时，我们都需要计算相同的点&lt;/strong&gt;P**,并且用的是不同的公式集。这就是为什么这个算法能够work的原因。&lt;/p&gt;&#xA;&lt;p&gt;###接触一下ECDSA&#xA;当然，我也写了一个简单的[python脚本]来演示签名的生成和验证。这个脚本有一些代码同ECDH的脚本相同，具体来说就是有关主要参数和公私钥对生成的部分。&lt;/p&gt;&#xA;&lt;p&gt;这里是这个脚本输出的内容：&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Curve: secp256k1&#xA;Private key: 0x9f4c9eb899bd86e0e83ecca659602a15b2edb648e2ae4ee4a256b17bb29a1a1e&#xA;Public key: (0xabd9791437093d377ca25ea974ddc099eafa3d97c7250d2ea32af6a1556f92a, 0x3fe60f6150b6d87ae8d64b78199b13f26977407c801f233288c97ddc4acca326)&#xA;&#xA;Message: b&amp;#39;Hello!&amp;#39;&#xA;Signature: (0xddcb8b5abfe46902f2ac54ab9cd5cf205e359c03fdf66ead1130826f79d45478, 0x551a5b2cd8465db43254df998ba577cb28e1ee73c5530430395e4fba96610151)&#xA;Verification: signature matches&#xA;&#xA;Message: b&amp;#39;Hi there!&amp;#39;&#xA;Verification: invalid signature&#xA;&#xA;Message: b&amp;#39;Hello!&amp;#39;&#xA;Public key: (0xc40572bb38dec72b82b3efb1efc8552588b8774149a32e546fb703021cf3b78a, 0x8c6e5c5a9c1ea4cad778072fe955ed1c6a2a92f516f02cab57e0ba7d0765f8bb)&#xA;Verification: invalid signature&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;正如你看到的，这个脚本首先将消息进行签名（“Hello!“的byte串），然后验证了这个签名，然后它尝试用同一个签名和不同的消息(“Hi there”)进行验证，然后失败了。最后它用相同的消息但是采用了另一个随机的公钥进行验签，再一次失败了。&lt;/p&gt;&#xA;&lt;h2 id=&#34;k的重要性&#34;&gt;&lt;a href=&#34;#k%e7%9a%84%e9%87%8d%e8%a6%81%e6%80%a7&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;k的重要性&#xA;&lt;/h2&gt;&lt;p&gt;当生成ECDSA的签名的时候，保持密钥k的保密性是非常重要的，如果我们在所有的签名中使用相同的k，过着我们的随机数生成器是可以预测的，那么&lt;strong&gt;攻击者就能够到私钥！&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a class=&#34;link&#34; href=&#34;http://www.bbc.com/news/technology-12116051&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;这是sony前几年犯的一个错误&lt;/a&gt;，简单地说，那时候的PS3本来只能运行Sony用ECDSA算法签名的游戏，本来就算我写了一个PS3上的游戏我们没有办法将其发布，除非我得到了Sony的签名，但是这个过程的问题是，这个签名Sony是用相同的k生成的。&#xA;(Apparently, Sony’s random number generator was inspired by either &lt;a class=&#34;link&#34; href=&#34;http://xkcd.com/221/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;XKCD&lt;/a&gt; or &lt;a class=&#34;link&#34; href=&#34;http://dilbert.com/strip/2001-10-25&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;Dilbert&lt;/a&gt;.)&lt;/p&gt;&#xA;&lt;p&gt;在这种情况下，我们能够轻易地通过两个签名过的游戏恢复得到Sony的私钥，我们提取出这两个游戏的hash（&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;z_1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;z_2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;）以及他们的签名&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;(r_1,s_1)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&#34;true&#34;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;(r_2,s_2)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;，以及他们的主要参数：&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;首先，我们可以得到 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;r_1 = r_2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;（因为 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/msub&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;r = x_P \mod n &lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;和&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mi&gt;G&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;P = kG&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; 对于两个签名而言是相同的）。&lt;/li&gt;&#xA;&lt;li&gt;得到 &lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;s_1 - s_2 \mod n = k^{-1} (z_1 - z_2) \ mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; （这个结论是从s的公式中推出的）&lt;/li&gt;&#xA;&lt;li&gt;现在在等式两边都乘以k:&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt; k(s_1 - s_2) \mod n = (z_1 - z_2) \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;两边同时除以(&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;s_1-s_2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;)来得到&lt;span class=&#34;article-inline-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;0.6667em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;k = (z_1 -z_2)(s_1 - s_2)-1 \mod n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;最后一个等会能够让我们通过两个hash和其对应的签名计算出k，现在我们可以通过下面的共识计算出s：&lt;/p&gt;&#xA;&lt;div class=&#34;article-equation&#34;&gt;&lt;span class=&#34;katex&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;1em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo&gt;⇒&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;mspace&gt;&lt;/mspace&gt;&lt;mspace width=&#34;1em&#34;/&gt;&lt;mrow&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&#34;normal&#34;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;&#xA;s = k^{-1}(z + rd_s) \mod n \Rightarrow d_s = r^{1}(sk -z) \mod n&#xA;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;就算k不是固定的但是是可预测的话，用类似的技术也能够得到私钥。&lt;/p&gt;&#xA;&lt;h2 id=&#34;未完待续&#34;&gt;&lt;a href=&#34;#%e6%9c%aa%e5%ae%8c%e5%be%85%e7%bb%ad&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;未完待续&#xA;&lt;/h2&gt;&lt;p&gt;接下来，我将会发布这个细节的第四篇文章，它将讨论如何解决离散对数问题，以及一些在椭圆曲线加密中较为重要的问题，以及ECC和RSA算法的区别，不要错过！&lt;/p&gt;&#xA;</description>
        </item>
    <item>
      <title>Elliptic Curve Cryptography: a gentle introduction (2)</title>
      <link>https://chenquan.me/posts/elliptic-curve-cryptography_a-gentle-introduction_2/</link>
      <pubDate>Wed, 14 Jun 2017 15:14:45 +0000</pubDate>
      
      <guid>https://chenquan.me/posts/elliptic-curve-cryptography_a-gentle-introduction_2/</guid>
      <description>这篇文章是ECC:优雅入门系列的第二篇文章
在前面的文章中，我们已经知道了椭圆曲线是如何在实数域内定义一个群的。特别地我们已经定义了一种点加的规则:给定三个齐次的点，它们的和为0 $(P+Q+R=0)$。我们已经通过一个几何方法和一种代数方法来描述计算点的加法。
然后我们介绍了一个扩展标量乘法$(nP = P+P+…+P)$我们也找到了一种较为简单的计算标量乘法的”简便“算法:double and add。
现在我们将我们的椭圆曲线严格限制到有限域（finiite fields）中，而不是在实数域中，我们看看会有什么变化。
p的整数模域(The field of integers modulo p) 首先，有限域，是一个有限数字元素的集合。一个有限域的例子就是p的证书模。其中p是一个素数。这通常会被称为$\mathbb{Z}/p,GF(p)$ 或者$\mathbb{F}_p$。我们会在后面用到这些符号。 在域中我们有两个双目运算，加法($+$)和乘法( $\times$ )。这两者都是闭集，满足结合律以及交换律。对于这两个操作，存在这样的唯一元素，有且仅有唯一的相反元素。最终，乘法可以分配到加法中：$ x\times (y+z) = x \times y+x \times z $。
这个p的整数模域包括了所有的从0到p-1的整数。加法和乘法也都能够在模运算中表现良好，这里有$\mathbb{F}_{23}$的一些样例操作：
 加法 $(18 + 9)\mod 23 = 4$ 减法 $(7 - 14)\mod 23 = 16$ 乘法 $4\cdot7\mod 23 = 5$ 相反加 $-5\mod 23 = 18$  特别地: $(5+(-5))\mod 23 = (5+18)\mod 23 = 0$   相反幂 $9^{-1} \mod 23 = 18$  特别地： $9\cdot9^{-1}\mod 23 = 9 \cdot 18\ mod\ 23 = 1$    如果这些等式对你来说不是很熟悉，那么你可能需要恶补一下有关模运算的有关知识，你可以到可汗学院学习一下。 前已经阐明，p 的模整数是一个域，并且其拥有的所有属性都已经列出。需要注意的是，p 必须是素数，这点非常重要。4的模整数就不是一个域：2没有相反幂（例如，等式 $2\cdot x\mod 4 = 1$没有解）</description>
    </item>
    <item>
      <title>Elliptic Curve Cryptography: a gentle introduction (1)</title>
      <link>https://chenquan.me/posts/elliptic-curve-cryptography_a-gentle-introduction_1/</link>
      <pubDate>Mon, 12 Jun 2017 15:37:22 +0000</pubDate>
      
      <guid>https://chenquan.me/posts/elliptic-curve-cryptography_a-gentle-introduction_1/</guid>
      <description>现在我们可以在TLS,PGP,SSH等应用中看到椭圆曲线加密系统的踪影，这三个应用几乎构建起了现代web应用和信息技术世界的基石，更不要说Bitcoin以及其他的加密货币。
在ECC流行之前，几乎所有的公钥算法都是基于RSA,DSA以及DH，这些算法都是基于同余理论构建的。RSA以及其同类算法现在还是很流行，往往配合ECC一同使用，相对于RSA这种原理很容易被人理解，也很容易实现的算法而言，ECC的内部机理对大多数人而言似乎是一种未解之谜。
我将会用这一系列的文章带领大家进入椭圆曲线加密的全新世界，我的目标不是详细地说明ECC的全部细节(这些在网上随手都能搜索到)，而是要提供一个简单易懂的教程说明什么是ECC，以及为什么它是安全的，当然我也不想花费大量的时间去进行数学证明。我将会提供一些有用的样例然后用一些生动的动态交互工具和脚本去展现它们。
特别地，这里有些点事我将要提及的：
为了理解这里都在说些什么，你需要预先理解一些理论：几何和现代代数，并且需要了解对称加密和非对称加密算法，最后你需要对什么是easy的问题，什么是hard的问题有一个清晰的认识。
准备好了吗？让我们开始吧！
   椭圆曲线 （Elliptic Curves）  首先，从什么是椭圆曲线（Elliptic Curver）开始，Wolfram MathWorld给了一个完整定义: 但是我们不玩这个，简单来说，椭圆曲线就是一个可以通过等式： $$ y^2 = x^3 + ax + b $$
描述的点集。
其中$4a^3+27b^2 \neq 0$
 因为需要排除掉 singular curves 也称奇异曲线。
 上述的等式叫做椭圆曲线_Weierstrass normal form_
 上图是不同椭圆曲线的形状（ b=1, a从2变化到-3 ）
  singularities 曲线:
左边, a curve with a cusp（尖点）:$y^2=x^3$
右边, a curve with a self-intersection（自交）$y^2 = x^3 - 3x + 2$上述两者均为不合法的椭圆曲线
 根据不同的a和b，椭圆曲线可能在平面上展现出不同的形状，很明显，椭圆曲线是关于x轴对称的。
在我们的设计当中，我们还需要一个_无穷点_ Point at infinity（或者称为理想点），现在我们用符号 0 作为作为我们的无穷点。</description>
    </item>
    
  </channel>
</rss>
