COSE H. Tschofenig Internet-Draft Arm Limited Intended status: Standards Track R. Housley Expires: 12 January 2023 Vigil Security B. Moran Arm Limited 11 July 2022 Use of Hybrid Public-Key Encryption (HPKE) with CBOR Object Signing and Encryption (COSE) draft-ietf-cose-hpke-02 Abstract This specification defines hybrid public-key encryption (HPKE) for use with CBOR Object Signing and Encryption (COSE). HPKE offers a variant of public-key encryption of arbitrary-sized plaintexts for a recipient public key. HPKE works for any combination of an asymmetric key encapsulation mechanism (KEM), key derivation function (KDF), and authenticated encryption with additional data (AEAD) encryption function. Authentication for HPKE in COSE is provided by COSE-native security mechanisms. Status of This Memo This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet- Drafts is at https://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." This Internet-Draft will expire on 12 January 2023. Copyright Notice Copyright (c) 2022 IETF Trust and the persons identified as the document authors. All rights reserved. Tschofenig, et al. Expires 12 January 2023 [Page 1] Internet-Draft COSE HPKE July 2022 This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/ license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License. This document may contain material from IETF Documents or IETF Contributions published or made publicly available before November 10, 2008. The person(s) controlling the copyright in some of this material may not have granted the IETF Trust the right to allow modifications of such material outside the IETF Standards Process. Without obtaining an adequate license from the person(s) controlling the copyright in such materials, this document may not be modified outside the IETF Standards Process, and derivative works of it may not be created outside the IETF Standards Process, except to format it for publication as an RFC or to translate it into languages other than English. Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Conventions and Terminology . . . . . . . . . . . . . . . . . 3 3. HPKE for COSE . . . . . . . . . . . . . . . . . . . . . . . . 3 3.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . 3 3.1.1. One Layer Structure . . . . . . . . . . . . . . . . . 4 3.2. One Layer Example . . . . . . . . . . . . . . . . . . . . 5 3.2.1. Two Layer Structure . . . . . . . . . . . . . . . . . 6 4. Security Considerations . . . . . . . . . . . . . . . . . . . 10 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 10 5.1. COSE Algorithms Registry . . . . . . . . . . . . . . . . 11 5.1.1. COSE_ALG_HPKE_AES_128_GCM . . . . . . . . . . . . . . 11 5.1.2. COSE_ALG_HPKE_AES_256_GCM . . . . . . . . . . . . . . 11 5.1.3. COSE_ALG_HPKE_CHACHA20_POLY1305 . . . . . . . . . . . 11 5.2. COSE Elliptic Curves Registry . . . . . . . . . . . . . . 12 5.2.1. COSE_CRV_HPKE_P256_SHA256 . . . . . . . . . . . . . . 12 5.2.2. COSE_CRV_HPKE_P384_SHA384 . . . . . . . . . . . . . . 12 5.2.3. COSE_CRV_HPKE_P521_SHA512 . . . . . . . . . . . . . . 12 5.2.4. COSE_CRV_HPKE_X25519_SHA256 . . . . . . . . . . . . . 13 5.2.5. COSE_CRV_HPKE_X448_SHA512 . . . . . . . . . . . . . . 13 6. References . . . . . . . . . . . . . . . . . . . . . . . . . 13 6.1. Normative References . . . . . . . . . . . . . . . . . . 13 6.2. Informative References . . . . . . . . . . . . . . . . . 14 Appendix A. Acknowledgements . . . . . . . . . . . . . . . . . . 14 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 14 Tschofenig, et al. Expires 12 January 2023 [Page 2] Internet-Draft COSE HPKE July 2022 1. Introduction Hybrid public-key encryption (HPKE) [RFC9180] is a scheme that provides public key encryption of arbitrary-sized plaintexts given a recipient's public key. HPKE utilizes a non-interactive ephemeral- static Diffie-Hellman exchange to establish a shared secret. The motivation for standardizing a public key encryption scheme is explained in the introduction of [RFC9180]. The HPKE specification defines several features for use with public key encryption and a subset of those features is applied to COSE [RFC8152]. Since COSE provides constructs for authentication, those are not re-used from the HPKE specification. This specification uses the "base" mode, as it is called in HPKE specification language. 2. Conventions and Terminology 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. This specification uses the following abbreviations and terms: - Content-encryption key (CEK), a term defined in CMS [RFC2630]. - Hybrid Public Key Encryption (HPKE) is defined in [RFC9180]. - pkR is the public key of the recipient, as defined in [RFC9180]. - skR is the private key of the recipient, as defined in [RFC9180]. 3. HPKE for COSE 3.1. Overview This specification supports two uses of HPKE in COSE, namely * HPKE in a single sender - single recipient setup. This use cases uses a one layer structure for efficiency. Section 3.1.1 provides the details. * HPKE in a single sender - multiple recipient setup. This use case requires a two layer structure. Section 3.2.1 provides the details. HPKE in "base" mode requires little information to be exchanged between a sender and a recipient, namely * algorithm information, Tschofenig, et al. Expires 12 January 2023 [Page 3] Internet-Draft COSE HPKE July 2022 * the ephemeral public key, and * an identifier of the static recipient key. In the subsections below we explain how this information is carried inside the COSE_Encrypt0 and the COSE_Encrypt1 for the one layer and the two layer structure, respectively. 3.1.1. One Layer Structure With the one layer structure the information carried inside the COSE_recipient structure is embedded inside the COSE_Encrypt0. HPKE is used to directly encrypt the plaintext. The resulting ciphertext may be included in the COSE_Encrypt0 or may be detached. A sender MUST set the alg parameter in the protected header, which indicates the use of HPKE. The values for the alg parameter MUST be taken from Section 5.1, or values registered in the future with the COSE_ALG_HPKE_* prefix. The sender MUST place the kid and ephemeral public key into the unprotected header. Figure 1 shows the COSE_Encrypt0 CDDL structure. COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0) ; Layer 0 COSE_Encrypt0 = [ Headers, ciphertext : bstr / nil, ] Figure 1: CDDL for HPKE-based COSE_Encrypt0 Structure The COSE_Encrypt0 MAY be tagged or untagged. An example is shown in Section 3.2. 3.1.1.1. HPKE Encryption with SealBase The SealBase(pkR, info, aad, pt) function is used to encrypt a plaintext pt to a recipient's public key (pkR). For use in COSE_Encrypt0, the plaintext "pt" passed into the SealBase is the raw plaintext. Tschofenig, et al. Expires 12 January 2023 [Page 4] Internet-Draft COSE HPKE July 2022 In the absence of an application profile standard specifying otherwise a COSE-HPKE-compliant application MUST use an empty "info" parameter. The Enc_structure, defined in Section 5.3 of [RFC8152], is used as input to the "aad" parameter. The CDDL fragment is defined as: Enc_structure = [ context : "Encrypt0", protected : empty_or_serialized_map, external_aad : bstr ] The "external_aad" is empty, unless an application profile standard specifies otherwise. If SealBase() is successful, it will output a ciphertext "ct" and an encapsulated key "enc". The content of enc is the ephemeral public key. 3.1.1.2. HPKE Decryption with OpenBase The recipient will use the OpenBase(enc, skR, info, aad, ct) function with the enc and ct parameters received from the sender. In the absence of an application profile standard specifying otherwise a COSE-HPKE-compliant application MUST use an empty "info" parameter. The Enc_structure, defined in Section 5.3 of [RFC8152], is used as input to the "aad" parameter. The CDDL fragment is shown in the previous section. The OpenBase function will, if successful, decrypt "ct". When decrypted, the result is the raw plaintext. 3.2. One Layer Example This example shows a COSE_Encrypt0 structure. HPKE was used to encrypt plaintext with AES-128-GCM. The ephemeral NIST P-256 key key generated by the HPKE SealBase(). Tschofenig, et al. Expires 12 January 2023 [Page 5] Internet-Draft COSE HPKE July 2022 96( [ / algorithm id TBD1 for COSE_ALG_HPKE_AES_128_GCM / << {1: TBD1} >>, { / ephemeral public key structure / -1: << { / kty set to EC2 / 1: 2, / crv set to P-256 / -1: 1, / x-coordinate / -2: h'985E2FDE3E67E1F7146AB305AA98FE89 B1CFE545965B6CFB066C0BB19DE7E489', / y-coordinate / -3: h'4AC5E777A7C96CB5D70B8A40E2951562 F20C21DB021AAD12E54A8DBE7EF9DF10' } >>, 4: 'kid-2' }, / encrypted plaintext / h'4123E7C3CD992723F0FA1CD3A903A588 42B1161E02D8E7FD842C4DA3B984B9CF' ] ) Figure 2: COSE_Encrypt0 Example for HPKE 3.2.1. Two Layer Structure With the two layer structure the HPKE information is conveyed in the COSE_recipient structure, i.e. one COSE_recipient structure per recipient. In this approach the following layers are involved: * Layer 0 (corresponding to the COSE_Encrypt structure) contains content (plaintext) encrypted with the CEK. This ciphertext may be detached. If not detached, then it is included in the COSE_Encrypt structure. * Layer 1 (corresponding to a recipient structure) contains parameters needed for HPKE to generate a shared secret used to encrypt the CEK. This layer conveys the encrypted CEK in the encCEK structure. The protected header MUST contain the algorithm information and the unprotected header MUST contain the ephemeral public key and the key id (kid) of the static recipient public key. Tschofenig, et al. Expires 12 January 2023 [Page 6] Internet-Draft COSE HPKE July 2022 This two-layer structure is used to encrypt content that can also be shared with multiple parties at the expense of a single additional encryption operation. As stated above, the specification uses a CEK to encrypt the content at layer 0. For example, the content encrypted at layer 0 may be a firmware image. The same ciphertext firmware image is processed by all of the recipients; however, each recipient uses their own private key to obtain the CEK. The COSE_recipient structure shown in Figure 3 is repeated for each recipient. COSE_Encrypt_Tagged = #6.96(COSE_Encrypt) / Layer 0 / COSE_Encrypt = [ Headers, ciphertext : bstr / nil, recipients : + COSE_recipient ] / Layer 1 / COSE_recipient = [ protected : bstr .cbor header_map, unprotected : header_map, encCEK : bstr, ] header_map = { Generic_Headers, * label => values, } Figure 3: CDDL for HPKE-based COSE_Encrypt Structure The COSE_Encrypt MAY be tagged or untagged. HPKE algorithms take an info parameter that can be used to influence the generation of keys (e.g., to fold in identity information) and an aad parameter that provides additional authenticated data to the AEAD algorithm in use. An example is shown in Section 3.2.1.3. Tschofenig, et al. Expires 12 January 2023 [Page 7] Internet-Draft COSE HPKE July 2022 3.2.1.1. HPKE Encryption with SealBase The SealBase(pkR, info, aad, pt) function is used to encrypt a plaintext pt to a recipient's public key (pkR). For use in COSE_Encrypt, the plaintext "pt" passed into the SealBase is the CEK. The CEK is a random byte sequence of length appropriate for the encryption algorithm selected in layer 0. For example, AES- 128-GCM requires a 16 byte key and the CEK would therefore be 16 bytes long. In the absence of an application profile standard specifying otherwise, a COSE-HPKE-compliant implementation MUST leave the info and the aad parameters empty when used with the two layer structure. If SealBase() is successful, it will output a ciphertext "ct" and an encapsulated key "enc". The content of enc is the ephemeral public key. 3.2.1.2. HPKE Decryption with OpenBase The recipient will use the OpenBase(enc, skR, info, aad, ct) function with the enc and ct parameters received from the sender. The "aad" and the "info" parameters are obtained via the context of the usage. In the absence of an application profile standard specifying otherwise, a COSE-HPKE-compliant implementation MUST leave the info and the aad parameters empty when used with the two layer structure. The OpenBase function will, if successful, decrypt "ct". When decrypted, the result will be the CEK. The CEK is the symmetric key used to decrypt the ciphertext in layer 0 of the COSE_Encrypt structure. 3.2.1.3. Two Layer Examples An example of the COSE_Encrypt structure using the HPKE scheme is shown in Figure 4. Line breaks and comments have been inserted for better readability. It uses the following algorithm combination: * AES-GCM-128 for encryption of detached ciphertext in layer 0. * Encryption of the CEK in layer 1 utilizing HPKE with NIST P-256 and HKDF-SHA256 as a Key Encapsulation Mechanism (KEM). The algorithm selection is based on the registry of the values offered by the alg parameters (see Section 5). Tschofenig, et al. Expires 12 January 2023 [Page 8] Internet-Draft COSE HPKE July 2022 96_0([ / protected header / << { / alg set to AES-GCM-128 / 1: 1 } >>, / unprotected header / { / nonce value / 5: h'938b528516193cc7123ff037809f4c2a' }, / detached ciphertext / null, / recipient structure / [ / algorithm id TBD4 for COSE_ALG_HPKE_AES_128_GCM / << {1: TBD4} >>, / unprotected header / { / ephemeral public key structure / -1: << { / kty set to EC2 / 1: 2, / crv set to P-256 / -1: 1, / x-coordinate / -2: h'985E2FDE3E67E1F7146AB305AA98FE89 B1CFE545965B6CFB066C0BB19DE7E489', / y-coordinate / -3: h'4AC5E777A7C96CB5D70B8A40E2951562 F20C21DB021AAD12E54A8DBE7EF9DF10' } >>, 4: 'kid-2' }, / encrypted CEK / h'9aba6fa44e9b2cef9d646614dcda670dbdb31a3b9d37c7a 65b099a8152533062', ], ]) Figure 4: COSE_Encrypt Example for HPKE To offer authentication of the sender the payload in Figure 4 is signed with a COSE_Sign1 wrapper, which is shown in Figure 5. The payload in Figure 5 corresponds to the content shown in Figure 4. Tschofenig, et al. Expires 12 January 2023 [Page 9] Internet-Draft COSE HPKE July 2022 18( [ / protected / h'a10126' / { \ alg \ 1:-7 \ ECDSA 256 \ } / , / unprotected / { / kid / 4:'sender@example.com' }, / payload / h'AA19...B80C', / signature / h'E3B8...25B8' ] ) Figure 5: COSE_Encrypt Example for HPKE 4. Security Considerations This specification is based on HPKE and the security considerations of HPKE [RFC9180] are therefore applicable also to this specification. HPKE assumes the sender is in possession of the public key of the recipient and HPKE COSE makes the same assumptions. Hence, some form of public key distribution mechanism is assumed to exist. HPKE relies on a source of randomness to be available on the device. Additionally, with the two layer structure the CEK is randomly generated and the it MUST be ensured that the guidelines for random number generations are followed. The COSE_Encrypt structure MUST be authenticated using COSE constructs like COSE_Sign, COSE_Sign1, COSE_MAC, or COSE_MAC0. When COSE_Encrypt or COSE_Encrypt0 is used with a detached ciphertext then the subsequently applied integrity protection via COSE_Sign, COSE_Sign1, COSE_MAC, or COSE_MAC0 does not cover this detached ciphertext. Implementers MUST ensure that the detached ciphertext also experiences integrity protection. This is, for example, the case when an AEAD cipher is used to produce the detached ciphertext but may not be guaranteed by non-AEAD ciphers. 5. IANA Considerations This document requests IANA to add new values to the COSE Algorithms registry and to the COSE Elliptic Curves registry, defined in [RFC8152] (in the Standards Action With Expert Review category). Tschofenig, et al. Expires 12 January 2023 [Page 10] Internet-Draft COSE HPKE July 2022 5.1. COSE Algorithms Registry 5.1.1. COSE_ALG_HPKE_AES_128_GCM * Name: COSE_ALG_HPKE_AES_128_GCM * Value: TBD1 * Description: HPKE with AES-128-GCM * Capabilities: [kty] * Change Controller: IESG * Reference: [[TBD: This RFC]] * Recommended: Yes 5.1.2. COSE_ALG_HPKE_AES_256_GCM * Name: COSE_ALG_HPKE_AES_256_GCM * Value: TBD2 * Description: HPKE with AES-256-GCM * Capabilities: [kty] * Change Controller: IESG * Reference: [[TBD: This RFC]] * Recommended: Yes 5.1.3. COSE_ALG_HPKE_CHACHA20_POLY1305 * Name: COSE_ALG_HPKE_CHACHA20_POLY1305 * Value: TBD3 * Description: HPKE with CHACHA20-POLY1305 * Capabilities: [kty] * Change Controller: IESG * Reference: [[TBD: This RFC]] Tschofenig, et al. Expires 12 January 2023 [Page 11] Internet-Draft COSE HPKE July 2022 * Recommended: Yes 5.2. COSE Elliptic Curves Registry 5.2.1. COSE_CRV_HPKE_P256_SHA256 * Name: COSE_CRV_HPKE_P256_SHA256 * Value: TBD4 * Key Type: * Description: NIST P256 and SHA256 for use with HPKE * Change Controller: IESG * Reference: [[TBD: This RFC]] * Recommended: Yes 5.2.2. COSE_CRV_HPKE_P384_SHA384 * Name: COSE_CRV_HPKE_P384_SHA384 * Value: TBD5 * Key Type: * Description: NIST P384 and SHA384 for use with HPKE * Change Controller: IESG * Reference: [[TBD: This RFC]] * Recommended: Yes 5.2.3. COSE_CRV_HPKE_P521_SHA512 * Name: COSE_CRV_HPKE_P521_SHA512 * Value: TBD6 * Key Type: * Description: NIST P521 and SHA512 for use with HPKE * Change Controller: IESG Tschofenig, et al. Expires 12 January 2023 [Page 12] Internet-Draft COSE HPKE July 2022 * Reference: [[TBD: This RFC]] * Recommended: Yes 5.2.4. COSE_CRV_HPKE_X25519_SHA256 * Name: COSE_CRV_HPKE_X25519_SHA256 * Value: TBD7 * Key Type: * Description: X25519 and SHA256 for use with HPKE * Change Controller: IESG * Reference: [[TBD: This RFC]] * Recommended: Yes 5.2.5. COSE_CRV_HPKE_X448_SHA512 * Name: COSE_CRV_HPKE_X448_SHA512 * Value: TBD8 * Key Type: * Description: X448 and SHA512 for use with HPKE * Change Controller: IESG * Reference: [[TBD: This RFC]] * Recommended: Yes 6. References 6.1. Normative References [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, . [RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", RFC 8152, DOI 10.17487/RFC8152, July 2017, . Tschofenig, et al. Expires 12 January 2023 [Page 13] Internet-Draft COSE HPKE July 2022 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017, . [RFC9180] Barnes, R., Bhargavan, K., Lipp, B., and C. Wood, "Hybrid Public Key Encryption", RFC 9180, DOI 10.17487/RFC9180, February 2022, . 6.2. Informative References [RFC2630] Housley, R., "Cryptographic Message Syntax", RFC 2630, DOI 10.17487/RFC2630, June 1999, . [RFC8937] Cremers, C., Garratt, L., Smyshlyaev, S., Sullivan, N., and C. Wood, "Randomness Improvements for Security Protocols", RFC 8937, DOI 10.17487/RFC8937, October 2020, . Appendix A. Acknowledgements We would like to thank Goeran Selander, John Mattsson and Ilari Liusvaara for their review feedback. Authors' Addresses Hannes Tschofenig Arm Limited Email: hannes.tschofenig@arm.com Russ Housley Vigil Security, LLC Email: housley@vigilsec.com Brendan Moran Arm Limited Email: Brendan.Moran@arm.com Tschofenig, et al. Expires 12 January 2023 [Page 14]