]>
SPAKE2, a PasswordAuthenticated Key Exchange
Akamai Technologies
watsonbladd@gmail.com
Crypto Forum
This document describes SPAKE2, which is a protocol for two
parties that share a password to derive a strong shared key
without disclosing the password. This method is compatible with
any group, is computationally efficient, and has a
security proof. This document predated the Crypto Forum
Research Group (CFRG) passwordauthenticated key exchange (PAKE) competition,
and it was not selected; however, given existing use of variants
in Kerberos and other applications, it was felt that publication was
beneficial.
Applications that need a symmetric PAKE, but are unable to hash onto an
elliptic curve at execution time, can use SPAKE2. This document is a product of the Crypto Forum Research Group in the Internet Research Task Force (IRTF).
Introduction
This document describes SPAKE2, which is a means for two parties that
share a password to derive a strong shared key without
disclosing the password. This passwordbased key exchange
protocol is compatible with any group (requiring only a
scheme to map a random input of a fixed length per group to a random
group element), is computationally efficient, and has a security
proof. Predetermined parameters for a selection of commonly
used groups are also provided for use by other protocols.
SPAKE2 was not selected as the result of the CFRG PAKE selection
competition. However, given existing use of variants in Kerberos and
other applications, it was felt that publication was beneficial. This RFC
represents the individual opinion(s) of one or more members of
the Crypto Forum Research Group of the IRTF.
Many of these applications predated methods to hash to
elliptic curves being available or predated the publication of
the PAKEs that were chosen as an outcome of the PAKE selection
competition. In cases where a symmetric PAKE is needed and
hashing onto an elliptic curve at protocol execution time is not
available, SPAKE2 is useful.
Requirements Notation
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED",
"MAY", and "OPTIONAL" in this document are to be interpreted as
described in BCP 14
when, and only when, they appear in all capitals, as shown here.
Definition of SPAKE2
Protocol Flow
SPAKE2 is a tworound protocol, wherein the first round establishes a shared secret
between A and B, and the second round serves as key confirmation. Prior to invocation, A and B are provisioned with
information, such as the input password needed to run the protocol. We assume that the roles of A and B
are agreed upon by both sides: A goes first and uses M, and B goes second and uses N. If this assignment
of roles is not possible, a symmetric variant MUST be used, as described later . For instance, A may be the client when
using TCP or TLS as an underlying protocol, and B may be the server. Most protocols have such a distinction.
During the first round, A sends a public value pA to B, and
B responds with its own public value pB. Both A and B then
derive a shared secret used to produce encryption and
authentication keys. The latter are used during the second
round for key confirmation. ( details
the key derivation and confirmation steps.) In particular, A
sends a key confirmation message cA to B, and B responds
with its own key confirmation message cB. A MUST NOT
consider the protocol complete until it receives and
verifies cB. Likewise, B MUST NOT consider the protocol
complete until it receives and verifies cA.
This sample flow is shown below.

 pB  (compute pB)
<
 
 (derive secrets) 
 
(compute cA)  cA 
>
 cB  (compute cB)
  (check cA)
<
(check cB)  
]]>
Setup
Let G be a group in which the gap DiffieHellman (GDH)
problem is hard. Suppose G has order p*h, where p is a large prime and
h will be called the cofactor. Let I be the unit element in
G, e.g., the point at infinity if G is an elliptic curve group. We denote the
operations in the group additively. We assume there is a representation of
elements of G as byte strings: common choices would be SEC1
uncompressed or compressed for elliptic curve groups or bigendian integers of a fixed (pergroup) length for prime field DH. Applications MUST
specify this encoding, typically by referring to the document defining the group.
We fix two elements, M and N, in
the primeorder subgroup of G, as defined in of this
document for common groups, as well as generator P of the (large)
primeorder subgroup of G. In the case of a composite order group,
we will work in the quotient group. For common groups used in this document,
P is specified in the document defining the group, so we do not repeat it here.
For elliptic curves other than the ones in this document, the methods described in
SHOULD be used to generate M and N, e.g., via
M = hash_to_curve("M SPAKE2 seed OID x") and N = hash_to_curve("N SPAKE2 seed OID x"), where
x is an OID for the curve. Applications MAY include a domain separation tag (DST) in this step, as specified
in , though this is not required.
 denotes concatenation of byte strings. We also let len(S) denote the
length of a string in bytes, represented as an eightbyte littleendian number. Finally, let nil represent an empty string, i.e.,
len(nil) = 0. Text strings in double quotes are treated as their ASCII encodings
throughout this document.
KDF(ikm, salt, info, L) is a keyderivation function that
takes as input a salt, input keying material (IKM), an
info string, and derived key length L to derive a
cryptographic key of length L. MAC(key, message) is a Message
Authentication Code algorithm that takes a secret key and
message as input to produce an output. Let Hash be a hash
function from arbitrary strings to bit strings of a fixed
length that is at least 256 bits long. Common choices for Hash are
SHA256 or SHA512 . Let MHF be a
memoryhard hash function designed to slow down bruteforce
attackers. Scrypt is a common example
of this function. The output length of MHF matches that of
Hash. Parameter selection for MHF is out of scope for this
document. specifies variants of
KDF, MAC, and Hash that are suitable for use with the protocols
contained herein.
Let A and B be two parties. A and B may also have digital
representations of the parties' identities, such as Media Access Control addresses
or other names (hostnames, usernames, etc.). A and B may share additional
authenticated data (AAD) of a length that is at most 2^{16}  128 bits and separate
from their identities, which they may want to include in the protocol execution.
One example of AAD is a list of supported protocol versions if SPAKE2 were
used in a higherlevel protocol that negotiates use of a particular PAKE. Including this list would ensure that both parties agree upon the
same set of supported protocols and therefore prevents downgrade attacks. We also assume A and B share integer w;
typically, w = MHF(pw) mod p for a usersupplied password, pw.
Standards, such as , suggest taking mod p of a
hash value that is 64 bits longer than that needed to represent p to remove
statistical bias introduced by the modulation. Protocols using this specification MUST define
the method used to compute w. In some cases, it may be necessary to carry out various
forms of normalization of the password before hashing .
The hashing algorithm SHOULD be an MHF so as to slow down bruteforce
attackers.
SPAKE2
To begin, A picks x randomly and uniformly from the integers in [0,p)
and calculates X=x*P and pA=w*M+X. Then, it transmits pA to B.
B selects y randomly and uniformly from the integers in [0,p) and calculates
Y=y*P and pB=w*N+Y. Then, it transmits pB to A.
Both A and B calculate group element K. A calculates it
as h*x*(pBw*N), while B calculates it as h*y*(pAw*M). A knows pB
because it has received it, and likewise B knows pA. The
multiplication by h prevents small subgroup confinement
attacks by computing a unique value in the quotient
group.
K is a shared value, though it MUST NOT be used or output as a shared secret
from the protocol. Both A and B must derive two additional shared secrets from
the protocol transcript, which includes K.
This use of the transcript ensures any manipulation of the messages
sent is reflected in the keys. The transcript TT is encoded as follows:
Here, w is encoded as a bigendian number padded to the length of p. This representation
prevents timing attacks that otherwise would reveal the length of w. len(w) is thus a constant for a given group.
We include it for consistency.
If an identity is absent, it is encoded as a zerolength string.
This MUST only be done for applications in which identities are implicit. Otherwise,
the protocol risks unknown keyshare attacks, where both sides of a connection disagree over who is authenticated.
Upon completion of this protocol, A and B compute shared secrets Ke, KcA, and KcB, as
specified in . A MUST send B a key confirmation message
so that both parties agree upon these shared secrets. The confirmation message cA
is computed as a MAC over the protocol transcript TT, using KcA as follows:
cA = MAC(KcA, TT). Similarly, B MUST send A a confirmation message using a MAC that is
computed equivalently, except with the use of KcB. Key confirmation verification
requires computing cA (or cB, respectively) and checking for equality against that which was received.
Key Schedule and Key Confirmation
The protocol transcript TT, as defined in , is unique and secret to A and B (though it contains some substrings that are not secret).
Both parties use TT to derive shared symmetric secrets Ke and Ka as Ke  Ka = Hash(TT), with Ke = Ka. The length of each key is equal to half of the digest output, e.g., 128 bits for SHA256. Keys MUST be at least
128 bits in length.
Both endpoints use Ka to derive subsequent MAC keys for key confirmation messages.
Specifically, KcA and KcB are the MAC keys used by A and B, respectively.
A and B compute them as KcA  KcB = KDF(Ka, nil, "ConfirmationKeys"  AAD, L), where AAD
is the associated data given to each endpoint or AAD is nil if none was provided.
The length of each of KcA and KcB is equal to half of the underlying hash output length, e.g.,
KcA = KcB = 128 bits for HKDF(SHA256), with L=256 bits.
The resulting key schedule for this protocol, given transcript TT and
AAD, is as follows.
Hash(TT) = Ke  Ka
AAD > KDF(Ka, nil, "ConfirmationKeys"  AAD) = KcA  KcB
]]>
A and B output Ke as the shared secret from the protocol. Ka and its derived keys are not
used for anything except key confirmation.
PerUser M and N and M=N
To avoid concerns that an attacker needs to solve a single Elliptic Curve DiffieHellman (ECDH) instance to break the authentication of SPAKE2, it is
possible to vary M and N using as follows:
There is also a symmetric variant where M=N. For this variant, we set:
This variant MUST be used when it is not possible to determine whether
A or B should use M (or N), due to asymmetries in the protocol
flows or the desire to use only a single shared secret with nil
identities for authentication. The security of these variants is examined in . The variant with peruser M and N may not be
suitable for protocols that require the initial messages to be
generated by each party at the same time and that do not know the
exact identity of the parties before the flow begins.
Ciphersuites
This section documents SPAKE2 ciphersuite
configurations. A ciphersuite indicates a group,
cryptographic hash function, and pair of KDF and MAC
functions, e.g., SPAKE2P256SHA256HKDFHMAC. This
ciphersuite indicates a SPAKE2 protocol instance over
P256 that uses SHA256, along with HMACbased Key Derivation Function (HKDF) and Hashed Message Authentication Code (HMAC) for
G, Hash, KDF, and MAC functions, respectively. For Ed25519,
the compressed encoding is used ;
all others use the uncompressed SEC1 encoding.
SPAKE2 Ciphersuites
G 
Hash 
KDF 
MAC 
P256 
SHA256 
HKDF 
HMAC 
P256 
SHA512 
HKDF 
HMAC 
P384 
SHA256 
HKDF 
HMAC 
P384 
SHA512 
HKDF 
HMAC 
P521 
SHA512 
HKDF 
HMAC 
edwards25519 
SHA256 
HKDF 
HMAC 
edwards448 
SHA512 
HKDF 
HMAC 
P256 
SHA256 
HKDF 
CMACAES128 
P256 
SHA512 
HKDF 
CMACAES128 
The following points represent permissible point generation seeds
for the groups listed in ,
using the algorithm presented in .
These byte strings are compressed points, as in ,
for curves from .
For P256:
For P384:
For P521:
For edwards25519:
For edwards448:
Security Considerations
A security proof of SPAKE2 for prime order groups is found in
, reducing the security of SPAKE2 to the
GDH assumption. Note that the choice of M and N
is critical for the security proof. The generation methods
specified in this document are designed to eliminate concerns
related to knowing discrete logs of M and N.
Elements received from a peer MUST be checked for group
membership. Failure to properly deserialize and validate group
elements can lead to attacks. An endpoint MUST abort the protocol
if any received public value is not a member of G.
The choices of random numbers MUST be uniform. Randomly
generated values, e.g., x and y, MUST NOT be reused; such reuse
violates the security assumptions of the protocol and results in significant insecurity.
It is RECOMMENDED
to generate these uniform numbers using rejection sampling.
Some implementations of elliptic curve multiplication may
leak information about the length of the scalar. These MUST NOT
be used. All operations on elliptic curve points must take time
independent of the inputs. Hashing of the transcript may take
time depending only on the length of the transcript but not the
contents.
SPAKE2 does not support augmentation. As a result, the server
has to store a password equivalent. This is considered a
significant drawback in some use cases. Applications that need
augmented PAKEs should use .
The HMAC keys in this document are shorter than recommended
in .
This is appropriate, as the
difficulty of the discrete logarithm problem is comparable with
the difficulty of brute forcing the keys.
IANA Considerations
This document has no IANA actions.
References
Normative References
Informative References
SEC 1: Elliptic Curve Cryptography
Standards for Efficient Cryptography Group
Universally Composable Relaxed Password Authenticated Key Exchange
in
Advances in Cryptology  CRYPTO 2020, Lecture
Notes in Computer Science, Volume 12170, Springer
Simple PasswordBased Encrypted Key Exchange Protocols
CryptographyCTRSA 2005, Lecture Notes in Computer
Science, Volume 3376, pages 191208, Springer
Recommendation for PairWise KeyEstablishment Schemes Using Discrete Logarithm Cryptography
National Institute of Standards and Technology
Revision 3
Algorithm Used for Point Generation
This section describes the algorithm that was used to generate
points M and N in .
For each curve in , we construct a string
using the curve OID from (as an ASCII
string) or its name,
combined with the needed constant, e.g., "1.3.132.0.35
point generation seed (M)" for P521. This string is turned
into a series of blocks by hashing with SHA256 and hashing that
output again to generate the next 32 bytes and so on. This
pattern is repeated for each group and value, with the string
modified appropriately.
A byte string of a length equal to that of an encoded group
element is constructed by concatenating as many blocks as are
required, starting from the first block and truncating to the
desired length. The byte string is then formatted as required
for the group. In the case of Weierstrass curves, we take the
desired length as the length for representing a compressed point
(Section 2.3.4 of )
and use the loworder bit of the first byte as the sign bit.
In order to obtain the correct format, the value of the first
byte is set to 0x02 or 0x03 (clearing the first six bits
and setting the seventh bit), leaving the sign bit as it was
in the byte string constructed by concatenating hash blocks.
For the curves in , a different
procedure is used.
For edwards448, the 57byte input has the leastsignificant 7 bits of the
last byte set to zero, and for edwards25519, the 32byte input is
not modified. For both the curves in ,
the (modified) input is then interpreted
as the representation of the group element.
If this interpretation yields a valid group element with the
correct order (p), the (modified) byte string is the output. Otherwise,
the initial hash block is discarded and a new byte string is constructed
from the remaining hash blocks. The procedure of constructing a
byte string of the appropriate length, formatting it as
required for the curve, and checking if it is a valid point of the correct
order is repeated until a valid element is found.
The following Python snippet generates the above points,
assuming an elliptic curve implementation follows the
interface of Edwards25519Point.stdbase() and
Edwards448Point.stdbase() in :
SPAKE2 Test Vectors
This section contains test vectors for SPAKE2, using
the P256SHA256HKDFHMAC ciphersuite. (The choice of MHF is omitted,
and the values for w, x, and y are provided directly.) All points are
encoded using the uncompressed format, i.e., with a 0x04 octet
prefix, specified in . A and B identity strings
are provided in the protocol invocation.
Line breaks have been added due to linelength limitations.
Acknowledgements
Special thanks to and
for
generating M and N and for generating test vectors. Thanks
to for advice on how to deal with cofactors.
also suggested the addition of warnings on the reuse of x
and y. Thanks to ,
, , and the members of the CFRG for comments and
advice. Thanks to and those Crypto Panel experts
involved in the PAKE selection process
() who have provided
valuable comments. contributed substantial text and
reformatting to address the excellent review comments from .
Contributors
Akamai Technologies
kaduk@mit.edu