]>
CFRG ECDH and signatures in JOSE
Independentilariliusvaara@welho.comThis document defines how to use the Diffie-Hellman algorithms "X25519" and "X448" as well
as the signature algorithms "Ed25519" and "Ed448" from the IRTF CFRG elliptic
curves work in JOSE.Internet Research Task Force (IRTF) Crypto Forum Research Group (CFRG) selected new
Diffie-Hellman algorithms ("X25519" and "X448"; ) and
signature algorithms ("Ed25519" and "Ed448";
) for asymmetric key cryptography. This document
defines how those algorithms are to be used in JOSE in interoperable manner.This document defines the conventions to be used in the context of
, and .While the CFRG also defined two pairs of isogenous elliptic curves that underlie these
algorithms, these curves are not directly exposed, as the algorithms laid on top are
sufficient for the purposes of JOSE and are much easier to use. (Trying to apply ECDSA
to those curves leads to nasty corner-cases and produces odd results.)All inputs to and outputs from the the ECDH and signature functions are defined to
be octet strings, with the exception of outputs of verification function, which are
booleans.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 ."JWS Signing Input" and "JWS Signature" are defined by
"Key Agreement with Elliptic Curve Diffie-Hellman Ephemeral Static" is defined
by , section 4.6The JOSE key format ("JSON Web Key (JWK)") is defined by ,
and thumbprints for it ("JSON Web Key (JWK) Thumbprint") in
.A new key type (kty) value "OKP" (Octet Key Pair) is defined for public key
algorithms that use octet strings as private and public keys. It has the following parameters:
The parameter "kty" MUST be "OKP".The parameter "crv" MUST be present and contain the subtype of the key (from "JSON
Web Elliptic Curve" registry).The parameter "x" MUST be present and contain the public key encoded using
the base64url encoding.The parameter "d" MUST be present for private keys and contain the private key
encoded using the base64url encoding. This parameter MUST NOT be present for public
keys.
Note: Do not assume that there is an underlying elliptic curve, despite the existence of the
"crv" and "x" parameters. (For instance, this key type could be extended to represent DH
algorithms based on hyperelliptic surfaces.)
When calculating JWK Thumbprints , the three public key fields are
included in the hash input lexicographic order: "crv", "kty", and
"x".For purpose of using EdDSA for signing data using "JSON Web Signature (JWS)"
(), algorithm "EdDSA" is defined here, to be applied
as value of "alg" parameter.The following key subtypes are defined here for use with EdDSA.The key type used with these keys is "OKP" and the algorithm used
for signing is "EdDSA". These subtypes MUST NOT be used for
ECDH-ES.The EdDSA variant used is determined by the subtype of the key (Ed25519 for
"Ed25519" and Ed448 for "Ed448").Signing for these is preformed by applying the signing algorithm
defined in to the private key (as private
key), public key (as public key) and the JWS Signing Input (as message).
The resulting signature is the JWS Signature. All inputs and outputs
are octet strings.Verification is performed by applying the verification algorithm
defined in to the public key (as public
key), the JWS Signing Input (as message) and the JWS Signature (as
signature). All inputs are octet strings. If the algorithm accepts, the
signature is valid; otherwise, the signature is invalid.The following key subtypes are defined here for purpose of "Key Agreement with
Elliptic Curve Diffie-Hellman Ephemeral Static" (ECDH-ES).The key type used with these keys is "OKP". These subtypes MUST NOT
be used for signing. Section 4.6 defines the ECDH-ES algorithms
"ECDH-ES+A128KW", "ECDH-ES+A192KW", "ECDH-ES+A256KW" and "ECDH-ES".The "x" parameter of the "epk" field is set as follows:Apply the appropriate ECDH function to the ephemeral private key (as scalar
input) and the standard basepoint (as u-coordinate input).
The base64url encoding of the output is the value for the "x" parameter of
the "epk" field. All inputs and outputs are octet strings.The Z value (raw key agreement output) for key agreement (to be used in
subsequent KDF as per section 4.6.2) is determined
as follows:Apply the appropriate ECDH function to the ephemeral private key (as scalar
input) and receiver public key (as u-coordinate input). The output is the Z
value. All inputs and outputs are octet strings.Security considerations from and
apply here.Do not separate key material from information about what key subtype it is for.
When using keys, check that the algorithm is compatible with the key subtype for the
key. To do otherwise opens the system up to attacks via mixing up algorithms. It is
particularly dangerous to mix up signature and MAC algorithms.Although for Ed25519 and Ed448, the signature binds the key used for signing, do not
assume this, as there are many signature algorithms that fail to make such a binding. If
key-binding is desired, include the key used for signing either inside the JWS protected
header or the data to sign.If key generation or batch signature verification is performed, a well-seeded
cryptographic random number generator is REQUIRED. Signing and non-batch signature
verification are deterministic operations and do not need random numbers of any kind.The JWA ECDH-ES KDF construction does not mix keys into the final shared secret. While
in key exchange such could be a bad mistake, here either the receiver public key has to be
chosen maliciously or the sender has to be malicious in order to cause problems. In
either case, all security evaporates.The nominal security strengths of X25519 and X448 are ~126 and ~223 bits. Therefore,
using 256-bit symmetric encryption (especially key wrapping and encryption) with X448 is
RECOMMENDED.Thanks to Michael B. Jones for his comments on an initial pre-draft and editorial help.Thanks to Matt Miller for some editorial help.The following is added to the "JSON Web Key Types" registry:"kty" Parameter Value: "OKP"Key Type Description: Octet string key pairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 2 of [RFC-THIS]The following is added to the "JSON Web Key Parameters" registry:Parameter Name: "crv"Parameter Description: The subtype of keypairParameter Information Class: PublicUsed with "kty" Value(s): "OKP"Change Controller: IESGSpecification Document(s): of [RFC-THIS]Parameter Name: "d"Parameter Description: The private keyParameter Information Class: PrivateUsed with "kty" Value(s): "OKP"Change Controller: IESGSpecification Document(s): of [RFC-THIS]Parameter Name: "x"Parameter Description: The public keyParameter Information Class: PublicUsed with "kty" Value(s): "OKP"Change Controller: IESGSpecification Document(s): of [RFC-THIS]The following is added to the "JSON Web Signature and Encryption Algorithms" registry:Algorithm Name: "EdDSA"Algorithm Description: EdDSA signature algorithmsAlgorithm Usage Location(s): "alg"JOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): of [RFC-THIS]Algorithm Analysis Documents(s): The following is added to the "JSON Web Key Elliptic Curve" registry:Curve Name: "Ed25519"Curve Description: Ed25519 signature algorithm keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): of [RFC-THIS]Curve Name: "Ed448"Curve Description: Ed448 signature algorithm keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): of [RFC-THIS]Curve name: "X25519"Curve Description: X25519 function keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): of [RFC-THIS]Analysis Documents(s): Curve Name: "X448"Curve Description: X448 function keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): of [RFC-THIS]Analysis Documents(s):
&RFC2119;
&RFC4648;
&RFC7515;
&RFC7517;
&RFC7518;
&RFC7638;
&RFC7748;
&EDDSA;
&RFC7516;
To the extent possible, the examples use material taken from test vectors of
and .The hexadecimal dump of private key is:And of the public key is:This is the public parts of the previous private key (which just omits "d"):The JWK Thumbprint canonicalization of the two above examples (with linebreak
inserted for formatting reasons) is:Which has the SHA-256 hash (in hexadecimal) of
90facafea9b1556698540f70c0117a22ea37bd5cf3ed3c47093c1707282b4b89,
which results in the base64url encoded JWK Thumbprint representation of
"kPrK_qmxVWaYVA9wwBF6Iuo3vVzz7TxHCTwXBygrS4k".The JWS protected header is:This has the base64url encoding of:The payload is (text):This has the base64url encoding of:The JWS signing input is (concatenation of base64url encoding of the (protected)
header, a dot and base64url encoding of the payload) is:Applying the Ed25519 signing algorithm using the private key, public key, and the
JWS signing input yields the signature (hex):Converting this to base64url yields:So the compact serialization of the JWS is (concatenation of signing input, a dot,
and base64url encoding of the signature):The JWS from above example is:This has 2 dots in it, so it might be valid a JWS. Base64url decoding the protected
header yields:So this is an EdDSA signature. Now the key has: "kty":"OKP" and "crv":"Ed25519", so
the signature is Ed25519 signature.The signing input is the part before second dot:Applying Ed25519 verification algorithm to the public key, JWS signing input and
the signature yields true. So the signature is valid. The message is the base64url
decoding of the part between the dots:The public key to encrypt to is:The public key from the target key is (hex):The ephemeral secret happens to be (hex):So the ephemeral public key is X25519(ephkey,G) (hex):This is represented as the ephemeral public key value:So the protected header could, for example, be:And the sender computes as the DH Z value as X25519(ephkey,recv_pub) (hex):The receiver computes as the DH Z value as X25519(seckey,ephkey_pub) (hex):Which is the same as the sender's value (the both sides run this through the KDF
before using it as a direct encryption key or AES128-KW key).The public key to encrypt to (with linebreak inserted for formatting reasons)
is:The public key from target key is (hex):The ephemeral secret happens to be (hex):So the ephemeral public key is X448(ephkey,G) (hex):This is packed into ephemeral public key value (linebreak inserted for formatting
purposes):So the protected header could for example be (linebreak inserted for formatting
purposes):And the sender computes as the DH Z value as X448(ephkey,recv_pub) (hex):The receiver computes as the DH Z value as X448(seckey,ephkey_pub) (hex):Which is the same as the sender's value (the both sides run this through KDF before
using as direct encryption key or AES256-KW key).