Internet Research Task Force (IRTF)                           A. Langley
Request for Comments: 7748                                        Google
Category: Informational                                       M. Hamburg
ISSN: 2070-1721                             Rambus Cryptography Research
                                                               S. Turner
                                                                   sn3rd
                                                            January 2016
        
Internet Research Task Force (IRTF)                           A. Langley
Request for Comments: 7748                                        Google
Category: Informational                                       M. Hamburg
ISSN: 2070-1721                             Rambus Cryptography Research
                                                               S. Turner
                                                                   sn3rd
                                                            January 2016
        

Elliptic Curves for Security

安全椭圆曲线

Abstract

摘要

This memo specifies two elliptic curves over prime fields that offer a high level of practical security in cryptographic applications, including Transport Layer Security (TLS). These curves are intended to operate at the ~128-bit and ~224-bit security level, respectively, and are generated deterministically based on a list of required properties.

此备忘录指定了素域上的两条椭圆曲线,它们在加密应用程序中提供了高级别的实用安全性,包括传输层安全性(TLS)。这些曲线分别在~128位和~224位安全级别下运行,并根据所需属性列表确定生成。

Status of This Memo

关于下段备忘

This document is not an Internet Standards Track specification; it is published for informational purposes.

本文件不是互联网标准跟踪规范;它是为了提供信息而发布的。

This document is a product of the Internet Research Task Force (IRTF). The IRTF publishes the results of Internet-related research and development activities. These results might not be suitable for deployment. This RFC represents the consensus of the Crypto Forum Research Group of the Internet Research Task Force (IRTF). Documents approved for publication by the IRSG are not a candidate for any level of Internet Standard; see Section 2 of RFC 5741.

本文件是互联网研究工作组(IRTF)的产品。IRTF发布互联网相关研究和开发活动的结果。这些结果可能不适合部署。本RFC代表了互联网研究工作组(IRTF)加密论坛研究小组的共识。IRSG批准发布的文件不适用于任何级别的互联网标准;见RFC 5741第2节。

Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at http://www.rfc-editor.org/info/rfc7748.

有关本文件当前状态、任何勘误表以及如何提供反馈的信息,请访问http://www.rfc-editor.org/info/rfc7748.

Copyright Notice

版权公告

Copyright (c) 2016 IETF Trust and the persons identified as the document authors. All rights reserved.

版权所有(c)2016 IETF信托基金和确定为文件作者的人员。版权所有。

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document.

本文件受BCP 78和IETF信托有关IETF文件的法律规定的约束(http://trustee.ietf.org/license-info)自本文件出版之日起生效。请仔细阅读这些文件,因为它们描述了您对本文件的权利和限制。

Table of Contents

目录

   1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . .   2
   2.  Requirements Language . . . . . . . . . . . . . . . . . . . .   3
   3.  Notation  . . . . . . . . . . . . . . . . . . . . . . . . . .   3
   4.  Recommended Curves  . . . . . . . . . . . . . . . . . . . . .   4
     4.1.  Curve25519  . . . . . . . . . . . . . . . . . . . . . . .   4
     4.2.  Curve448  . . . . . . . . . . . . . . . . . . . . . . . .   5
   5.  The X25519 and X448 Functions . . . . . . . . . . . . . . . .   7
     5.1.  Side-Channel Considerations . . . . . . . . . . . . . . .  10
     5.2.  Test Vectors  . . . . . . . . . . . . . . . . . . . . . .  11
   6.  Diffie-Hellman  . . . . . . . . . . . . . . . . . . . . . . .  14
     6.1.  Curve25519  . . . . . . . . . . . . . . . . . . . . . . .  14
     6.2.  Curve448  . . . . . . . . . . . . . . . . . . . . . . . .  15
   7.  Security Considerations . . . . . . . . . . . . . . . . . . .  15
   8.  References  . . . . . . . . . . . . . . . . . . . . . . . . .  16
     8.1.  Normative References  . . . . . . . . . . . . . . . . . .  16
     8.2.  Informative References  . . . . . . . . . . . . . . . . .  17
   Appendix A.  Deterministic Generation . . . . . . . . . . . . . .  19
     A.1.  p = 1 mod 4 . . . . . . . . . . . . . . . . . . . . . . .  20
     A.2.  p = 3 mod 4 . . . . . . . . . . . . . . . . . . . . . . .  21
     A.3.  Base Points . . . . . . . . . . . . . . . . . . . . . . .  21
   Acknowledgements  . . . . . . . . . . . . . . . . . . . . . . . .  22
   Authors' Addresses  . . . . . . . . . . . . . . . . . . . . . . .  22
        
   1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . .   2
   2.  Requirements Language . . . . . . . . . . . . . . . . . . . .   3
   3.  Notation  . . . . . . . . . . . . . . . . . . . . . . . . . .   3
   4.  Recommended Curves  . . . . . . . . . . . . . . . . . . . . .   4
     4.1.  Curve25519  . . . . . . . . . . . . . . . . . . . . . . .   4
     4.2.  Curve448  . . . . . . . . . . . . . . . . . . . . . . . .   5
   5.  The X25519 and X448 Functions . . . . . . . . . . . . . . . .   7
     5.1.  Side-Channel Considerations . . . . . . . . . . . . . . .  10
     5.2.  Test Vectors  . . . . . . . . . . . . . . . . . . . . . .  11
   6.  Diffie-Hellman  . . . . . . . . . . . . . . . . . . . . . . .  14
     6.1.  Curve25519  . . . . . . . . . . . . . . . . . . . . . . .  14
     6.2.  Curve448  . . . . . . . . . . . . . . . . . . . . . . . .  15
   7.  Security Considerations . . . . . . . . . . . . . . . . . . .  15
   8.  References  . . . . . . . . . . . . . . . . . . . . . . . . .  16
     8.1.  Normative References  . . . . . . . . . . . . . . . . . .  16
     8.2.  Informative References  . . . . . . . . . . . . . . . . .  17
   Appendix A.  Deterministic Generation . . . . . . . . . . . . . .  19
     A.1.  p = 1 mod 4 . . . . . . . . . . . . . . . . . . . . . . .  20
     A.2.  p = 3 mod 4 . . . . . . . . . . . . . . . . . . . . . . .  21
     A.3.  Base Points . . . . . . . . . . . . . . . . . . . . . . .  21
   Acknowledgements  . . . . . . . . . . . . . . . . . . . . . . . .  22
   Authors' Addresses  . . . . . . . . . . . . . . . . . . . . . . .  22
        
1. Introduction
1. 介绍

Since the initial standardization of Elliptic Curve Cryptography (ECC [RFC6090]) in [SEC1], there has been significant progress related to both efficiency and security of curves and implementations. Notable examples are algorithms protected against certain side-channel attacks, various "special" prime shapes that allow faster modular arithmetic, and a larger set of curve models from which to choose. There is also concern in the community regarding the generation and potential weaknesses of the curves defined by NIST [NIST].

自[SEC1]中椭圆曲线密码(ECC[RFC6090])的初始标准化以来,在曲线和实现的效率和安全性方面取得了重大进展。值得注意的例子包括针对某些侧通道攻击的算法、允许更快的模块化算法的各种“特殊”素数形状,以及可供选择的更大的曲线模型集。社区也关注NIST[NIST]定义的曲线的生成和潜在缺陷。

This memo specifies two elliptic curves ("curve25519" and "curve448") that lend themselves to constant-time implementation and an exception-free scalar multiplication that is resistant to a wide range of side-channel attacks, including timing and cache attacks. They are Montgomery curves (where v^2 = u^3 + A*u^2 + u) and thus have birationally equivalent Edwards versions. Edwards curves support the fastest (currently known) complete formulas for the elliptic-curve group operations, specifically the Edwards curve x^2 + y^2 = 1 + d*x^2*y^2 for primes p when p = 3 mod 4, and the twisted Edwards curve -x^2 + y^2 = 1 + d*x^2*y^2 when p = 1 mod 4. The maps to/from the Montgomery curves to their (twisted) Edwards equivalents are also given.

此备忘录指定了两条椭圆曲线(“curve25519”和“curve448”),它们适合于恒定时间实现和一个无异常标量乘法,该标量乘法可抵抗各种边通道攻击,包括定时和缓存攻击。它们是蒙哥马利曲线(其中v^2=u^3+A*u^2+u),因此具有双民族等效的爱德华兹曲线。Edwards曲线支持椭圆曲线组运算的最快(目前已知)完整公式,特别是p=3模4时素数p的Edwards曲线x^2+y^2=1+d*x^2*y^2,以及p=1模4时的扭曲Edwards曲线-x^2+y^2=1+d*x^2*y^2。还给出了从蒙哥马利曲线到其(扭曲的)爱德华兹等值线的映射。

This memo also specifies how these curves can be used with the Diffie-Hellman protocol for key agreement.

本备忘录还规定了如何将这些曲线与Diffie-Hellman协议一起用于密钥协商。

2. Requirements Language
2. 需求语言

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].

本文件中的关键词“必须”、“不得”、“要求”、“应”、“不应”、“应”、“不应”、“建议”、“可”和“可选”应按照RFC 2119[RFC2119]中所述进行解释。

3. Notation
3. 符号

Throughout this document, the following notation is used:

在本文件中,使用了以下符号:

p Denotes the prime number defining the underlying field.

p表示定义基础字段的素数。

GF(p) The finite field with p elements.

GF(p)具有p元的有限域。

A An element in the finite field GF(p), not equal to -2 or 2.

有限域GF(p)中的一个元素,不等于-2或2。

d A non-zero element in the finite field GF(p), not equal to 1, in the case of an Edwards curve, or not equal to -1, in the case of a twisted Edwards curve.

d有限域GF(p)中的非零元素,对于爱德华兹曲线不等于1,对于扭曲爱德华兹曲线不等于-1。

order The order of the prime-order subgroup.

阶素数阶子群的阶。

P A generator point defined over GF(p) of prime order.

定义在素数阶GF(P)上的生成元点。

U(P) The u-coordinate of the elliptic curve point P on a Montgomery curve.

U(P)蒙哥马利曲线上椭圆曲线点P的U坐标。

V(P) The v-coordinate of the elliptic curve point P on a Montgomery curve.

V(P)蒙哥马利曲线上椭圆曲线点P的V坐标。

X(P) The x-coordinate of the elliptic curve point P on a (twisted) Edwards curve.

X(P)椭圆曲线点P在(扭曲的)爱德华兹曲线上的X坐标。

Y(P) The y-coordinate of the elliptic curve point P on a (twisted) Edwards curve.

Y(P)椭圆曲线点P在(扭曲的)爱德华兹曲线上的Y坐标。

u, v Coordinates on a Montgomery curve.

u、 蒙哥马利曲线上的v坐标。

x, y Coordinates on a (twisted) Edwards curve.

x、 (扭曲的)爱德华兹曲线上的y坐标。

4. Recommended Curves
4. 推荐曲线
4.1. Curve25519
4.1. 曲线25519

For the ~128-bit security level, the prime 2^255 - 19 is recommended for performance on a wide range of architectures. Few primes of the form 2^c-s with s small exist between 2^250 and 2^521, and other choices of coefficient are not as competitive in performance. This prime is congruent to 1 mod 4, and the derivation procedure in Appendix A results in the following Montgomery curve v^2 = u^3 + A*u^2 + u, called "curve25519":

对于~128位安全级别,建议使用prime 2^255-19,以在多种体系结构上实现性能。在2^250和2^521之间,几乎不存在s小的2^c-s形式的素数,其他系数的选择在性能上没有竞争力。该素数与1模4全等,附录A中的推导程序得出以下蒙哥马利曲线v^2=u^3+A*u^2+u,称为“曲线25519”:

p 2^255 - 19

p 2^255-19

A 486662

A 486662

   order  2^252 + 0x14def9dea2f79cd65812631a5cf5d3ed
        
   order  2^252 + 0x14def9dea2f79cd65812631a5cf5d3ed
        

cofactor 8

辅因子8

U(P) 9

U(P)9

V(P) 147816194475895447910205935684099868872646061346164752889648818 37755586237401

V(P)1478161944758954479102059356840998688726460613461647528896488818 37755586237401

The base point is u = 9, v = 1478161944758954479102059356840998688726 4606134616475288964881837755586237401.

基点为u=9,v=1478161944758954479102059356840998688726 46061346164752889684881837755586237401。

This curve is birationally equivalent to a twisted Edwards curve -x^2 + y^2 = 1 + d*x^2*y^2, called "edwards25519", where:

该曲线在双方向上等效于扭曲爱德华兹曲线-x^2+y^2=1+d*x^2*y^2,称为“edwards25519”,其中:

p 2^255 - 19

p 2^255-19

d 370957059346694393431380835087545651895421138798432190163887855330 85940283555

d 370957059346694393431380835087545651895421138798483219016388855330 85940283555

   order  2^252 + 0x14def9dea2f79cd65812631a5cf5d3ed
        
   order  2^252 + 0x14def9dea2f79cd65812631a5cf5d3ed
        

cofactor 8

辅因子8

X(P) 151122213495354007725011514095885315114540126930418572060461132 83949847762202

X(P)15112221349554007725011514095885315114540126930418572060461132 83949847762202

Y(P) 463168356949264781694283940034751631413079938662562256157830336 03165251855960

Y(P)4631683569492647816942839400347516314130799338662562256157830336 03165251855960

The birational maps are:

双民族地图是:

     (u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)
     (x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))
        
     (u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)
     (x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))
        

The Montgomery curve defined here is equal to the one defined in [curve25519], and the equivalent twisted Edwards curve is equal to the one defined in [ed25519].

此处定义的蒙哥马利曲线等于[Curve2519]中定义的曲线,等效扭曲爱德华兹曲线等于[ed25519]中定义的曲线。

4.2. Curve448
4.2. 曲线448

For the ~224-bit security level, the prime 2^448 - 2^224 - 1 is recommended for performance on a wide range of architectures. This prime is congruent to 3 mod 4, and the derivation procedure in Appendix A results in the following Montgomery curve, called "curve448":

对于~224位的安全级别,建议使用prime 2^448-2^224-1在各种体系结构上实现性能。该素数与3模4全等,附录A中的推导程序得出以下蒙哥马利曲线,称为“曲线448”:

   p  2^448 - 2^224 - 1
        
   p  2^448 - 2^224 - 1
        

A 156326

A 156326

   order  2^446 -
      0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
        
   order  2^446 -
      0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
        

cofactor 4

辅因子4

U(P) 5

U(P)5

V(P) 355293926785568175264127502063783334808976399387714271831880898 435169088786967410002932673765864550910142774147268105838985595290 606362

V(P)35529392692678556817526412727006378333480898973993877142831880898 43516908878696741000293267365864550910142774147268105838985595290606362

This curve is birationally equivalent to the Edwards curve x^2 + y^2 = 1 + d*x^2*y^2 where:

该曲线与爱德华兹曲线x^2+y^2=1+d*x^2*y^2的双稳态等效,其中:

   p  2^448 - 2^224 - 1
        
   p  2^448 - 2^224 - 1
        

d 611975850744529176160423220965553317543219696871016626328968936415 087860042636474891785599283666020414768678979989378147065462815545 017

d 61197585507445291761604232209655533175432196968710166263289689364150878600426364748917855992836602041476867897998781470654628155017

   order  2^446 -
      0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
        
   order  2^446 -
      0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
        

cofactor 4

辅因子4

X(P) 345397493039729516374008604150537410266655260075183290216406970 281645695073672344430481787759340633221708391583424041788924124567 700732

X(P)34539749303972951637408604150537410266655260075183290216406970 2816456950736723444304817877593406322170839158342404178892412467700732

Y(P) 363419362147803445274661903944002267176820680343659030140745099 590306164083365386343198191849338272965044442230921818680526749009 182718

Y(P)3634193621478034527466190394400226717682068034659030140745099 59030164083365386343198191849338272296504442230921818680526749009182718

The birational maps are:

双民族地图是:

     (u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)
     (x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))
        
     (u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)
     (x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))
        

Both of those curves are also 4-isogenous to the following Edwards curve x^2 + y^2 = 1 + d*x^2*y^2, called "edwards448", where:

这两条曲线与以下爱德华兹曲线x^2+y^2=1+d*x^2*y^2(称为“爱德华兹448”)也是4-同构的,其中:

   p  2^448 - 2^224 - 1
        
   p  2^448 - 2^224 - 1
        

d -39081

d-39081

   order  2^446 -
      0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
        
   order  2^446 -
      0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
        

cofactor 4

辅因子4

X(P) 224580040295924300187604334099896036246789641632564134246125461 686950415467406032909029192869357953282578032075146446173674602635 247710

X(P)22458004029592430018760433409989960362467896461632564134246125461 68695041546740603290902919286935795328257803207514646173674602635 247710

Y(P) 298819210078481492676017930443930673437544040154080242095928241 372331506189835876003536878655418784733982303233503462500531545062 832660

Y(P)2988192100784814926760179304439306734375440401540802422095928241 372331506189835876003536878655418784733982303233503462500531545062832660

The 4-isogeny maps between the Montgomery curve and this Edwards curve are:

蒙哥马利曲线和爱德华兹曲线之间的4-等成因图为:

     (u, v) = (y^2/x^2, (2 - x^2 - y^2)*y/x^3)
     (x, y) = (4*v*(u^2 - 1)/(u^4 - 2*u^2 + 4*v^2 + 1),
               -(u^5 - 2*u^3 - 4*u*v^2 + u)/
               (u^5 - 2*u^2*v^2 - 2*u^3 - 2*v^2 + u))
        
     (u, v) = (y^2/x^2, (2 - x^2 - y^2)*y/x^3)
     (x, y) = (4*v*(u^2 - 1)/(u^4 - 2*u^2 + 4*v^2 + 1),
               -(u^5 - 2*u^3 - 4*u*v^2 + u)/
               (u^5 - 2*u^2*v^2 - 2*u^3 - 2*v^2 + u))
        

The curve edwards448 defined here is also called "Goldilocks" and is equal to the one defined in [goldilocks].

此处定义的edwards448曲线也称为“Goldilocks”,与[Goldilocks]中定义的曲线相同。

5. The X25519 and X448 Functions
5. X25519和X448的功能

The "X25519" and "X448" functions perform scalar multiplication on the Montgomery form of the above curves. (This is used when implementing Diffie-Hellman.) The functions take a scalar and a u-coordinate as inputs and produce a u-coordinate as output. Although the functions work internally with integers, the inputs and outputs are 32-byte strings (for X25519) or 56-byte strings (for X448) and this specification defines their encoding.

“X25519”和“X448”函数对上述曲线的蒙哥马利形式执行标量乘法。(这在实现Diffie Hellman时使用。)函数将标量和u坐标作为输入,并生成u坐标作为输出。尽管函数在内部使用整数,但输入和输出是32字节字符串(对于X25519)或56字节字符串(对于X448),本规范定义了它们的编码。

The u-coordinates are elements of the underlying field GF(2^255 - 19) or GF(2^448 - 2^224 - 1) and are encoded as an array of bytes, u, in little-endian order such that u[0] + 256*u[1] + 256^2*u[2] + ... + 256^(n-1)*u[n-1] is congruent to the value modulo p and u[n-1] is minimal. When receiving such an array, implementations of X25519 (but not X448) MUST mask the most significant bit in the final byte. This is done to preserve compatibility with point formats that reserve the sign bit for use in other protocols and to increase resistance to implementation fingerprinting.

u坐标是基础字段GF(2^255-19)或GF(2^448-2^224-1)的元素,并以小尾数顺序编码为字节数组u,以便u[0]+256*u[1]+256^2*u[2]+…+256^(n-1)*u[n-1]与模p的值全等,且u[n-1]最小。当接收这样一个数组时,X25519(而不是X448)的实现必须屏蔽最后一个字节中的最高有效位。这样做是为了保持与保留符号位供其他协议使用的点格式的兼容性,并增加对实现指纹识别的阻力。

Implementations MUST accept non-canonical values and process them as if they had been reduced modulo the field prime. The non-canonical values are 2^255 - 19 through 2^255 - 1 for X25519 and 2^448 - 2^224 - 1 through 2^448 - 1 for X448.

实现必须接受非规范值,并将其作为字段素数的模进行处理。对于X25519,非规范值为2^255-19到2^255-1;对于X448,非规范值为2^448-2^224-1到2^448-1。

The following functions implement this in Python, although the Python code is not intended to be performant nor side-channel free. Here, the "bits" parameter should be set to 255 for X25519 and 448 for X448:

下面的函数在Python中实现了这一点,尽管Python代码既不具有性能也不具有侧通道自由。这里,X25519的“bits”参数应设置为255,X448的“bits”参数应设置为448:

   <CODE BEGINS>
   def decodeLittleEndian(b, bits):
       return sum([b[i] << 8*i for i in range((bits+7)/8)])
        
   <CODE BEGINS>
   def decodeLittleEndian(b, bits):
       return sum([b[i] << 8*i for i in range((bits+7)/8)])
        
   def decodeUCoordinate(u, bits):
       u_list = [ord(b) for b in u]
       # Ignore any unused bits.
       if bits % 8:
           u_list[-1] &= (1<<(bits%8))-1
       return decodeLittleEndian(u_list, bits)
        
   def decodeUCoordinate(u, bits):
       u_list = [ord(b) for b in u]
       # Ignore any unused bits.
       if bits % 8:
           u_list[-1] &= (1<<(bits%8))-1
       return decodeLittleEndian(u_list, bits)
        
   def encodeUCoordinate(u, bits):
       u = u % p
       return ''.join([chr((u >> 8*i) & 0xff)
                       for i in range((bits+7)/8)])
   <CODE ENDS>
        
   def encodeUCoordinate(u, bits):
       u = u % p
       return ''.join([chr((u >> 8*i) & 0xff)
                       for i in range((bits+7)/8)])
   <CODE ENDS>
        

Scalars are assumed to be randomly generated bytes. For X25519, in order to decode 32 random bytes as an integer scalar, set the three least significant bits of the first byte and the most significant bit of the last to zero, set the second most significant bit of the last byte to 1 and, finally, decode as little-endian. This means that the resulting integer is of the form 2^254 plus eight times a value between 0 and 2^251 - 1 (inclusive). Likewise, for X448, set the two least significant bits of the first byte to 0, and the most significant bit of the last byte to 1. This means that the resulting integer is of the form 2^447 plus four times a value between 0 and 2^445 - 1 (inclusive).

标量被假定为随机生成的字节。对于X25519,为了将32个随机字节解码为整数标量,将第一个字节的三个最低有效位和最后一个字节的最高有效位设置为零,将最后一个字节的第二个最高有效位设置为1,最后解码为小端。这意味着结果整数的形式为2^254加上8倍0和2^251-1(包括)之间的值。同样,对于X448,将第一个字节的两个最低有效位设置为0,将最后一个字节的最高有效位设置为1。这意味着结果整数的形式为2^447加上0和2^445-1(包括)之间的值的四倍。

   <CODE BEGINS>
   def decodeScalar25519(k):
       k_list = [ord(b) for b in k]
       k_list[0] &= 248
       k_list[31] &= 127
       k_list[31] |= 64
       return decodeLittleEndian(k_list, 255)
        
   <CODE BEGINS>
   def decodeScalar25519(k):
       k_list = [ord(b) for b in k]
       k_list[0] &= 248
       k_list[31] &= 127
       k_list[31] |= 64
       return decodeLittleEndian(k_list, 255)
        
   def decodeScalar448(k):
       k_list = [ord(b) for b in k]
       k_list[0] &= 252
       k_list[55] |= 128
       return decodeLittleEndian(k_list, 448)
   <CODE ENDS>
        
   def decodeScalar448(k):
       k_list = [ord(b) for b in k]
       k_list[0] &= 252
       k_list[55] |= 128
       return decodeLittleEndian(k_list, 448)
   <CODE ENDS>
        

To implement the X25519(k, u) and X448(k, u) functions (where k is the scalar and u is the u-coordinate), first decode k and u and then perform the following procedure, which is taken from [curve25519] and based on formulas from [montgomery]. All calculations are performed in GF(p), i.e., they are performed modulo p. The constant a24 is (486662 - 2) / 4 = 121665 for curve25519/X25519 and (156326 - 2) / 4 = 39081 for curve448/X448.

To implement the X25519(k, u) and X448(k, u) functions (where k is the scalar and u is the u-coordinate), first decode k and u and then perform the following procedure, which is taken from [curve25519] and based on formulas from [montgomery]. All calculations are performed in GF(p), i.e., they are performed modulo p. The constant a24 is (486662 - 2) / 4 = 121665 for curve25519/X25519 and (156326 - 2) / 4 = 39081 for curve448/X448.translate error, please retry

x_1 = u x_2 = 1 z_2 = 0 x_3 = u z_3 = 1 swap = 0

x_1=ux_2=1z_2=0x_3=uz_3=1swap=0

   For t = bits-1 down to 0:
       k_t = (k >> t) & 1
       swap ^= k_t
       // Conditional swap; see text below.
       (x_2, x_3) = cswap(swap, x_2, x_3)
       (z_2, z_3) = cswap(swap, z_2, z_3)
       swap = k_t
        
   For t = bits-1 down to 0:
       k_t = (k >> t) & 1
       swap ^= k_t
       // Conditional swap; see text below.
       (x_2, x_3) = cswap(swap, x_2, x_3)
       (z_2, z_3) = cswap(swap, z_2, z_3)
       swap = k_t
        
       A = x_2 + z_2
       AA = A^2
       B = x_2 - z_2
       BB = B^2
       E = AA - BB
       C = x_3 + z_3
       D = x_3 - z_3
       DA = D * A
       CB = C * B
       x_3 = (DA + CB)^2
       z_3 = x_1 * (DA - CB)^2
       x_2 = AA * BB
       z_2 = E * (AA + a24 * E)
        
       A = x_2 + z_2
       AA = A^2
       B = x_2 - z_2
       BB = B^2
       E = AA - BB
       C = x_3 + z_3
       D = x_3 - z_3
       DA = D * A
       CB = C * B
       x_3 = (DA + CB)^2
       z_3 = x_1 * (DA - CB)^2
       x_2 = AA * BB
       z_2 = E * (AA + a24 * E)
        
   // Conditional swap; see text below.
   (x_2, x_3) = cswap(swap, x_2, x_3)
   (z_2, z_3) = cswap(swap, z_2, z_3)
   Return x_2 * (z_2^(p - 2))
        
   // Conditional swap; see text below.
   (x_2, x_3) = cswap(swap, x_2, x_3)
   (z_2, z_3) = cswap(swap, z_2, z_3)
   Return x_2 * (z_2^(p - 2))
        

(Note that these formulas are slightly different from Montgomery's original paper. Implementations are free to use any correct formulas.)

(请注意,这些公式与蒙哥马利的原始论文略有不同。实现可以自由使用任何正确的公式。)

Finally, encode the resulting value as 32 or 56 bytes in little-endian order. For X25519, the unused, most significant bit MUST be zero.

最后,以小尾数顺序将结果值编码为32或56字节。对于X25519,未使用的最高有效位必须为零。

The cswap function SHOULD be implemented in constant time (i.e., independent of the swap argument). For example, this can be done as follows:

cswap函数应在恒定时间内实现(即,独立于交换参数)。例如,这可以通过以下方式完成:

cswap(swap, x_2, x_3): dummy = mask(swap) AND (x_2 XOR x_3) x_2 = x_2 XOR dummy x_3 = x_3 XOR dummy Return (x_2, x_3)

cswap(交换,x_2,x_3):虚拟=掩码(交换)和(x_2异或x_3)x_2=x_2异或虚拟x_3=x_3异或虚拟返回(x_2,x_3)

Where mask(swap) is the all-1 or all-0 word of the same length as x_2 and x_3, computed, e.g., as mask(swap) = 0 - swap.

其中,mask(swap)是长度与x_2和x_3相同的all-1或all-0字,计算得到,例如,as mask(swap)=0-swap。

5.1. Side-Channel Considerations
5.1. 侧通道注意事项

X25519 and X448 are designed so that fast, constant-time implementations are easier to produce. The procedure above ensures that the same sequence of field operations is performed for all values of the secret key, thus eliminating a common source of side-channel leakage. However, this alone does not prevent all side-channels by itself. It is important that the pattern of memory accesses and jumps not depend on the values of any of the bits of k. It is also important that the arithmetic used not leak information about the integers modulo p, for example by having b*c be distinguishable from c*c. On some architectures, even primitive machine instructions, such as single-word division, can have variable timing based on their inputs.

X25519和X448的设计使快速、恒定时间的实现更容易实现。上述过程确保对密钥的所有值执行相同的字段操作序列,从而消除侧信道泄漏的公共源。然而,这本身并不能阻止所有旁道。重要的是,内存访问和跳转的模式不依赖于k的任何位的值。同样重要的是,所使用的算法不泄漏关于模p的整数的信息,例如,通过使b*c与c*c区分开来。在某些体系结构上,即使是原始的机器指令,如单字分割,也可以根据其输入进行可变定时。

Side-channel attacks are an active research area that still sees significant, new results. Implementors are advised to follow this research closely.

侧通道攻击是一个活跃的研究领域,仍然有重大的新成果。建议实施者密切关注这项研究。

5.2. Test Vectors
5.2. 测试向量

Two types of tests are provided. The first is a pair of test vectors for each function that consist of expected outputs for the given inputs. The inputs are generally given as 64 or 112 hexadecimal digits that need to be decoded as 32 or 56 binary bytes before processing.

提供了两种类型的测试。第一个是每个函数的一对测试向量,由给定输入的预期输出组成。输入通常为64或112个十六进制数字,需要在处理前解码为32或56个二进制字节。

X25519:

X25519:

   Input scalar:
     a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac4
   Input scalar as a number (base 10):
     31029842492115040904895560451863089656
     472772604678260265531221036453811406496
   Input u-coordinate:
     e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c
   Input u-coordinate as a number (base 10):
     34426434033919594451155107781188821651
     316167215306631574996226621102155684838
   Output u-coordinate:
     c3da55379de9c6908e94ea4df28d084f32eccf03491c71f754b4075577a28552
        
   Input scalar:
     a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac4
   Input scalar as a number (base 10):
     31029842492115040904895560451863089656
     472772604678260265531221036453811406496
   Input u-coordinate:
     e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c
   Input u-coordinate as a number (base 10):
     34426434033919594451155107781188821651
     316167215306631574996226621102155684838
   Output u-coordinate:
     c3da55379de9c6908e94ea4df28d084f32eccf03491c71f754b4075577a28552
        
   Input scalar:
     4b66e9d4d1b4673c5ad22691957d6af5c11b6421e0ea01d42ca4169e7918ba0d
   Input scalar as a number (base 10):
     35156891815674817266734212754503633747
     128614016119564763269015315466259359304
   Input u-coordinate:
     e5210f12786811d3f4b7959d0538ae2c31dbe7106fc03c3efc4cd549c715a493
   Input u-coordinate as a number (base 10):
     88838573511839298940907593866106493194
     17338800022198945255395922347792736741
   Output u-coordinate:
     95cbde9476e8907d7aade45cb4b873f88b595a68799fa152e6f8f7647aac7957
        
   Input scalar:
     4b66e9d4d1b4673c5ad22691957d6af5c11b6421e0ea01d42ca4169e7918ba0d
   Input scalar as a number (base 10):
     35156891815674817266734212754503633747
     128614016119564763269015315466259359304
   Input u-coordinate:
     e5210f12786811d3f4b7959d0538ae2c31dbe7106fc03c3efc4cd549c715a493
   Input u-coordinate as a number (base 10):
     88838573511839298940907593866106493194
     17338800022198945255395922347792736741
   Output u-coordinate:
     95cbde9476e8907d7aade45cb4b873f88b595a68799fa152e6f8f7647aac7957
        

X448:

X448:

   Input scalar:
     3d262fddf9ec8e88495266fea19a34d28882acef045104d0d1aae121
     700a779c984c24f8cdd78fbff44943eba368f54b29259a4f1c600ad3
   Input scalar as a number (base 10):
     599189175373896402783756016145213256157230856
     085026129926891459468622403380588640249457727
     683869421921443004045221642549886377526240828
   Input u-coordinate:
     06fce640fa3487bfda5f6cf2d5263f8aad88334cbd07437f020f08f9
     814dc031ddbdc38c19c6da2583fa5429db94ada18aa7a7fb4ef8a086
   Input u-coordinate as a number (base 10):
     382239910814107330116229961234899377031416365
     240571325148346555922438025162094455820962429
     142971339584360034337310079791515452463053830
   Output u-coordinate:
     ce3e4ff95a60dc6697da1db1d85e6afbdf79b50a2412d7546d5f239f
     e14fbaadeb445fc66a01b0779d98223961111e21766282f73dd96b6f
        
   Input scalar:
     3d262fddf9ec8e88495266fea19a34d28882acef045104d0d1aae121
     700a779c984c24f8cdd78fbff44943eba368f54b29259a4f1c600ad3
   Input scalar as a number (base 10):
     599189175373896402783756016145213256157230856
     085026129926891459468622403380588640249457727
     683869421921443004045221642549886377526240828
   Input u-coordinate:
     06fce640fa3487bfda5f6cf2d5263f8aad88334cbd07437f020f08f9
     814dc031ddbdc38c19c6da2583fa5429db94ada18aa7a7fb4ef8a086
   Input u-coordinate as a number (base 10):
     382239910814107330116229961234899377031416365
     240571325148346555922438025162094455820962429
     142971339584360034337310079791515452463053830
   Output u-coordinate:
     ce3e4ff95a60dc6697da1db1d85e6afbdf79b50a2412d7546d5f239f
     e14fbaadeb445fc66a01b0779d98223961111e21766282f73dd96b6f
        
   Input scalar:
     203d494428b8399352665ddca42f9de8fef600908e0d461cb021f8c5
     38345dd77c3e4806e25f46d3315c44e0a5b4371282dd2c8d5be3095f
   Input scalar as a number (base 10):
     633254335906970592779259481534862372382525155
     252028961056404001332122152890562527156973881
     968934311400345568203929409663925541994577184
   Input u-coordinate:
     0fbcc2f993cd56d3305b0b7d9e55d4c1a8fb5dbb52f8e9a1e9b6201b
     165d015894e56c4d3570bee52fe205e28a78b91cdfbde71ce8d157db
   Input u-coordinate as a number (base 10):
     622761797758325444462922068431234180649590390
     024811299761625153767228042600197997696167956
     134770744996690267634159427999832340166786063
   Output u-coordinate:
     884a02576239ff7a2f2f63b2db6a9ff37047ac13568e1e30fe63c4a7
     ad1b3ee3a5700df34321d62077e63633c575c1c954514e99da7c179d
        
   Input scalar:
     203d494428b8399352665ddca42f9de8fef600908e0d461cb021f8c5
     38345dd77c3e4806e25f46d3315c44e0a5b4371282dd2c8d5be3095f
   Input scalar as a number (base 10):
     633254335906970592779259481534862372382525155
     252028961056404001332122152890562527156973881
     968934311400345568203929409663925541994577184
   Input u-coordinate:
     0fbcc2f993cd56d3305b0b7d9e55d4c1a8fb5dbb52f8e9a1e9b6201b
     165d015894e56c4d3570bee52fe205e28a78b91cdfbde71ce8d157db
   Input u-coordinate as a number (base 10):
     622761797758325444462922068431234180649590390
     024811299761625153767228042600197997696167956
     134770744996690267634159427999832340166786063
   Output u-coordinate:
     884a02576239ff7a2f2f63b2db6a9ff37047ac13568e1e30fe63c4a7
     ad1b3ee3a5700df34321d62077e63633c575c1c954514e99da7c179d
        

The second type of test vector consists of the result of calling the function in question a specified number of times. Initially, set k and u to be the following values:

第二种类型的测试向量由调用相关函数指定次数的结果组成。最初,将k和u设置为以下值:

   For X25519:
     0900000000000000000000000000000000000000000000000000000000000000
   For X448:
     05000000000000000000000000000000000000000000000000000000
     00000000000000000000000000000000000000000000000000000000
        
   For X25519:
     0900000000000000000000000000000000000000000000000000000000000000
   For X448:
     05000000000000000000000000000000000000000000000000000000
     00000000000000000000000000000000000000000000000000000000
        

For each iteration, set k to be the result of calling the function and u to be the old value of k. The final result is the value left in k.

对于每次迭代,将k设置为调用函数的结果,将u设置为k的旧值。最终结果是k中的剩余值。

X25519:

X25519:

   After one iteration:
       422c8e7a6227d7bca1350b3e2bb7279f7897b87bb6854b783c60e80311ae3079
   After 1,000 iterations:
       684cf59ba83309552800ef566f2f4d3c1c3887c49360e3875f2eb94d99532c51
   After 1,000,000 iterations:
       7c3911e0ab2586fd864497297e575e6f3bc601c0883c30df5f4dd2d24f665424
        
   After one iteration:
       422c8e7a6227d7bca1350b3e2bb7279f7897b87bb6854b783c60e80311ae3079
   After 1,000 iterations:
       684cf59ba83309552800ef566f2f4d3c1c3887c49360e3875f2eb94d99532c51
   After 1,000,000 iterations:
       7c3911e0ab2586fd864497297e575e6f3bc601c0883c30df5f4dd2d24f665424
        

X448:

X448:

   After one iteration:
       3f482c8a9f19b01e6c46ee9711d9dc14fd4bf67af30765c2ae2b846a
       4d23a8cd0db897086239492caf350b51f833868b9bc2b3bca9cf4113
   After 1,000 iterations:
       aa3b4749d55b9daf1e5b00288826c467274ce3ebbdd5c17b975e09d4
       af6c67cf10d087202db88286e2b79fceea3ec353ef54faa26e219f38
   After 1,000,000 iterations:
       077f453681caca3693198420bbe515cae0002472519b3e67661a7e89
       cab94695c8f4bcd66e61b9b9c946da8d524de3d69bd9d9d66b997e37
        
   After one iteration:
       3f482c8a9f19b01e6c46ee9711d9dc14fd4bf67af30765c2ae2b846a
       4d23a8cd0db897086239492caf350b51f833868b9bc2b3bca9cf4113
   After 1,000 iterations:
       aa3b4749d55b9daf1e5b00288826c467274ce3ebbdd5c17b975e09d4
       af6c67cf10d087202db88286e2b79fceea3ec353ef54faa26e219f38
   After 1,000,000 iterations:
       077f453681caca3693198420bbe515cae0002472519b3e67661a7e89
       cab94695c8f4bcd66e61b9b9c946da8d524de3d69bd9d9d66b997e37
        
6. Diffie-Hellman
6. 密钥交换
6.1. Curve25519
6.1. 曲线25519

The X25519 function can be used in an Elliptic Curve Diffie-Hellman (ECDH) protocol as follows:

X25519函数可用于椭圆曲线Diffie-Hellman(ECDH)协议,如下所示:

Alice generates 32 random bytes in a[0] to a[31] and transmits K_A = X25519(a, 9) to Bob, where 9 is the u-coordinate of the base point and is encoded as a byte with value 9, followed by 31 zero bytes.

Alice在[0]到[31]之间生成32个随机字节,并将K_a=X25519(a,9)传输到Bob,其中9是基点的u坐标,编码为值为9的字节,后跟31个零字节。

Bob similarly generates 32 random bytes in b[0] to b[31], computes K_B = X25519(b, 9), and transmits it to Alice.

Bob同样在b[0]到b[31]中生成32个随机字节,计算K_b=X25519(b,9),并将其传输给Alice。

Using their generated values and the received input, Alice computes X25519(a, K_B) and Bob computes X25519(b, K_A).

Alice使用生成的值和接收到的输入计算X25519(a,K_B),Bob计算X25519(B,K_a)。

Both now share K = X25519(a, X25519(b, 9)) = X25519(b, X25519(a, 9)) as a shared secret. Both MAY check, without leaking extra information about the value of K, whether K is the all-zero value and abort if so (see below). Alice and Bob can then use a key-derivation function that includes K, K_A, and K_B to derive a symmetric key.

现在两者都将K=X25519(a,X25519(b,9))=X25519(b,X25519(a,9))作为共享秘密共享。两者都可以在不泄露关于K值的额外信息的情况下检查K是否为全零值,如果为全零值则中止(见下文)。然后,Alice和Bob可以使用包含K、K_a和K_B的密钥派生函数来派生对称密钥。

The check for the all-zero value results from the fact that the X25519 function produces that value if it operates on an input corresponding to a point with small order, where the order divides the cofactor of the curve (see Section 7). The check may be performed by ORing all the bytes together and checking whether the result is zero, as this eliminates standard side-channels in software implementations.

检查全零值的原因是,如果X25519函数对与小阶点对应的输入进行操作,则会产生该值,其中阶数除以曲线的余因子(参见第7节)。检查可以通过将所有字节存储在一起并检查结果是否为零来执行,因为这消除了软件实现中的标准侧通道。

Test vector:

测试向量:

   Alice's private key, a:
     77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a
   Alice's public key, X25519(a, 9):
     8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a
   Bob's private key, b:
     5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb
   Bob's public key, X25519(b, 9):
     de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f
   Their shared secret, K:
     4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742
        
   Alice's private key, a:
     77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a
   Alice's public key, X25519(a, 9):
     8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a
   Bob's private key, b:
     5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb
   Bob's public key, X25519(b, 9):
     de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f
   Their shared secret, K:
     4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742
        
6.2. Curve448
6.2. 曲线448

The X448 function can be used in an ECDH protocol very much like the X25519 function.

X448函数可以在ECDH协议中使用,非常类似于X25519函数。

If X448 is to be used, the only differences are that Alice and Bob generate 56 random bytes (not 32) and calculate K_A = X448(a, 5) or K_B = X448(b, 5), where 5 is the u-coordinate of the base point and is encoded as a byte with value 5, followed by 55 zero bytes.

如果要使用X448,唯一的区别是Alice和Bob生成56个随机字节(不是32个),并计算K_A=X448(A,5)或K_B=X448(B,5),其中5是基点的u坐标,编码为值为5的字节,后跟55个零字节。

As with X25519, both sides MAY check, without leaking extra information about the value of K, whether the resulting shared K is the all-zero value and abort if so.

与X25519一样,双方可以在不泄漏关于K值的额外信息的情况下检查结果共享K是否为全零值,如果是,则中止。

Test vector:

测试向量:

   Alice's private key, a:
     9a8f4925d1519f5775cf46b04b5800d4ee9ee8bae8bc5565d498c28d
     d9c9baf574a9419744897391006382a6f127ab1d9ac2d8c0a598726b
   Alice's public key, X448(a, 5):
     9b08f7cc31b7e3e67d22d5aea121074a273bd2b83de09c63faa73d2c
     22c5d9bbc836647241d953d40c5b12da88120d53177f80e532c41fa0
   Bob's private key, b:
     1c306a7ac2a0e2e0990b294470cba339e6453772b075811d8fad0d1d
     6927c120bb5ee8972b0d3e21374c9c921b09d1b0366f10b65173992d
   Bob's public key, X448(b, 5):
     3eb7a829b0cd20f5bcfc0b599b6feccf6da4627107bdb0d4f345b430
     27d8b972fc3e34fb4232a13ca706dcb57aec3dae07bdc1c67bf33609
   Their shared secret, K:
     07fff4181ac6cc95ec1c16a94a0f74d12da232ce40a77552281d282b
     b60c0b56fd2464c335543936521c24403085d59a449a5037514a879d
        
   Alice's private key, a:
     9a8f4925d1519f5775cf46b04b5800d4ee9ee8bae8bc5565d498c28d
     d9c9baf574a9419744897391006382a6f127ab1d9ac2d8c0a598726b
   Alice's public key, X448(a, 5):
     9b08f7cc31b7e3e67d22d5aea121074a273bd2b83de09c63faa73d2c
     22c5d9bbc836647241d953d40c5b12da88120d53177f80e532c41fa0
   Bob's private key, b:
     1c306a7ac2a0e2e0990b294470cba339e6453772b075811d8fad0d1d
     6927c120bb5ee8972b0d3e21374c9c921b09d1b0366f10b65173992d
   Bob's public key, X448(b, 5):
     3eb7a829b0cd20f5bcfc0b599b6feccf6da4627107bdb0d4f345b430
     27d8b972fc3e34fb4232a13ca706dcb57aec3dae07bdc1c67bf33609
   Their shared secret, K:
     07fff4181ac6cc95ec1c16a94a0f74d12da232ce40a77552281d282b
     b60c0b56fd2464c335543936521c24403085d59a449a5037514a879d
        
7. Security Considerations
7. 安全考虑

The security level (i.e., the number of "operations" needed for a brute-force attack on a primitive) of curve25519 is slightly under the standard 128-bit level. This is acceptable because the standard security levels are primarily driven by much simpler, symmetric primitives where the security level naturally falls on a power of two. For asymmetric primitives, rigidly adhering to a power-of-two security level would require compromises in other parts of the design, which we reject. Additionally, comparing security levels between types of primitives can be misleading under common threat models where multiple targets can be attacked concurrently [bruteforce].

curve25519的安全级别(即对原语进行暴力攻击所需的“操作”数量)略低于标准128位级别。这是可以接受的,因为标准安全级别主要由更简单的对称原语驱动,其中安全级别自然为二的幂。对于非对称原语,严格遵守两个安全级别的幂将需要在设计的其他部分做出妥协,我们拒绝这样做。此外,在常见的威胁模型下,比较不同类型原语之间的安全级别可能会产生误导,在这种模型中,多个目标可能会同时受到攻击[bruteforce]。

The ~224-bit security level of curve448 is a trade-off between performance and paranoia. Large quantum computers, if ever created, will break both curve25519 and curve448, and reasonable projections of the abilities of classical computers conclude that curve25519 is perfectly safe. However, some designs have relaxed performance requirements and wish to hedge against some amount of analytical advance against elliptic curves and thus curve448 is also provided.

curve448的~224位安全级别是性能和偏执之间的折衷。大型量子计算机,如果被创造出来,将同时破坏curve25519和curve448,对经典计算机能力的合理预测得出结论,curve25519是完全安全的。然而,一些设计放宽了性能要求,希望避免椭圆曲线的一些分析进展,因此也提供了曲线448。

Protocol designers using Diffie-Hellman over the curves defined in this document must not assume "contributory behaviour". Specially, contributory behaviour means that both parties' private keys contribute to the resulting shared key. Since curve25519 and curve448 have cofactors of 8 and 4 (respectively), an input point of small order will eliminate any contribution from the other party's private key. This situation can be detected by checking for the all-zero output, which implementations MAY do, as specified in Section 6. However, a large number of existing implementations do not do this.

在本文件定义的曲线上使用Diffie-Hellman的协议设计者不得假设“贡献行为”。特别是,贡献行为意味着双方的私钥都贡献给产生的共享密钥。由于curve25519和curve448的辅因子分别为8和4,因此小阶输入点将消除来自另一方私钥的任何贡献。这种情况可以通过检查全零输出来检测,实现可能会这样做,如第6节所述。然而,大量现有的实现并没有做到这一点。

Designers using these curves should be aware that for each public key, there are several publicly computable public keys that are equivalent to it, i.e., they produce the same shared secrets. Thus using a public key as an identifier and knowledge of a shared secret as proof of ownership (without including the public keys in the key derivation) might lead to subtle vulnerabilities.

使用这些曲线的设计者应该意识到,对于每个公钥,都有几个与之等价的可公开计算的公钥,即它们产生相同的共享秘密。因此,使用公钥作为标识符和共享秘密的知识作为所有权证明(在密钥派生中不包括公钥)可能会导致微妙的漏洞。

Designers should also be aware that implementations of these curves might not use the Montgomery ladder as specified in this document, but could use generic, elliptic-curve libraries instead. These implementations could reject points on the twist and could reject non-minimal field elements. While not recommended, such implementations will interoperate with the Montgomery ladder specified here but may be trivially distinguishable from it. For example, sending a non-canonical value or a point on the twist may cause such implementations to produce an observable error while an implementation that follows the design in this text would successfully produce a shared key.

设计人员还应注意,这些曲线的实现可能不会使用本文档中指定的蒙哥马利阶梯,而是可以使用通用的椭圆曲线库。这些实现可以拒绝扭曲上的点,也可以拒绝非最小字段元素。虽然不推荐使用,但此类实现将与此处指定的Montgomery梯形图互操作,但可能与它有细微的区别。例如,发送非规范值或扭曲点可能会导致此类实现产生可观察的错误,而遵循本文设计的实现将成功生成共享密钥。

8. References
8. 工具书类
8.1. Normative References
8.1. 规范性引用文件

[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, <http://www.rfc-editor.org/info/rfc2119>.

[RFC2119]Bradner,S.,“RFC中用于表示需求水平的关键词”,BCP 14,RFC 2119,DOI 10.17487/RFC2119,1997年3月<http://www.rfc-editor.org/info/rfc2119>.

8.2. Informative References
8.2. 资料性引用

[brainpool] ECC Brainpool, "ECC Brainpool Standard Curves and Curve Generation", October 2005, <http://www.ecc-brainpool.org/download/ Domain-parameters.pdf>.

[brainpool]ECC brainpool,“ECC brainpool标准曲线和曲线生成”,2005年10月<http://www.ecc-brainpool.org/download/ 域参数.pdf>。

[bruteforce] Bernstein, D., "Understanding brute force", April 2005, <http://cr.yp.to/snuffle/bruteforce-20050425.pdf>.

[bruteforce]Bernstein,D.,“理解暴力”,2005年4月<http://cr.yp.to/snuffle/bruteforce-20050425.pdf>.

[curve25519] Bernstein, D., "Curve25519: new Diffie-Hellman speed records", 2006, <http://www.iacr.org/cryptodb/archive/2006/ PKC/3351/3351.pdf>.

[Curve2519]Bernstein,D.,“curve25519:新的Diffie-Hellman速度记录”,2006年<http://www.iacr.org/cryptodb/archive/2006/ PKC/3351/3351.pdf>。

[ed25519] Bernstein, D., Duif, N., Lange, T., Schwabe, P., and B. Yang, "High-Speed High-Security Signatures", 2011, <http://link.springer.com/ chapter/10.1007/978-3-642-23951-9_9>.

[ed25519]Bernstein,D.,Duif,N.,Lange,T.,Schwabe,P.,和B.Yang,“高速高安全性签名”,2011年<http://link.springer.com/ 第/10.1007/978-3-642-23951-9章>。

[goldilocks] Hamburg, M., "Ed448-Goldilocks, a new elliptic curve", 2015, <http://eprint.iacr.org/2015/625.pdf>.

[金发姑娘]汉堡,M.,“Ed448金发姑娘,一条新的椭圆曲线”,2015年<http://eprint.iacr.org/2015/625.pdf>.

[montgomery] Montgomery, P., "Speeding the Pollard and Elliptic Curve Methods of Factorization", January 1987, <http://www.ams.org/journals/mcom/1987-48-177/ S0025-5718-1987-0866113-7/S0025-5718-1987-0866113-7.pdf>.

[montgomery]montgomery,P.,“加速因子分解的Pollard和椭圆曲线方法”,1987年1月<http://www.ams.org/journals/mcom/1987-48-177/ S0025-5718-1987-0866113-7/S0025-5718-1987-0866113-7.pdf>。

[NIST] National Institute of Standards, "Recommended Elliptic Curves for Federal Government Use", July 1999, <http://csrc.nist.gov/groups/ST/toolkit/documents/dss/ NISTReCur.pdf>.

[NIST]国家标准研究所,“联邦政府使用的建议椭圆曲线”,1999年7月<http://csrc.nist.gov/groups/ST/toolkit/documents/dss/ nistrucr.pdf>。

[reducing] Menezes, A., Okamoto, T., and S. Vanstone, "Reducing elliptic curve logarithms to logarithms in a finite field", DOI 10.1109/18.259647, 1993, <http://ieeexplore.ieee.org/xpl/ articleDetails.jsp?arnumber=259647>.

[还原]Menezes,A.,Okamoto,T.,和S.Vanstone,“将椭圆曲线对数还原为有限域中的对数”,DOI 10.1109/18.2596471993<http://ieeexplore.ieee.org/xpl/ articleDetails.jsp?arnumber=259647>。

[RFC6090] McGrew, D., Igoe, K., and M. Salter, "Fundamental Elliptic Curve Cryptography Algorithms", RFC 6090, DOI 10.17487/RFC6090, February 2011, <http://www.rfc-editor.org/info/rfc6090>.

[RFC6090]McGrew,D.,Igoe,K.,和M.Salter,“基本椭圆曲线密码算法”,RFC 6090,DOI 10.17487/RFC6090,2011年2月<http://www.rfc-editor.org/info/rfc6090>.

[safecurves] Bernstein, D. and T. Lange, "SafeCurves: choosing safe curves for elliptic-curve cryptography", Oct 2013, <http://safecurves.cr.yp.to/>.

[安全曲线]Bernstein,D.和T.Lange,“安全曲线:为椭圆曲线加密选择安全曲线”,2013年10月<http://safecurves.cr.yp.to/>.

[satoh] Satoh, T. and K. Araki, "Fermat quotients and the polynomial time discrete log algorithm for anomalous elliptic curves", 1998.

[satoh]satoh,T.和K.Araki,“Fermat商和异常椭圆曲线的多项式时间离散对数算法”,1998年。

[SEC1] Certicom Research, "SEC 1: Elliptic Curve Cryptography", September 2000, <http://www.secg.org/sec1-v2.pdf>.

[SEC1]Certicom Research,“第1节:椭圆曲线密码术”,2000年9月<http://www.secg.org/sec1-v2.pdf>.

[semaev] Semaev, I., "Evaluation of discrete logarithms on some elliptic curves", 1998, <http://www.ams.org/journals/ mcom/1998-67-221/S0025-5718-98-00887-4/ S0025-5718-98-00887-4.pdf>.

[semaev]semaev,I.,“某些椭圆曲线上离散对数的计算”,1998年<http://www.ams.org/journals/ mcom/1998-67-221/S0025-5718-98-00887-4/S0025-5718-98-00887-4.pdf>。

[smart] Smart, N., "The Discrete Logarithm Problem on Elliptic Curves of Trace One", 1999, <http://www.hpl.hp.com/techreports/97/HPL-97-128.pdf>.

[smart]smart,N.,“迹1椭圆曲线上的离散对数问题”,1999年<http://www.hpl.hp.com/techreports/97/HPL-97-128.pdf>.

Appendix A. Deterministic Generation
附录A.确定性生成

This section specifies the procedure that was used to generate the above curves; specifically, it defines how to generate the parameter A of the Montgomery curve y^2 = x^3 + A*x^2 + x. This procedure is intended to be as objective as can reasonably be achieved so that it's clear that no untoward considerations influenced the choice of curve. The input to this process is p, the prime that defines the underlying field. The size of p determines the amount of work needed to compute a discrete logarithm in the elliptic curve group, and choosing a precise p depends on many implementation concerns. The performance of the curve will be dominated by operations in GF(p), so carefully choosing a value that allows for easy reductions on the intended architecture is critical. This document does not attempt to articulate all these considerations.

本节规定了用于生成上述曲线的程序;具体来说,它定义了如何生成蒙哥马利曲线y^2=x^3+A*x^2+x的参数A。该程序旨在尽可能客观地合理实现,以便明确无不利因素影响曲线的选择。这个过程的输入是p,它是定义基础字段的素数。p的大小决定了在椭圆曲线组中计算离散对数所需的工作量,选择精确的p取决于许多实现问题。曲线的性能将由GF(p)中的操作控制,因此仔细选择一个允许在预期架构上轻松减少的值是至关重要的。本文件并不试图阐明所有这些考虑因素。

The value (A-2)/4 is used in several of the elliptic curve point arithmetic formulas. For simplicity and performance reasons, it is beneficial to make this constant small, i.e., to choose A so that (A-2) is a small integer that is divisible by four.

值(A-2)/4用于几个椭圆曲线点算术公式中。出于简单性和性能方面的原因,将该常数设置为小值是有益的,即选择A,使(A-2)是一个可被4整除的小整数。

For each curve at a specific security level:

对于特定安全级别的每条曲线:

1. The trace of Frobenius MUST NOT be in {0, 1} in order to rule out the attacks described in [smart], [satoh], and [semaev], as in [brainpool] and [safecurves].

1. 为了排除[smart]、[satoh]和[semaev]中描述的攻击,Frobenius的痕迹不能在{0,1}中,如[brainpool]和[safecurves]中所述。

2. MOV Degree [reducing]: the embedding degree MUST be greater than (order - 1) / 100, as in [brainpool] and [safecurves].

2. MOV阶数[减少]:嵌入阶数必须大于(阶数-1)/100,如[brainpool]和[safecurves]。

3. CM Discriminant: discriminant D MUST be greater than 2^100, as in [safecurves].

3. CM鉴别器:鉴别器D必须大于2^100,如[safecurves]中所示。

A.1. p = 1 mod 4
A.1. p=1模4

For primes congruent to 1 mod 4, the minimal cofactors of the curve and its twist are either {4, 8} or {8, 4}. We choose a curve with the latter cofactors so that any algorithms that take the cofactor into account don't have to worry about checking for points on the twist, because the twist cofactor will be the smaller of the two.

对于与1模4全等的素数,曲线及其扭曲的最小余因子是{4,8}或{8,4}。我们选择一条带有后一个余因子的曲线,这样任何考虑余因子的算法都不必担心检查扭曲上的点,因为扭曲余因子将是两者中较小的一个。

To generate the Montgomery curve, we find the minimal, positive A value such that A > 2 and (A-2) is divisible by four and where the cofactors are as desired. The find1Mod4 function in the following Sage script returns this value given p:

为了生成蒙哥马利曲线,我们找到最小的正A值,使得A>2和(A-2)可以被4整除,并且辅因子是所需的。以下Sage脚本中的find1Mod4函数返回给定p的该值:

   <CODE BEGINS>
   def findCurve(prime, curveCofactor, twistCofactor):
       F = GF(prime)
        
   <CODE BEGINS>
   def findCurve(prime, curveCofactor, twistCofactor):
       F = GF(prime)
        
       for A in xrange(3, int(1e9)):
           if (A-2) % 4 != 0:
             continue
        
       for A in xrange(3, int(1e9)):
           if (A-2) % 4 != 0:
             continue
        

try: E = EllipticCurve(F, [0, A, 0, 1, 0]) except: continue

try:E=EllipticCurve(F[0,A,0,1,0]),除了:continue

           groupOrder = E.order()
           twistOrder = 2*(prime+1)-groupOrder
        
           groupOrder = E.order()
           twistOrder = 2*(prime+1)-groupOrder
        
           if (groupOrder % curveCofactor == 0 and
               is_prime(groupOrder // curveCofactor) and
               twistOrder % twistCofactor == 0 and
               is_prime(twistOrder // twistCofactor)):
               return A
        
           if (groupOrder % curveCofactor == 0 and
               is_prime(groupOrder // curveCofactor) and
               twistOrder % twistCofactor == 0 and
               is_prime(twistOrder // twistCofactor)):
               return A
        
   def find1Mod4(prime):
       assert((prime % 4) == 1)
       return findCurve(prime, 8, 4)
   <CODE ENDS>
        
   def find1Mod4(prime):
       assert((prime % 4) == 1)
       return findCurve(prime, 8, 4)
   <CODE ENDS>
        

Generating a curve where p = 1 mod 4

生成p=1 mod 4的曲线

A.2. p = 3 mod 4
A.2. p=3模4

For a prime congruent to 3 mod 4, both the curve and twist cofactors can be 4, and this is minimal. Thus, we choose the curve with these cofactors and minimal, positive A such that A > 2 and (A-2) is divisible by four. The find3Mod4 function in the following Sage script returns this value given p:

对于3模4的素数全等式,曲线和扭曲余子都可以是4,这是最小的。因此,我们选择具有这些辅因子和最小正A的曲线,使得A>2和(A-2)可被4整除。以下Sage脚本中的find3Mod4函数在给定p时返回此值:

   <CODE BEGINS>
   def find3Mod4(prime):
       assert((prime % 4) == 3)
       return findCurve(prime, 4, 4)
   <CODE ENDS>
        
   <CODE BEGINS>
   def find3Mod4(prime):
       assert((prime % 4) == 3)
       return findCurve(prime, 4, 4)
   <CODE ENDS>
        

Generating a curve where p = 3 mod 4

生成p=3 mod 4的曲线

A.3. Base Points
A.3. 基点

The base point for a curve is the point with minimal, positive u value that is in the correct subgroup. The findBasepoint function in the following Sage script returns this value given p and A:

曲线的基点是在正确的子组中具有最小正u值的点。以下Sage脚本中的findBasepoint函数在给定p和A的情况下返回此值:

   <CODE BEGINS>
   def findBasepoint(prime, A):
       F = GF(prime)
       E = EllipticCurve(F, [0, A, 0, 1, 0])
        
   <CODE BEGINS>
   def findBasepoint(prime, A):
       F = GF(prime)
       E = EllipticCurve(F, [0, A, 0, 1, 0])
        
       for uInt in range(1, 1e3):
         u = F(uInt)
         v2 = u^3 + A*u^2 + u
         if not v2.is_square():
           continue
         v = v2.sqrt()
        
       for uInt in range(1, 1e3):
         u = F(uInt)
         v2 = u^3 + A*u^2 + u
         if not v2.is_square():
           continue
         v = v2.sqrt()
        
         point = E(u, v)
         pointOrder = point.order()
         if pointOrder > 8 and pointOrder.is_prime():
           return point
   <CODE ENDS>
        
         point = E(u, v)
         pointOrder = point.order()
         if pointOrder > 8 and pointOrder.is_prime():
           return point
   <CODE ENDS>
        

Generating the base point

生成基点

Acknowledgements

致谢

This document is the result of a combination of draft-black-rpgecc-01 and draft-turner-thecurve25519function-01. The following authors of those documents wrote much of the text and figures but are not listed as authors on this document: Benjamin Black, Joppe W. Bos, Craig Costello, Patrick Longa, Michael Naehrig, Watson Ladd, and Rich Salz.

本文件是draft-black-rpgecc-01和draft-turner-thecurve25519function-01组合的结果。这些文件的以下作者撰写了大部分文本和数字,但未被列为本文件的作者:本杰明·布莱克、约佩·博斯、克雷格·科斯特洛、帕特里克·隆加、迈克尔·纳赫里格、沃森·拉德和里奇·萨尔兹。

The authors would also like to thank Tanja Lange, Rene Struik, Rich Salz, Ilari Liusvaara, Deirdre Connolly, Simon Josefsson, Stephen Farrell, Georg Nestmann, Trevor Perrin, and John Mattsson for their reviews and contributions.

作者还要感谢Tanja Lange、Rene Struik、Rich Salz、Ilari Liusvaara、Deirdre Connolly、Simon Josefsson、Stephen Farrell、Georg Nestmann、Trevor Perrin和John Mattsson的评论和贡献。

The X25519 function was developed by Daniel J. Bernstein in [curve25519].

X25519函数由Daniel J.Bernstein在[curve25519]中开发。

Authors' Addresses

作者地址

Adam Langley Google 345 Spear Street San Francisco, CA 94105 United States

Adam Langley Google 345枪街旧金山,加州94105美国

   Email: agl@google.com
        
   Email: agl@google.com
        

Mike Hamburg Rambus Cryptography Research 425 Market Street, 11th Floor San Francisco, CA 94105 United States

迈克汉堡RAMBUS密码学研究425市场街,第十一楼旧金山,CA 94105美国

   Email: mike@shiftleft.org
        
   Email: mike@shiftleft.org
        

Sean Turner sn3rd

肖恩·特纳

   Email: sean@sn3rd.com
        
   Email: sean@sn3rd.com