RFC8032
RFC8032
Josefsson
Request for Comments: 8032 SJD AB
Category: Informational I. Liusvaara
ISSN: 2070-1721 Independent
January 2017
Abstract
Copyright Notice
Copyright (c) 2017 IETF Trust and the persons identified as the
document authors. All rights reserved.
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3
2. Notation and Conventions . . . . . . . . . . . . . . . . . . 4
3. EdDSA Algorithm . . . . . . . . . . . . . . . . . . . . . . . 5
3.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2. Keys . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3. Sign . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.4. Verify . . . . . . . . . . . . . . . . . . . . . . . . . 8
4. PureEdDSA, HashEdDSA, and Naming . . . . . . . . . . . . . . 8
5. EdDSA Instances . . . . . . . . . . . . . . . . . . . . . . . 9
5.1. Ed25519ph, Ed25519ctx, and Ed25519 . . . . . . . . . . . 9
5.1.1. Modular Arithmetic . . . . . . . . . . . . . . . . . 10
5.1.2. Encoding . . . . . . . . . . . . . . . . . . . . . . 10
5.1.3. Decoding . . . . . . . . . . . . . . . . . . . . . . 11
5.1.4. Point Addition . . . . . . . . . . . . . . . . . . . 11
5.1.5. Key Generation . . . . . . . . . . . . . . . . . . . 13
5.1.6. Sign . . . . . . . . . . . . . . . . . . . . . . . . 13
5.1.7. Verify . . . . . . . . . . . . . . . . . . . . . . . 14
5.2. Ed448ph and Ed448 . . . . . . . . . . . . . . . . . . . . 15
5.2.1. Modular Arithmetic . . . . . . . . . . . . . . . . . 16
5.2.2. Encoding . . . . . . . . . . . . . . . . . . . . . . 16
5.2.3. Decoding . . . . . . . . . . . . . . . . . . . . . . 16
5.2.4. Point Addition . . . . . . . . . . . . . . . . . . . 17
5.2.5. Key Generation . . . . . . . . . . . . . . . . . . . 18
5.2.6. Sign . . . . . . . . . . . . . . . . . . . . . . . . 19
5.2.7. Verify . . . . . . . . . . . . . . . . . . . . . . . 19
6. Ed25519 Python Illustration . . . . . . . . . . . . . . . . . 20
7. Test Vectors . . . . . . . . . . . . . . . . . . . . . . . . 23
7.1. Test Vectors for Ed25519 . . . . . . . . . . . . . . . . 24
7.2. Test Vectors for Ed25519ctx . . . . . . . . . . . . . . . 27
7.3. Test Vectors for Ed25519ph . . . . . . . . . . . . . . . 30
7.4. Test Vectors for Ed448 . . . . . . . . . . . . . . . . . 30
7.5. Test Vectors for Ed448ph . . . . . . . . . . . . . . . . 38
8. Security Considerations . . . . . . . . . . . . . . . . . . . 40
8.1. Side-Channel Leaks . . . . . . . . . . . . . . . . . . . 40
8.2. Randomness Considerations . . . . . . . . . . . . . . . . 40
8.3. Use of Contexts . . . . . . . . . . . . . . . . . . . . . 41
8.4. Signature Malleability . . . . . . . . . . . . . . . . . 41
8.5. Choice of Signature Primitive . . . . . . . . . . . . . . 41
8.6. Mixing Different Prehashes . . . . . . . . . . . . . . . 42
8.7. Signing Large Amounts of Data at Once . . . . . . . . . . 42
8.8. Multiplication by Cofactor in Verification . . . . . . . 43
8.9. Use of SHAKE256 as a Hash Function . . . . . . . . . . . 43
9. References . . . . . . . . . . . . . . . . . . . . . . . . . 43
9.1. Normative References . . . . . . . . . . . . . . . . . . 43
9.2. Informative References . . . . . . . . . . . . . . . . . 44
1. Introduction
4. EdDSA uses small public keys (32 or 57 bytes) and signatures (64
or 114 bytes) for Ed25519 and Ed448, respectively;
5. The formulas are "complete", i.e., they are valid for all points
on the curve, with no exceptions. This obviates the need for
EdDSA to perform expensive point validation on untrusted public
values; and
i/j Division of i by j
Bit strings are converted to octet strings by taking bits from left
to right, packing those from the least significant bit of each octet
to the most significant bit, and moving to the next octet when each
octet fills up. The conversion from octet string to bit string is
the reverse of this process; for example, the 16-bit bit string
Little-endian encoding into bits places bits from left to right and
from least significant to most significant. If combined with
bit-string-to-octet-string conversion defined above, this results in
little-endian encoding into octets (if length is not a multiple of 8,
the most significant bits of the last octet remain unused).
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 [RFC2119].
3. EdDSA Algorithm
10. An odd prime L such that [L]B = 0 and 2^c * L = #E. The number
#E (the number of points on the curve) is part of the standard
data provided for an elliptic curve E, or it can be computed as
cofactor * order.
One misinterpretation I had: most implementations do not prehash!
11. A "prehash" function PH. PureEdDSA means EdDSA where PH is the
identity function, i.e., PH(M) = M. HashEdDSA means EdDSA where
PH generates a short output, no matter how long the message is;
for example, PH(M) = SHA-512(M).
Points on the curve form a group under addition, (x3, y3) = (x1, y1)
+ (x2, y2), with the formulas
A non-square element ‘d’ of
x1 * y2 + x2 * y1 GF(p) y1 * y2 - a * x1 * x2
x3 = --------------------------, y3 = ---------------------------
1 + d * x1 * x2 * y1 * y2 1 - d * x1 * x2 * y1 * y2
A non-zero square element
The neutral element in the group is (0,1).
‘a’ of GF(p)
Unlike many other curves used for cryptographic applications, these The first
formulas are "complete"; they are valid for all points on the curve, half of the
with no exceptions. In particular, the denominators are non-zero for hash is used
all input points. to create the
secret
There are more efficient formulas, which are still complete, that use
homogeneous coordinates to avoid the expensive modulo p inversions. scalar. The
See [Faster-ECC] and [Edwards-revisited]. second half
of the hash
3.1. Encoding is used
during
An integer 0 < S < L - 1 is encoded in little-endian form as a b-bit signing. This
string ENC(S). is why
Ed25519 used
An element (x,y) of E is encoded as a b-bit string called ENC(x,y), sha-512
which is the (b-1)-bit encoding of y concatenated with one bit that instead of
is 1 if x is negative and 0 if x is not negative.
sha-256. One
The encoding of GF(p) is used to define "negative" elements of GF(p): operation
specifically, x is negative if the (b-1)-bit encoding of x is instead of
lexicographically larger than the (b-1)-bit encoding of -x. two for more
bits to
3.2. Keys incorporate
s: secret scalar used in elliptic curve ops in this alg.
An EdDSA private key is a b-bit string k. Let the hash H(k) = I’ll call the
k: the true (h_0, h_1, ..., h_(2b-1)) determine an integer s, which is 2^n plus
key contents the sum of m = 2^i * h_i for all integer i, c <= i < n. Let s second half a
which then “key tag”.
determine the multiple A = [s]B. The EdDSA public key is ENC(A).
derives s the The bits h_b, ..., h_(2b-1) are used below during signing. c: cofactor, 2 or 3
secret scalar This is a convoluted way of saying take only the for a 4 or 8
highest bit, minus one “n”, to the lowest bits, except cofactored curve
for the cofactor “c” respectively
Josefsson & Liusvaara Informational [Page 7]
This appears to say the hash function returns a bit string
of 2b bits long (it is zero indexed)
The secret key ‘k’ is hashed first (with sha-512) and then clamped.
‘s’ the secret scalar is the clamped value used in equations in the future.
‘A’ the public key is calculated from ‘s’ rather than ‘k’
RFC 8032 EdDSA: Ed25519 and Ed448 January 2017
The Ed25519 we know and love DOES The purpose of “r”
is a deterministic
NOT use pre-hashing, hence PH is challenge for the
3.3. Sign
“r” is not crossed out as a no-op function signature. It
clamped like The EdDSA signature of a message M under a private key k is defined happens to include
the public aux secret info
as the PureEdDSA signature of PH(M). In other words, EdDSA simply
(the “key tag”
key. “r” is uses PureEdDSA to sign PH(M). which is not
the hash of Small “s” is the secret scalar public) which
the “key The PureEdDSA signature of a message M under a private key k is the falsely suggests
tag” and the 2*b-bit string ENC(R) || ENC(S). R and S are derived as follows. that R is bound to
message “M” First define r = H(h_b || ... || h_(2b-1) || M) interpreting 2*b-bit the private key and
strings in little-endian form as integers in {0, 1, ..., 2^(2*b) - message.
1}. Let R = [r]B and S = (r + H(ENC(R) || ENC(A) || PH(M)) * s) mod Given the verifier
L. The s used here is from the previous section. has no means to
verify the
deterministic “r”
3.4. Verify
is bound to the
E: the edwards curve S mod L key, use of the
ENC(?): To verify a PureEdDSA signature ENC(R) || ENC(S) on a message M under “key tag” is a
a public key ENC(A), proceed as follows. Parse the inputs so that A distraction to the
little- and R are elements of E, and S is a member of the set {0, 1, ..., security properties
endian L-1}. Compute h = H(ENC(R) || ENC(A) || M), and check the group of this alg.
encoding equation [2^c * S] B = 2^c * R + [2^c * h] A in E. The signature is
rejected if parsing fails (including S being out of range) or if the
group equation does not hold. c is cofactor, 2 or 3 (for Why a deterministic challenge “r”
4 or 8 respectively) ECDSA implementations were broken
EdDSA verification for a message M is defined as PureEdDSA they had bad randomness. This aff
verification for PH(M). Sony’s PS3 console.
It is important
4. PureEdDSA, HashEdDSA, and Naming that each distinct
message under the
One of the parameters of the EdDSA algorithm is the "prehash" same private key
function. This may be the identity function, resulting in an have a different
algorithm called PureEdDSA, or a collision-resistant hash function challenge so that
such as SHA-512, resulting in an algorithm called HashEdDSA. the secret key
cannot be
Choosing which variant to use depends on which property is deemed to extracted. If the
be more important between 1) collision resilience and 2) a single- same challenge “r”
is signed twice
pass interface for creating signatures. The collision resilience
with different
property means EdDSA is secure even if it is feasible to compute messages (or
collisions for the hash function. The single-pass interface property possibly an
means that only one pass over the input message is required to create unrelated public
a signature. PureEdDSA requires two passes over the input. Many key), the secret
existing APIs, protocols, and environments assume digital signature scalar “s” can be
algorithms only need one pass over the input and may have API or recovered (but not
bandwidth concerns supporting anything else. One-shot “k” the secret key)
with some math.
Note that single-pass verification is not possible with most uses of
signatures, no matter which signature algorithm is chosen. This is
because most of the time, one can’t process the message until the
signature is validated, which needs a pass on the entire message.
5. EdDSA Instances
+-----------+-------------------------------------------------------+
| Parameter | Value |
+-----------+-------------------------------------------------------+
| p | p of edwards25519 in [RFC7748] (i.e., 2^255 - 19) |
| b | 256 |
| encoding | 255-bit little-endian encoding of {0, 1, ..., p-1} |
| of GF(p) | |
| H(x) | SHA-512(dom2(phflag,context)||x) [RFC6234] |
| c | base 2 logarithm of cofactor of edwards25519 in |
| | [RFC7748] (i.e., 3) |
| n | 254 |
| d | d of edwards25519 in [RFC7748] (i.e., -121665/121666 |
| | = 370957059346694393431380835087545651895421138798432 |
| | 19016388785533085940283555) |
| a | -1 |
| B | (X(P),Y(P)) of edwards25519 in [RFC7748] (i.e., (1511 |
| | 22213495354007725011514095885315114540126930418572060 |
| | 46113283949847762202, 4631683569492647816942839400347 |
| | 5163141307993866256225615783033603165251855960)) |
| L | order of edwards25519 in [RFC7748] (i.e., |
| | 2^252+27742317777372353535851937790883648493). |
| PH(x) | x (i.e., the identity function) |
+-----------+-------------------------------------------------------+
For Ed25519ph, phflag=1 and PH is SHA512 instead. That is, the input
is hashed using SHA-512 before signing with Ed25519.
5.1.2. Encoding
All values are coded as octet strings, and integers are coded using
little-endian convention, i.e., a 32-octet string h h[0],...h[31]
represents the integer h[0] + 2^8 * h[1] + ... + 2^248 * h[31].
A curve point (x,y), with coordinates in the range 0 <= x,y < p, is
coded as follows. First, encode the y-coordinate as a little-endian
string of 32 octets. The most significant bit of the final octet is
always zero. To form the encoding of the point, copy the least
significant bit of the x-coordinate to the most significant bit of
the final octet.
5.1.3. Decoding
(p+3)/8 3 (p-5)/8
x = (u/v) = u v (u v^7) (mod p)
4. Finally, use the x_0 bit to select the right square root. If
x = 0, and x_0 = 1, decoding fails. Otherwise, if x_0 != x mod
2, set x <-- p - x. Return the decoded point (x,y).
A = (Y1-X1)*(Y2-X2)
B = (Y1+X1)*(Y2+X2)
C = T1*2*d*T2
D = Z1*2*Z2
E = B-A
F = D-C
G = D+C
H = B+A
X3 = E*F
Y3 = G*H
T3 = E*H
Z3 = F*G
A = X1^2
B = Y1^2
C = 2*Z1^2
H = A+B
E = H-(X1+Y1)^2
G = A-B
F = C+G
X3 = E*F
Y3 = G*H
T3 = E*H
Z3 = F*G
1. Hash the 32-byte private key using SHA-512, storing the digest in
a 64-octet large buffer, denoted h. Only the lower 32 bytes are
used for generating the public key.
Clamp the buffer Remember c is 3
2. Prune the buffer: The lowest three bits of the first octet are
cleared, the highest bit of the last octet is cleared, and the
second highest bit of the last octet is set. Highest bit for timing
attack resistance
3. Interpret the buffer as the little-endian integer, forming a
secret scalar s. Perform a fixed-base scalar multiplication
[s]B.
5.1.6. Sign
1. Hash the private key, 32 octets, using SHA-512. Let h denote the
resulting digest. Construct the secret scalar s from the first
half of the digest, and the corresponding public key A, as
described in the previous section. Let prefix denote the second
half of the hash digest, h[32],...,h[63].
5.1.7. Verify