]>
CFRG ECDH and signatures in JOSE
Independentilariliusvaara@welho.comThis document defines how to use Diffie-Hellman algorithms "X25519" and "X448" as well
as signature algorithms "Ed25519", "Ed25519ph", "Ed448" and "Ed448ph" from 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", "Ed25519ph", "Ed448" and "Ed448ph";
) for asymmetric key cryptography. This document
defines how those algorithms are to be used in JOSE in inter-operable manner.This document defines the conventions to be used in 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 (e.g. 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 output of verification function, which is a
boolean.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 .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
base64url encoding.The parameter "d" MUST be present for private keys, and contain the private key
encoded using 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 thumbprints , the three public key fields are
included in the hash. That is, in lexicographic order: "crv", "kty" and
"x".[TBD: Switch to "alg" parameter for subtyping? But normally "alg" is not included in JWK
thumbprints and there are multiple "ECDH-ES" algorithms already in JWA.]The following signature algorithms are defined here (to be applied as
values of "alg" parameter). All these have keys with subtype ("crv") of the
same name:The key type for these keys is "OKP" and key subtype for
these algorithms MUST be the same as the algorithm name.The keys of these subtypes MUST NOT be used for ECDH-ES.[TBD: Merge the alg values into a single one that can perform signing
with any signature-capable OKP subtype? That would remove a source of
possible errors, since then the message and key could not mismatch in
algorithm.]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 value. 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 value (as
signature). All inputs are octet strings. If the algorithm accepts, the
signature is valid, otherwise signature is invalid.The following key subtypes 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 "Enc".The "x" parameter of "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 output is the
value for "x" parameter of "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.Some algorithms interact in bad ways (e.g. "Ed25519" and "Ed25519ph"). For this reason,
those algorithms have different subtypes, so keys for each are not mixed up.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 system up to attacks via mixing up algorithms. It is particularly
dangerous to mix up signature and MAC algorithms.Do not assume that signature also binds the key used for signing, it does not (there are
also other widespread signature algorithms where this binding fails, as such binding is not
part of the definition of secure signature primitive). As an example of such failure, the
Ed25519ph signature of X under key (Ed25519ph,Y) is identical to Ed25519 signature of
SHA512(X) under key (Ed25519,Y). And often it takes only setting a few bits of message (easy
to do by brute force) to make the message valid enough to be processed in some very surprising
way.If key generation or batch signature verification is performed, a well-seed
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 receiver public key has to be
chosen maliciously or the sender has to be malicious in order to cause problems. And in
either case, all security evaporates anyway.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.Mike Jones for comments on initial pre-draft.The following is added to 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 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): Section 2 of [RFC-THIS]Parameter Name: "d"Parameter Description: The private keyParameter Information Class: PrivateUsed with "kty" Value(s): "OKP"Change Controller: IESGSpecification Document(s): Section 2 of [RFC-THIS]Parameter Name: "x"Parameter Description: The public keyParameter Information Class: PublicUsed with "kty" Value(s): "OKP"Change Controller: IESGSpecification Document(s): Section 2 of [RFC-THIS]The following is added to JSON Web Signature and Encryption Algorithms Registry:Algorithm Name: "Ed25519"Algorithm Description: Ed25519 signature algorithmAlgorithm Usage Location(s): "alg"JOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.1 of [RFC-THIS]Algorithm Analysis Documents(s): Algorithm Name: "Ed25519ph"Algorithm Description: Ed25519 signature algorithm with prehashAlgorithm Usage Location(s): "alg"JOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.1 of [RFC-THIS]Algorithm Analysis Documents(s): Algorithm Name: "Ed448"Algorithm Description: Ed448 signature algorithmAlgorithm Usage Location(s): "alg"JOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.1 of [RFC-THIS]Algorithm Analysis Documents(s): Algorithm Name: "Ed448ph"Algorithm Description: Ed448 signature algorithm with prehashAlgorithm Usage Location(s): "alg"JOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.1 of [RFC-THIS]Algorithm Analysis Documents(s): The following is added to JSON Web Key Elliptic Curve Registry:Curve Name: "Ed25519"Curve Description: Ed25519 signature algorithm keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.1 of [RFC-THIS]Curve Name: "Ed25519ph"Curve Description: Ed25519 signature algorithm with prehash keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.1 of [RFC-THIS]Curve Name: "Ed448"Curve Description: Ed448 signature algorithm keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.1 of [RFC-THIS]Curve Name: "Ed448ph"Curve Description: Ed448 signature algorithm with prehash keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.1 of [RFC-THIS]Curve name: "X25519"Curve Description: X25519 function keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.2 of [RFC-THIS]Analysis Documents(s): Curve Name: "X448"Curve Description: X448 function keypairsJOSE Implementation Requirements: OptionalChange Controller: IESGSpecification Document(s): Section 3.2 of [RFC-THIS]Analysis Documents(s):
&RFC2119;
&RFC4648;
&CURVES;
&EDDSA;
&RFC7517;
&RFC7518;
&RFC7638;
To the extent possible, the examples use material lifted from test vectors of
and The hexadecimal dump of private key is:And of the public key:This is the public parts of the previous private key (just omits "d"):The JWK thumbprint canonicalization of the two above examples is (linebreak
inserted for formatting reasons)Which has the SHA-256 hash of:
90facafea9b1556698540f70c0117a22ea37bd5cf3ed3c47093c1707282b4b89The JWS protected header is:This has base64url encoding of:The payload is (text):This has 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 Ed25519 signing algorithm to the private key, public key and the JWS
signing input yields signature (hex):Converting this to base64url yields:So the compact serialization of 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 JWS. Base64url decoding the protected
header yields:So this is Ed25519 signature. Now the key has: "kty":"OKP" and "crv":"Ed25519", so
the key is valid for the algorithm (if it had other values, the validation would have
failed).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 base64 decoding
of the part between the dots:The public key to encrypt to is:The public key from target key is (hex):The ephemeral secret happens to be (hex):So the ephemeral public key is X25519(ephkey,G) (hex):This is packed into ephemeral public key value:So the protected header could for example be:And 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 sender's value (the both sides run this through KDF before
using as direct encryption key or AES128-KW key).The public key to encrypt to is (linebreak inserted for formatting reasons):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 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 sender's value (the both sides run this through KDF before
using as direct encryption key or AES256-KW key).