RFC 9382: SPAKE2, a Password-Authenticated Key Exchange
- W. Ladd
Abstract
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) password
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
Information about the current status of this document, any
errata, and how to provide feedback on it may be obtained at
https://
Copyright Notice
Copyright (c) 2023 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents
(https://
1. 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 password-based 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.¶
2. 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 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.¶
3. Definition of SPAKE2
3.1. Protocol Flow
SPAKE2 is a two-round 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 Section 5. 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. (Section 4 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.¶
3.2. Setup
Let G be a group in which the gap Diffie-Hellman (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 [SEC1] uncompressed or compressed for elliptic curve groups or big-endian integers of a fixed (per-group) 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 prime-order subgroup of G, as defined in Table 1 of this document for common groups, as well as generator P of the (large) prime-order 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
[RFC9380] SHOULD be used to generate M and N, e.g., via
M = hash
|| denotes concatenation of byte strings. We also let len(S) denote the length of a string in bytes, represented as an eight-byte little-endian 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 key-derivation 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 SHA-256 or SHA-512 [RFC6234]. Let MHF be a memory-hard hash function designed to slow down brute-force attackers. Scrypt [RFC7914] 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. Section 6 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 216 - 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 higher-level 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 user-supplied password, pw.
Standards, such as [NIST
3.3. 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*(pB-w*N), while B calculates it as h*y*(pA-w*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 big-endian 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 zero-length string. This MUST only be done for applications in which identities are implicit. Otherwise, the protocol risks unknown key-share 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 Section 4. 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.¶
4. Key Schedule and Key Confirmation
The protocol transcript TT, as defined in Section 3.3, 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 SHA-256. 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, "Confirmation
The resulting key schedule for this protocol, given transcript TT and AAD, is as follows.¶
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.¶
5. Per-User M and N and M=N
To avoid concerns that an attacker needs to solve a single Elliptic Curve Diffie-Hellman (ECDH) instance to break the authentication of SPAKE2, it is possible to vary M and N using [RFC9380] 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 [MNVAR]. The variant with per-user 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.¶
6. Ciphersuites
This section documents SPAKE2 ciphersuite
configurations. A ciphersuite indicates a group,
cryptographic hash function, and pair of KDF and MAC
functions, e.g., SPAKE2
The following points represent permissible point generation seeds for the groups listed in Table 1, using the algorithm presented in Appendix A. These byte strings are compressed points, as in [SEC1], for curves from [SEC1].¶
For P-256:¶
For P-384:¶
For P-521:¶
For edwards25519:¶
For edwards448:¶
7. Security Considerations
A security proof of SPAKE2 for prime order groups is found in [REF], 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 [CFRG-OPAQUE].¶
The HMAC keys in this document are shorter than recommended in [RFC8032]. This is appropriate, as the difficulty of the discrete logarithm problem is comparable with the difficulty of brute forcing the keys.¶
8. IANA Considerations
This document has no IANA actions.¶
9. References
9.1. Normative References
- [RFC2104]
-
Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-Hashing for Message Authentication", RFC 2104, DOI 10
.17487 , , <https:///RFC2104 www >..rfc -editor .org /info /rfc2104 - [RFC2119]
-
Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10
.17487 , , <https:///RFC2119 www >..rfc -editor .org /info /rfc2119 - [RFC4493]
-
Song, JH., Poovendran, R., Lee, J., and T. Iwata, "The AES-CMAC Algorithm", RFC 4493, DOI 10
.17487 , , <https:///RFC4493 www >..rfc -editor .org /info /rfc4493 - [RFC5480]
-
Turner, S., Brown, D., Yiu, K., Housley, R., and T. Polk, "Elliptic Curve Cryptography Subject Public Key Information", RFC 5480, DOI 10
.17487 , , <https:///RFC5480 www >..rfc -editor .org /info /rfc5480 - [RFC5869]
-
Krawczyk, H. and P. Eronen, "HMAC-based Extract
-and , RFC 5869, DOI 10-Expand Key Derivation Function (HKDF)" .17487 , , <https:///RFC5869 www >..rfc -editor .org /info /rfc5869 - [RFC6234]
-
Eastlake 3rd, D. and T. Hansen, "US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)", RFC 6234, DOI 10
.17487 , , <https:///RFC6234 www >..rfc -editor .org /info /rfc6234 - [RFC7914]
-
Percival, C. and S. Josefsson, "The scrypt Password-Based Key Derivation Function", RFC 7914, DOI 10
.17487 , , <https:///RFC7914 www >..rfc -editor .org /info /rfc7914 - [RFC8032]
-
Josefsson, S. and I. Liusvaara, "Edwards-Curve Digital Signature Algorithm (EdDSA)", RFC 8032, DOI 10
.17487 , , <https:///RFC8032 www >..rfc -editor .org /info /rfc8032 - [RFC8174]
-
Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10
.17487 , , <https:///RFC8174 www >..rfc -editor .org /info /rfc8174 - [RFC9380]
-
Faz-Hernandez, A., Scott, S., Sullivan, N., Wahby, R. S., and C. A. Wood, "Hashing to Elliptic Curves", RFC 9380, DOI 10
.17487 , , <https:///RFC9380 www >..rfc -editor .org /info /rfc9380
9.2. Informative References
- [CFRG-OPAQUE]
-
Bourdrez, D., Krawczyk, H., Lewi, K., and C. A. Wood, "The OPAQUE Asymmetric PAKE Protocol", Work in Progress, Internet-Draft, draft
-irtf , , <https://-cfrg -opaque -11 datatracker >..ietf .org /doc /html /draft -irtf -cfrg -opaque -11 - [MNVAR]
-
Abdalla, M., Barbosa, M., Bradley, T., Jarecki, S., Katz, J., and J. Xu, "Universally Composable Relaxed Password Authenticated Key Exchange", in
Advances in Cryptology - CRYPTO 2020, Lecture
Notes in Computer Science, Volume 12170, Springer, DOI 10
.1007 , , <https:///978 -3 -030 -56784 -2 _10 doi >..org /10 .1007 /978 -3 -030 -56784 -2 _10 - [NIST
.SP .800 -56Ar3] -
National Institute of Standards and Technology, "Recommendation for Pair-Wise Key
-Establishment Schemes Using Discrete Logarithm Cryptography" , Revision 3, NIST Special Publication 800-56A, DOI 10.6028 , , <https:///NIST .SP .800 -56Ar3 doi >..org /10 .6028 /NIST .SP .800 -56Ar3 - [REF]
-
Abdalla, M. and D. Pointcheval, "Simple Password-Based Encrypted Key Exchange Protocols",
Cryptography
-CT , DOI 10-RSA 2005, Lecture Notes in Computer Science, Volume 3376, pages 191-208, Springer .1007 , , <https:///978 -3 -540 -30574 -3 _14 doi >..org /10 .1007 /978 -3 -540 -30574 -3 _14 - [RFC8265]
-
Saint-Andre, P. and A. Melnikov, "Preparation, Enforcement, and Comparison of Internationaliz
ed Strings Representing Usernames and Passwords" , RFC 8265, DOI 10.17487 , , <https:///RFC8265 www >..rfc -editor .org /info /rfc8265 - [SEC1]
- Standards for Efficient Cryptography Group, "SEC 1: Elliptic Curve Cryptography", .
Appendix A. Algorithm Used for Point Generation
This section describes the algorithm that was used to generate points M and N in Table 1.¶
For each curve in Table 1, we construct a string using the curve OID from [RFC5480] (as an ASCII string) or its name, combined with the needed constant, e.g., "1.3.132.0.35 point generation seed (M)" for P-521. This string is turned into a series of blocks by hashing with SHA-256 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 [SEC1])
and use the low-order 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 [RFC8032], a different
procedure is used.
For edwards448, the 57-byte input has the least
The following Python snippet generates the above points,
assuming an elliptic curve implementation follows the
interface of Edwards25519Poi
Appendix B. SPAKE2 Test Vectors
This section contains test vectors for SPAKE2, using
the P256
Line breaks have been added due to line-length limitations.¶
Acknowledgements
Special thanks to Nathaniel McCallum and
Greg Hudson for
generating M and N and Chris Wood for generating test vectors. Thanks
to Mike Hamburg for advice on how to deal with cofactors.
Greg Hudson also suggested the addition of warnings on the reuse of x
and y. Thanks to Fedor Brunner,
Adam Langley, Liliya Akhmetzyanova, and the members of the CFRG for comments and
advice. Thanks to Scott Fluhrer and those Crypto Panel experts
involved in the PAKE selection process
(https://