idnits 2.17.1 draft-ietf-cose-rfc8152bis-algs-05.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The abstract seems to contain references ([I-D.ietf-cose-RFC8152bis-struct]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (September 11, 2019) is 1688 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Possible downref: Non-RFC (?) normative reference: ref. 'AES-GCM' -- Possible downref: Non-RFC (?) normative reference: ref. 'DSS' == Outdated reference: A later version (-15) exists of draft-ietf-cose-rfc8152bis-struct-05 -- Possible downref: Normative reference to a draft: ref. 'I-D.ietf-cose-rfc8152bis-struct' -- Possible downref: Non-RFC (?) normative reference: ref. 'MAC' ** Downref: Normative reference to an Informational RFC: RFC 2104 ** Downref: Normative reference to an Informational RFC: RFC 3394 ** Downref: Normative reference to an Informational RFC: RFC 3610 ** Downref: Normative reference to an Informational RFC: RFC 5869 ** Downref: Normative reference to an Informational RFC: RFC 6090 ** Downref: Normative reference to an Informational RFC: RFC 6979 ** Obsolete normative reference: RFC 7049 (Obsoleted by RFC 8949) ** Downref: Normative reference to an Informational RFC: RFC 7748 ** Downref: Normative reference to an Informational RFC: RFC 8032 ** Downref: Normative reference to an Informational RFC: RFC 8439 -- Possible downref: Non-RFC (?) normative reference: ref. 'SEC1' -- Obsolete informational reference (is this intentional?): RFC 8152 (Obsoleted by RFC 9052, RFC 9053) Summary: 11 errors (**), 0 flaws (~~), 2 warnings (==), 7 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 COSE Working Group J. Schaad 3 Internet-Draft August Cellars 4 Obsoletes: 8152 (if approved) September 11, 2019 5 Intended status: Standards Track 6 Expires: March 14, 2020 8 CBOR Object Signing and Encryption (COSE): Initial Algorithms 9 draft-ietf-cose-rfc8152bis-algs-05 11 Abstract 13 Concise Binary Object Representation (CBOR) is a data format designed 14 for small code size and small message size. There is a need for the 15 ability to have basic security services defined for this data format. 16 This document defines the CBOR Object Signing and Encryption (COSE) 17 protocol. This specification describes how to create and process 18 signatures, message authentication codes, and encryption using CBOR 19 for serialization. COSE additionally describes how to represent 20 cryptographic keys using CBOR. 22 In this specification the conventions for the use of a number of 23 cryptographic algorithms with COSE. The details of the structure of 24 COSE are defined in [I-D.ietf-cose-rfc8152bis-struct]. 26 This document along with [I-D.ietf-cose-rfc8152bis-struct] obsoletes 27 RFC8152. 29 Contributing to this document 31 This note is to be removed before publishing as an RFC. 33 The source for this draft is being maintained in GitHub. Suggested 34 changes should be submitted as pull requests at https://github.com/ 35 cose-wg/cose-rfc8152bis. Instructions are on that page as well. 36 Editorial changes can be managed in GitHub, but any substantial 37 issues need to be discussed on the COSE mailing list. 39 Status of This Memo 41 This Internet-Draft is submitted in full conformance with the 42 provisions of BCP 78 and BCP 79. 44 Internet-Drafts are working documents of the Internet Engineering 45 Task Force (IETF). Note that other groups may also distribute 46 working documents as Internet-Drafts. The list of current Internet- 47 Drafts is at https://datatracker.ietf.org/drafts/current/. 49 Internet-Drafts are draft documents valid for a maximum of six months 50 and may be updated, replaced, or obsoleted by other documents at any 51 time. It is inappropriate to use Internet-Drafts as reference 52 material or to cite them other than as "work in progress." 54 This Internet-Draft will expire on 14 March 2020. 56 Copyright Notice 58 Copyright (c) 2019 IETF Trust and the persons identified as the 59 document authors. All rights reserved. 61 This document is subject to BCP 78 and the IETF Trust's Legal 62 Provisions Relating to IETF Documents (https://trustee.ietf.org/ 63 license-info) in effect on the date of publication of this document. 64 Please review these documents carefully, as they describe your rights 65 and restrictions with respect to this document. Code Components 66 extracted from this document must include Simplified BSD License text 67 as described in Section 4.e of the Trust Legal Provisions and are 68 provided without warranty as described in the Simplified BSD License. 70 Table of Contents 72 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 73 1.1. Requirements Terminology . . . . . . . . . . . . . . . . 4 74 1.2. Changes from RFC8152 . . . . . . . . . . . . . . . . . . 4 75 1.3. Document Terminology . . . . . . . . . . . . . . . . . . 4 76 1.4. CBOR Grammar . . . . . . . . . . . . . . . . . . . . . . 4 77 1.5. Examples . . . . . . . . . . . . . . . . . . . . . . . . 4 78 2. Signature Algorithms . . . . . . . . . . . . . . . . . . . . 5 79 2.1. ECDSA . . . . . . . . . . . . . . . . . . . . . . . . . . 5 80 2.1.1. Security Considerations . . . . . . . . . . . . . . . 6 81 2.2. Edwards-Curve Digital Signature Algorithms 82 (EdDSAs) . . . . . . . . . . . . . . . . . . . . . . . . 7 83 2.2.1. Security Considerations . . . . . . . . . . . . . . . 8 84 3. Message Authentication Code (MAC) Algorithms . . . . . . . . 8 85 3.1. Hash-Based Message Authentication Codes (HMACs) . . . . . 9 86 3.1.1. Security Considerations . . . . . . . . . . . . . . . 10 87 3.2. AES Message Authentication Code (AES-CBC-MAC) . . . . . . 10 88 3.2.1. Security Considerations . . . . . . . . . . . . . . . 11 89 4. Content Encryption Algorithms . . . . . . . . . . . . . . . . 12 90 4.1. AES GCM . . . . . . . . . . . . . . . . . . . . . . . . . 12 91 4.1.1. Security Considerations . . . . . . . . . . . . . . . 13 92 4.2. AES CCM . . . . . . . . . . . . . . . . . . . . . . . . . 13 93 4.2.1. Security Considerations . . . . . . . . . . . . . . . 16 94 4.3. ChaCha20 and Poly1305 . . . . . . . . . . . . . . . . . . 16 95 4.3.1. Security Considerations . . . . . . . . . . . . . . . 17 96 5. Key Derivation Functions (KDFs) . . . . . . . . . . . . . . . 17 97 5.1. HMAC-Based Extract-and-Expand Key Derivation Function 98 (HKDF) . . . . . . . . . . . . . . . . . . . . . . . . . 18 99 5.2. Context Information Structure . . . . . . . . . . . . . . 19 100 6. Content Key Distribution Methods . . . . . . . . . . . . . . 24 101 6.1. Direct Encryption . . . . . . . . . . . . . . . . . . . . 25 102 6.1.1. Direct Key . . . . . . . . . . . . . . . . . . . . . 25 103 6.1.2. Direct Key with KDF . . . . . . . . . . . . . . . . . 26 104 6.2. AES Key Wrap . . . . . . . . . . . . . . . . . . . . . . 28 105 6.2.1. Security Considerations for AES-KW . . . . . . . . . 28 106 6.3. Direct ECDH . . . . . . . . . . . . . . . . . . . . . . . 29 107 6.3.1. Security Considerations . . . . . . . . . . . . . . . 32 108 6.4. ECDH with Key Wrap . . . . . . . . . . . . . . . . . . . 32 109 7. Key Object Parameters . . . . . . . . . . . . . . . . . . . . 34 110 7.1. Elliptic Curve Keys . . . . . . . . . . . . . . . . . . . 34 111 7.1.1. Double Coordinate Curves . . . . . . . . . . . . . . 35 112 7.2. Octet Key Pair . . . . . . . . . . . . . . . . . . . . . 36 113 7.3. Symmetric Keys . . . . . . . . . . . . . . . . . . . . . 37 114 8. CBOR Encoding Restrictions . . . . . . . . . . . . . . . . . 38 115 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 38 116 10. Security Considerations . . . . . . . . . . . . . . . . . . . 38 117 11. References . . . . . . . . . . . . . . . . . . . . . . . . . 40 118 11.1. Normative References . . . . . . . . . . . . . . . . . . 40 119 11.2. Informative References . . . . . . . . . . . . . . . . . 42 120 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 43 121 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 44 123 1. Introduction 125 There has been an increased focus on small, constrained devices that 126 make up the Internet of Things (IoT). One of the standards that has 127 come out of this process is "Concise Binary Object Representation 128 (CBOR)" [RFC7049]. CBOR extended the data model of the JavaScript 129 Object Notation (JSON) [RFC8259] by allowing for binary data, among 130 other changes. CBOR is being adopted by several of the IETF working 131 groups dealing with the IoT world as their encoding of data 132 structures. CBOR was designed specifically to be both small in terms 133 of messages transport and implementation size and be a schema-free 134 decoder. A need exists to provide message security services for IoT, 135 and using CBOR as the message-encoding format makes sense. 137 The core COSE specification consists of two documents. 138 [I-D.ietf-cose-rfc8152bis-struct] contains the serialization 139 structures and the procedures for using the different cryptographic 140 algorithms. This document provides an initial set of algorithms for 141 use with those structures. Additional algorithms beyond what are in 142 this document are defined elsewhere. 144 1.1. Requirements Terminology 146 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 147 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 148 "OPTIONAL" in this document are to be interpreted as described in BCP 149 14 [RFC2119] [RFC8174] when, and only when, they appear in all 150 capitals, as shown here. 152 1.2. Changes from RFC8152 154 * Extract the sections dealing with specific algorithms into this 155 document. The sections dealing with structure and general 156 processing rules are placed in [I-D.ietf-cose-rfc8152bis-struct]. 158 1.3. Document Terminology 160 In this document, we use the following terminology: 162 Byte is a synonym for octet. 164 Constrained Application Protocol (CoAP) is a specialized web transfer 165 protocol for use in constrained systems. It is defined in [RFC7252]. 167 Authenticated Encryption (AE) [RFC5116] algorithms are those 168 encryption algorithms that provide an authentication check of the 169 plain text contents as part of the encryption service. 171 Authenticated Encryption with Associated Data (AEAD) [RFC5116] 172 algorithms provide the same content authentication service as AE 173 algorithms, but they additionally provide for authentication of non- 174 encrypted data as well. 176 1.4. CBOR Grammar 178 At the time that [RFC8152] was initially published, the CBOR Data 179 Definition Language (CDDL) [RFC8610] had not yet been published. 180 This document uses a variant of CDDL which is described in 181 [I-D.ietf-cose-rfc8152bis-struct] 183 1.5. Examples 185 A GitHub project has been created at that contains a set of testing examples as well. Each 187 example is found in a JSON file that contains the inputs used to 188 create the example, some of the intermediate values that can be used 189 in debugging the example and the output of the example presented in 190 both a hex and a CBOR diagnostic notation format. Some of the 191 examples at the site are designed failure testing cases; these are 192 clearly marked as such in the JSON file. If errors in the examples 193 in this document are found, the examples on GitHub will be updated, 194 and a note to that effect will be placed in the JSON file. 196 2. Signature Algorithms 198 Appendix Section 9.1 of [I-D.ietf-cose-rfc8152bis-struct] contains a 199 generic description of signature algorithms. The document defines 200 signature algorithm identifiers for two signature algorithms. 202 2.1. ECDSA 204 ECDSA [DSS] defines a signature algorithm using ECC. Implementations 205 SHOULD use a deterministic version of ECDSA such as the one defined 206 in [RFC6979]. The use of a deterministic signature algorithm allows 207 for systems to avoid relying on random number generators in order to 208 avoid generating the same value of 'k' (the per-message random 209 value). Biased generation of the value 'k' can be attacked, and 210 collisions of this value leads to leaked keys. It additionally 211 allows for doing deterministic tests for the signature algorithm. 212 The use of deterministic ECDSA does not lessen the need to have good 213 random number generation when creating the private key. 215 The ECDSA signature algorithm is parameterized with a hash function 216 (h). In the event that the length of the hash function output is 217 greater than the group of the key, the leftmost bytes of the hash 218 output are used. 220 The algorithms defined in this document can be found in Table 1. 222 +-------+-------+---------+------------------+ 223 | Name | Value | Hash | Description | 224 +=======+=======+=========+==================+ 225 | ES256 | -7 | SHA-256 | ECDSA w/ SHA-256 | 226 +-------+-------+---------+------------------+ 227 | ES384 | -35 | SHA-384 | ECDSA w/ SHA-384 | 228 +-------+-------+---------+------------------+ 229 | ES512 | -36 | SHA-512 | ECDSA w/ SHA-512 | 230 +-------+-------+---------+------------------+ 232 Table 1: ECDSA Algorithm Values 234 This document defines ECDSA to work only with the curves P-256, 235 P-384, and P-521. This document requires that the curves be encoded 236 using the 'EC2' (2 coordinate elliptic curve) key type. 237 Implementations need to check that the key type and curve are correct 238 when creating and verifying a signature. Other documents can define 239 it to work with other curves and points in the future. 241 In order to promote interoperability, it is suggested that SHA-256 be 242 used only with curve P-256, SHA-384 be used only with curve P-384, 243 and SHA-512 be used with curve P-521. This is aligned with the 244 recommendation in Section 4 of [RFC5480]. 246 The signature algorithm results in a pair of integers (R, S). These 247 integers will be the same length as the length of the key used for 248 the signature process. The signature is encoded by converting the 249 integers into bit strings of the same length as the key size. The 250 length is rounded up to the nearest byte and is left padded with zero 251 bits to get to the correct length. The two integers are then 252 concatenated together to form a byte string that is the resulting 253 signature. 255 Using the function defined in [RFC8017], the signature is: 257 Signature = I2OSP(R, n) | I2OSP(S, n) 259 where n = ceiling(key_length / 8) 261 When using a COSE key for this algorithm, the following checks are 262 made: 264 * The 'kty' field MUST be present, and it MUST be 'EC2'. 266 * If the 'alg' field is present, it MUST match the ECDSA signature 267 algorithm being used. 269 * If the 'key_ops' field is present, it MUST include 'sign' when 270 creating an ECDSA signature. 272 * If the 'key_ops' field is present, it MUST include 'verify' when 273 verifying an ECDSA signature. 275 2.1.1. Security Considerations 277 The security strength of the signature is no greater than the minimum 278 of the security strength associated with the bit length of the key 279 and the security strength of the hash function. 281 Note: Use of a deterministic signature technique is a good idea even 282 when good random number generation exists. Doing so both reduces the 283 possibility of having the same value of 'k' in two signature 284 operations and allows for reproducible signature values, which helps 285 testing. 287 There are two substitution attacks that can theoretically be mounted 288 against the ECDSA signature algorithm. 290 * Changing the curve used to validate the signature: If one changes 291 the curve used to validate the signature, then potentially one 292 could have two messages with the same signature, each computed 293 under a different curve. The only requirement on the new curve is 294 that its order be the same as the old one and it be acceptable to 295 the client. An example would be to change from using the curve 296 secp256r1 (aka P-256) to using secp256k1. (Both are 256-bit 297 curves.) We currently do not have any way to deal with this 298 version of the attack except to restrict the overall set of curves 299 that can be used. 301 * Change the hash function used to validate the signature: If one 302 either has two different hash functions of the same length or can 303 truncate a hash function down, then one could potentially find 304 collisions between the hash functions rather than within a single 305 hash function (for example, truncating SHA-512 to 256 bits might 306 collide with a SHA-256 bit hash value). As the hash algorithm is 307 part of the signature algorithm identifier, this attack is 308 mitigated by including a signature algorithm identifier in the 309 protected header. 311 2.2. Edwards-Curve Digital Signature Algorithms (EdDSAs) 313 [RFC8032] describes the elliptic curve signature scheme Edwards-curve 314 Digital Signature Algorithm (EdDSA). In that document, the signature 315 algorithm is instantiated using parameters for edwards25519 and 316 edwards448 curves. The document additionally describes two variants 317 of the EdDSA algorithm: Pure EdDSA, where no hash function is applied 318 to the content before signing, and HashEdDSA, where a hash function 319 is applied to the content before signing and the result of that hash 320 function is signed. For EdDSA, the content to be signed (either the 321 message or the pre-hash value) is processed twice inside of the 322 signature algorithm. For use with COSE, only the pure EdDSA version 323 is used. This is because it is not expected that extremely large 324 contents are going to be needed and, based on the arrangement of the 325 message structure, the entire message is going to need to be held in 326 memory in order to create or verify a signature. This means that 327 there does not appear to be a need to be able to do block updates of 328 the hash, followed by eliminating the message from memory. 329 Applications can provide the same features by defining the content of 330 the message as a hash value and transporting the COSE object (with 331 the hash value) and the content as separate items. 333 The algorithms defined in this document can be found in Table 2. A 334 single signature algorithm is defined, which can be used for multiple 335 curves. 337 +-------+-------+-------------+ 338 | Name | Value | Description | 339 +=======+=======+=============+ 340 | EdDSA | -8 | EdDSA | 341 +-------+-------+-------------+ 343 Table 2: EdDSA Algorithm Values 345 [RFC8032] describes the method of encoding the signature value. 347 When using a COSE key for this algorithm, the following checks are 348 made: 350 * The 'kty' field MUST be present, and it MUST be 'OKP' (Octet Key 351 Pair). 353 * The 'crv' field MUST be present, and it MUST be a curve defined 354 for this signature algorithm. 356 * If the 'alg' field is present, it MUST match 'EdDSA'. 358 * If the 'key_ops' field is present, it MUST include 'sign' when 359 creating an EdDSA signature. 361 * If the 'key_ops' field is present, it MUST include 'verify' when 362 verifying an EdDSA signature. 364 2.2.1. Security Considerations 366 How public values are computed is not the same when looking at EdDSA 367 and Elliptic Curve Diffie-Hellman (ECDH); for this reason, they 368 should not be used with the other algorithm. 370 If batch signature verification is performed, a well-seeded 371 cryptographic random number generator is REQUIRED. Signing and non- 372 batch signature verification are deterministic operations and do not 373 need random numbers of any kind. 375 3. Message Authentication Code (MAC) Algorithms 377 Appendix Section 9.2 of [I-D.ietf-cose-rfc8152bis-struct] contains a 378 generic description of MAC algorithms. This section defines the 379 conventions for two MAC algorithms. 381 3.1. Hash-Based Message Authentication Codes (HMACs) 383 HMAC [RFC2104] [RFC4231] was designed to deal with length extension 384 attacks. The algorithm was also designed to allow for new hash 385 algorithms to be directly plugged in without changes to the hash 386 function. The HMAC design process has been shown as solid since, 387 while the security of hash algorithms such as MD5 has decreased over 388 time; the security of HMAC combined with MD5 has not yet been shown 389 to be compromised [RFC6151]. 391 The HMAC algorithm is parameterized by an inner and outer padding, a 392 hash function (h), and an authentication tag value length. For this 393 specification, the inner and outer padding are fixed to the values 394 set in [RFC2104]. The length of the authentication tag corresponds 395 to the difficulty of producing a forgery. For use in constrained 396 environments, we define one HMAC algorithm that is truncated. There 397 are currently no known issues with truncation; however, the security 398 strength of the message tag is correspondingly reduced in strength. 399 When truncating, the leftmost tag length bits are kept and 400 transmitted. 402 The algorithms defined in this document can be found in Table 3. 404 +-------------+-------+---------+------------+----------------------+ 405 | Name | Value | Hash | Tag Length | Description | 406 +=============+=======+=========+============+======================+ 407 | HMAC | 4 | SHA-256 | 64 | HMAC w/ SHA-256 | 408 | 256/64 | | | | truncated to 64 bits | 409 +-------------+-------+---------+------------+----------------------+ 410 | HMAC | 5 | SHA-256 | 256 | HMAC w/ SHA-256 | 411 | 256/256 | | | | | 412 +-------------+-------+---------+------------+----------------------+ 413 | HMAC | 6 | SHA-384 | 384 | HMAC w/ SHA-384 | 414 | 384/384 | | | | | 415 +-------------+-------+---------+------------+----------------------+ 416 | HMAC | 7 | SHA-512 | 512 | HMAC w/ SHA-512 | 417 | 512/512 | | | | | 418 +-------------+-------+---------+------------+----------------------+ 420 Table 3: HMAC Algorithm Values 422 Some recipient algorithms carry the key while others derive a key 423 from secret data. For those algorithms that carry the key (such as 424 AES Key Wrap), the size of the HMAC key SHOULD be the same size as 425 the underlying hash function. For those algorithms that derive the 426 key (such as ECDH), the derived key MUST be the same size as the 427 underlying hash function. 429 When using a COSE key for this algorithm, the following checks are 430 made: 432 * The 'kty' field MUST be present, and it MUST be 'Symmetric'. 434 * If the 'alg' field is present, it MUST match the HMAC algorithm 435 being used. 437 * If the 'key_ops' field is present, it MUST include 'MAC create' 438 when creating an HMAC authentication tag. 440 * If the 'key_ops' field is present, it MUST include 'MAC verify' 441 when verifying an HMAC authentication tag. 443 Implementations creating and validating MAC values MUST validate that 444 the key type, key length, and algorithm are correct and appropriate 445 for the entities involved. 447 3.1.1. Security Considerations 449 HMAC has proved to be resistant to attack even when used with 450 weakened hash algorithms. The current best known attack is to brute 451 force the key. This means that key size is going to be directly 452 related to the security of an HMAC operation. 454 3.2. AES Message Authentication Code (AES-CBC-MAC) 456 AES-CBC-MAC is defined in [MAC]. (Note that this is not the same 457 algorithm as AES Cipher-Based Message Authentication Code (AES-CMAC) 458 [RFC4493].) 460 AES-CBC-MAC is parameterized by the key length, the authentication 461 tag length, and the IV used. For all of these algorithms, the IV is 462 fixed to all zeros. We provide an array of algorithms for various 463 key lengths and tag lengths. The algorithms defined in this document 464 are found in Table 4. 466 +---------+-------+------------+------------+------------------+ 467 | Name | Value | Key Length | Tag Length | Description | 468 +=========+=======+============+============+==================+ 469 | AES-MAC | 14 | 128 | 64 | AES-MAC 128-bit | 470 | 128/64 | | | | key, 64-bit tag | 471 +---------+-------+------------+------------+------------------+ 472 | AES-MAC | 15 | 256 | 64 | AES-MAC 256-bit | 473 | 256/64 | | | | key, 64-bit tag | 474 +---------+-------+------------+------------+------------------+ 475 | AES-MAC | 25 | 128 | 128 | AES-MAC 128-bit | 476 | 128/128 | | | | key, 128-bit tag | 477 +---------+-------+------------+------------+------------------+ 478 | AES-MAC | 26 | 256 | 128 | AES-MAC 256-bit | 479 | 256/128 | | | | key, 128-bit tag | 480 +---------+-------+------------+------------+------------------+ 482 Table 4: AES-MAC Algorithm Values 484 Keys may be obtained either from a key structure or from a recipient 485 structure. Implementations creating and validating MAC values MUST 486 validate that the key type, key length, and algorithm are correct and 487 appropriate for the entities involved. 489 When using a COSE key for this algorithm, the following checks are 490 made: 492 * The 'kty' field MUST be present, and it MUST be 'Symmetric'. 494 * If the 'alg' field is present, it MUST match the AES-MAC algorithm 495 being used. 497 * If the 'key_ops' field is present, it MUST include 'MAC create' 498 when creating an AES-MAC authentication tag. 500 * If the 'key_ops' field is present, it MUST include 'MAC verify' 501 when verifying an AES-MAC authentication tag. 503 3.2.1. Security Considerations 505 A number of attacks exist against Cipher Block Chaining Message 506 Authentication Code (CBC-MAC) that need to be considered. 508 * A single key must only be used for messages of a fixed or known 509 length. If this is not the case, an attacker will be able to 510 generate a message with a valid tag given two message and tag 511 pairs. This can be addressed by using different keys for messages 512 of different lengths. The current structure mitigates this 513 problem, as a specific encoding structure that includes lengths is 514 built and signed. (CMAC also addresses this issue.) 516 * Cipher Block Chaining (CBC) mode, if the same key is used for both 517 encryption and authentication operations, an attacker can produce 518 messages with a valid authentication code. 520 * If the IV can be modified, then messages can be forged. This is 521 addressed by fixing the IV to all zeros. 523 4. Content Encryption Algorithms 525 Appendix Section 9.3 of [I-D.ietf-cose-rfc8152bis-struct] contains a 526 generic description of Content Encryption algorithms. This document 527 defines the identifier and usages for three content encryption 528 algorithms. 530 4.1. AES GCM 532 The Galois/Counter Mode (GCM) mode is a generic authenticated 533 encryption block cipher mode defined in [AES-GCM]. The GCM mode is 534 combined with the AES block encryption algorithm to define an AEAD 535 cipher. 537 The GCM mode is parameterized by the size of the authentication tag 538 and the size of the nonce. This document fixes the size of the nonce 539 at 96 bits. The size of the authentication tag is limited to a small 540 set of values. For this document however, the size of the 541 authentication tag is fixed at 128 bits. 543 The set of algorithms defined in this document are in Table 5. 545 +---------+-------+------------------------------------------+ 546 | Name | Value | Description | 547 +=========+=======+==========================================+ 548 | A128GCM | 1 | AES-GCM mode w/ 128-bit key, 128-bit tag | 549 +---------+-------+------------------------------------------+ 550 | A192GCM | 2 | AES-GCM mode w/ 192-bit key, 128-bit tag | 551 +---------+-------+------------------------------------------+ 552 | A256GCM | 3 | AES-GCM mode w/ 256-bit key, 128-bit tag | 553 +---------+-------+------------------------------------------+ 555 Table 5: Algorithm Value for AES-GCM 557 Keys may be obtained either from a key structure or from a recipient 558 structure. Implementations encrypting and decrypting MUST validate 559 that the key type, key length, and algorithm are correct and 560 appropriate for the entities involved. 562 When using a COSE key for this algorithm, the following checks are 563 made: 565 * The 'kty' field MUST be present, and it MUST be 'Symmetric'. 567 * If the 'alg' field is present, it MUST match the AES-GCM algorithm 568 being used. 570 * If the 'key_ops' field is present, it MUST include 'encrypt' or 571 'wrap key' when encrypting. 573 * If the 'key_ops' field is present, it MUST include 'decrypt' or 574 'unwrap key' when decrypting. 576 4.1.1. Security Considerations 578 When using AES-GCM, the following restrictions MUST be enforced: 580 * The key and nonce pair MUST be unique for every message encrypted. 582 * The total amount of data encrypted for a single key MUST NOT 583 exceed 2^39 - 256 bits. An explicit check is required only in 584 environments where it is expected that it might be exceeded. 586 Consideration was given to supporting smaller tag values; the 587 constrained community would desire tag sizes in the 64-bit range. 588 Doing so drastically changes both the maximum messages size 589 (generally not an issue) and the number of times that a key can be 590 used. Given that Counter with CBC-MAC (CCM) is the usual mode for 591 constrained environments, restricted modes are not supported. 593 4.2. AES CCM 595 CCM is a generic authentication encryption block cipher mode defined 596 in [RFC3610]. The CCM mode is combined with the AES block encryption 597 algorithm to define a commonly used content encryption algorithm used 598 in constrained devices. 600 The CCM mode has two parameter choices. The first choice is M, the 601 size of the authentication field. The choice of the value for M 602 involves a trade-off between message growth (from the tag) and the 603 probability that an attacker can undetectably modify a message. The 604 second choice is L, the size of the length field. This value 605 requires a trade-off between the maximum message size and the size of 606 the Nonce. 608 It is unfortunate that the specification for CCM specified L and M as 609 a count of bytes rather than a count of bits. This leads to possible 610 misunderstandings where AES-CCM-8 is frequently used to refer to a 611 version of CCM mode where the size of the authentication is 64 bits 612 and not 8 bits. These values have traditionally been specified as 613 bit counts rather than byte counts. This document will follow the 614 convention of using bit counts so that it is easier to compare the 615 different algorithms presented in this document. 617 We define a matrix of algorithms in this document over the values of 618 L and M. Constrained devices are usually operating in situations 619 where they use short messages and want to avoid doing recipient- 620 specific cryptographic operations. This favors smaller values of 621 both L and M. Less-constrained devices will want to be able to use 622 larger messages and are more willing to generate new keys for every 623 operation. This favors larger values of L and M. 625 The following values are used for L: 627 16 bits (2): This limits messages to 2^16 bytes (64 KiB) in length. 628 This is sufficiently long for messages in the constrained world. 629 The nonce length is 13 bytes allowing for 2^104 possible values of 630 the nonce without repeating. 632 64 bits (8): This limits messages to 2^64 bytes in length. The 633 nonce length is 7 bytes allowing for 2^56 possible values of the 634 nonce without repeating. 636 The following values are used for M: 638 64 bits (8): This produces a 64-bit authentication tag. This 639 implies that there is a 1 in 2^64 chance that a modified message 640 will authenticate. 642 128 bits (16): This produces a 128-bit authentication tag. This 643 implies that there is a 1 in 2^128 chance that a modified message 644 will authenticate. 646 +--------------------+-------+----+-----+-----+---------------------+ 647 | Name | Value | L | M | k | Description | 648 +====================+=======+====+=====+=====+=====================+ 649 | AES-CCM-16-64-128 | 10 | 16 | 64 | 128 | AES-CCM mode | 650 | | | | | | 128-bit key, | 651 | | | | | | 64-bit tag, | 652 | | | | | | 13-byte nonce | 653 +--------------------+-------+----+-----+-----+---------------------+ 654 | AES-CCM-16-64-256 | 11 | 16 | 64 | 256 | AES-CCM mode | 655 | | | | | | 256-bit key, | 656 | | | | | | 64-bit tag, | 657 | | | | | | 13-byte nonce | 658 +--------------------+-------+----+-----+-----+---------------------+ 659 | AES-CCM-64-64-128 | 12 | 64 | 64 | 128 | AES-CCM mode | 660 | | | | | | 128-bit key, | 661 | | | | | | 64-bit tag, | 662 | | | | | | 7-byte nonce | 663 +--------------------+-------+----+-----+-----+---------------------+ 664 | AES-CCM-64-64-256 | 13 | 64 | 64 | 256 | AES-CCM mode | 665 | | | | | | 256-bit key, | 666 | | | | | | 64-bit tag, | 667 | | | | | | 7-byte nonce | 668 +--------------------+-------+----+-----+-----+---------------------+ 669 | AES-CCM-16-128-128 | 30 | 16 | 128 | 128 | AES-CCM mode | 670 | | | | | | 128-bit key, | 671 | | | | | | 128-bit tag, | 672 | | | | | | 13-byte nonce | 673 +--------------------+-------+----+-----+-----+---------------------+ 674 | AES-CCM-16-128-256 | 31 | 16 | 128 | 256 | AES-CCM mode | 675 | | | | | | 256-bit key, | 676 | | | | | | 128-bit tag, | 677 | | | | | | 13-byte nonce | 678 +--------------------+-------+----+-----+-----+---------------------+ 679 | AES-CCM-64-128-128 | 32 | 64 | 128 | 128 | AES-CCM mode | 680 | | | | | | 128-bit key, | 681 | | | | | | 128-bit tag, | 682 | | | | | | 7-byte nonce | 683 +--------------------+-------+----+-----+-----+---------------------+ 684 | AES-CCM-64-128-256 | 33 | 64 | 128 | 256 | AES-CCM mode | 685 | | | | | | 256-bit key, | 686 | | | | | | 128-bit tag, | 687 | | | | | | 7-byte nonce | 688 +--------------------+-------+----+-----+-----+---------------------+ 690 Table 6: Algorithm Values for AES-CCM 692 Keys may be obtained either from a key structure or from a recipient 693 structure. Implementations encrypting and decrypting MUST validate 694 that the key type, key length, and algorithm are correct and 695 appropriate for the entities involved. 697 When using a COSE key for this algorithm, the following checks are 698 made: 700 * The 'kty' field MUST be present, and it MUST be 'Symmetric'. 702 * If the 'alg' field is present, it MUST match the AES-CCM algorithm 703 being used. 705 * If the 'key_ops' field is present, it MUST include 'encrypt' or 706 'wrap key' when encrypting. 708 * If the 'key_ops' field is present, it MUST include 'decrypt' or 709 'unwrap key' when decrypting. 711 4.2.1. Security Considerations 713 When using AES-CCM, the following restrictions MUST be enforced: 715 * The key and nonce pair MUST be unique for every message encrypted. 716 Note that the value of L influences the number of unique nonces. 718 * The total number of times the AES block cipher is used MUST NOT 719 exceed 2^61 operations. This limitation is the sum of times the 720 block cipher is used in computing the MAC value and in performing 721 stream encryption operations. An explicit check is required only 722 in environments where it is expected that it might be exceeded. 724 [RFC3610] additionally calls out one other consideration of note. It 725 is possible to do a pre-computation attack against the algorithm in 726 cases where portions of the plaintext are highly predictable. This 727 reduces the security of the key size by half. Ways to deal with this 728 attack include adding a random portion to the nonce value and/or 729 increasing the key size used. Using a portion of the nonce for a 730 random value will decrease the number of messages that a single key 731 can be used for. Increasing the key size may require more resources 732 in the constrained device. See Sections 5 and 10 of [RFC3610] for 733 more information. 735 4.3. ChaCha20 and Poly1305 737 ChaCha20 and Poly1305 combined together is an AEAD mode that is 738 defined in [RFC8439]. This is an algorithm defined to be a cipher 739 that is not AES and thus would not suffer from any future weaknesses 740 found in AES. These cryptographic functions are designed to be fast 741 in software-only implementations. 743 The ChaCha20/Poly1305 AEAD construction defined in [RFC8439] has no 744 parameterization. It takes a 256-bit key and a 96-bit nonce, as well 745 as the plaintext and additional data as inputs and produces the 746 ciphertext as an option. We define one algorithm identifier for this 747 algorithm in Table 7. 749 +-------------------+-------+--------------------------+ 750 | Name | Value | Description | 751 +===================+=======+==========================+ 752 | ChaCha20/Poly1305 | 24 | ChaCha20/Poly1305 w/ | 753 | | | 256-bit key, 128-bit tag | 754 +-------------------+-------+--------------------------+ 756 Table 7: Algorithm Value for AES-GCM 758 Keys may be obtained either from a key structure or from a recipient 759 structure. Implementations encrypting and decrypting MUST validate 760 that the key type, key length, and algorithm are correct and 761 appropriate for the entities involved. 763 When using a COSE key for this algorithm, the following checks are 764 made: 766 * The 'kty' field MUST be present, and it MUST be 'Symmetric'. 768 * If the 'alg' field is present, it MUST match the ChaCha20/Poly1305 769 algorithm being used. 771 * If the 'key_ops' field is present, it MUST include 'encrypt' or 772 'wrap key' when encrypting. 774 * If the 'key_ops' field is present, it MUST include 'decrypt' or 775 'unwrap key' when decrypting. 777 4.3.1. Security Considerations 779 The key and nonce values MUST be a unique pair for every invocation 780 of the algorithm. Nonce counters are considered to be an acceptable 781 way of ensuring that they are unique. 783 5. Key Derivation Functions (KDFs) 785 Appendix Section 9.4 of [I-D.ietf-cose-rfc8152bis-struct] contains a 786 generic description of Key Derivation Functions. This document 787 defines a single context structure and a single KDF. These elements 788 are used for all of the recipient algorithms defined in this document 789 that require a KDF process. These algorithms are defined in Sections 790 6.1.2, 6.3, and 6.4. 792 5.1. HMAC-Based Extract-and-Expand Key Derivation Function (HKDF) 794 The HKDF key derivation algorithm is defined in [RFC5869]. 796 The HKDF algorithm takes these inputs: 798 secret -- a shared value that is secret. Secrets may be either 799 previously shared or derived from operations like a Diffie-Hellman 800 (DH) key agreement. 802 salt -- an optional value that is used to change the generation 803 process. The salt value can be either public or private. If the 804 salt is public and carried in the message, then the 'salt' 805 algorithm header parameter defined in Table 9 is used. While 806 [RFC5869] suggests that the length of the salt be the same as the 807 length of the underlying hash value, any positive salt length will 808 improve the security as different key values will be generated. 809 This parameter is protected by being included in the key 810 computation and does not need to be separately authenticated. The 811 salt value does not need to be unique for every message sent. 813 length -- the number of bytes of output that need to be generated. 815 context information -- Information that describes the context in 816 which the resulting value will be used. Making this information 817 specific to the context in which the material is going to be used 818 ensures that the resulting material will always be tied to that 819 usage. The context structure defined in Section 5.2 is used by 820 the KDFs in this document. 822 PRF -- The underlying pseudorandom function to be used in the HKDF 823 algorithm. The PRF is encoded into the HKDF algorithm selection. 825 HKDF is defined to use HMAC as the underlying PRF. However, it is 826 possible to use other functions in the same construct to provide a 827 different KDF that is more appropriate in the constrained world. 828 Specifically, one can use AES-CBC-MAC as the PRF for the expand step, 829 but not for the extract step. When using a good random shared secret 830 of the correct length, the extract step can be skipped. For the AES 831 algorithm versions, the extract step is always skipped. 833 The extract step cannot be skipped if the secret is not uniformly 834 random, for example, if it is the result of an ECDH key agreement 835 step. This implies that the AES HKDF version cannot be used with 836 ECDH. If the extract step is skipped, the 'salt' value is not used 837 as part of the HKDF functionality. 839 The algorithms defined in this document are found in Table 8. 841 +--------------+-------------------+------------------------+ 842 | Name | PRF | Description | 843 +==============+===================+========================+ 844 | HKDF SHA-256 | HMAC with SHA-256 | HKDF using HMAC | 845 | | | SHA-256 as the PRF | 846 +--------------+-------------------+------------------------+ 847 | HKDF SHA-512 | HMAC with SHA-512 | HKDF using HMAC | 848 | | | SHA-512 as the PRF | 849 +--------------+-------------------+------------------------+ 850 | HKDF AES- | AES-CBC-MAC-128 | HKDF using AES-MAC as | 851 | MAC-128 | | the PRF w/ 128-bit key | 852 +--------------+-------------------+------------------------+ 853 | HKDF AES- | AES-CBC-MAC-256 | HKDF using AES-MAC as | 854 | MAC-256 | | the PRF w/ 256-bit key | 855 +--------------+-------------------+------------------------+ 857 Table 8: HKDF Algorithms 859 +------+-------+------+----------------------------+-------------+ 860 | Name | Label | Type | Algorithm | Description | 861 +======+=======+======+============================+=============+ 862 | salt | -20 | bstr | direct+HKDF-SHA-256, | Random salt | 863 | | | | direct+HKDF-SHA-512, | | 864 | | | | direct+HKDF-AES-128, | | 865 | | | | direct+HKDF-AES-256, ECDH- | | 866 | | | | ES+HKDF-256, ECDH-ES+HKDF- | | 867 | | | | 512, ECDH- SS+HKDF-256, | | 868 | | | | ECDH-SS+HKDF-512, ECDH- | | 869 | | | | ES+A128KW, ECDH-ES+A192KW, | | 870 | | | | ECDH-ES+A256KW, ECDH- | | 871 | | | | SS+A128KW, ECDH-SS+A192KW, | | 872 | | | | ECDH-SS+A256KW | | 873 +------+-------+------+----------------------------+-------------+ 875 Table 9: HKDF Algorithm Parameters 877 5.2. Context Information Structure 879 The context information structure is used to ensure that the derived 880 keying material is "bound" to the context of the transaction. The 881 context information structure used here is based on that defined in 882 [SP800-56A]. By using CBOR for the encoding of the context 883 information structure, we automatically get the same type and length 884 separation of fields that is obtained by the use of ASN.1. This 885 means that there is no need to encode the lengths for the base 886 elements, as it is done by the encoding used in JOSE (Section 4.6.2 887 of [RFC7518]). 889 The context information structure refers to PartyU and PartyV as the 890 two parties that are doing the key derivation. Unless the 891 application protocol defines differently, we assign PartyU to the 892 entity that is creating the message and PartyV to the entity that is 893 receiving the message. By doing this association, different keys 894 will be derived for each direction as the context information is 895 different in each direction. 897 The context structure is built from information that is known to both 898 entities. This information can be obtained from a variety of 899 sources: 901 * Fields can be defined by the application. This is commonly used 902 to assign fixed names to parties, but it can be used for other 903 items such as nonces. 905 * Fields can be defined by usage of the output. Examples of this 906 are the algorithm and key size that are being generated. 908 * Fields can be defined by parameters from the message. We define a 909 set of parameters in Table 10 that can be used to carry the values 910 associated with the context structure. Examples of this are 911 identities and nonce values. These parameters are designed to be 912 placed in the unprotected bucket of the recipient structure; they 913 do not need to be in the protected bucket since they already are 914 included in the cryptographic computation by virtue of being 915 included in the context structure. 917 +----------+-------+------+---------------------------+-------------+ 918 | Name | Label | Type | Algorithm | Description | 919 +==========+=======+======+===========================+=============+ 920 | PartyU | -21 | bstr | direct+HKDF-SHA-256, | Party U | 921 | identity | | | direct+HKDF-SHA-512, | identity | 922 | | | | direct+HKDF-AES-128, | information | 923 | | | | direct+HKDF-AES-256, | | 924 | | | | ECDH-ES+HKDF-256, | | 925 | | | | ECDH-ES+HKDF-512, | | 926 | | | | ECDH- SS+HKDF-256, | | 927 | | | | ECDH-SS+HKDF-512, | | 928 | | | | ECDH-ES+A128KW, | | 929 | | | | ECDH-ES+A192KW, | | 930 | | | | ECDH-ES+A256KW, | | 931 | | | | ECDH-SS+A128KW, | | 932 | | | | ECDH-SS+A192KW, | | 933 | | | | ECDH-SS+A256KW | | 934 +----------+-------+------+---------------------------+-------------+ 935 | PartyU | -22 | bstr | direct+HKDF-SHA-256, | Party U | 936 | nonce | | / | direct+HKDF-SHA-512, | provided | 937 | | | int | direct+HKDF-AES-128, | nonce | 938 | | | | direct+HKDF-AES-256, | | 939 | | | | ECDH-ES+HKDF-256, | | 940 | | | | ECDH-ES+HKDF-512, | | 941 | | | | ECDH- SS+HKDF-256, | | 942 | | | | ECDH-SS+HKDF-512, | | 943 | | | | ECDH-ES+A128KW, | | 944 | | | | ECDH-ES+A192KW, | | 945 | | | | ECDH-ES+A256KW, | | 946 | | | | ECDH-SS+A128KW, | | 947 | | | | ECDH-SS+A192KW, | | 948 | | | | ECDH-SS+A256KW | | 949 +----------+-------+------+---------------------------+-------------+ 950 | PartyU | -23 | bstr | direct+HKDF-SHA-256, | Party U | 951 | other | | | direct+HKDF-SHA-512, | other | 952 | | | | direct+HKDF-AES-128, | provided | 953 | | | | direct+HKDF-AES-256, | information | 954 | | | | ECDH-ES+HKDF-256, | | 955 | | | | ECDH-ES+HKDF-512, | | 956 | | | | ECDH- SS+HKDF-256, | | 957 | | | | ECDH-SS+HKDF-512, | | 958 | | | | ECDH-ES+A128KW, | | 959 | | | | ECDH-ES+A192KW, | | 960 | | | | ECDH-ES+A256KW, | | 961 | | | | ECDH-SS+A128KW, | | 962 | | | | ECDH-SS+A192KW, | | 963 | | | | ECDH-SS+A256KW | | 964 +----------+-------+------+---------------------------+-------------+ 965 | PartyV | -24 | bstr | direct+HKDF-SHA-256, | Party V | 966 | identity | | | direct+HKDF-SHA-512, | identity | 967 | | | | direct+HKDF-AES-128, | information | 968 | | | | direct+HKDF-AES-256, | | 969 | | | | ECDH-ES+HKDF-256, | | 970 | | | | ECDH-ES+HKDF-512, | | 971 | | | | ECDH- SS+HKDF-256, | | 972 | | | | ECDH-SS+HKDF-512, | | 973 | | | | ECDH-ES+A128KW, | | 974 | | | | ECDH-ES+A192KW, | | 975 | | | | ECDH-ES+A256KW, | | 976 | | | | ECDH-SS+A128KW, | | 977 | | | | ECDH-SS+A192KW, | | 978 | | | | ECDH-SS+A256KW | | 979 +----------+-------+------+---------------------------+-------------+ 980 | PartyV | -25 | bstr | direct+HKDF-SHA-256, | Party V | 981 | nonce | | / | direct+HKDF-SHA-512, | provided | 982 | | | int | direct+HKDF-AES-128, | nonce | 983 | | | | direct+HKDF-AES-256, | | 984 | | | | ECDH-ES+HKDF-256, | | 985 | | | | ECDH-ES+HKDF-512, | | 986 | | | | ECDH- SS+HKDF-256, | | 987 | | | | ECDH-SS+HKDF-512, | | 988 | | | | ECDH-ES+A128KW, | | 989 | | | | ECDH-ES+A192KW, | | 990 | | | | ECDH-ES+A256KW, | | 991 | | | | ECDH-SS+A128KW, | | 992 | | | | ECDH-SS+A192KW, | | 993 | | | | ECDH-SS+A256KW | | 994 +----------+-------+------+---------------------------+-------------+ 995 | PartyV | -26 | bstr | direct+HKDF-SHA-256, | Party V | 996 | other | | | direct+HKDF-SHA-512, | other | 997 | | | | direct+HKDF-AES-128, | provided | 998 | | | | direct+HKDF-AES-256, | information | 999 | | | | ECDH-ES+HKDF-256, | | 1000 | | | | ECDH-ES+HKDF-512, | | 1001 | | | | ECDH- SS+HKDF-256, | | 1002 | | | | ECDH-SS+HKDF-512, | | 1003 | | | | ECDH-ES+A128KW, | | 1004 | | | | ECDH-ES+A192KW, | | 1005 | | | | ECDH-ES+A256KW, | | 1006 | | | | ECDH-SS+A128KW, | | 1007 | | | | ECDH-SS+A192KW, | | 1008 | | | | ECDH-SS+A256KW | | 1009 +----------+-------+------+---------------------------+-------------+ 1011 Table 10: Context Algorithm Parameters 1013 We define a CBOR object to hold the context information. This object 1014 is referred to as COSE_KDF_Context. The object is based on a CBOR 1015 array type. The fields in the array are: 1017 AlgorithmID: This field indicates the algorithm for which the key 1018 material will be used. This normally is either a key wrap 1019 algorithm identifier or a content encryption algorithm identifier. 1020 The values are from the "COSE Algorithms" registry. This field is 1021 required to be present. The field exists in the context 1022 information so that a different key is generated for each 1023 algorithm even of all of the other context information is the 1024 same. In practice, this means if algorithm A is broken and thus 1025 finding the key is relatively easy, the key derived for algorithm 1026 B will not be the same as the key derived for algorithm A. 1028 PartyUInfo: This field holds information about party U. The 1029 PartyUInfo is encoded as a CBOR array. The elements of PartyUInfo 1030 are encoded in the order presented below. The elements of the 1031 PartyUInfo array are: 1033 identity: This contains the identity information for party U. 1034 The identities can be assigned in one of two manners. First, a 1035 protocol can assign identities based on roles. For example, 1036 the roles of "client" and "server" may be assigned to different 1037 entities in the protocol. Each entity would then use the 1038 correct label for the data they send or receive. The second 1039 way for a protocol to assign identities is to use a name based 1040 on a naming system (i.e., DNS, X.509 names). 1042 We define an algorithm parameter 'PartyU identity' that can be 1043 used to carry identity information in the message. However, 1044 identity information is often known as part of the protocol and 1045 can thus be inferred rather than made explicit. If identity 1046 information is carried in the message, applications SHOULD have 1047 a way of validating the supplied identity information. The 1048 identity information does not need to be specified and is set 1049 to nil in that case. 1051 nonce: This contains a nonce value. The nonce can either be 1052 implicit from the protocol or be carried as a value in the 1053 unprotected headers. 1055 We define an algorithm parameter 'PartyU nonce' that can be 1056 used to carry this value in the message; however, the nonce 1057 value could be determined by the application and the value 1058 determined from elsewhere. 1060 This option does not need to be specified and is set to nil in 1061 that case. 1063 other: This contains other information that is defined by the 1064 protocol. This option does not need to be specified and is set 1065 to nil in that case. 1067 PartyVInfo: This field holds information about party V. The content 1068 of the structure is the same as for the PartyUInfo but for party 1069 V. 1071 SuppPubInfo: This field contains public information that is mutually 1072 known to both parties. 1074 keyDataLength: This is set to the number of bits of the desired 1075 output value. This practice means if algorithm A can use two 1076 different key lengths, the key derived for longer key size will 1077 not contain the key for shorter key size as a prefix. 1079 protected: This field contains the protected parameter field. If 1080 there are no elements in the protected field, then use a zero- 1081 length bstr. 1083 other: This field is for free form data defined by the 1084 application. An example is that an application could define 1085 two different strings to be placed here to generate different 1086 keys for a data stream versus a control stream. This field is 1087 optional and will only be present if the application defines a 1088 structure for this information. Applications that define this 1089 SHOULD use CBOR to encode the data so that types and lengths 1090 are correctly included. 1092 SuppPrivInfo: This field contains private information that is 1093 mutually known private information. An example of this 1094 information would be a preexisting shared secret. (This could, 1095 for example, be used in combination with an ECDH key agreement to 1096 provide a secondary proof of identity.) The field is optional and 1097 will only be present if the application defines a structure for 1098 this information. Applications that define this SHOULD use CBOR 1099 to encode the data so that types and lengths are correctly 1100 included. 1102 The following CDDL fragment corresponds to the text above. 1104 PartyInfo = ( 1105 identity : bstr / nil, 1106 nonce : bstr / int / nil, 1107 other : bstr / nil 1108 ) 1110 COSE_KDF_Context = [ 1111 AlgorithmID : int / tstr, 1112 PartyUInfo : [ PartyInfo ], 1113 PartyVInfo : [ PartyInfo ], 1114 SuppPubInfo : [ 1115 keyDataLength : uint, 1116 protected : empty_or_serialized_map, 1117 ? other : bstr 1118 ], 1119 ? SuppPrivInfo : bstr 1120 ] 1122 6. Content Key Distribution Methods 1124 Appendix Section 9.5 of [I-D.ietf-cose-rfc8152bis-struct] contains a 1125 generic description of content key distribution methods. This 1126 document defines the identifiers and usage for a number of content 1127 key distribution methods. 1129 6.1. Direct Encryption 1131 Direct encryption algorithm is defined in Appendix Section 9.5.1 of 1132 [I-D.ietf-cose-rfc8152bis-struct]. Information about how to fill in 1133 the COSE_Recipient structure are detailed there. 1135 6.1.1. Direct Key 1137 This recipient algorithm is the simplest; the identified key is 1138 directly used as the key for the next layer down in the message. 1139 There are no algorithm parameters defined for this algorithm. The 1140 algorithm identifier value is assigned in Table 11. 1142 When this algorithm is used, the protected field MUST be zero length. 1143 The key type MUST be 'Symmetric'. 1145 +--------+-------+-------------------+ 1146 | Name | Value | Description | 1147 +========+=======+===================+ 1148 | direct | -6 | Direct use of CEK | 1149 +--------+-------+-------------------+ 1151 Table 11: Direct Key 1153 6.1.1.1. Security Considerations 1155 This recipient algorithm has several potential problems that need to 1156 be considered: 1158 * These keys need to have some method to be regularly updated over 1159 time. All of the content encryption algorithms specified in this 1160 document have limits on how many times a key can be used without 1161 significant loss of security. 1163 * These keys need to be dedicated to a single algorithm. There have 1164 been a number of attacks developed over time when a single key is 1165 used for multiple different algorithms. One example of this is 1166 the use of a single key for both the CBC encryption mode and the 1167 CBC-MAC authentication mode. 1169 * Breaking one message means all messages are broken. If an 1170 adversary succeeds in determining the key for a single message, 1171 then the key for all messages is also determined. 1173 6.1.2. Direct Key with KDF 1175 These recipient algorithms take a common shared secret between the 1176 two parties and applies the HKDF function (Section 5.1), using the 1177 context structure defined in Section 5.2 to transform the shared 1178 secret into the CEK. The 'protected' field can be of non-zero 1179 length. Either the 'salt' parameter of HKDF or the 'PartyU nonce' 1180 parameter of the context structure MUST be present. The salt/nonce 1181 parameter can be generated either randomly or deterministically. The 1182 requirement is that it be a unique value for the shared secret in 1183 question. 1185 If the salt/nonce value is generated randomly, then it is suggested 1186 that the length of the random value be the same length as the hash 1187 function underlying HKDF. While there is no way to guarantee that it 1188 will be unique, there is a high probability that it will be unique. 1189 If the salt/nonce value is generated deterministically, it can be 1190 guaranteed to be unique, and thus there is no length requirement. 1192 A new IV must be used for each message if the same key is used. The 1193 IV can be modified in a predictable manner, a random manner, or an 1194 unpredictable manner (i.e., encrypting a counter). 1196 The IV used for a key can also be generated from the same HKDF 1197 functionality as the key is generated. If HKDF is used for 1198 generating the IV, the algorithm identifier is set to "IV- 1199 GENERATION". 1201 When these algorithms are used, the key type MUST be 'symmetric'. 1203 The set of algorithms defined in this document can be found in 1204 Table 12. 1206 +---------------------+-------+--------------+---------------------+ 1207 | Name | Value | KDF | Description | 1208 +=====================+=======+==============+=====================+ 1209 | direct+HKDF-SHA-256 | -10 | HKDF SHA-256 | Shared secret w/ | 1210 | | | | HKDF and SHA-256 | 1211 +---------------------+-------+--------------+---------------------+ 1212 | direct+HKDF-SHA-512 | -11 | HKDF SHA-512 | Shared secret w/ | 1213 | | | | HKDF and SHA-512 | 1214 +---------------------+-------+--------------+---------------------+ 1215 | direct+HKDF-AES-128 | -12 | HKDF AES- | Shared secret w/ | 1216 | | | MAC-128 | AES-MAC 128-bit key | 1217 +---------------------+-------+--------------+---------------------+ 1218 | direct+HKDF-AES-256 | -13 | HKDF AES- | Shared secret w/ | 1219 | | | MAC-256 | AES-MAC 256-bit key | 1220 +---------------------+-------+--------------+---------------------+ 1222 Table 12: Direct Key with KDF 1224 When using a COSE key for this algorithm, the following checks are 1225 made: 1227 * The 'kty' field MUST be present, and it MUST be 'Symmetric'. 1229 * If the 'alg' field is present, it MUST match the algorithm being 1230 used. 1232 * If the 'key_ops' field is present, it MUST include 'deriveKey' or 1233 'deriveBits'. 1235 6.1.2.1. Security Considerations 1237 The shared secret needs to have some method to be regularly updated 1238 over time. The shared secret forms the basis of trust. Although not 1239 used directly, it should still be subject to scheduled rotation. 1241 While these methods do not provide for perfect forward secrecy, as 1242 the same shared secret is used for all of the keys generated, if the 1243 key for any single message is discovered, only the message (or series 1244 of messages) using that derived key are compromised. A new key 1245 derivation step will generate a new key that requires the same amount 1246 of work to get the key. 1248 6.2. AES Key Wrap 1250 The AES Key Wrap algorithm is defined in [RFC3394]. This algorithm 1251 uses an AES key to wrap a value that is a multiple of 64 bits. As 1252 such, it can be used to wrap a key for any of the content encryption 1253 algorithms defined in this document. The algorithm requires a single 1254 fixed parameter, the initial value. This is fixed to the value 1255 specified in Section 2.2.3.1 of [RFC3394]. There are no public 1256 parameters that vary on a per-invocation basis. The protected header 1257 field MUST be empty. 1259 Keys may be obtained either from a key structure or from a recipient 1260 structure. Implementations encrypting and decrypting MUST validate 1261 that the key type, key length, and algorithm are correct and 1262 appropriate for the entities involved. 1264 When using a COSE key for this algorithm, the following checks are 1265 made: 1267 * The 'kty' field MUST be present, and it MUST be 'Symmetric'. 1269 * If the 'alg' field is present, it MUST match the AES Key Wrap 1270 algorithm being used. 1272 * If the 'key_ops' field is present, it MUST include 'encrypt' or 1273 'wrap key' when encrypting. 1275 * If the 'key_ops' field is present, it MUST include 'decrypt' or 1276 'unwrap key' when decrypting. 1278 +--------+-------+----------+-----------------------------+ 1279 | Name | Value | Key Size | Description | 1280 +========+=======+==========+=============================+ 1281 | A128KW | -3 | 128 | AES Key Wrap w/ 128-bit key | 1282 +--------+-------+----------+-----------------------------+ 1283 | A192KW | -4 | 192 | AES Key Wrap w/ 192-bit key | 1284 +--------+-------+----------+-----------------------------+ 1285 | A256KW | -5 | 256 | AES Key Wrap w/ 256-bit key | 1286 +--------+-------+----------+-----------------------------+ 1288 Table 13: AES Key Wrap Algorithm Values 1290 6.2.1. Security Considerations for AES-KW 1292 The shared secret needs to have some method to be regularly updated 1293 over time. The shared secret is the basis of trust. 1295 6.3. Direct ECDH 1297 The mathematics for ECDH can be found in [RFC6090]. In this 1298 document, the algorithm is extended to be used with the two curves 1299 defined in [RFC7748]. 1301 ECDH is parameterized by the following: 1303 * Curve Type/Curve: The curve selected controls not only the size of 1304 the shared secret, but the mathematics for computing the shared 1305 secret. The curve selected also controls how a point in the curve 1306 is represented and what happens for the identity points on the 1307 curve. In this specification, we allow for a number of different 1308 curves to be used. A set of curves are defined in Table 18. 1310 The math used to obtain the computed secret is based on the curve 1311 selected and not on the ECDH algorithm. For this reason, a new 1312 algorithm does not need to be defined for each of the curves. 1314 * Computed Secret to Shared Secret: Once the computed secret is 1315 known, the resulting value needs to be converted to a byte string 1316 to run the KDF. The x-coordinate is used for all of the curves 1317 defined in this document. For curves X25519 and X448, the 1318 resulting value is used directly as it is a byte string of a known 1319 length. For the P-256, P-384, and P-521 curves, the x-coordinate 1320 is run through the I2OSP function defined in [RFC8017], using the 1321 same computation for n as is defined in Section 2.1. 1323 * Ephemeral-Static or Static-Static: The key agreement process may 1324 be done using either a static or an ephemeral key for the sender's 1325 side. When using ephemeral keys, the sender MUST generate a new 1326 ephemeral key for every key agreement operation. The ephemeral 1327 key is placed in the 'ephemeral key' parameter and MUST be present 1328 for all algorithm identifiers that use ephemeral keys. When using 1329 static keys, the sender MUST either generate a new random value or 1330 create a unique value. For the KDFs used, this means either the 1331 'salt' parameter for HKDF (Table 9) or the 'PartyU nonce' 1332 parameter for the context structure (Table 10) MUST be present 1333 (both can be present if desired). The value in the parameter MUST 1334 be unique for the pair of keys being used. It is acceptable to 1335 use a global counter that is incremented for every static-static 1336 operation and use the resulting value. When using static keys, 1337 the static key should be identified to the recipient. The static 1338 key can be identified either by providing the key ('static key') 1339 or by providing a key identifier for the static key ('static key 1340 id'). Both of these parameters are defined in Table 15. 1342 * Key Derivation Algorithm: The result of an ECDH key agreement 1343 process does not provide a uniformly random secret. As such, it 1344 needs to be run through a KDF in order to produce a usable key. 1345 Processing the secret through a KDF also allows for the 1346 introduction of context material: how the key is going to be used 1347 and one-time material for static-static key agreement. All of the 1348 algorithms defined in this document use one of the HKDF algorithms 1349 defined in Section 5.1 with the context structure defined in 1350 Section 5.2. 1352 * Key Wrap Algorithm: No key wrap algorithm is used. This is 1353 represented in Table 14 as 'none'. The key size for the context 1354 structure is the content layer encryption algorithm size. 1356 COSE does not have an Ephemeral-Ephemeral version defined. The 1357 reason for this is that COSE is not an online protocol by itself and 1358 thus does not have a method to establish ephemeral secrets on both 1359 sides. The expectation is that a protocol would establish the 1360 secrets for both sides, and then they would be used as static-static 1361 for the purposes of COSE, or that the protocol would generate a 1362 shared secret and a direct encryption would be used. 1364 The set of direct ECDH algorithms defined in this document are found 1365 in Table 14. 1367 +-----------+-------+---------+------------+------+-----------------+ 1368 | Name | Value | KDF | Ephemeral- | Key | Description | 1369 | | | | Static | Wrap | | 1370 +===========+=======+=========+============+======+=================+ 1371 | ECDH-ES | -25 | HKDF - | yes | none | ECDH ES w/ HKDF | 1372 | + | | SHA-256 | | | - generate key | 1373 | HKDF-256 | | | | | directly | 1374 +-----------+-------+---------+------------+------+-----------------+ 1375 | ECDH-ES | -26 | HKDF - | yes | none | ECDH ES w/ HKDF | 1376 | + | | SHA-512 | | | - generate key | 1377 | HKDF-512 | | | | | directly | 1378 +-----------+-------+---------+------------+------+-----------------+ 1379 | ECDH-SS | -27 | HKDF - | no | none | ECDH SS w/ HKDF | 1380 | + | | SHA-256 | | | - generate key | 1381 | HKDF-256 | | | | | directly | 1382 +-----------+-------+---------+------------+------+-----------------+ 1383 | ECDH-SS | -28 | HKDF - | no | none | ECDH SS w/ HKDF | 1384 | + | | SHA-512 | | | - generate key | 1385 | HKDF-512 | | | | | directly | 1386 +-----------+-------+---------+------------+------+-----------------+ 1388 Table 14: ECDH Algorithm Values 1390 +-----------+-------+----------+-------------------+-------------+ 1391 | Name | Label | Type | Algorithm | Description | 1392 +===========+=======+==========+===================+=============+ 1393 | ephemeral | -1 | COSE_Key | ECDH-ES+HKDF-256, | Ephemeral | 1394 | key | | | ECDH-ES+HKDF-512, | public key | 1395 | | | | ECDH-ES+A128KW, | for the | 1396 | | | | ECDH- ES+A192KW, | sender | 1397 | | | | ECDH-ES+A256KW | | 1398 +-----------+-------+----------+-------------------+-------------+ 1399 | static | -2 | COSE_Key | ECDH-SS+HKDF-256, | Static | 1400 | key | | | ECDH-SS+HKDF-512, | public key | 1401 | | | | ECDH-SS+A128KW, | for the | 1402 | | | | ECDH- SS+A192KW, | sender | 1403 | | | | ECDH-SS+A256KW | | 1404 +-----------+-------+----------+-------------------+-------------+ 1405 | static | -3 | bstr | ECDH-SS+HKDF-256, | Static | 1406 | key id | | | ECDH-SS+HKDF-512, | public key | 1407 | | | | ECDH-SS+A128KW, | identifier | 1408 | | | | ECDH- SS+A192KW, | for the | 1409 | | | | ECDH-SS+A256KW | sender | 1410 +-----------+-------+----------+-------------------+-------------+ 1412 Table 15: ECDH Algorithm Parameters 1414 This document defines these algorithms to be used with the curves 1415 P-256, P-384, P-521, X25519, and X448. Implementations MUST verify 1416 that the key type and curve are correct. Different curves are 1417 restricted to different key types. Implementations MUST verify that 1418 the curve and algorithm are appropriate for the entities involved. 1420 When using a COSE key for this algorithm, the following checks are 1421 made: 1423 * The 'kty' field MUST be present, and it MUST be 'EC2' or 'OKP'. 1425 * If the 'alg' field is present, it MUST match the key agreement 1426 algorithm being used. 1428 * If the 'key_ops' field is present, it MUST include 'derive key' or 1429 'derive bits' for the private key. 1431 * If the 'key_ops' field is present, it MUST be empty for the public 1432 key. 1434 6.3.1. Security Considerations 1436 There is a method of checking that points provided from external 1437 entities are valid. For the 'EC2' key format, this can be done by 1438 checking that the x and y values form a point on the curve. For the 1439 'OKP' format, there is no simple way to do point validation. 1441 Consideration was given to requiring that the public keys of both 1442 entities be provided as part of the key derivation process (as 1443 recommended in Section 6.1 of [RFC7748]). This was not done as COSE 1444 is used in a store and forward format rather than in online key 1445 exchange. In order for this to be a problem, either the receiver 1446 public key has to be chosen maliciously or the sender has to be 1447 malicious. In either case, all security evaporates anyway. 1449 A proof of possession of the private key associated with the public 1450 key is recommended when a key is moved from untrusted to trusted 1451 (either by the end user or by the entity that is responsible for 1452 making trust statements on keys). 1454 6.4. ECDH with Key Wrap 1456 These algorithms are defined in Table 16. 1458 ECDH with Key Agreement is parameterized by the same parameters as 1459 for ECDH; see Section 6.3, with the following modifications: 1461 * Key Wrap Algorithm: Any of the key wrap algorithms defined in 1462 Section 6.2 are supported. The size of the key used for the key 1463 wrap algorithm is fed into the KDF. The set of identifiers are 1464 found in Table 16. 1466 +---------+-------+---------+------------+--------+----------------+ 1467 | Name | Value | KDF | Ephemeral- | Key | Description | 1468 | | | | Static | Wrap | | 1469 +=========+=======+=========+============+========+================+ 1470 | ECDH-ES | -29 | HKDF - | yes | A128KW | ECDH ES w/ | 1471 | + | | SHA-256 | | | Concat KDF and | 1472 | A128KW | | | | | AES Key Wrap | 1473 | | | | | | w/ 128-bit key | 1474 +---------+-------+---------+------------+--------+----------------+ 1475 | ECDH-ES | -30 | HKDF - | yes | A192KW | ECDH ES w/ | 1476 | + | | SHA-256 | | | Concat KDF and | 1477 | A192KW | | | | | AES Key Wrap | 1478 | | | | | | w/ 192-bit key | 1479 +---------+-------+---------+------------+--------+----------------+ 1480 | ECDH-ES | -31 | HKDF - | yes | A256KW | ECDH ES w/ | 1481 | + | | SHA-256 | | | Concat KDF and | 1482 | A256KW | | | | | AES Key Wrap | 1483 | | | | | | w/ 256-bit key | 1484 +---------+-------+---------+------------+--------+----------------+ 1485 | ECDH-SS | -32 | HKDF - | no | A128KW | ECDH SS w/ | 1486 | + | | SHA-256 | | | Concat KDF and | 1487 | A128KW | | | | | AES Key Wrap | 1488 | | | | | | w/ 128-bit key | 1489 +---------+-------+---------+------------+--------+----------------+ 1490 | ECDH-SS | -33 | HKDF - | no | A192KW | ECDH SS w/ | 1491 | + | | SHA-256 | | | Concat KDF and | 1492 | A192KW | | | | | AES Key Wrap | 1493 | | | | | | w/ 192-bit key | 1494 +---------+-------+---------+------------+--------+----------------+ 1495 | ECDH-SS | -34 | HKDF - | no | A256KW | ECDH SS w/ | 1496 | + | | SHA-256 | | | Concat KDF and | 1497 | A256KW | | | | | AES Key Wrap | 1498 | | | | | | w/ 256-bit key | 1499 +---------+-------+---------+------------+--------+----------------+ 1501 Table 16: ECDH Algorithm Values with Key Wrap 1503 When using a COSE key for this algorithm, the following checks are 1504 made: 1506 * The 'kty' field MUST be present, and it MUST be 'EC2' or 'OKP'. 1508 * If the 'alg' field is present, it MUST match the key agreement 1509 algorithm being used. 1511 * If the 'key_ops' field is present, it MUST include 'derive key' or 1512 'derive bits' for the private key. 1514 * If the 'key_ops' field is present, it MUST be empty for the public 1515 key. 1517 7. Key Object Parameters 1519 The COSE_Key object defines a way to hold a single key object. It is 1520 still required that the members of individual key types be defined. 1521 This section of the document is where we define an initial set of 1522 members for specific key types. 1524 For each of the key types, we define both public and private members. 1525 The public members are what is transmitted to others for their usage. 1526 Private members allow for the archival of keys by individuals. 1527 However, there are some circumstances in which private keys may be 1528 distributed to entities in a protocol. Examples include: entities 1529 that have poor random number generation, centralized key creation for 1530 multi-cast type operations, and protocols in which a shared secret is 1531 used as a bearer token for authorization purposes. 1533 Key types are identified by the 'kty' member of the COSE_Key object. 1534 In this document, we define four values for the member: 1536 +-----------+-------+--------------------------+ 1537 | Name | Value | Description | 1538 +===========+=======+==========================+ 1539 | OKP | 1 | Octet Key Pair | 1540 +-----------+-------+--------------------------+ 1541 | EC2 | 2 | Elliptic Curve Keys w/ | 1542 | | | x- and y-coordinate pair | 1543 +-----------+-------+--------------------------+ 1544 | Symmetric | 4 | Symmetric Keys | 1545 +-----------+-------+--------------------------+ 1546 | Reserved | 0 | This value is reserved | 1547 +-----------+-------+--------------------------+ 1549 Table 17: Key Type Values 1551 7.1. Elliptic Curve Keys 1553 Two different key structures are defined for elliptic curve keys. 1554 One version uses both an x-coordinate and a y-coordinate, potentially 1555 with point compression ('EC2'). This is the traditional EC point 1556 representation that is used in [RFC5480]. The other version uses 1557 only the x-coordinate as the y-coordinate is either to be recomputed 1558 or not needed for the key agreement operation ('OKP'). 1560 Applications MUST check that the curve and the key type are 1561 consistent and reject a key if they are not. 1563 +---------+-------+----------+------------------------------------+ 1564 | Name | Value | Key Type | Description | 1565 +=========+=======+==========+====================================+ 1566 | P-256 | 1 | EC2 | NIST P-256 also known as secp256r1 | 1567 +---------+-------+----------+------------------------------------+ 1568 | P-384 | 2 | EC2 | NIST P-384 also known as secp384r1 | 1569 +---------+-------+----------+------------------------------------+ 1570 | P-521 | 3 | EC2 | NIST P-521 also known as secp521r1 | 1571 +---------+-------+----------+------------------------------------+ 1572 | X25519 | 4 | OKP | X25519 for use w/ ECDH only | 1573 +---------+-------+----------+------------------------------------+ 1574 | X448 | 5 | OKP | X448 for use w/ ECDH only | 1575 +---------+-------+----------+------------------------------------+ 1576 | Ed25519 | 6 | OKP | Ed25519 for use w/ EdDSA only | 1577 +---------+-------+----------+------------------------------------+ 1578 | Ed448 | 7 | OKP | Ed448 for use w/ EdDSA only | 1579 +---------+-------+----------+------------------------------------+ 1581 Table 18: Elliptic Curves 1583 7.1.1. Double Coordinate Curves 1585 The traditional way of sending ECs has been to send either both the 1586 x-coordinate and y-coordinate or the x-coordinate and a sign bit for 1587 the y-coordinate. The latter encoding has not been recommended in 1588 the IETF due to potential IPR issues. However, for operations in 1589 constrained environments, the ability to shrink a message by not 1590 sending the y-coordinate is potentially useful. 1592 For EC keys with both coordinates, the 'kty' member is set to 2 1593 (EC2). The key parameters defined in this section are summarized in 1594 Table 19. The members that are defined for this key type are: 1596 crv: This contains an identifier of the curve to be used with the 1597 key. The curves defined in this document for this key type can 1598 be found in Table 18. Other curves may be registered in the 1599 future, and private curves can be used as well. 1601 x: This contains the x-coordinate for the EC point. The integer is 1602 converted to an octet string as defined in [SEC1]. Leading zero 1603 octets MUST be preserved. 1605 y: This contains either the sign bit or the value of the 1606 y-coordinate for the EC point. When encoding the value y, the 1607 integer is converted to an octet string (as defined in [SEC1]) 1608 and encoded as a CBOR bstr. Leading zero octets MUST be 1609 preserved. The compressed point encoding is also supported. 1610 Compute the sign bit as laid out in the Elliptic-Curve-Point-to- 1611 Octet-String Conversion function of [SEC1]. If the sign bit is 1612 zero, then encode y as a CBOR false value; otherwise, encode y 1613 as a CBOR true value. The encoding of the infinity point is not 1614 supported. 1616 d: This contains the private key. 1618 For public keys, it is REQUIRED that 'crv', 'x', and 'y' be present 1619 in the structure. For private keys, it is REQUIRED that 'crv' and 1620 'd' be present in the structure. For private keys, it is RECOMMENDED 1621 that 'x' and 'y' also be present, but they can be recomputed from the 1622 required elements and omitting them saves on space. 1624 +------+------+-------+--------+---------------------------------+ 1625 | Key | Name | Label | CBOR | Description | 1626 | Type | | | Type | | 1627 +======+======+=======+========+=================================+ 1628 | 2 | crv | -1 | int / | EC identifier - Taken from the | 1629 | | | | tstr | "COSE Elliptic Curves" registry | 1630 +------+------+-------+--------+---------------------------------+ 1631 | 2 | x | -2 | bstr | x-coordinate | 1632 +------+------+-------+--------+---------------------------------+ 1633 | 2 | y | -3 | bstr / | y-coordinate | 1634 | | | | bool | | 1635 +------+------+-------+--------+---------------------------------+ 1636 | 2 | d | -4 | bstr | Private key | 1637 +------+------+-------+--------+---------------------------------+ 1639 Table 19: EC Key Parameters 1641 7.2. Octet Key Pair 1643 A new key type is defined for Octet Key Pairs (OKP). Do not assume 1644 that keys using this type are elliptic curves. This key type could 1645 be used for other curve types (for example, mathematics based on 1646 hyper-elliptic surfaces). 1648 The key parameters defined in this section are summarized in 1649 Table 20. The members that are defined for this key type are: 1651 crv: This contains an identifier of the curve to be used with the 1652 key. The curves defined in this document for this key type can 1653 be found in Table 18. Other curves may be registered in the 1654 future and private curves can be used as well. 1656 x: This contains the x-coordinate for the EC point. The octet 1657 string represents a little-endian encoding of x. 1659 d: This contains the private key. 1661 For public keys, it is REQUIRED that 'crv' and 'x' be present in the 1662 structure. For private keys, it is REQUIRED that 'crv' and 'd' be 1663 present in the structure. For private keys, it is RECOMMENDED that 1664 'x' also be present, but it can be recomputed from the required 1665 elements and omitting it saves on space. 1667 +------+----------+-------+-------+---------------------------------+ 1668 | Name | Key | Label | Type | Description | 1669 | | Type | | | | 1670 +======+==========+=======+=======+=================================+ 1671 | crv | 1 | -1 | int / | EC identifier - Taken from the | 1672 | | | | tstr | "COSE Elliptic Curves" registry | 1673 +------+----------+-------+-------+---------------------------------+ 1674 | x | 1 | -2 | bstr | x-coordinate | 1675 +------+----------+-------+-------+---------------------------------+ 1676 | d | 1 | -4 | bstr | Private key | 1677 +------+----------+-------+-------+---------------------------------+ 1679 Table 20: Octet Key Pair Parameters 1681 7.3. Symmetric Keys 1683 Occasionally it is required that a symmetric key be transported 1684 between entities. This key structure allows for that to happen. 1686 For symmetric keys, the 'kty' member is set to 4 ('Symmetric'). The 1687 member that is defined for this key type is: 1689 k: This contains the value of the key. 1691 This key structure does not have a form that contains only public 1692 members. As it is expected that this key structure is going to be 1693 transmitted, care must be taken that it is never transmitted 1694 accidentally or insecurely. For symmetric keys, it is REQUIRED that 1695 'k' be present in the structure. 1697 +------+----------+-------+------+-------------+ 1698 | Name | Key Type | Label | Type | Description | 1699 +======+==========+=======+======+=============+ 1700 | k | 4 | -1 | bstr | Key Value | 1701 +------+----------+-------+------+-------------+ 1703 Table 21: Symmetric Key Parameters 1705 8. CBOR Encoding Restrictions 1707 There has been an attempt to limit the number of places where the 1708 document needs to impose restrictions on how the CBOR Encoder needs 1709 to work. We have managed to narrow it down to the following 1710 restrictions: 1712 * The restriction applies to the encoding of the COSE_KDF_Context. 1714 * Encoding MUST be done using definite lengths and the length of the 1715 MUST be the minimum possible length. This means that the integer 1716 1 is encoded as "0x01" and not "0x1801". 1718 * Applications MUST NOT generate messages with the same label used 1719 twice as a key in a single map. Applications MUST NOT parse and 1720 process messages with the same label used twice as a key in a 1721 single map. Applications can enforce the parse and process 1722 requirement by using parsers that will fail the parse step or by 1723 using parsers that will pass all keys to the application, and the 1724 application can perform the check for duplicate keys. 1726 9. IANA Considerations 1728 There are no IANA actions. The required actions are in 1729 [I-D.ietf-cose-rfc8152bis-struct]. 1731 10. Security Considerations 1733 There are a number of security considerations that need to be taken 1734 into account by implementers of this specification. The security 1735 considerations that are specific to an individual algorithm are 1736 placed next to the description of the algorithm. While some 1737 considerations have been highlighted here, additional considerations 1738 may be found in the documents listed in the references. 1740 Implementations need to protect the private key material for any 1741 individuals. There are some cases in this document that need to be 1742 highlighted on this issue. 1744 * Using the same key for two different algorithms can leak 1745 information about the key. It is therefore recommended that keys 1746 be restricted to a single algorithm. 1748 * Use of 'direct' as a recipient algorithm combined with a second 1749 recipient algorithm exposes the direct key to the second 1750 recipient. 1752 * Several of the algorithms in this document have limits on the 1753 number of times that a key can be used without leaking information 1754 about the key. 1756 The use of ECDH and direct plus KDF (with no key wrap) will not 1757 directly lead to the private key being leaked; the one way function 1758 of the KDF will prevent that. There is, however, a different issue 1759 that needs to be addressed. Having two recipients requires that the 1760 CEK be shared between two recipients. The second recipient therefore 1761 has a CEK that was derived from material that can be used for the 1762 weak proof of origin. The second recipient could create a message 1763 using the same CEK and send it to the first recipient; the first 1764 recipient would, for either static-static ECDH or direct plus KDF, 1765 make an assumption that the CEK could be used for proof of origin 1766 even though it is from the wrong entity. If the key wrap step is 1767 added, then no proof of origin is implied and this is not an issue. 1769 Although it has been mentioned before, the use of a single key for 1770 multiple algorithms has been demonstrated in some cases to leak 1771 information about a key, provide the opportunity for attackers to 1772 forge integrity tags, or gain information about encrypted content. 1773 Binding a key to a single algorithm prevents these problems. Key 1774 creators and key consumers are strongly encouraged not only to create 1775 new keys for each different algorithm, but to include that selection 1776 of algorithm in any distribution of key material and strictly enforce 1777 the matching of algorithms in the key structure to algorithms in the 1778 message structure. In addition to checking that algorithms are 1779 correct, the key form needs to be checked as well. Do not use an 1780 'EC2' key where an 'OKP' key is expected. 1782 Before using a key for transmission, or before acting on information 1783 received, a trust decision on a key needs to be made. Is the data or 1784 action something that the entity associated with the key has a right 1785 to see or a right to request? A number of factors are associated 1786 with this trust decision. Some of the ones that are highlighted here 1787 are: 1789 * What are the permissions associated with the key owner? 1791 * Is the cryptographic algorithm acceptable in the current context? 1793 * Have the restrictions associated with the key, such as algorithm 1794 or freshness, been checked and are they correct? 1796 * Is the request something that is reasonable, given the current 1797 state of the application? 1799 * Have any security considerations that are part of the message been 1800 enforced (as specified by the application or 'crit' parameter)? 1802 There are a large number of algorithms presented in this document 1803 that use nonce values. For all of the nonces defined in this 1804 document, there is some type of restriction on the nonce being a 1805 unique value either for a key or for some other conditions. In all 1806 of these cases, there is no known requirement on the nonce being both 1807 unique and unpredictable; under these circumstances, it's reasonable 1808 to use a counter for creation of the nonce. In cases where one wants 1809 the pattern of the nonce to be unpredictable as well as unique, one 1810 can use a key created for that purpose and encrypt the counter to 1811 produce the nonce value. 1813 One area that has been starting to get exposure is doing traffic 1814 analysis of encrypted messages based on the length of the message. 1815 This specification does not provide for a uniform method of providing 1816 padding as part of the message structure. An observer can 1817 distinguish between two different strings (for example, 'YES' and 1818 'NO') based on the length for all of the content encryption 1819 algorithms that are defined in this document. This means that it is 1820 up to the applications to document how content padding is to be done 1821 in order to prevent or discourage such analysis. (For example, the 1822 strings could be defined as 'YES' and 'NO '.) 1824 11. References 1826 11.1. Normative References 1828 [AES-GCM] National Institute of Standards and Technology, 1829 "Recommendation for Block Cipher Modes of Operation: 1830 Galois/Counter Mode (GCM) and GMAC", 1831 DOI 10.6028/NIST.SP.800-38D, NIST Special 1832 Publication 800-38D, November 2007, 1833 . 1836 [DSS] National Institute of Standards and Technology, "Digital 1837 Signature Standard (DSS)", DOI 10.6028/NIST.FIPS.186-4, 1838 FIPS PUB 186-4, July 2013, 1839 . 1842 [I-D.ietf-cose-rfc8152bis-struct] 1843 Schaad, J., "CBOR Object Signing and Encryption (COSE): 1844 Structures and Process", Internet Draft, draft-ietf-cose- 1845 rfc8152bis-struct-05, August 18, 2019, 1846 . 1849 [MAC] National Institute of Standards and Technology, "Computer 1850 Data Authentication", FIPS PUB 113, May 1985, 1851 . 1854 [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- 1855 Hashing for Message Authentication", RFC 2104, 1856 DOI 10.17487/RFC2104, February 1997, 1857 . 1859 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1860 Requirement Levels", BCP 14, RFC 2119, 1861 DOI 10.17487/RFC2119, March 1997, 1862 . 1864 [RFC3394] Schaad, J. and R. Housley, "Advanced Encryption Standard 1865 (AES) Key Wrap Algorithm", RFC 3394, DOI 10.17487/RFC3394, 1866 September 2002, . 1868 [RFC3610] Whiting, D., Housley, R., and N. Ferguson, "Counter with 1869 CBC-MAC (CCM)", RFC 3610, DOI 10.17487/RFC3610, September 1870 2003, . 1872 [RFC5869] Krawczyk, H. and P. Eronen, "HMAC-based Extract-and-Expand 1873 Key Derivation Function (HKDF)", RFC 5869, 1874 DOI 10.17487/RFC5869, May 2010, 1875 . 1877 [RFC6090] McGrew, D., Igoe, K., and M. Salter, "Fundamental Elliptic 1878 Curve Cryptography Algorithms", RFC 6090, 1879 DOI 10.17487/RFC6090, February 2011, 1880 . 1882 [RFC6979] Pornin, T., "Deterministic Usage of the Digital Signature 1883 Algorithm (DSA) and Elliptic Curve Digital Signature 1884 Algorithm (ECDSA)", RFC 6979, DOI 10.17487/RFC6979, August 1885 2013, . 1887 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 1888 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 1889 October 2013, . 1891 [RFC7748] Langley, A., Hamburg, M., and S. Turner, "Elliptic Curves 1892 for Security", RFC 7748, DOI 10.17487/RFC7748, January 1893 2016, . 1895 [RFC8032] Josefsson, S. and I. Liusvaara, "Edwards-Curve Digital 1896 Signature Algorithm (EdDSA)", RFC 8032, 1897 DOI 10.17487/RFC8032, January 2017, 1898 . 1900 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 1901 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 1902 May 2017, . 1904 [RFC8439] Nir, Y. and A. Langley, "ChaCha20 and Poly1305 for IETF 1905 Protocols", RFC 8439, DOI 10.17487/RFC8439, June 2018, 1906 . 1908 [SEC1] Certicom Research, "SEC 1: Elliptic Curve Cryptography", 1909 May 2009, . 1911 11.2. Informative References 1913 [RFC4231] Nystrom, M., "Identifiers and Test Vectors for HMAC-SHA- 1914 224, HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512", 1915 RFC 4231, DOI 10.17487/RFC4231, December 2005, 1916 . 1918 [RFC4493] Song, JH., Poovendran, R., Lee, J., and T. Iwata, "The 1919 AES-CMAC Algorithm", RFC 4493, DOI 10.17487/RFC4493, June 1920 2006, . 1922 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 1923 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 1924 . 1926 [RFC5480] Turner, S., Brown, D., Yiu, K., Housley, R., and T. Polk, 1927 "Elliptic Curve Cryptography Subject Public Key 1928 Information", RFC 5480, DOI 10.17487/RFC5480, March 2009, 1929 . 1931 [RFC6151] Turner, S. and L. Chen, "Updated Security Considerations 1932 for the MD5 Message-Digest and the HMAC-MD5 Algorithms", 1933 RFC 6151, DOI 10.17487/RFC6151, March 2011, 1934 . 1936 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 1937 Application Protocol (CoAP)", RFC 7252, 1938 DOI 10.17487/RFC7252, June 2014, 1939 . 1941 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 1942 DOI 10.17487/RFC7518, May 2015, 1943 . 1945 [RFC8017] Moriarty, K., Ed., Kaliski, B., Jonsson, J., and A. Rusch, 1946 "PKCS #1: RSA Cryptography Specifications Version 2.2", 1947 RFC 8017, DOI 10.17487/RFC8017, November 2016, 1948 . 1950 [RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", 1951 RFC 8152, DOI 10.17487/RFC8152, July 2017, 1952 . 1954 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 1955 Interchange Format", STD 90, RFC 8259, 1956 DOI 10.17487/RFC8259, December 2017, 1957 . 1959 [RFC8610] Birkholz, H., Vigano, C., and C. Bormann, "Concise Data 1960 Definition Language (CDDL): A Notational Convention to 1961 Express Concise Binary Object Representation (CBOR) and 1962 JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, 1963 June 2019, . 1965 [SP800-56A] 1966 Barker, E., Chen, L., Roginsky, A., and M. Smid, 1967 "Recommendation for Pair-Wise Key Establishment Schemes 1968 Using Discrete Logarithm Cryptography", 1969 DOI 10.6028/NIST.SP.800-56Ar2, NIST Special Publication 1970 800-56A, Revision 2, May 2013, 1971 . 1974 Acknowledgments 1976 This document is a product of the COSE working group of the IETF. 1978 The following individuals are to blame for getting me started on this 1979 project in the first place: Richard Barnes, Matt Miller, and Martin 1980 Thomson. 1982 The initial version of the specification was based to some degree on 1983 the outputs of the JOSE and S/MIME working groups. 1985 The following individuals provided input into the final form of the 1986 document: Carsten Bormann, John Bradley, Brain Campbell, Michael B. 1987 Jones, Ilari Liusvaara, Francesca Palombini, Ludwig Seitz, and Goran 1988 Selander. 1990 Author's Address 1992 Jim Schaad 1993 August Cellars 1995 Email: ietf@augustcellars.com