idnits 2.17.1 draft-ietf-cose-msg-23.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 : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Line 754 has weird spacing: '...otected as de...' == Line 756 has weird spacing: '...otected as de...' == Line 758 has weird spacing: '...payload conta...' == Line 774 has weird spacing: '...natures is an...' == Line 789 has weird spacing: '...otected as de...' == (28 more instances...) -- The document date (October 18, 2016) is 2740 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' ** Downref: Normative reference to an Informational draft: draft-irtf-cfrg-eddsa (ref. 'I-D.irtf-cfrg-eddsa') -- 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) ** Obsolete normative reference: RFC 7539 (Obsoleted by RFC 8439) ** Downref: Normative reference to an Informational RFC: RFC 7748 -- Possible downref: Non-RFC (?) normative reference: ref. 'SEC1' == Outdated reference: A later version (-11) exists of draft-greevenbosch-appsawg-cbor-cddl-09 == Outdated reference: A later version (-06) exists of draft-selander-ace-object-security-05 -- Obsolete informational reference (is this intentional?): RFC 2633 (Obsoleted by RFC 3851) -- Obsolete informational reference (is this intentional?): RFC 5751 (Obsoleted by RFC 8551) -- Obsolete informational reference (is this intentional?): RFC 7159 (Obsoleted by RFC 8259) Summary: 10 errors (**), 0 flaws (~~), 9 warnings (==), 8 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 Intended status: Standards Track October 18, 2016 5 Expires: April 21, 2017 7 CBOR Object Signing and Encryption (COSE) 8 draft-ietf-cose-msg-23 10 Abstract 12 Concise Binary Object Representation (CBOR) is data format designed 13 for small code size and small message size. There is a need for the 14 ability to have basic security services defined for this data format. 15 This document defines the CBOR Object Signing and Encryption (COSE) 16 specification. This specification describes how to create and 17 process signature, message authentication codes and encryption using 18 CBOR for serialization. This specification additionally specifies 19 how to represent cryptographic keys using CBOR. 21 Contributing to this document 23 The source for this draft is being maintained in GitHub. Suggested 24 changes should be submitted as pull requests at . Instructions are on that page as well. 26 Editorial changes can be managed in GitHub, but any substantial 27 issues need to be discussed on the COSE mailing list. 29 Status of This Memo 31 This Internet-Draft is submitted in full conformance with the 32 provisions of BCP 78 and BCP 79. 34 Internet-Drafts are working documents of the Internet Engineering 35 Task Force (IETF). Note that other groups may also distribute 36 working documents as Internet-Drafts. The list of current Internet- 37 Drafts is at http://datatracker.ietf.org/drafts/current/. 39 Internet-Drafts are draft documents valid for a maximum of six months 40 and may be updated, replaced, or obsoleted by other documents at any 41 time. It is inappropriate to use Internet-Drafts as reference 42 material or to cite them other than as "work in progress." 44 This Internet-Draft will expire on April 21, 2017. 46 Copyright Notice 48 Copyright (c) 2016 IETF Trust and the persons identified as the 49 document authors. All rights reserved. 51 This document is subject to BCP 78 and the IETF Trust's Legal 52 Provisions Relating to IETF Documents 53 (http://trustee.ietf.org/license-info) in effect on the date of 54 publication of this document. Please review these documents 55 carefully, as they describe your rights and restrictions with respect 56 to this document. Code Components extracted from this document must 57 include Simplified BSD License text as described in Section 4.e of 58 the Trust Legal Provisions and are provided without warranty as 59 described in the Simplified BSD License. 61 Table of Contents 63 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 64 1.1. Design changes from JOSE . . . . . . . . . . . . . . . . 5 65 1.2. Requirements Terminology . . . . . . . . . . . . . . . . 6 66 1.3. CBOR Grammar . . . . . . . . . . . . . . . . . . . . . . 6 67 1.4. CBOR Related Terminology . . . . . . . . . . . . . . . . 7 68 1.5. Document Terminology . . . . . . . . . . . . . . . . . . 8 69 2. Basic COSE Structure . . . . . . . . . . . . . . . . . . . . 8 70 3. Header Parameters . . . . . . . . . . . . . . . . . . . . . . 10 71 3.1. Common COSE Headers Parameters . . . . . . . . . . . . . 12 72 4. Signing Objects . . . . . . . . . . . . . . . . . . . . . . . 16 73 4.1. Signing with One or More Signers . . . . . . . . . . . . 16 74 4.2. Signing with One Signer . . . . . . . . . . . . . . . . . 18 75 4.3. Externally Supplied Data . . . . . . . . . . . . . . . . 19 76 4.4. Signing and Verification Process . . . . . . . . . . . . 20 77 4.5. Computing Counter Signatures . . . . . . . . . . . . . . 21 78 5. Encryption Objects . . . . . . . . . . . . . . . . . . . . . 22 79 5.1. Enveloped COSE Structure . . . . . . . . . . . . . . . . 22 80 5.1.1. Content Key Distribution Methods . . . . . . . . . . 24 81 5.2. Single Recipient Encrypted . . . . . . . . . . . . . . . 25 82 5.3. How to encrypt and decrypt for AEAD Algorithms . . . . . 25 83 5.4. How to encrypt and decrypt for AE Algorithms . . . . . . 28 84 6. MAC Objects . . . . . . . . . . . . . . . . . . . . . . . . . 29 85 6.1. MACed Message with Recipients . . . . . . . . . . . . . . 30 86 6.2. MACed Messages with Implicit Key . . . . . . . . . . . . 31 87 6.3. How to compute and verify a MAC . . . . . . . . . . . . . 31 88 7. Key Objects . . . . . . . . . . . . . . . . . . . . . . . . . 33 89 7.1. COSE Key Common Parameters . . . . . . . . . . . . . . . 33 90 8. Signature Algorithms . . . . . . . . . . . . . . . . . . . . 36 91 8.1. ECDSA . . . . . . . . . . . . . . . . . . . . . . . . . . 37 92 8.1.1. Security Considerations . . . . . . . . . . . . . . . 39 93 8.2. Edwards-curve Digital Signature Algorithms (EdDSA) . . . 40 94 8.2.1. Security Considerations . . . . . . . . . . . . . . . 41 95 9. Message Authentication (MAC) Algorithms . . . . . . . . . . . 41 96 9.1. Hash-based Message Authentication Codes (HMAC) . . . . . 41 97 9.1.1. Security Considerations . . . . . . . . . . . . . . . 43 98 9.2. AES Message Authentication Code (AES-CBC-MAC) . . . . . . 43 99 9.2.1. Security Considerations . . . . . . . . . . . . . . . 44 100 10. Content Encryption Algorithms . . . . . . . . . . . . . . . . 45 101 10.1. AES GCM . . . . . . . . . . . . . . . . . . . . . . . . 45 102 10.1.1. Security Considerations . . . . . . . . . . . . . . 46 103 10.2. AES CCM . . . . . . . . . . . . . . . . . . . . . . . . 47 104 10.2.1. Security Considerations . . . . . . . . . . . . . . 50 105 10.3. ChaCha20 and Poly1305 . . . . . . . . . . . . . . . . . 50 106 10.3.1. Security Considerations . . . . . . . . . . . . . . 51 107 11. Key Derivation Functions (KDF) . . . . . . . . . . . . . . . 51 108 11.1. HMAC-based Extract-and-Expand Key Derivation Function 109 (HKDF) . . . . . . . . . . . . . . . . . . . . . . . . . 52 110 11.2. Context Information Structure . . . . . . . . . . . . . 54 111 12. Content Key Distribution Methods . . . . . . . . . . . . . . 59 112 12.1. Direct Encryption . . . . . . . . . . . . . . . . . . . 59 113 12.1.1. Direct Key . . . . . . . . . . . . . . . . . . . . . 60 114 12.1.2. Direct Key with KDF . . . . . . . . . . . . . . . . 60 115 12.2. Key Wrapping . . . . . . . . . . . . . . . . . . . . . . 62 116 12.2.1. AES Key Wrapping . . . . . . . . . . . . . . . . . . 63 117 12.3. Key Transport . . . . . . . . . . . . . . . . . . . . . 64 118 12.4. Direct Key Agreement . . . . . . . . . . . . . . . . . . 64 119 12.4.1. ECDH . . . . . . . . . . . . . . . . . . . . . . . . 65 120 12.4.2. Security Considerations . . . . . . . . . . . . . . 69 121 12.5. Key Agreement with Key Wrap . . . . . . . . . . . . . . 69 122 12.5.1. ECDH . . . . . . . . . . . . . . . . . . . . . . . . 69 123 13. Key Object Parameters . . . . . . . . . . . . . . . . . . . . 71 124 13.1. Elliptic Curve Keys . . . . . . . . . . . . . . . . . . 72 125 13.1.1. Double Coordinate Curves . . . . . . . . . . . . . . 72 126 13.2. Octet Key Pair . . . . . . . . . . . . . . . . . . . . . 73 127 13.3. Symmetric Keys . . . . . . . . . . . . . . . . . . . . . 74 128 14. CBOR Encoder Restrictions . . . . . . . . . . . . . . . . . . 75 129 15. Application Profiling Considerations . . . . . . . . . . . . 75 130 16. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 77 131 16.1. CBOR Tag assignment . . . . . . . . . . . . . . . . . . 77 132 16.2. COSE Header Parameters Registry . . . . . . . . . . . . 77 133 16.3. COSE Header Algorithm Parameters Registry . . . . . . . 78 134 16.4. COSE Algorithms Registry . . . . . . . . . . . . . . . . 78 135 16.5. COSE Key Common Parameters Registry . . . . . . . . . . 79 136 16.6. COSE Key Type Parameters Registry . . . . . . . . . . . 80 137 16.7. COSE Key Type Registry . . . . . . . . . . . . . . . . . 81 138 16.8. COSE Elliptic Curve Parameters Registry . . . . . . . . 81 139 16.9. Media Type Registrations . . . . . . . . . . . . . . . . 82 140 16.9.1. COSE Security Message . . . . . . . . . . . . . . . 82 141 16.9.2. COSE Key media type . . . . . . . . . . . . . . . . 83 143 16.10. CoAP Content-Format Registrations . . . . . . . . . . . 85 144 16.11. Expert Review Instructions . . . . . . . . . . . . . . . 86 145 17. Implementation Status . . . . . . . . . . . . . . . . . . . . 87 146 17.1. Author's Versions . . . . . . . . . . . . . . . . . . . 88 147 17.2. COSE Testing Library . . . . . . . . . . . . . . . . . . 88 148 18. Security Considerations . . . . . . . . . . . . . . . . . . . 89 149 19. References . . . . . . . . . . . . . . . . . . . . . . . . . 91 150 19.1. Normative References . . . . . . . . . . . . . . . . . . 91 151 19.2. Informative References . . . . . . . . . . . . . . . . . 92 152 Appendix A. Making Mandatory Algorithm Header Optional . . . . . 95 153 A.1. Algorithm Identification . . . . . . . . . . . . . . . . 95 154 A.2. Counter Signature Without Headers . . . . . . . . . . . . 98 155 Appendix B. Two Layers of Recipient Information . . . . . . . . 99 156 Appendix C. Examples . . . . . . . . . . . . . . . . . . . . . . 101 157 C.1. Examples of Signed Message . . . . . . . . . . . . . . . 102 158 C.1.1. Single Signature . . . . . . . . . . . . . . . . . . 102 159 C.1.2. Multiple Signers . . . . . . . . . . . . . . . . . . 103 160 C.1.3. Counter Signature . . . . . . . . . . . . . . . . . . 104 161 C.1.4. Signature w/ Criticality . . . . . . . . . . . . . . 105 162 C.2. Single Signer Examples . . . . . . . . . . . . . . . . . 106 163 C.2.1. Single ECDSA signature . . . . . . . . . . . . . . . 106 164 C.3. Examples of Enveloped Messages . . . . . . . . . . . . . 107 165 C.3.1. Direct ECDH . . . . . . . . . . . . . . . . . . . . . 107 166 C.3.2. Direct plus Key Derivation . . . . . . . . . . . . . 108 167 C.3.3. Counter Signature on Encrypted Content . . . . . . . 109 168 C.3.4. Encrypted Content with External Data . . . . . . . . 111 169 C.4. Examples of Encrypted Messages . . . . . . . . . . . . . 111 170 C.4.1. Simple Encrypted Message . . . . . . . . . . . . . . 111 171 C.4.2. Encrypted Message w/ a Partial IV . . . . . . . . . . 112 172 C.5. Examples of MACed messages . . . . . . . . . . . . . . . 112 173 C.5.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 112 174 C.5.2. ECDH Direct MAC . . . . . . . . . . . . . . . . . . . 113 175 C.5.3. Wrapped MAC . . . . . . . . . . . . . . . . . . . . . 114 176 C.5.4. Multi-recipient MACed message . . . . . . . . . . . . 115 177 C.6. Examples of MAC0 messages . . . . . . . . . . . . . . . . 116 178 C.6.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 116 179 C.7. COSE Keys . . . . . . . . . . . . . . . . . . . . . . . . 117 180 C.7.1. Public Keys . . . . . . . . . . . . . . . . . . . . . 117 181 C.7.2. Private Keys . . . . . . . . . . . . . . . . . . . . 118 182 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 120 183 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 121 185 1. Introduction 187 There has been an increased focus on small, constrained devices that 188 make up the Internet of Things (IoT). One of the standards that has 189 come out of this process is the Concise Binary Object Representation 190 (CBOR) [RFC7049]. CBOR extended the data model of the JavaScript 191 Object Notation (JSON) [RFC7159] by allowing for binary data, among 192 other changes. CBOR is being adopted by several of the IETF working 193 groups dealing with the IoT world as their encoding of data 194 structures. CBOR was designed specifically to be both small in terms 195 of messages transport and implementation size, as well having a 196 schema free decoder. A need exists to provide message security 197 services for IoT, and using CBOR as the message encoding format makes 198 sense. 200 The JOSE working group produced a set of documents 201 [RFC7515][RFC7516][RFC7517][RFC7518] using JSON that specified how to 202 process encryption, signatures and Message Authentication Code (MAC) 203 operations, and how to encode keys using JSON. This document defines 204 the CBOR Object Encryption and Signing (COSE) standard which does the 205 same thing for the CBOR encoding format. While there is a strong 206 attempt to keep the flavor of the original JOSE documents, two 207 considerations are taken into account: 209 o CBOR has capabilities that are not present in JSON and are 210 appropriate to use. One example of this is the fact that CBOR has 211 a method of encoding binary directly without first converting it 212 into a base64 encoded string. 214 o COSE is not a direct copy of the JOSE specification. In the 215 process of creating COSE, decisions that were made for JOSE were 216 re-examined. In many cases different results were decided on as 217 the criteria was not always the same. 219 1.1. Design changes from JOSE 221 o Define a single top message structure so that encrypted, signed 222 and MACed messages can easily be identified and still have a 223 consistent view. 225 o Signed messages distinguish between the protected and unprotected 226 parameters that relate to the content from those that relate to 227 the signature. 229 o MACed messages are separated from signed messages. 231 o MACed messages have the ability to use the same set of recipient 232 algorithms as enveloped messages for obtaining the MAC 233 authentication key. 235 o Use binary encodings for binary data rather than base64url 236 encodings. 238 o Combine the authentication tag for encryption algorithms with the 239 cipher text. 241 o The set of cryptographic algorithms has been expanded in some 242 directions, and trimmed in others. 244 1.2. Requirements Terminology 246 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 247 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 248 "OPTIONAL" in this document are to be interpreted as described in 249 [RFC2119]. 251 When the words appear in lower case, their natural language meaning 252 is used. 254 1.3. CBOR Grammar 256 There is currently no standard CBOR grammar available for use by 257 specifications. The CBOR structures are therefore described in 258 prose. 260 The document was developed by first working on the grammar and then 261 developing the prose to go with it. An artifact of this is that the 262 prose was written using the primitive type strings defined by CBOR 263 Data Definition Language (CDDL) [I-D.greevenbosch-appsawg-cbor-cddl]. 264 In this specification, the following primitive types are used: 266 any - non-specific value that permits all CBOR values to be placed 267 here. 269 bool - a boolean value (true: major type 7, value 21; false: major 270 type 7, value 20). 272 bstr - byte string (major type 2). 274 int - an unsigned integer or a negative integer. 276 nil - a null value (major type 7, value 22). 278 nint - a negative integer (major type 1). 280 tstr - a UTF-8 text string (major type 3). 282 uint - an unsigned integer (major type 0). 284 Two syntaxes from CDDL appear in this document as shorthand. These 285 are: 287 FOO / BAR - indicates that either FOO or BAR can appear here 289 [+ FOO] - indicates that the type FOO appears one or more times in 290 an array 292 As well as the prose description, a version of a CBOR grammar is 293 presented in CDDL. Since CDDL has not been published as an RFC, this 294 grammar may not work with the final version of CDDL. The CDDL 295 grammar is informational, the prose description is normative. 297 The collected CDDL can be extracted from the XML version of this 298 document via the following XPath expression below. (Depending on the 299 XPath evaluator one is using, it may be necessary to deal with > 300 as an entity.) 302 //artwork[@type='CDDL']/text() 304 CDDL expects the initial non-terminal symbol to be the first symbol 305 in the file. For this reason the first fragment of CDDL is presented 306 here. 308 start = COSE_Messages / COSE_Key / COSE_KeySet / Internal_Types 310 ; This is defined to make the tool quieter: 311 Internal_Types = Sig_structure / Enc_structure / MAC_structure / 312 COSE_KDF_Context 314 The non-terminal Internal_Types is defined for dealing with the 315 automated validation tools used during the writing of this document. 316 It references those non-terminals that are used for security 317 computations, but are not emitted for transport. 319 1.4. CBOR Related Terminology 321 In JSON, maps are called objects and only have one kind of map key: a 322 string. In COSE, we use strings, negative integers and unsigned 323 integers as map keys. The integers are used for compactness of 324 encoding and easy comparison. The inclusion of strings allows for an 325 additional range of short encoded values to be used as well. Since 326 the word "key" is mainly used in its other meaning, as a 327 cryptographic key, we use the term "label" for this usage as a map 328 key. 330 The presence of a label in a COSE map which is not a string or an 331 integer is an error. Applications can either fail processing or 332 process messages with incorrect labels, however they MUST NOT create 333 messages with incorrect labels. 335 A CDDL grammar fragment is defined that defines the non-terminals 336 'label', as in the previous paragraph and 'values', which permits any 337 value to be used. 339 label = int / tstr 340 values = any 342 1.5. Document Terminology 344 In this document, we use the following terminology: 346 Byte is a synonym for octet. 348 Constrained Application Protocol (CoAP) is a specialized web transfer 349 protocol for use in constrained systems. It is defined in [RFC7252]. 351 Authenticated Encryption (AE) [RFC5116] algorithms are those 352 encryption algorithms which provide an authentication check of the 353 contents algorithm with the encryption service. 355 Authenticated Encryption with Authenticated Data (AEAD) [RFC5116] 356 algorithms provide the same content authentication service as AE 357 algorithms, but additionally provide for authentication of non- 358 encrypted data as well. 360 2. Basic COSE Structure 362 The COSE object structure is designed so that there can be a large 363 amount of common code when parsing and processing the different types 364 of security messages. All of the message structures are built on the 365 CBOR array type. The first three elements of the array always 366 contain the same information: 368 1. The set of protected header parameters wrapped in a bstr. 370 2. The set of unprotected header parameters as a map. 372 3. The content of the message. The content is either the plain text 373 or the cipher text as appropriate. The content may be detached, 374 but the location is still used. The content is wrapped in a bstr 375 when present and is a nil value when detached. 377 Elements after this point are dependent on the specific message type. 379 COSE messages are also built using the concept of layers to separate 380 different types of cryptographic concepts. As an example of how this 381 works, consider the COSE_Encrypt message (Section 5.1). This message 382 type is broken into two layers: the content layer and the recipient 383 layer. In the content layer, the plain text is encrypted and 384 information about the encrypted message are placed. In the recipient 385 layer, the content encryption key (CEK) is encrypted and information 386 about how it is encrypted for each recipient is placed. A single 387 layer version of the encryption message COSE_Encrypt0 (Section 5.2) 388 is provided for cases where the CEK is pre-shared. 390 Identification of which type of message has been presented is done by 391 the following methods: 393 1. The specific message type is known from the context. This may be 394 defined by a marker in the containing structure or by 395 restrictions specified by the application protocol. 397 2. The message type is identified by a CBOR tag. Messages with a 398 CBOR tag are known in this specification as tagged messages, 399 while those without the CBOR tag are known as untagged messages. 400 This document defines a CBOR tag for each of the message 401 structures. These tags can be found in Table 1. 403 3. When a COSE object is carried in a media type of application/ 404 cose, the optional parameter 'cose-type' can be used to identify 405 the embedded object. The parameter is OPTIONAL if the tagged 406 version of the structure is used. The parameter is REQUIRED if 407 the untagged version of the structure is used. The value to use 408 with the parameter for each of the structures can be found in 409 Table 1. 411 4. When a COSE object is carried as a CoAP payload, the CoAP 412 Content-Format Option can be used to identify the message 413 content. The CoAP Content-Format values can be found in 414 Table 26. The CBOR tag for the message structure is not required 415 as each security message is uniquely identified. 417 +-------+---------------+---------------+---------------------------+ 418 | CBOR | cose-type | Data Item | Semantics | 419 | Tag | | | | 420 +-------+---------------+---------------+---------------------------+ 421 | TBD1 | cose-sign | COSE_Sign | COSE Signed Data Object | 422 | | | | | 423 | TBD7 | cose-sign1 | COSE_Sign1 | COSE Single Signer Data | 424 | | | | Object | 425 | | | | | 426 | TBD2 | cose-encrypt | COSE_Encrypt | COSE Encrypted Data | 427 | | | | Object | 428 | | | | | 429 | TBD3 | cose-encrypt0 | COSE_Encrypt0 | COSE Single Recipient | 430 | | | | Encrypted Data Object | 431 | | | | | 432 | TBD4 | cose-mac | COSE_Mac | COSE Mac-ed Data Object | 433 | | | | | 434 | TBD6 | cose-mac0 | COSE_Mac0 | COSE Mac w/o Recipients | 435 | | | | Object | 436 +-------+---------------+---------------+---------------------------+ 438 Table 1: COSE Message Identification 440 The following CDDL fragment identifies all of the top messages 441 defined in this document. Separate non-terminals are defined for the 442 tagged and the untagged versions of the messages. 444 COSE_Messages = COSE_Untagged_Message / COSE_Tagged_Message 446 COSE_Untagged_Message = COSE_Sign / COSE_Sign1 / 447 COSE_Encrypt / COSE_Encrypt0 / 448 COSE_Mac / COSE_Mac0 450 COSE_Tagged_Message = COSE_Sign_Tagged / COSE_Sign1_Tagged / 451 COSE_Encrypt_Tagged / COSE_Encrypt0_Tagged / 452 COSE_Mac_Tagged / COSE_Mac0_Tagged 454 3. Header Parameters 456 The structure of COSE has been designed to have two buckets of 457 information that are not considered to be part of the payload itself, 458 but are used for holding information about content, algorithms, keys, 459 or evaluation hints for the processing of the layer. These two 460 buckets are available for use in all of the structures except for 461 keys. While these buckets are present, they may not all be usable in 462 all instances. For example, while the protected bucket is defined as 463 part of the recipient structure, some of the algorithms used for 464 recipient structures do not provide for authenticated data. If this 465 is the case, the protected bucket is left empty. 467 Both buckets are implemented as CBOR maps. The map key is a 'label' 468 (Section 1.4). The value portion is dependent on the definition for 469 the label. Both maps use the same set of label/value pairs. The 470 integer and string values for labels have been divided into several 471 sections with a standard range, a private range, and a range that is 472 dependent on the algorithm selected. The defined labels can be found 473 in the "COSE Header Parameters" IANA registry (Section 16.2). 475 Two buckets are provided for each layer: 477 protected: Contains parameters about the current layer that are to 478 be cryptographically protected. This bucket MUST be empty if it 479 is not going to be included in a cryptographic computation. This 480 bucket is encoded in the message as a binary object. This value 481 is obtained by CBOR encoding the protected map and wrapping it in 482 a bstr object. Senders SHOULD encode a zero length map as a zero 483 length string rather than as a zero length map (encoded as h'a0'). 484 The zero length binary encoding is preferred because it is both 485 shorter and the version used in the serialization structures for 486 cryptographic computation. After encoding the map, the value is 487 wrapped in the binary object. Recipients MUST accept both a zero 488 length binary value and a zero length map encoded in the binary 489 value. The wrapping allows for the encoding of the protected map 490 to be transported with a greater chance that it will not be 491 altered in transit. (Badly behaved intermediates could decode and 492 re-encode, but this will result in a failure to verify unless the 493 re-encoded byte string is identical to the decoded byte string.) 494 This avoids the problem of all parties needing to be able to do a 495 common canonical encoding. 497 unprotected: Contains parameters about the current layer that are 498 not cryptographically protected. 500 Only parameters that deal with the current layer are to be placed at 501 that layer. As an example of this, the parameter 'content type' 502 describes the content of the message being carried in the message. 503 As such, this parameter is placed only in the content layer and is 504 not placed in the recipient or signature layers. In principle, one 505 should be able to process any given layer without reference to any 506 other layer. With the exception of the COSE_Sign structure, the only 507 data that needs to cross layers is the cryptographic key. 509 The buckets are present in all of the security objects defined in 510 this document. The fields in order are the 'protected' bucket (as a 511 CBOR 'bstr' type) and then the 'unprotected' bucket (as a CBOR 'map' 512 type). The presence of both buckets is required. The parameters 513 that go into the buckets come from the IANA "COSE Header Parameters" 514 registry (Section 16.2). Some common parameters are defined in the 515 next section, but a number of parameters are defined throughout this 516 document. 518 Labels in each of the maps MUST be unique. When processing messages, 519 if a label appears multiple times, the message MUST be rejected as 520 malformed. Applications SHOULD verify that the same label does not 521 occur in both the protected and unprotected headers. If the message 522 is not rejected as malformed, attributes MUST be obtained from the 523 protected bucket before they are obtained from the unprotected 524 bucket. 526 The following CDDL fragment represents the two header buckets. A 527 group Headers is defined in CDDL that represents the two buckets in 528 which attributes are placed. This group is used to provide these two 529 fields consistently in all locations. A type is also defined which 530 represents the map of common headers. 532 Headers = ( 533 protected : empty_or_serialized_map, 534 unprotected : header_map 535 ) 537 header_map = { 538 Generic_Headers, 539 * label => values 540 } 542 empty_or_serialized_map = bstr .cbor header_map / bstr .size 0 544 3.1. Common COSE Headers Parameters 546 This section defines a set of common header parameters. A summary of 547 these parameters can be found in Table 2. This table should be 548 consulted to determine the value of label, and the type of the value. 550 The set of header parameters defined in this section are: 552 alg: This parameter is used to indicate the algorithm used for the 553 security processing. This parameter MUST be present in the 554 COSE_Signature, COSE_Sign1, COSE_Encrypt, COSE_Encrypt0, COSE_Mac, 555 and COSE_Mac0 structures. When the algorithm supports 556 authenticating associated data, this parameter MUST be in the 557 protected header bucket. The value is taken from the "COSE 558 Algorithms" Registry (see Section 16.4). 560 crit: The parameter is used to indicate which protected header 561 labels an application that is processing a message is required to 562 understand. Parameters defined in this document do not need to be 563 included as they should be understood by all implementations. 564 When present, this parameter MUST be placed in the protected 565 header bucket. The array MUST have at least one value in it. 566 Not all labels need to be included in the 'crit' parameter. The 567 rules for deciding which header labels are placed in the array 568 are: 570 * Integer labels in the range of 0 to 8 SHOULD be omitted. 572 * Integer labels in the range -1 to -128 can be omitted as they 573 are algorithm dependent. If an application can correctly 574 process an algorithm, it can be assumed that it will correctly 575 process all of the common parameters associated with that 576 algorithm. Integer labels in the range -129 to -65536 SHOULD 577 be included as these would be less common parameters that might 578 not be generally supported. 580 * Labels for parameters required for an application MAY be 581 omitted. Applications should have a statement if the label can 582 be omitted. 584 The header parameter values indicated by 'crit' can be processed 585 by either the security library code or by an application using a 586 security library; the only requirement is that the parameter is 587 processed. If the 'crit' value list includes a value for which 588 the parameter is not in the protected bucket, this is a fatal 589 error in processing the message. 591 content type: This parameter is used to indicate the content type of 592 the data in the payload or cipher text fields. Integers are from 593 the "CoAP Content-Formats" IANA registry table [COAP.Formats]. 594 Text values following the syntax of "/" 595 where and are defined in Section 4.2 of 596 [RFC6838]. Leading and trailing whitespace is also omitted. 597 Textual content values along with parameters and subparameters can 598 be located using the IANA "Media Types" registry. Applications 599 SHOULD provide this parameter if the content structure is 600 potentially ambiguous. 602 kid: This parameter identifies one piece of data that can be used as 603 input to find the needed cryptographic key. The value of this 604 parameter can be matched against the 'kid' member in a COSE_Key 605 structure. Other methods of key distribution can define an 606 equivalent field to be matched. Applications MUST NOT assume that 607 'kid' values are unique. There may be more than one key with the 608 same 'kid' value, so all of the keys associated with this 'kid' 609 may need to be checked. The internal structure of 'kid' values is 610 not defined and cannot be relied on by applications. Key 611 identifier values are hints about which key to use. This is not a 612 security critical field. For this reason, it can be placed in the 613 unprotected headers bucket. 615 IV: This parameter holds the Initialization Vector (IV) value. For 616 some symmetric encryption algorithms this may be referred to as a 617 nonce. The IV can be placed in the unprotected header as 618 modifying the IV will cause the decryption to yield plaintext that 619 is readily detectable as garbled. 621 Partial IV This parameter holds a part of the IV value. When using 622 the COSE_Encrypt0 structure, a portion of the IV can be part of 623 the context associated with the key. This field is used to carry 624 a value that causes the IV to be changed for each message. The IV 625 can be placed in the unprotected header as modifying the IV will 626 cause the decryption to yield plaintext that is readily detectable 627 as garbled. The 'Initialization Vector' and 'Partial 628 Initialization Vector' parameters MUST NOT both be present in the 629 same security layer. 630 The message IV is generated by the following steps: 632 1. Left pad the partial IV with zeros to the length of IV. 634 2. XOR the padded partial IV with the context IV. 636 counter signature: This parameter holds one or more counter 637 signature values. Counter signatures provide a method of having a 638 second party sign some data. The counter signature parameter can 639 occur as an unprotected attribute in any of the following 640 structures: COSE_Sign1, COSE_Signature, COSE_Encrypt, 641 COSE_recipient, COSE_Encrypt0, COSE_Mac and COSE_Mac0. These 642 structures all have the same beginning elements so that a 643 consistent calculation of the counter signature can be computed. 644 Details on computing counter signatures are found in Section 4.5. 646 +-----------+-------+----------------+-------------+----------------+ 647 | name | label | value type | value | description | 648 | | | | registry | | 649 +-----------+-------+----------------+-------------+----------------+ 650 | alg | 1 | int / tstr | COSE | Cryptographic | 651 | | | | Algorithms | algorithm to | 652 | | | | registry | use | 653 | | | | | | 654 | crit | 2 | [+ label] | COSE Header | Critical | 655 | | | | Labels | headers to be | 656 | | | | registry | understood | 657 | | | | | | 658 | content | 3 | tstr / uint | CoAP | Content type | 659 | type | | | Content- | of the payload | 660 | | | | Formats or | | 661 | | | | Media Types | | 662 | | | | registry | | 663 | | | | | | 664 | kid | 4 | bstr | | Key identifier | 665 | | | | | | 666 | IV | 5 | bstr | | Full | 667 | | | | | Initialization | 668 | | | | | Vector | 669 | | | | | | 670 | Partial | 6 | bstr | | Partial | 671 | IV | | | | Initialization | 672 | | | | | Vector | 673 | | | | | | 674 | counter | 7 | COSE_Signature | | CBOR encoded | 675 | signature | | / [+ | | signature | 676 | | | COSE_Signature | | structure | 677 | | | ] | | | 678 +-----------+-------+----------------+-------------+----------------+ 680 Table 2: Common Header Parameters 682 The CDDL fragment that represents the set of headers defined in this 683 section is given below. Each of the headers is tagged as optional 684 because they do not need to be in every map; headers required in 685 specific maps are discussed above. 687 Generic_Headers = ( 688 ? 1 => int / tstr, ; algorithm identifier 689 ? 2 => [+label], ; criticality 690 ? 3 => tstr / int, ; content type 691 ? 4 => bstr, ; key identifier 692 ? 5 => bstr, ; IV 693 ? 6 => bstr, ; Partial IV 694 ? 7 => COSE_Signature / [+COSE_Signature] ; Counter signature 695 ) 697 4. Signing Objects 699 COSE supports two different signature structures. COSE_Sign allows 700 for one or more signatures to be applied to the same content. 701 COSE_Sign1 is restricted to a single signer. The structures cannot 702 be converted between each other; as the signature computation 703 includes a parameter identifying which structure is being used, the 704 converted structure will fail signature validation. 706 4.1. Signing with One or More Signers 708 The COSE_Sign structure allows for one or more signatures to be 709 applied to a message payload. Parameters relating to the content and 710 parameters relating to the signature are carried along with the 711 signature itself. These parameters may be authenticated by the 712 signature, or just present. An example of a parameter about the 713 content is the content type. Examples of parameters about the 714 signature would be the algorithm and key used to create the signature 715 and counter signatures. 717 When more than one signature is present, the successful validation of 718 one signature associated with a given signer is usually treated as a 719 successful signature by that signer. However, there are some 720 application environments where other rules are needed. An 721 application that employs a rule other than one valid signature for 722 each signer must specify those rules. Also, where simple matching of 723 the signer identifier is not sufficient to determine whether the 724 signatures were generated by the same signer, the application 725 specification must describe how to determine which signatures were 726 generated by the same signer. Support for different communities of 727 recipients is the primary reason that signers choose to include more 728 than one signature. For example, the COSE_Sign structure might 729 include signatures generated with the Edwards Digital Signature 730 Algorithm (EdDSA) [I-D.irtf-cfrg-eddsa] signature algorithm and with 731 the Elliptic Curve Digital Signature Algorithm (ECDSA) [DSS] 732 signature algorithm. This allows recipients to verify the signature 733 associated with one algorithm or the other. (The original source of 734 this text is [RFC5652].) More detailed information on multiple 735 signature evaluation can be found in [RFC5752]. 737 The signature structure can be encoded either as tagged or untagged 738 depending on the context it will be used in. A tagged COSE_Sign 739 structure is identified by the CBOR tag TBD1. The CDDL fragment that 740 represents this is: 742 COSE_Sign_Tagged = #6.991(COSE_Sign) ; Replace 991 with TBD1 744 A COSE Signed Message is defined in two parts. The CBOR object that 745 carries the body and information about the body is called the 746 COSE_Sign structure. The CBOR object that carries the signature and 747 information about the signature is called the COSE_Signature 748 structure. Examples of COSE Signed Messages can be found in 749 Appendix C.1. 751 The COSE_Sign structure is a CBOR array. The fields of the array in 752 order are: 754 protected as described in Section 3. 756 unprotected as described in Section 3. 758 payload contains the serialized content to be signed. If the 759 payload is not present in the message, the application is required 760 to supply the payload separately. The payload is wrapped in a 761 bstr to ensure that it is transported without changes. If the 762 payload is transported separately ("detached content"), then a nil 763 CBOR object is placed in this location and it is the 764 responsibility of the application to ensure that it will be 765 transported without changes. 767 Note: When a signature with message recovery algorithm is used 768 (Section 8), the maximum number of bytes that can be recovered is 769 the length of the payload. The size of the payload is reduced by 770 the number of bytes that will be recovered. If all of the bytes 771 of the payload are consumed, then the payload is encoded as a zero 772 length binary string rather than as being absent. 774 signatures is an array of signatures. Each signature is represented 775 as a COSE_Signature structure. 777 The CDDL fragment that represents the above text for COSE_Sign 778 follows. 780 COSE_Sign = [ 781 Headers, 782 payload : bstr / nil, 783 signatures : [+ COSE_Signature] 784 ] 786 The COSE_Signature structure is a CBOR array. The fields of the 787 array in order are: 789 protected as described in Section 3. 791 unprotected as described in Section 3. 793 signature contains the computed signature value. The type of the 794 field is a bstr. Algorithms MUST specify padding if the signature 795 value is not a multiple of 8 bits. 797 The CDDL fragment that represents the above text for COSE_Signature 798 follows. 800 COSE_Signature = [ 801 Headers, 802 signature : bstr 803 ] 805 4.2. Signing with One Signer 807 The COSE_Sign1 signature structure is used when only one signature is 808 going to be placed on a message. The parameters dealing with the 809 content and the signature are placed in the same pair of buckets 810 rather than having the separation of COSE_Sign. 812 The structure can be encoded either tagged or untagged depending on 813 the context it will be used in. A tagged COSE_Sign1 structure is 814 identified by the CBOR tag TBD7. The CDDL fragment that represents 815 this is: 817 COSE_Sign1_Tagged = #6.997(COSE_Sign1) ; Replace 997 with TBD7 819 The CBOR object that carries the body, the signature, and the 820 information about the body and signature is called the COSE_Sign1 821 structure. Examples of COSE_Sign1 messages can be found in 822 Appendix C.2. 824 The COSE_Sign1 structure is a CBOR array. The fields of the array in 825 order are: 827 protected as described in Section 3. 829 unprotected as described in Section 3. 831 payload as described in Section 4.1. 833 signature contains the computed signature value. The type of the 834 field is a bstr. 836 The CDDL fragment that represents the above text for COSE_Sign1 837 follows. 839 COSE_Sign1 = [ 840 Headers, 841 payload : bstr / nil, 842 signature : bstr 843 ] 845 4.3. Externally Supplied Data 847 One of the features offered in the COSE document is the ability for 848 applications to provide additional data to be authenticated, but that 849 is not carried as part of the COSE object. The primary reason for 850 supporting this can be seen by looking at the CoAP message structure 851 [RFC7252], where the facility exists for options to be carried before 852 the payload. Examples of data that can be placed in this location 853 would be the CoAP code or CoAP options. If the data is in the header 854 section, then it is available for proxies to help in performing its 855 operations. For example, the Accept Option can be used by a proxy to 856 determine if an appropriate value is in the Proxy's cache. But the 857 sender can prevent a proxy from changing the set of values that it 858 will accept by including that value in the resulting authentication 859 tag. However, it may also be desired to protect these values so that 860 if they are modified in transit, it can be detected. 862 This document describes the process for using a byte array of 863 externally supplied authenticated data; however, the method of 864 constructing the byte array is a function of the application. 865 Applications that use this feature need to define how the externally 866 supplied authenticated data is to be constructed. Such a 867 construction needs to take into account the following issues: 869 o If multiple items are included, applications need to ensure that 870 the same byte string is not produced if there are different 871 inputs. This could occur by appending the strings 'AB' and 'CDE' 872 or by appending the strings 'ABC' and 'DE'. This is usually 873 addressed by making fields a fixed width and/or encoding the 874 length of the field as part of the output. Using options from 875 CoAP [RFC7252] as an example, these fields use a TLV structure so 876 they can be concatenated without any problems. 878 o If multiple items are included, an order for the items needs to be 879 defined. Using options from CoAP as an example, an application 880 could state that the fields are to be ordered by the option 881 number. 883 o Applications need to ensure that the byte stream is going to be 884 the same on both sides. Using options from CoAP might give a 885 problem if the same relative numbering is kept. An intermediate 886 node could insert or remove an option, changing how the relative 887 number is done. An application would need to specify that the 888 relative number must be re-encoded to be relative only to the 889 options that are in the external data. 891 4.4. Signing and Verification Process 893 In order to create a signature, a well-defined byte stream is needed. 894 The Sig_struture is used to create the canonical form. This signing 895 and verification process takes in the body information (COSE_Sign or 896 COSE_Sign1), the signer information (COSE_Signature), and the 897 application data (external source). A Sig_structure is a CBOR array. 898 The fields of the Sig_struture in order are: 900 1. A text string identifying the context of the signature. The 901 context string is: 903 "Signature" for signatures using the COSE_Signature structure. 905 "Signature1" for signatures using the COSE_Sign1 structure. 907 "CounterSignature" for signatures used as counter signature 908 attributes. 910 2. The protected attributes from the body structure encoded in a 911 bstr type. If there are no protected attributes, a bstr of 912 length zero is used. 914 3. The protected attributes from the signer structure encoded in a 915 bstr type. If there are no protected attributes, a bstr of 916 length zero is used. This field is omitted for the COSE_Sign1 917 signature structure. 919 4. The protected attributes from the application encoded in a bstr 920 type. If this field is not supplied, it defaults to a zero 921 length binary string. (See Section 4.3 for application guidance 922 on constructing this field.) 924 5. The payload to be signed encoded in a bstr type. The payload is 925 placed here independent of how it is transported. 927 The CDDL fragment that describes the above text is. 929 Sig_structure = [ 930 context : "Signature" / "Signature1" / "CounterSignature", 931 body_protected : empty_or_serialized_map, 932 ? sign_protected : empty_or_serialized_map, 933 external_aad : bstr, 934 payload : bstr 935 ] 937 How to compute a signature: 939 1. Create a Sig_structure and populate it with the appropriate 940 fields. 942 2. Create the value ToBeSigned by encoding the Sig_structure to a 943 byte string, using the encoding described in Section 14. 945 3. Call the signature creation algorithm passing in K (the key to 946 sign with), alg (the algorithm to sign with), and ToBeSigned (the 947 value to sign). 949 4. Place the resulting signature value in the 'signature' field of 950 the array. 952 The steps for verifying a signature are: 954 1. Create a Sig_structure object and populate it with the 955 appropriate fields. 957 2. Create the value ToBeSigned by encoding the Sig_structure to a 958 byte string, using the encoding described in Section 14. 960 3. Call the signature verification algorithm passing in K (the key 961 to verify with), alg (the algorithm used sign with), ToBeSigned 962 (the value to sign), and sig (the signature to be verified). 964 In addition to performing the signature verification, the application 965 may also perform the appropriate checks to ensure that the key is 966 correctly paired with the signing identity and that the signing 967 identity is authorized before performing actions. 969 4.5. Computing Counter Signatures 971 Counter signatures provide a method of associating different 972 signature generated by different signers with some piece of content. 973 This is normally used to provide a signature on a signature allowing 974 for a proof that a signature existed at a given time (i.e., a 975 Timestamp). In this document, we allow for counter signatures to 976 exist in a greater number of environments. As an example, it is 977 possible to place a counter signature in the unprotected attributes 978 of a COSE_Encrypt object. This would allow for an intermediary to 979 either verify that the encrypted byte stream has not been modified, 980 without being able to decrypt it, or for the intermediary to assert 981 that an encrypted byte stream either existed at a given time or 982 passed through it in terms of routing (i.e., a proxy signature). 984 An example of a counter signature on a signature can be found in 985 Appendix C.1.3. An example of a counter signature in an encryption 986 object can be found in Appendix C.3.3. 988 The creation and validation of counter signatures over the different 989 items relies on the fact that the structure of the objects have the 990 same structure. The elements are a set of protected attributes, a 991 set of unprotected attributes, and a body, in that order. This means 992 that the Sig_structure can be used in a uniform manner to get the 993 byte stream for processing a signature. If the counter signature is 994 going to be computed over a COSE_Encrypt structure, the 995 body_protected and payload items can be mapped into the Sig_structure 996 in the same manner as from the COSE_Sign structure. 998 It should be noted that only a signature algorithm with appendix (see 999 Section 8) can be used for counter signatures. This is because the 1000 body should be able to be processed without having to evaluate the 1001 counter signature, and this is not possible for signature schemes 1002 with message recovery. 1004 5. Encryption Objects 1006 COSE supports two different encryption structures. COSE_Encrypt0 is 1007 used when a recipient structure is not needed because the key to be 1008 used is known implicitly. COSE_Encrypt is used the rest of the time. 1009 This includes cases where there are multiple recipients or a 1010 recipient algorithm other than direct is used. 1012 5.1. Enveloped COSE Structure 1014 The enveloped structure allows for one or more recipients of a 1015 message. There are provisions for parameters about the content and 1016 parameters about the recipient information to be carried in the 1017 message. The protected parameters associated with the content are 1018 authenticated by the content encryption algorithm. The protected 1019 parameters associated with the recipient are authenticated by the 1020 recipient algorithm (when the algorithm supports it). Examples of 1021 parameters about the content are the type of the content and the 1022 content encryption algorithm. Examples of parameters about the 1023 recipient are the recipient's key identifier and the recipient's 1024 encryption algorithm. 1026 The same techniques and structures are used for encrypting both the 1027 plain text and the keys. This is different from the approach used by 1028 both CMS [RFC5652] and JSON Web Encryption (JWE) [RFC7516] where 1029 different structures are used for the content layer and for the 1030 recipient layer. Two structures are defined: COSE_Encrypt to hold 1031 the encrypted content and COSE_recipient to hold the encrypted keys 1032 for recipients. Examples of encrypted messages can be found in 1033 Appendix C.3. 1035 The COSE_Encrypt structure can be encoded either tagged or untagged 1036 depending on the context it will be used in. A tagged COSE_Encrypt 1037 structure is identified by the CBOR tag TBD2. The CDDL fragment that 1038 represents this is: 1040 COSE_Encrypt_Tagged = #6.992(COSE_Encrypt) ; Replace 992 with TBD2 1042 The COSE_Encrypt structure is a CBOR array. The fields of the array 1043 in order are: 1045 protected as described in Section 3. 1047 unprotected as described in Section 3. ' 1049 ciphertext contains the cipher text encoded as a bstr. If the 1050 cipher text is to be transported independently of the control 1051 information about the encryption process (i.e., detached content) 1052 then the field is encoded as a nil value. 1054 recipients contains an array of recipient information structures. 1055 The type for the recipient information structure is a 1056 COSE_recipient. 1058 The CDDL fragment that corresponds to the above text is: 1060 COSE_Encrypt = [ 1061 Headers, 1062 ciphertext : bstr / nil, 1063 recipients : [+COSE_recipient] 1064 ] 1066 The COSE_recipient structure is a CBOR array. The fields of the 1067 array in order are: 1069 protected as described in Section 3. 1071 unprotected as described in Section 3. 1073 ciphertext contains the encrypted key encoded as a bstr. All 1074 encoded keys are symetric keys, the binary value of the key is the 1075 content. If there is not an encrypted key, then this field is 1076 encoded as a nil value. 1078 recipients contains an array of recipient information structures. 1079 The type for the recipient information structure is a 1080 COSE_recipient. (An example of this can be found in Appendix B.) 1081 If there are no recipient information structures, this element is 1082 absent. 1084 The CDDL fragment that corresponds to the above text for 1085 COSE_recipient is: 1087 COSE_recipient = [ 1088 Headers, 1089 ciphertext : bstr / nil, 1090 ? recipients : [+COSE_recipient] 1091 ] 1093 5.1.1. Content Key Distribution Methods 1095 An encrypted message consists of an encrypted content and an 1096 encrypted CEK for one or more recipients. The CEK is encrypted for 1097 each recipient, using a key specific to that recipient. The details 1098 of this encryption depend on which class the recipient algorithm 1099 falls into. Specific details on each of the classes can be found in 1100 Section 12. A short summary of the five content key distribution 1101 methods is: 1103 direct: The CEK is the same as the identified previously distributed 1104 symmetric key or derived from a previously distributed secret. No 1105 CEK is transported in the message. 1107 symmetric key-encryption keys: The CEK is encrypted using a 1108 previously distributed symmetric KEK. 1110 key agreement: The recipient's public key and a sender's private key 1111 are used to generate a pairwise secret, a KDF is applied to derive 1112 a key, and then the CEK is either the derived key or encrypted by 1113 the derived key. 1115 key transport: The CEK is encrypted with the recipient's public key. 1116 No key transport algorithms are defined in this document. 1118 passwords: The CEK is encrypted in a KEK that is derived from a 1119 password. No password algorithms are defined in this document. 1121 5.2. Single Recipient Encrypted 1123 The COSE_Encrypt0 encrypted structure does not have the ability to 1124 specify recipients of the message. The structure assumes that the 1125 recipient of the object will already know the identity of the key to 1126 be used in order to decrypt the message. If a key needs to be 1127 identified to the recipient, the enveloped structure ought to be 1128 used. 1130 Examples of encrypted messages can be found in Appendix C.3. 1132 The COSE_Encrypt0 structure can be encoded either tagged or untagged 1133 depending on the context it will be used in. A tagged COSE_Encrypt0 1134 structure is identified by the CBOR tag TBD3. The CDDL fragment that 1135 represents this is: 1137 COSE_Encrypt0_Tagged = #6.993(COSE_Encrypt0) ; Replace 993 with TBD3 1139 The COSE_Encrypt0 structure is a CBOR array. The fields of the array 1140 in order are: 1142 protected as described in Section 3. 1144 unprotected as described in Section 3. 1146 ciphertext as described in Section 5.1. 1148 The CDDL fragment for COSE_Encrypt0 that corresponds to the above 1149 text is: 1151 COSE_Encrypt0 = [ 1152 Headers, 1153 ciphertext : bstr / nil, 1154 ] 1156 5.3. How to encrypt and decrypt for AEAD Algorithms 1158 The encryption algorithm for AEAD algorithms is fairly simple. The 1159 first step is to create a consistent byte stream for the 1160 authenticated data structure. For this purpose, we use an 1161 Enc_structure. The Enc_structure is a CBOR array. The fields of the 1162 Enc_structure in order are: 1164 1. A text string identifying the context of the authenticated data 1165 structure. The context string is: 1167 "Encrypt0" for the content encryption of a COSE_Encrypt0 data 1168 structure. 1170 "Encrypt" for the first layer of a COSE_Encrypt data structure 1171 (i.e., for content encryption). 1173 "Enc_Recipient" for a recipient encoding to be placed in an 1174 COSE_Encrypt data structure. 1176 "Mac_Recipient" for a recipient encoding to be placed in a MACed 1177 message structure. 1179 "Rec_Recipient" for a recipient encoding to be placed in a 1180 recipient structure. 1182 2. The protected attributes from the body structure encoded in a 1183 bstr type. If there are no protected attributes, a bstr of 1184 length zero is used. 1186 3. The protected attributes from the application encoded in a bstr 1187 type. If this field is not supplied, it defaults to a zero 1188 length bstr. (See Section 4.3 for application guidance on 1189 constructing this field.) 1191 The CDDL fragment that describes the above text is: 1193 Enc_structure = [ 1194 context : "Encrypt" / "Encrypt0" / "Enc_Recipient" / 1195 "Mac_Recipient" / "Rec_Recipient", 1196 protected : empty_or_serialized_map, 1197 external_aad : bstr 1198 ] 1200 How to encrypt a message: 1202 1. Create an Enc_structure and populate it with the appropriate 1203 fields. 1205 2. Encode the Enc_structure to a byte stream (AAD), using the 1206 encoding described in Section 14. 1208 3. Determine the encryption key (K). This step is dependent on the 1209 class of recipient algorithm being used. For: 1211 No Recipients: The key to be used is determined by the algorithm 1212 and key at the current layer. Examples are key transport keys 1213 Section 12.3, key wrap keys Section 12.2.1 or pre-shared 1214 secrets. 1216 Direct Encryption and Direct Key Agreement: The key is 1217 determined by the key and algorithm in the recipient 1218 structure. The encryption algorithm and size of the key to be 1219 used are inputs into the KDF used for the recipient. (For 1220 direct, the KDF can be thought of as the identity operation.) 1221 Examples of these algorithms are found in Section 12.1.2 and 1222 Section 12.4.1. 1224 Other: The key is randomly or pseudo-randomly generated. 1226 4. Call the encryption algorithm with K (the encryption key), P (the 1227 plain text) and AAD. Place the returned cipher text into the 1228 'ciphertext' field of the structure. 1230 5. For recipients of the message, recursively perform the encryption 1231 algorithm for that recipient, using K (the encryption key) as the 1232 plain text. 1234 How to decrypt a message: 1236 1. Create a Enc_structure and populate it with the appropriate 1237 fields. 1239 2. Encode the Enc_structure to a byte stream (AAD), using the 1240 encoding described in Section 14. 1242 3. Determine the decryption key. This step is dependent on the 1243 class of recipient algorithm being used. For: 1245 No Recipients: The key to be used is determined by the algorithm 1246 and key at the current layer. Examples are key transport keys 1247 Section 12.3, key wrap keys Section 12.2.1 or pre-shared 1248 secrets. 1250 Direct Encryption and Direct Key Agreement: The key is 1251 determined by the key and algorithm in the recipient 1252 structure. The encryption algorithm and size of the key to be 1253 used are inputs into the KDF used for the recipient. (For 1254 direct, the KDF can be thought of as the identity operation.) 1255 Examples of these algorithms are found in Section 12.1.2 and 1256 Section 12.4.1. 1258 Other: The key is determined by decoding and decrypting one of 1259 the recipient structures. 1261 4. Call the decryption algorithm with K (the decryption key to use), 1262 C (the cipher text) and AAD. 1264 5.4. How to encrypt and decrypt for AE Algorithms 1266 How to encrypt a message: 1268 1. Verify that the 'protected' field is empty. 1270 2. Verify that there was no external additional authenticated data 1271 supplied for this operation. 1273 3. Determine the encryption key. This step is dependent on the 1274 class of recipient algorithm being used. For: 1276 No Recipients: The key to be used is determined by the algorithm 1277 and key at the current layer. Examples are key transport keys 1278 Section 12.3, key wrap keys Section 12.2.1 or pre-shared 1279 secrets. 1281 Direct Encryption and Direct Key Agreement: The key is 1282 determined by the key and algorithm in the recipient 1283 structure. The encryption algorithm and size of the key to be 1284 used are inputs into the KDF used for the recipient. (For 1285 direct, the KDF can be thought of as the identity operation.) 1286 Examples of these algorithms are found in Section 12.1.2 and 1287 Section 12.4.1. 1289 Other: The key is randomly generated. 1291 4. Call the encryption algorithm with K (the encryption key to use) 1292 and the P (the plain text). Place the returned cipher text into 1293 the 'ciphertext' field of the structure. 1295 5. For recipients of the message, recursively perform the encryption 1296 algorithm for that recipient, using K (the encryption key) as the 1297 plain text. 1299 How to decrypt a message: 1301 1. Verify that the 'protected' field is empty. 1303 2. Verify that there was no external additional authenticated data 1304 supplied for this operation. 1306 3. Determine the decryption key. This step is dependent on the 1307 class of recipient algorithm being used. For: 1309 No Recipients: The key to be used is determined by the algorithm 1310 and key at the current layer. Examples are key transport keys 1311 Section 12.3, key wrap keys Section 12.2.1 or pre-shared 1312 secrets. 1314 Direct Encryption and Direct Key Agreement: The key is 1315 determined by the key and algorithm in the recipient 1316 structure. The encryption algorithm and size of the key to be 1317 used are inputs into the KDF used for the recipient. (For 1318 direct, the KDF can be thought of as the identity operation.) 1319 Examples of these algorithms are found in Section 12.1.2 and 1320 Section 12.4.1. 1322 Other: The key is determined by decoding and decrypting one of 1323 the recipient structures. 1325 4. Call the decryption algorithm with K (the decryption key to use), 1326 and C (the cipher text). 1328 6. MAC Objects 1330 COSE supports two different MAC structures. COSE_MAC0 is used when a 1331 recipient structure is not needed because the key to be used is 1332 implicitly known. COSE_MAC is used for all other cases. These 1333 include a requirement for multiple recipients, the key being unknown, 1334 and a recipient algorithm of other than direct. 1336 In this section, we describe the structure and methods to be used 1337 when doing MAC authentication in COSE. This document allows for the 1338 use of all of the same classes of recipient algorithms as are allowed 1339 for encryption. 1341 When using MAC operations, there are two modes in which they can be 1342 used. The first is just a check that the content has not been 1343 changed since the MAC was computed. Any class of recipient algorithm 1344 can be used for this purpose. The second mode is to both check that 1345 the content has not been changed since the MAC was computed, and to 1346 use the recipient algorithm to verify who sent it. The classes of 1347 recipient algorithms that support this are those that use a pre- 1348 shared secret or do static-static key agreement (without the key wrap 1349 step). In both of these cases, the entity that created and sent the 1350 message MAC can be validated. (This knowledge of sender assumes that 1351 there are only two parties involved and you did not send the message 1352 to yourself.) The origination property can be obtained with both of 1353 the MAC message structures. 1355 6.1. MACed Message with Recipients 1357 The multiple recipient MACed message uses two structures, the 1358 COSE_Mac structure defined in this section for carrying the body and 1359 the COSE_recipient structure (Section 5.1) to hold the key used for 1360 the MAC computation. Examples of MACed messages can be found in 1361 Appendix C.5. 1363 The MAC structure can be encoded either tagged or untagged depending 1364 on the context it will be used in. A tagged COSE_Mac structure is 1365 identified by the CBOR tag TBD4. The CDDL fragment that represents 1366 this is: 1368 COSE_Mac_Tagged = #6.994(COSE_Mac) ; Replace 994 with TBD4 1370 The COSE_Mac structure is a CBOR array. The fields of the array in 1371 order are: 1373 protected as described in Section 3. 1375 unprotected as described in Section 3. 1377 payload contains the serialized content to be MACed. If the payload 1378 is not present in the message, the application is required to 1379 supply the payload separately. The payload is wrapped in a bstr 1380 to ensure that it is transported without changes. If the payload 1381 is transported separately (i.e., detached content), then a nil 1382 CBOR value is placed in this location and it is the responsibility 1383 of the application to ensure that it will be transported without 1384 changes. 1386 tag contains the MAC value. 1388 recipients as described in Section 5.1. 1390 The CDDL fragment that represents the above text for COSE_Mac 1391 follows. 1393 COSE_Mac = [ 1394 Headers, 1395 payload : bstr / nil, 1396 tag : bstr, 1397 recipients :[+COSE_recipient] 1398 ] 1400 6.2. MACed Messages with Implicit Key 1402 In this section, we describe the structure and methods to be used 1403 when doing MAC authentication for those cases where the recipient is 1404 implicitly known. 1406 The MACed message uses the COSE_Mac0 structure defined in this 1407 section for carrying the body. Examples of MACed messages with an 1408 implicit key can be found in Appendix C.6. 1410 The MAC structure can be encoded either tagged or untagged depending 1411 on the context it will be used in. A tagged COSE_Mac0 structure is 1412 identified by the CBOR tag TBD6. The CDDL fragment that represents 1413 this is: 1415 COSE_Mac0_Tagged = #6.996(COSE_Mac0) ; Replace 996 with TBD6 1417 The COSE_Mac0 structure is a CBOR array. The fields of the array in 1418 order are: 1420 protected as described in Section 3. 1422 unprotected as described in Section 3. 1424 payload as described in Section 6.1. 1426 tag contains the MAC value. 1428 The CDDL fragment that corresponds to the above text is: 1430 COSE_Mac0 = [ 1431 Headers, 1432 payload : bstr / nil, 1433 tag : bstr, 1434 ] 1436 6.3. How to compute and verify a MAC 1438 In order to get a consistent encoding of the data to be 1439 authenticated, the MAC_structure is used to have a canonical form. 1440 The MAC_structure is a CBOR array. The fields of the MAC_structure 1441 in order are: 1443 1. A text string that identifies the structure that is being 1444 encoded. This string is "MAC" for the COSE_Mac structure. This 1445 string is "MAC0" for the COSE_Mac0 structure. 1447 2. The protected attributes from the COSE_MAC structure. If there 1448 are no protected attributes, a zero length bstr is used. 1450 3. The protected attributes from the application encoded as a bstr 1451 type. If this field is not supplied, it defaults to a zero 1452 length binary string. (See Section 4.3 for application guidance 1453 on constructing this field.) 1455 4. The payload to be MAC-ed encoded in a bstr type. The payload is 1456 placed here independent of how it is transported. 1458 The CDDL fragment that corresponds to the above text is: 1460 MAC_structure = [ 1461 context : "MAC" / "MAC0", 1462 protected : empty_or_serialized_map, 1463 external_aad : bstr, 1464 payload : bstr 1465 ] 1467 The steps to compute a MAC are: 1469 1. Create a MAC_structure and populate it with the appropriate 1470 fields. 1472 2. Create the value ToBeMaced by encoding the MAC_structure to a 1473 byte stream, using the encoding described in Section 14. 1475 3. Call the MAC creation algorithm passing in K (the key to use), 1476 alg (the algorithm to MAC with) and ToBeMaced (the value to 1477 compute the MAC on). 1479 4. Place the resulting MAC in the 'tag' field of the COSE_Mac or 1480 COSE_Mac0 structure. 1482 5. Encrypt and encode the MAC key for each recipient of the message. 1484 The steps to verify a MAC are: 1486 1. Create a MAC_structure object and populate it with the 1487 appropriate fields. 1489 2. Create the value ToBeMaced by encoding the MAC_structure to a 1490 byte stream, using the encoding described in Section 14. 1492 3. Obtain the cryptographic key from one of the recipients of the 1493 message. 1495 4. Call the MAC creation algorithm passing in K (the key to use), 1496 alg (the algorithm to MAC with) and ToBeMaced (the value to 1497 compute the MAC on). 1499 5. Compare the MAC value to the 'tag' field of the COSE_Mac or 1500 COSE_Mac0 structure. 1502 7. Key Objects 1504 A COSE Key structure is built on a CBOR map object. The set of 1505 common parameters that can appear in a COSE Key can be found in the 1506 IANA "COSE Key Common Parameters" registry (Section 16.5). 1507 Additional parameters defined for specific key types can be found in 1508 the IANA "COSE Key Type Parameters" registry (Section 16.6). 1510 A COSE Key Set uses a CBOR array object as its underlying type. The 1511 values of the array elements are COSE Keys. A Key Set MUST have at 1512 least one element in the array. Examples of Key Sets can be found in 1513 Appendix C.7. 1515 Each element in a key set MUST be processed independently. If one 1516 element in a key set is either malformed or uses a key that is not 1517 understood by an application, that key is ignored and the other keys 1518 are processed normally. 1520 The element "kty" is a required element in a COSE_Key map. 1522 The CDDL grammar describing COSE_Key and COSE_KeySet is: 1524 COSE_Key = { 1525 1 => tstr / int, ; kty 1526 ? 2 => bstr, ; kid 1527 ? 3 => tstr / int, ; alg 1528 ? 4 => [+ (tstr / int) ], ; key_ops 1529 ? 5 => bstr, ; Base IV 1530 * label => values 1531 } 1533 COSE_KeySet = [+COSE_Key] 1535 7.1. COSE Key Common Parameters 1537 This document defines a set of common parameters for a COSE Key 1538 object. Table 3 provides a summary of the parameters defined in this 1539 section. There are also parameters that are defined for specific key 1540 types. Key type specific parameters can be found in Section 13. 1542 +---------+-------+----------------+------------+-------------------+ 1543 | name | label | CBOR type | registry | description | 1544 +---------+-------+----------------+------------+-------------------+ 1545 | kty | 1 | tstr / int | COSE Key | Identification of | 1546 | | | | Common | the key type | 1547 | | | | Parameters | | 1548 | | | | | | 1549 | alg | 3 | tstr / int | COSE | Key usage | 1550 | | | | Algorithm | restriction to | 1551 | | | | Values | this algorithm | 1552 | | | | | | 1553 | kid | 2 | bstr | | Key | 1554 | | | | | Identification | 1555 | | | | | value - match to | 1556 | | | | | kid in message | 1557 | | | | | | 1558 | key_ops | 4 | [+ (tstr/int)] | | Restrict set of | 1559 | | | | | permissible | 1560 | | | | | operations | 1561 | | | | | | 1562 | Base IV | 5 | bstr | | Base IV to be | 1563 | | | | | xor-ed with | 1564 | | | | | Partial IVs | 1565 +---------+-------+----------------+------------+-------------------+ 1567 Table 3: Key Map Labels 1569 kty: This parameter is used to identify the family of keys for this 1570 structure, and thus the set of key type specific parameters to be 1571 found. The set of values defined in this document can be found in 1572 Table 21. This parameter MUST be present in a key object. 1573 Implementations MUST verify that the key type is appropriate for 1574 the algorithm being processed. The key type MUST be included as 1575 part of the trust decision process. 1577 alg: This parameter is used to restrict the algorithm that is used 1578 with the key. If this parameter is present in the key structure, 1579 the application MUST verify that this algorithm matches the 1580 algorithm for which the key is being used. If the algorithms do 1581 not match, then this key object MUST NOT be used to perform the 1582 cryptographic operation. Note that the same key can be in a 1583 different key structure with a different or no algorithm 1584 specified, however this is considered to be a poor security 1585 practice. 1587 kid: This parameter is used to give an identifier for a key. The 1588 identifier is not structured and can be anything from a user 1589 provided string to a value computed on the public portion of the 1590 key. This field is intended for matching against a 'kid' 1591 parameter in a message in order to filter down the set of keys 1592 that need to be checked. 1594 key_ops: This parameter is defined to restrict the set of operations 1595 that a key is to be used for. The value of the field is an array 1596 of values from Table 4. Algorithms define the values of key ops 1597 that are permitted to appear and are required for specific 1598 operations. The set of values matches that in [RFC7517] and 1599 [W3C.WebCrypto]. 1601 Base IV: This parameter is defined to carry the base portion of an 1602 IV. It is designed to be used with the partial IV header 1603 parameter defined in Section 3.1. This field provides the ability 1604 to associate a partial IV with a key that is then modified on a 1605 per message basis with the partial IV. 1607 Extreme care needs to be taken when using a Base IV in an 1608 application. Many encryption algorithms lose security if the same 1609 IV is used twice. 1611 If different keys are derived for each sender, using the same base 1612 IV with partial IVs starting at zero is likely to ensure that the 1613 IV would not be used twice for a single key. If different keys 1614 are derived for each sender, starting at the same base IV is 1615 likely to satisfy this condition. If the same key is used for 1616 multiple senders, then the application needs to provide for a 1617 method of dividing the IV space up between the senders. This 1618 could be done by providing a different base point to start from or 1619 a different partial IV to start with and restricting the number of 1620 messages to be sent before re-keying. 1622 +---------+-------+-------------------------------------------------+ 1623 | name | value | description | 1624 +---------+-------+-------------------------------------------------+ 1625 | sign | 1 | The key is used to create signatures. Requires | 1626 | | | private key fields. | 1627 | | | | 1628 | verify | 2 | The key is used for verification of signatures. | 1629 | | | | 1630 | encrypt | 3 | The key is used for key transport encryption. | 1631 | | | | 1632 | decrypt | 4 | The key is used for key transport decryption. | 1633 | | | Requires private key fields. | 1634 | | | | 1635 | wrap | 5 | The key is used for key wrapping. | 1636 | key | | | 1637 | | | | 1638 | unwrap | 6 | The key is used for key unwrapping. Requires | 1639 | key | | private key fields. | 1640 | | | | 1641 | derive | 7 | The key is used for deriving keys. Requires | 1642 | key | | private key fields. | 1643 | | | | 1644 | derive | 8 | The key is used for deriving bits not to be | 1645 | bits | | used as a key. Requires private key fields. | 1646 | | | | 1647 | MAC | 9 | The key is used for creating MACs. | 1648 | create | | | 1649 | | | | 1650 | MAC | 10 | The key is used for validating MACs. | 1651 | verify | | | 1652 +---------+-------+-------------------------------------------------+ 1654 Table 4: Key Operation Values 1656 8. Signature Algorithms 1658 There are two signature algorithm schemes. The first is signature 1659 with appendix. In this scheme, the message content is processed and 1660 a signature is produced, the signature is called the appendix. This 1661 is the scheme used by algorithms such as ECDSA and RSASSA-PSS. (In 1662 fact the SSA in RSASSA-PSS stands for Signature Scheme with 1663 Appendix.) 1665 The signature functions for this scheme are: 1667 signature = Sign(message content, key) 1669 valid = Verification(message content, key, signature) 1670 The second scheme is signature with message recovery. (An example of 1671 such an algorithm is [PVSig].) In this scheme, the message content 1672 is processed, but part of it is included in the signature. Moving 1673 bytes of the message content into the signature allows for smaller 1674 signatures, the signature size is still potentially large, but the 1675 message content has shrunk. This has implications for systems 1676 implementing these algorithms and for applications that use them. 1677 The first is that the message content is not fully available until 1678 after a signature has been validated. Until that point the part of 1679 the message contained inside of the signature is unrecoverable. The 1680 second is that the security analysis of the strength of the signature 1681 is very much based on the structure of the message content. Messages 1682 that are highly predictable require additional randomness to be 1683 supplied as part of the signature process. In the worst case, it 1684 becomes the same as doing a signature with appendix. Finally, in the 1685 event that multiple signatures are applied to a message, all of the 1686 signature algorithms are going to be required to consume the same 1687 number of bytes of message content. This means that mixing of the 1688 different schemes in a single message is not supported, and if a 1689 recovery signature scheme is used, then the same amount of content 1690 needs to be consumed by all of the signatures. 1692 The signature functions for this scheme are: 1694 signature, message sent = Sign(message content, key) 1696 valid, message content = Verification(message sent, key, signature) 1698 Signature algorithms are used with the COSE_Signature and COSE_Sign1 1699 structures. At this time, only signatures with appendixes are 1700 defined for use with COSE, however considerable interest has been 1701 expressed in using a signature with message recovery algorithm due to 1702 the effective size reduction that is possible. Implementations will 1703 need to keep this in mind for later possible integration. 1705 8.1. ECDSA 1707 ECDSA [DSS] defines a signature algorithm using ECC. Implementations 1708 SHOULD use a deterministic version of ECDSA such as the one defined 1709 in [RFC6979]. The use of a deterministic signature algorithms allows 1710 for systems to avoid relying on random number generators in order to 1711 avoid generating the same value of 'k' (the per-message random 1712 value). Biased generation of the value be attacked and collisions 1713 will lead to leaked keys. It additionally allows for doing 1714 deterministic tests for the signature algorithm. The use of 1715 deterministic ECDSA does not lessen the need to to have good random 1716 number generation when creating the private key. 1718 The ECDSA signature algorithm is parameterized with a hash function 1719 (h). In the event that the length of the hash function output is 1720 greater than the group of the key, the left-most bytes of the hash 1721 output are used. 1723 The algorithms defined in this document can be found in Table 5. 1725 +-------+-------+---------+------------------+ 1726 | name | value | hash | description | 1727 +-------+-------+---------+------------------+ 1728 | ES256 | -7 | SHA-256 | ECDSA w/ SHA-256 | 1729 | | | | | 1730 | ES384 | -35 | SHA-384 | ECDSA w/ SHA-384 | 1731 | | | | | 1732 | ES512 | -36 | SHA-512 | ECDSA w/ SHA-512 | 1733 +-------+-------+---------+------------------+ 1735 Table 5: ECDSA Algorithm Values 1737 This document defines ECDSA to work only with the curves P-256, P-384 1738 and P-521. This document requires that the curves be encoded using 1739 the 'EC2' (2 coordinate Elliptic Curve) key type. Implementations 1740 need to check that the key type and curve are correct when creating 1741 and verifying a signature. Other documents can define it to work 1742 with other curves and points in the future. 1744 In order to promote interoperability, it is suggested that SHA-256 be 1745 used only with curve P-256, SHA-384 be used only with curve P-384 and 1746 SHA-512 be used with curve P-521. This is aligned with the 1747 recommendation in Section 4 of [RFC5480]. 1749 The signature algorithm results in a pair of integers (R, S). These 1750 integers will the same length as length of the key used for the 1751 signature process. The signature is encoded by converting the 1752 integers into byte strings of the same length as the key size. The 1753 length is rounded up to the nearest byte and is left padded with zero 1754 bits to get to the correct length. The two integers are then 1755 concatenated together to form a byte string that is the resulting 1756 signature. 1758 Using the function defined in [I-D.moriarty-pkcs1] the signature is: 1759 Signature = I2OSP(R, n) | I2OSP(S, n) 1760 where n = ceiling(key_length / 8) 1762 When using a COSE key for this algorithm, the following checks are 1763 made: 1765 o The 'kty' field MUST be present and it MUST be 'EC2'. 1767 o If the 'alg' field is present, it MUST match the ECDSA signature 1768 algorithm being used. 1770 o If the 'key_ops' field is present, it MUST include 'sign' when 1771 creating an ECDSA signature. 1773 o If the 'key_ops' field is present, it MUST include 'verify' when 1774 verifying an ECDSA signature. 1776 8.1.1. Security Considerations 1778 The security strength of the signature is no greater than the minimum 1779 of the security strength associated with the bit length of the key 1780 and the security strength of the hash function. 1782 Note: Use of this technique is a good idea even when good random 1783 number generation exists. Doing so both reduces the possibility of 1784 having the same value of 'k' in two signature operations and allows 1785 for reproducible signature values, which helps testing. 1787 There are two substitution attacks that can theoretically be mounted 1788 against the ECDSA signature algorithm. 1790 o Changing the curve used to validate the signature: If one changes 1791 the curve used to validate the signature, then potentially one 1792 could have a two messages with the same signature each computed 1793 under a different curve. The only requirement on the new curve is 1794 that its order be the same as the old one and it be acceptable to 1795 the client. An example would be to change from using the curve 1796 secp256r1 (aka P-256) to using secp256k1. (Both are 256 bit 1797 curves.) We current do not have any way to deal with this version 1798 of the attack except to restrict the overall set of curves that 1799 can be used. 1801 o Change the hash function used to validate the signature: If one 1802 has either two different hash functions of the same length, or one 1803 can truncate a hash function down, then one could potentially find 1804 collisions between the hash functions rather than within a single 1805 hash function. (For example, truncating SHA-512 to 256 bits might 1806 collide with a SHA-256 bit hash value.) As the hash algorithm is 1807 part of the signature algorithm identifier, this attack is 1808 mitigated by including signature algorithm identifier in the 1809 protected header. 1811 8.2. Edwards-curve Digital Signature Algorithms (EdDSA) 1813 [I-D.irtf-cfrg-eddsa] describes the elliptic curve signature scheme 1814 Edwards-curve Digital Signature Algorithm (EdDSA). In that document, 1815 the signature algorithm is instantiated using parameters for 1816 edwards25519 and edwards448 curves. The document additionally 1817 describes two variants of the EdDSA algorithm: Pure EdDSA, where no 1818 hash function is applied to the content before signing and, HashEdDSA 1819 where a hash function is applied to the content before signing and 1820 the result of that hash function is signed. For the EdDSA, the 1821 content to be signed (either the message or the pre-hash value) is 1822 processed twice inside of the signature algorithm. For use with 1823 COSE, only the pure EdDSA version is used. This is because it is not 1824 expected that extremely large contents are going to be needed and, 1825 based on the arrangement of the message structure, the entire message 1826 is going to need to be held in memory in order to create or verify a 1827 signature. This means that there does not appear to be a need to be 1828 able to do block updates of the hash, followed by eliminating the 1829 message from memory. Applications can provide the same features by 1830 defining the content of the message as a hash value and transporting 1831 the COSE object (with the hash value) and the content as separate 1832 items. 1834 The algorithms defined in this document can be found in Table 6. A 1835 single signature algorithm is defined, which can be used for multiple 1836 curves. 1838 +-------+-------+-------------+ 1839 | name | value | description | 1840 +-------+-------+-------------+ 1841 | EdDSA | -8 | EdDSA | 1842 +-------+-------+-------------+ 1844 Table 6: EdDSA Algorithm Values 1846 [I-D.irtf-cfrg-eddsa] describes the method of encoding the signature 1847 value. 1849 When using a COSE key for this algorithm the following checks are 1850 made: 1852 o The 'kty' field MUST be present and it MUST be 'OKP' (Octet Key 1853 Pair). 1855 o The 'crv' field MUST be present, and it MUST be a curve defined 1856 for this signature algorithm. 1858 o If the 'alg' field is present, it MUST match 'EdDSA'. 1860 o If the 'key_ops' field is present, it MUST include 'sign' when 1861 creating an EdDSA signature. 1863 o If the 'key_ops' field is present, it MUST include 'verify' when 1864 verifying an EdDSA signature. 1866 8.2.1. Security Considerations 1868 How public values are computed is not the same when looking at EdDSA 1869 and ECDH, for this reason they should not be used with the other 1870 algorithm. 1872 If batch signature verification is performed, a well-seeded 1873 cryptographic random number generator is REQUIRED. Signing and non- 1874 batch signature verification are deterministic operations and do not 1875 need random numbers of any kind. 1877 9. Message Authentication (MAC) Algorithms 1879 Message Authentication Codes (MACs) provide data authentication and 1880 integrity protection. They provide either no or very limited data 1881 origination. A MAC, for example, be used to prove the identity of 1882 the sender to a third party. 1884 MACs use the same scheme as signature with appendix algorithms. The 1885 message content is processed and an authentication code is produced. 1886 The authentication code is frequently called a tag. 1888 The MAC functions are: 1890 tag = MAC_Create(message content, key) 1892 valid = MAC_Verify(message content, key, tag) 1894 MAC algorithms can be based on either a block cipher algorithm (i.e., 1895 AES-MAC) or a hash algorithm (i.e., HMAC). This document defines a 1896 MAC algorithm using each of these constructions. 1898 MAC algorithms are used in the COSE_Mac and COSE_Mac0 structures. 1900 9.1. Hash-based Message Authentication Codes (HMAC) 1902 The Hash-based Message Authentication Code algorithm (HMAC) 1903 [RFC2104][RFC4231] was designed to deal with length extension 1904 attacks. The algorithm was also designed to allow for new hash 1905 algorithms to be directly plugged in without changes to the hash 1906 function. The HMAC design process has been shown as solid since, 1907 while the security of hash algorithms such as MD5 has decreased over 1908 time, the security of HMAC combined with MD5 has not yet been shown 1909 to be compromised [RFC6151]. 1911 The HMAC algorithm is parameterized by an inner and outer padding, a 1912 hash function (h), and an authentication tag value length. For this 1913 specification, the inner and outer padding are fixed to the values 1914 set in [RFC2104]. The length of the authentication tag corresponds 1915 to the difficulty of producing a forgery. For use in constrained 1916 environments, we define a set of HMAC algorithms that are truncated. 1917 There are currently no known issues with truncation, however the 1918 security strength of the message tag is correspondingly reduced in 1919 strength. When truncating, the left-most tag length bits are kept 1920 and transmitted. 1922 The algorithms defined in this document can be found in Table 7. 1924 +-----------+-------+---------+----------+--------------------------+ 1925 | name | value | Hash | Tag | description | 1926 | | | | Length | | 1927 +-----------+-------+---------+----------+--------------------------+ 1928 | HMAC | 4 | SHA-256 | 64 | HMAC w/ SHA-256 | 1929 | 256/64 | | | | truncated to 64 bits | 1930 | | | | | | 1931 | HMAC | 5 | SHA-256 | 256 | HMAC w/ SHA-256 | 1932 | 256/256 | | | | | 1933 | | | | | | 1934 | HMAC | 6 | SHA-384 | 384 | HMAC w/ SHA-384 | 1935 | 384/384 | | | | | 1936 | | | | | | 1937 | HMAC | 7 | SHA-512 | 512 | HMAC w/ SHA-512 | 1938 | 512/512 | | | | | 1939 +-----------+-------+---------+----------+--------------------------+ 1941 Table 7: HMAC Algorithm Values 1943 Some recipient algorithms carry the key while others derive a key 1944 from secret data. For those algorithms that carry the key (such as 1945 AES-KeyWrap), the size of the HMAC key SHOULD be the same size as the 1946 underlying hash function. For those algorithms that derive the key 1947 (such as ECDH), the derived key MUST be the same size as the 1948 underlying hash function. 1950 When using a COSE key for this algorithm, the following checks are 1951 made: 1953 o The 'kty' field MUST be present and it MUST be 'Symmetric'. 1955 o If the 'alg' field is present, it MUST match the HMAC algorithm 1956 being used. 1958 o If the 'key_ops' field is present, it MUST include 'MAC create' 1959 when creating an HMAC authentication tag. 1961 o If the 'key_ops' field is present, it MUST include 'MAC verify' 1962 when verifying an HMAC authentication tag. 1964 Implementations creating and validating MAC values MUST validate that 1965 the key type, key length, and algorithm are correct and appropriate 1966 for the entities involved. 1968 9.1.1. Security Considerations 1970 HMAC has proved to be resistant to attack even when used with 1971 weakened hash algorithms. The current best known attack appears is 1972 to brute force the key. This means that key size is going to be 1973 directly related to the security of an HMAC operation. 1975 9.2. AES Message Authentication Code (AES-CBC-MAC) 1977 AES-CBC-MAC is defined in [MAC]. (Note this is not the same 1978 algorithm as AES-CMAC [RFC4493]). 1980 AES-CBC-MAC is parameterized by the key length, the authentication 1981 tag length and the IV used. For all of these algorithms, the IV is 1982 fixed to all zeros. We provide an array of algorithms for various 1983 key lengths and tag lengths. The algorithms defined in this document 1984 are found in Table 8. 1986 +-------------+-------+----------+----------+-----------------------+ 1987 | name | value | key | tag | description | 1988 | | | length | length | | 1989 +-------------+-------+----------+----------+-----------------------+ 1990 | AES-MAC | 14 | 128 | 64 | AES-MAC 128 bit key, | 1991 | 128/64 | | | | 64-bit tag | 1992 | | | | | | 1993 | AES-MAC | 15 | 256 | 64 | AES-MAC 256 bit key, | 1994 | 256/64 | | | | 64-bit tag | 1995 | | | | | | 1996 | AES-MAC | 25 | 128 | 128 | AES-MAC 128 bit key, | 1997 | 128/128 | | | | 128-bit tag | 1998 | | | | | | 1999 | AES-MAC | 26 | 256 | 128 | AES-MAC 256 bit key, | 2000 | 256/128 | | | | 128-bit tag | 2001 +-------------+-------+----------+----------+-----------------------+ 2003 Table 8: AES-MAC Algorithm Values 2005 Keys may be obtained either from a key structure or from a recipient 2006 structure. Implementations creating and validating MAC values MUST 2007 validate that the key type, key length and algorithm are correct and 2008 appropriate for the entities involved. 2010 When using a COSE key for this algorithm, the following checks are 2011 made: 2013 o The 'kty' field MUST be present and it MUST be 'Symmetric'. 2015 o If the 'alg' field is present, it MUST match the AES-MAC algorithm 2016 being used. 2018 o If the 'key_ops' field is present, it MUST include 'MAC create' 2019 when creating an AES-MAC authentication tag. 2021 o If the 'key_ops' field is present, it MUST include 'MAC verify' 2022 when verifying an AES-MAC authentication tag. 2024 9.2.1. Security Considerations 2026 A number of attacks exist against CBC-MAC that need to be considered. 2027 - 2029 o A single key must only be used for messages of a fixed and known 2030 length. If this is not the case, an attacker will be able to 2031 generate a message with a valid tag given two message and tag 2032 pairs. This can be addressed by using different keys for 2033 different length messages. The current structure mitigates this 2034 problem, as a specific encoding structure that includes lengths is 2035 built and signed. (CMAC also addresses this issue.) 2037 o When using CBC mode, if the same key is used for both encryption 2038 and authentication operations, an attacker can produce messages 2039 with a valid authentication code. 2041 o If the IV can be modified, then messages can be forged. This is 2042 addressed by fixing the IV to all zeros. 2044 10. Content Encryption Algorithms 2046 Content Encryption Algorithms provide data confidentiality for 2047 potentially large blocks of data using a symmetric key. They provide 2048 integrity on the data that was encrypted, however they provide either 2049 no or very limited data origination. (One cannot, for example, be 2050 used to prove the identity of the sender to a third party.) The 2051 ability to provide data origination is linked to how the CEK is 2052 obtained. 2054 COSE restricts the set of legal content encryption algorithms to 2055 those that support authentication both of the content and additional 2056 data. The encryption process will generate some type of 2057 authentication value, but that value may be either explicit or 2058 implicit in terms of the algorithm definition. For simplicity sake, 2059 the authentication code will normally be defined as being appended to 2060 the cipher text stream. The encryption functions are: 2062 ciphertext = Encrypt(message content, key, additional data) 2064 valid, message content = Decrypt(cipher text, key, additional data) 2066 Most AEAD algorithms are logically defined as returning the message 2067 content only if the decryption is valid. Many but not all 2068 implementations will follow this convention. The message content 2069 MUST NOT be used if the decryption does not validate. 2071 These algorithms are used in COSE_Encrypt and COSE_Encrypt0. 2073 10.1. AES GCM 2075 The GCM mode is a generic authenticated encryption block cipher mode 2076 defined in [AES-GCM]. The GCM mode is combined with the AES block 2077 encryption algorithm to define an AEAD cipher. 2079 The GCM mode is parameterized by the size of the authentication tag 2080 and the size of the nonce. This document fixes the size of the nonce 2081 at 96 bits. The size of the authentication tag is limited to a small 2082 set of values. For this document however, the size of the 2083 authentication tag is fixed at 128 bits. 2085 The set of algorithms defined in this document are in Table 9. 2087 +---------+-------+------------------------------------------+ 2088 | name | value | description | 2089 +---------+-------+------------------------------------------+ 2090 | A128GCM | 1 | AES-GCM mode w/ 128-bit key, 128-bit tag | 2091 | | | | 2092 | A192GCM | 2 | AES-GCM mode w/ 192-bit key, 128-bit tag | 2093 | | | | 2094 | A256GCM | 3 | AES-GCM mode w/ 256-bit key, 128-bit tag | 2095 +---------+-------+------------------------------------------+ 2097 Table 9: Algorithm Value for AES-GCM 2099 Keys may be obtained either from a key structure or from a recipient 2100 structure. Implementations encrypting and decrypting MUST validate 2101 that the key type, key length and algorithm are correct and 2102 appropriate for the entities involved. 2104 When using a COSE key for this algorithm, the following checks are 2105 made: 2107 o The 'kty' field MUST be present and it MUST be 'Symmetric'. 2109 o If the 'alg' field is present, it MUST match the AES-GCM algorithm 2110 being used. 2112 o If the 'key_ops' field is present, it MUST include 'encrypt' or 2113 'wrap key' when encrypting. 2115 o If the 'key_ops' field is present, it MUST include 'decrypt' or 2116 'unwrap key' when decrypting. 2118 10.1.1. Security Considerations 2120 When using AES-GCM, the following restrictions MUST be enforced: 2122 o The key and nonce pair MUST be unique for every message encrypted. 2124 o The total amount of data encrypted for a single key MUST NOT 2125 exceed 2^39 - 256 bits. An explicit check is required only in 2126 environments where it is expected that it might be exceeded. 2128 Consideration was given to supporting smaller tag values; the 2129 constrained community would desire tag sizes in the 64-bit range. 2131 Doing so drastically changes both the maximum messages size 2132 (generally not an issue) and the number of times that a key can be 2133 used. Given that CCM is the usual mode for constrained environments, 2134 restricted modes are not supported. 2136 10.2. AES CCM 2138 Counter with CBC-MAC (CCM) is a generic authentication encryption 2139 block cipher mode defined in [RFC3610]. The CCM mode is combined 2140 with the AES block encryption algorithm to define a commonly used 2141 content encryption algorithm used in constrained devices. 2143 The CCM mode has two parameter choices. The first choice is M, the 2144 size of the authentication field. The choice of the value for M 2145 involves a trade-off between message growth (from the tag) and the 2146 probably that an attacker can undetectably modify a message. The 2147 second choice is L, the size of the length field. This value 2148 requires a trade-off between the maximum message size and the size of 2149 the Nonce. 2151 It is unfortunate that the specification for CCM specified L and M as 2152 a count of bytes rather than a count of bits. This leads to possible 2153 misunderstandings where AES-CCM-8 is frequently used to refer to a 2154 version of CCM mode where the size of the authentication is 64 bits 2155 and not 8 bits. These values have traditionally been specified as 2156 bit counts rather than byte counts. This document will follow the 2157 convention of using bit counts so that it is easier to compare the 2158 different algorithms presented in this document. 2160 We define a matrix of algorithms in this document over the values of 2161 L and M. Constrained devices are usually operating in situations 2162 where they use short messages and want to avoid doing recipient 2163 specific cryptographic operations. This favors smaller values of 2164 both L and M. Less constrained devices will want to be able to use 2165 larger messages and are more willing to generate new keys for every 2166 operation. This favors larger values of L and M. 2168 The following values are used for L: 2170 16 bits (2) limits messages to 2^16 bytes (64 KiB) in length. This 2171 is sufficiently long for messages in the constrained world. The 2172 nonce length is 13 bytes allowing for 2^(13*8) possible values of 2173 the nonce without repeating. 2175 64 bits (8) limits messages to 2^64 bytes in length. The nonce 2176 length is 7 bytes allowing for 2^56 possible values of the nonce 2177 without repeating. 2179 The following values are used for M: 2181 64 bits (8) produces a 64-bit authentication tag. This implies that 2182 there is a 1 in 2^64 chance that a modified message will 2183 authenticate. 2185 128 bits (16) produces a 128-bit authentication tag. This implies 2186 that there is a 1 in 2^128 chance that a modified message will 2187 authenticate. 2189 +--------------------+-------+----+-----+-----+---------------------+ 2190 | name | value | L | M | k | description | 2191 +--------------------+-------+----+-----+-----+---------------------+ 2192 | AES-CCM-16-64-128 | 10 | 16 | 64 | 128 | AES-CCM mode | 2193 | | | | | | 128-bit key, 64-bit | 2194 | | | | | | tag, 13-byte nonce | 2195 | | | | | | | 2196 | AES-CCM-16-64-256 | 11 | 16 | 64 | 256 | AES-CCM mode | 2197 | | | | | | 256-bit key, 64-bit | 2198 | | | | | | tag, 13-byte nonce | 2199 | | | | | | | 2200 | AES-CCM-64-64-128 | 12 | 64 | 64 | 128 | AES-CCM mode | 2201 | | | | | | 128-bit key, 64-bit | 2202 | | | | | | tag, 7-byte nonce | 2203 | | | | | | | 2204 | AES-CCM-64-64-256 | 13 | 64 | 64 | 256 | AES-CCM mode | 2205 | | | | | | 256-bit key, 64-bit | 2206 | | | | | | tag, 7-byte nonce | 2207 | | | | | | | 2208 | AES-CCM-16-128-128 | 30 | 16 | 128 | 128 | AES-CCM mode | 2209 | | | | | | 128-bit key, | 2210 | | | | | | 128-bit tag, | 2211 | | | | | | 13-byte nonce | 2212 | | | | | | | 2213 | AES-CCM-16-128-256 | 31 | 16 | 128 | 256 | AES-CCM mode | 2214 | | | | | | 256-bit key, | 2215 | | | | | | 128-bit tag, | 2216 | | | | | | 13-byte nonce | 2217 | | | | | | | 2218 | AES-CCM-64-128-128 | 32 | 64 | 128 | 128 | AES-CCM mode | 2219 | | | | | | 128-bit key, | 2220 | | | | | | 128-bit tag, 7-byte | 2221 | | | | | | nonce | 2222 | | | | | | | 2223 | AES-CCM-64-128-256 | 33 | 64 | 128 | 256 | AES-CCM mode | 2224 | | | | | | 256-bit key, | 2225 | | | | | | 128-bit tag, 7-byte | 2226 | | | | | | nonce | 2227 +--------------------+-------+----+-----+-----+---------------------+ 2229 Table 10: Algorithm Values for AES-CCM 2231 Keys may be obtained either from a key structure or from a recipient 2232 structure. Implementations encrypting and decrypting MUST validate 2233 that the key type, key length and algorithm are correct and 2234 appropriate for the entities involved. 2236 When using a COSE key for this algorithm, the following checks are 2237 made: 2239 o The 'kty' field MUST be present and it MUST be 'Symmetric'. 2241 o If the 'alg' field is present, it MUST match the AES-CCM algorithm 2242 being used. 2244 o If the 'key_ops' field is present, it MUST include 'encrypt' or 2245 'wrap key' when encrypting. 2247 o If the 'key_ops' field is present, it MUST include 'decrypt' or 2248 'unwrap key' when decrypting. 2250 10.2.1. Security Considerations 2252 When using AES-CCM, the following restrictions MUST be enforced: 2254 o The key and nonce pair MUST be unique for every message encrypted. 2255 Note that the value of L influences the number of unique nonces. 2257 o The total number of times the AES block cipher is used MUST NOT 2258 exceed 2^61 operations. This limitation is the sum of times the 2259 block cipher is used in computing the MAC value and in performing 2260 stream encryption operations. An explicit check is required only 2261 in environments where it is expected that it might be exceeded. 2263 [RFC3610] additionally calls out one other consideration of note. It 2264 is possible to do a pre-computation attack against the algorithm in 2265 cases where portions of the plaintext are highly predictable. This 2266 reduces the security of the key size by half. Ways to deal with this 2267 attack include adding a random portion to the nonce value and/or 2268 increasing the key size used. Using a portion of the nonce for a 2269 random value will decrease the number of messages that a single key 2270 can be used for. Increasing the key size may require more resources 2271 in the constrained device. See sections 5 and 10 of [RFC3610] for 2272 more information. 2274 10.3. ChaCha20 and Poly1305 2276 ChaCha20 and Poly1305 combined together is an AEAD mode that is 2277 defined in [RFC7539]. This is an algorithm defined to be a cipher 2278 that is not AES and thus would not suffer from any future weaknesses 2279 found in AES. These cryptographic functions are designed to be fast 2280 in software-only implementations. 2282 The ChaCha20/Poly1305 AEAD construction defined in [RFC7539] has no 2283 parameterization. It takes a 256-bit key and a 96-bit nonce, as well 2284 as the plain text and additional data as inputs and produces the 2285 cipher text as an option. We define one algorithm identifier for 2286 this algorithm in Table 11. 2288 +-------------------+-------+---------------------------------------+ 2289 | name | value | description | 2290 +-------------------+-------+---------------------------------------+ 2291 | ChaCha20/Poly1305 | 24 | ChaCha20/Poly1305 w/ 256-bit key, | 2292 | | | 128-bit tag | 2293 +-------------------+-------+---------------------------------------+ 2295 Table 11: Algorithm Value for AES-GCM 2297 Keys may be obtained either from a key structure or from a recipient 2298 structure. Implementations encrypting and decrypting MUST validate 2299 that the key type, key length and algorithm are correct and 2300 appropriate for the entities involved. 2302 When using a COSE key for this algorithm, the following checks are 2303 made: 2305 o The 'kty' field MUST be present and it MUST be 'Symmetric'. 2307 o If the 'alg' field is present, it MUST match the ChaCha20/Poly1305 2308 algorithm being used. 2310 o If the 'key_ops' field is present, it MUST include 'encrypt' or 2311 'wrap key' when encrypting. 2313 o If the 'key_ops' field is present, it MUST include 'decrypt' or 2314 'unwrap key' when decrypting. 2316 10.3.1. Security Considerations 2318 The pair of key, nonce MUST be unique for every invocation of the 2319 algorithm. Nonce counters are considered to be an acceptable way of 2320 ensuring that they are unique. 2322 11. Key Derivation Functions (KDF) 2324 Key Derivation Functions (KDFs) are used to take some secret value 2325 and generate a different one. The secret value comes in three 2326 flavors: 2328 o Secrets that are uniformly random: This is the type of secret that 2329 is created by a good random number generator. 2331 o Secrets that are not uniformly random: This is type of secret that 2332 is created by operations like key agreement. 2334 o Secrets that are not random: This is the type of secret that 2335 people generate for things like passwords. 2337 General KDF functions work well with the first type of secret, can do 2338 reasonably well with the second type of secret, and generally do 2339 poorly with the last type of secret. None of the KDF functions in 2340 this section are designed to deal with the type of secrets that are 2341 used for passwords. Functions like PBES2 [I-D.moriarty-pkcs5-v2dot1] 2342 need to be used for that type of secret. 2344 The same KDF function can be setup to deal with the first two types 2345 of secrets in a different way. The KDF function defined in 2346 Section 11.1 is such a function. This is reflected in the set of 2347 algorithms defined for HKDF. 2349 When using KDF functions, one component that is included is context 2350 information. Context information is used to allow for different 2351 keying information to be derived from the same secret. The use of 2352 context based keying material is considered to be a good security 2353 practice. 2355 This document defines a single context structure and a single KDF 2356 function. These elements are used for all of the recipient 2357 algorithms defined in this document that require a KDF process. 2358 These algorithms are defined in Section 12.1.2, Section 12.4.1, and 2359 Section 12.5.1. 2361 11.1. HMAC-based Extract-and-Expand Key Derivation Function (HKDF) 2363 The HKDF key derivation algorithm is defined in [RFC5869]. 2365 The HKDF algorithm takes these inputs: 2367 secret - a shared value that is secret. Secrets may be either 2368 previously shared or derived from operations like a DH key 2369 agreement. 2371 salt - an optional value that is used to change the generation 2372 process. The salt value can be either public or private. If the 2373 salt is public and carried in the message, then the 'salt' 2374 algorithm header parameter defined in Table 13 is used. While 2375 [RFC5869] suggests that the length of the salt be the same as the 2376 length of the underlying hash value, any amount of salt will 2377 improve the security as different key values will be generated. 2378 This parameter is protected by being included in the key 2379 computation and does not need to be separately authenticated. The 2380 salt value does not need to be unique for every message sent. 2382 length - the number of bytes of output that need to be generated. 2384 context information - Information that describes the context in 2385 which the resulting value will be used. Making this information 2386 specific to the context in which the material is going to be used 2387 ensures that the resulting material will always be tied to that 2388 usage. The context structure defined in Section 11.2 is used by 2389 the KDF functions in this document. 2391 PRF - The underlying pseudo-random function to be used in the HKDF 2392 algorithm. The PRF is encoded into the HKDF algorithm selection. 2394 HKDF is defined to use HMAC as the underlying PRF. However, it is 2395 possible to use other functions in the same construct to provide a 2396 different KDF function that is more appropriate in the constrained 2397 world. Specifically, one can use AES-CBC-MAC as the PRF for the 2398 expand step, but not for the extract step. When using a good random 2399 shared secret of the correct length, the extract step can be skipped. 2400 For the AES algorithm versions, the extract step is always skipped. 2402 The extract step cannot be skipped if the secret is not uniformly 2403 random, for example, if it is the result of an ECDH key agreement 2404 step. (This implies that the AES HKDF version cannot be used with 2405 ECDH.) If the extract step is skipped, the 'salt' value is not used 2406 as part of the HKDF functionality. 2408 The algorithms defined in this document are found in Table 12. 2410 +---------------+-----------------+---------------------------------+ 2411 | name | PRF | description | 2412 +---------------+-----------------+---------------------------------+ 2413 | HKDF SHA-256 | HMAC with | HKDF using HMAC SHA-256 as the | 2414 | | SHA-256 | PRF | 2415 | | | | 2416 | HKDF SHA-512 | HMAC with | HKDF using HMAC SHA-512 as the | 2417 | | SHA-512 | PRF | 2418 | | | | 2419 | HKDF AES- | AES-CBC-MAC-128 | HKDF using AES-MAC as the PRF | 2420 | MAC-128 | | w/ 128-bit key | 2421 | | | | 2422 | HKDF AES- | AES-CBC-MAC-256 | HKDF using AES-MAC as the PRF | 2423 | MAC-256 | | w/ 256-bit key | 2424 +---------------+-----------------+---------------------------------+ 2426 Table 12: HKDF algorithms 2428 +------+-------+------+-------------------------------+-------------+ 2429 | name | label | type | algorithm | description | 2430 +------+-------+------+-------------------------------+-------------+ 2431 | salt | -20 | bstr | direct+HKDF-SHA-256, direct | Random salt | 2432 | | | | +HKDF-SHA-512, direct+HKDF- | | 2433 | | | | AES-128, direct+HKDF-AES-256, | | 2434 | | | | ECDH-ES+HKDF-256, ECDH- | | 2435 | | | | ES+HKDF-512, ECDH- | | 2436 | | | | SS+HKDF-256, ECDH- | | 2437 | | | | SS+HKDF-512, ECDH-ES+A128KW, | | 2438 | | | | ECDH-ES+A192KW, ECDH- | | 2439 | | | | ES+A256KW, ECDH-SS+A128KW, | | 2440 | | | | ECDH-SS+A192KW, ECDH- | | 2441 | | | | SS+A256KW | | 2442 +------+-------+------+-------------------------------+-------------+ 2444 Table 13: HKDF Algorithm Parameters 2446 11.2. Context Information Structure 2448 The context information structure is used to ensure that the derived 2449 keying material is "bound" to the context of the transaction. The 2450 context information structure used here is based on that defined in 2451 [SP800-56A]. By using CBOR for the encoding of the context 2452 information structure, we automatically get the same type and length 2453 separation of fields that is obtained by the use of ASN.1. This 2454 means that there is no need to encode the lengths for the base 2455 elements as it is done by the encoding used in JOSE (Section 4.6.2 of 2456 [RFC7518]). 2458 The context information structure refers to PartyU and PartyV as the 2459 two parties that are doing the key derivation. Unless the 2460 application protocol defines differently, we assign PartyU to the 2461 entity that is creating the message and PartyV to the entity that is 2462 receiving the message. By doing this association, different keys 2463 will be derived for each direction as the context information is 2464 different in each direction. 2466 The context structure is built from information that is known to both 2467 entities. This information can be obtained from a variety of 2468 sources: 2470 o Fields can be defined by the application. This is commonly used 2471 to assign fixed names to parties, but can be used for other items 2472 such as nonces. 2474 o Fields can be defined by usage of the output. Examples of this 2475 are the algorithm and key size that are being generated. 2477 o Fields can be defined by parameters from the message. We define a 2478 set of parameters in Table 14 that can be used to carry the values 2479 associated with the context structure. Examples of this are 2480 identities and nonce values. These parameters are designed to be 2481 placed in the unprotected bucket of the recipient structure. 2482 (They do not need to be in the protected bucket since they already 2483 are included in the cryptographic computation by virtue of being 2484 included in the context structure.) 2486 +----------+-------+------+---------------------------+-------------+ 2487 | name | label | type | algorithm | description | 2488 +----------+-------+------+---------------------------+-------------+ 2489 | PartyU | -21 | bstr | direct+HKDF-SHA-256, | Party U | 2490 | identity | | | direct+HKDF-SHA-512, | identity | 2491 | | | | direct+HKDF-AES-128, | Information | 2492 | | | | direct+HKDF-AES-256, | | 2493 | | | | ECDH-ES+HKDF-256, ECDH- | | 2494 | | | | ES+HKDF-512, ECDH- | | 2495 | | | | SS+HKDF-256, ECDH- | | 2496 | | | | SS+HKDF-512, ECDH- | | 2497 | | | | ES+A128KW, ECDH- | | 2498 | | | | ES+A192KW, ECDH- | | 2499 | | | | ES+A256KW, ECDH- | | 2500 | | | | SS+A128KW, ECDH- | | 2501 | | | | SS+A192KW, ECDH-SS+A256KW | | 2502 | | | | | | 2503 | PartyU | -22 | bstr | direct+HKDF-SHA-256, | Party U | 2504 | nonce | | / | direct+HKDF-SHA-512, | provided | 2505 | | | int | direct+HKDF-AES-128, | nonce | 2506 | | | | direct+HKDF-AES-256, | | 2507 | | | | ECDH-ES+HKDF-256, ECDH- | | 2508 | | | | ES+HKDF-512, ECDH- | | 2509 | | | | SS+HKDF-256, ECDH- | | 2510 | | | | SS+HKDF-512, ECDH- | | 2511 | | | | ES+A128KW, ECDH- | | 2512 | | | | ES+A192KW, ECDH- | | 2513 | | | | ES+A256KW, ECDH- | | 2514 | | | | SS+A128KW, ECDH- | | 2515 | | | | SS+A192KW, ECDH-SS+A256KW | | 2516 | | | | | | 2517 | PartyU | -23 | bstr | direct+HKDF-SHA-256, | Party U | 2518 | other | | | direct+HKDF-SHA-512, | other | 2519 | | | | direct+HKDF-AES-128, | provided | 2520 | | | | direct+HKDF-AES-256, | information | 2521 | | | | ECDH-ES+HKDF-256, ECDH- | | 2522 | | | | ES+HKDF-512, ECDH- | | 2523 | | | | SS+HKDF-256, ECDH- | | 2524 | | | | SS+HKDF-512, ECDH- | | 2525 | | | | ES+A128KW, ECDH- | | 2526 | | | | ES+A192KW, ECDH- | | 2527 | | | | ES+A256KW, ECDH- | | 2528 | | | | SS+A128KW, ECDH- | | 2529 | | | | SS+A192KW, ECDH-SS+A256KW | | 2530 | | | | | | 2531 | PartyV | -24 | bstr | direct+HKDF-SHA-256, | Party V | 2532 | identity | | | direct+HKDF-SHA-512, | identity | 2533 | | | | direct+HKDF-AES-128, | Information | 2534 | | | | direct+HKDF-AES-256, | | 2535 | | | | ECDH-ES+HKDF-256, ECDH- | | 2536 | | | | ES+HKDF-512, ECDH- | | 2537 | | | | SS+HKDF-256, ECDH- | | 2538 | | | | SS+HKDF-512, ECDH- | | 2539 | | | | ES+A128KW, ECDH- | | 2540 | | | | ES+A192KW, ECDH- | | 2541 | | | | ES+A256KW, ECDH- | | 2542 | | | | SS+A128KW, ECDH- | | 2543 | | | | SS+A192KW, ECDH-SS+A256KW | | 2544 | | | | | | 2545 | PartyV | -25 | bstr | direct+HKDF-SHA-256, | Party V | 2546 | nonce | | / | direct+HKDF-SHA-512, | provided | 2547 | | | int | direct+HKDF-AES-128, | nonce | 2548 | | | | direct+HKDF-AES-256, | | 2549 | | | | ECDH-ES+HKDF-256, ECDH- | | 2550 | | | | ES+HKDF-512, ECDH- | | 2551 | | | | SS+HKDF-256, ECDH- | | 2552 | | | | SS+HKDF-512, ECDH- | | 2553 | | | | ES+A128KW, ECDH- | | 2554 | | | | ES+A192KW, ECDH- | | 2555 | | | | ES+A256KW, ECDH- | | 2556 | | | | SS+A128KW, ECDH- | | 2557 | | | | SS+A192KW, ECDH-SS+A256KW | | 2558 | | | | | | 2559 | PartyV | -26 | bstr | direct+HKDF-SHA-256, | Party V | 2560 | other | | | direct+HKDF-SHA-512, | other | 2561 | | | | direct+HKDF-AES-128, | provided | 2562 | | | | direct+HKDF-AES-256, | information | 2563 | | | | ECDH-ES+HKDF-256, ECDH- | | 2564 | | | | ES+HKDF-512, ECDH- | | 2565 | | | | SS+HKDF-256, ECDH- | | 2566 | | | | SS+HKDF-512, ECDH- | | 2567 | | | | ES+A128KW, ECDH- | | 2568 | | | | ES+A192KW, ECDH- | | 2569 | | | | ES+A256KW, ECDH- | | 2570 | | | | SS+A128KW, ECDH- | | 2571 | | | | SS+A192KW, ECDH-SS+A256KW | | 2572 +----------+-------+------+---------------------------+-------------+ 2573 Table 14: Context Algorithm Parameters 2575 We define a CBOR object to hold the context information. This object 2576 is referred to as COSE_KDF_Context. The object is based on a CBOR 2577 array type. The fields in the array are: 2579 AlgorithmID This field indicates the algorithm for which the key 2580 material will be used. This normally is either a Key Wrap 2581 algorithm identifier or a Content Encryption algorithm identifier. 2582 The values are from the "COSE Algorithm Value" registry. This 2583 field is required to be present. The field exists in the context 2584 information so that if the same environment is used for different 2585 algorithms, then completely different keys will be generated for 2586 each of those algorithms. (This practice means if algorithm A is 2587 broken and thus is easier to find, the key derived for algorithm B 2588 will not be the same as the key derived for algorithm A.) 2590 PartyUInfo This field holds information about party U. The 2591 PartyUInfo is encoded as a CBOR array. The elements of PartyUInfo 2592 are encoded in the order presented, however if the element does 2593 not exist no element is placed in the array. The elements of the 2594 PartyUInfo array are: 2596 identity This contains the identity information for party U. The 2597 identities can be assigned in one of two manners. Firstly, a 2598 protocol can assign identities based on roles. For example, 2599 the roles of "client" and "server" may be assigned to different 2600 entities in the protocol. Each entity would then use the 2601 correct label for the data they send or receive. The second 2602 way for a protocol to assign identities is to use a name based 2603 on a naming system (i.e., DNS, X.509 names). 2604 We define an algorithm parameter 'PartyU identity' that can be 2605 used to carry identity information in the message. However, 2606 identity information is often known as part of the protocol and 2607 can thus be inferred rather than made explicit. If identity 2608 information is carried in the message, applications SHOULD have 2609 a way of validating the supplied identity information. The 2610 identity information does not need to be specified and is set 2611 to nil in that case. 2613 nonce This contains a nonce value. The nonce can either be 2614 implicit from the protocol or carried as a value in the 2615 unprotected headers. 2616 We define an algorithm parameter 'PartyU nonce' that can be 2617 used to carry this value in the message However, the nonce 2618 value could be determined by the application and the value 2619 determined from elsewhere. 2621 This option does not need to be specified and is set to nil in 2622 that case 2624 other This contains other information that is defined by the 2625 protocol. 2626 This option does not need to be specified and is set to nil in 2627 that case 2629 PartyVInfo This field holds information about party V. The content 2630 of the structure are the same as for the PartyUInfo but for party 2631 V. 2633 SuppPubInfo This field contains public information that is mutually 2634 known to both parties. 2636 keyDataLength This is set to the number of bits of the desired 2637 output value. (This practice means if algorithm A can use two 2638 different key lengths, the key derived for longer key size will 2639 not contain the key for shorter key size as a prefix.) 2641 protected This field contains the protected parameter field. If 2642 there are no elements in the protected field, then use a zero 2643 length bstr. 2645 other This field is for free form data defined by the 2646 application. An example is that an application could define 2647 two different strings to be placed here to generate different 2648 keys for a data stream vs a control stream. This field is 2649 optional and will only be present if the application defines a 2650 structure for this information. Applications that define this 2651 SHOULD use CBOR to encode the data so that types and lengths 2652 are correctly included. 2654 SuppPrivInfo This field contains private information that is 2655 mutually known private information. An example of this 2656 information would be a pre-existing shared secret. (This could, 2657 for example, be used in combination with an ECDH key agreement to 2658 provide a secondary proof of identity.) The field is optional and 2659 will only be present if the application defines a structure for 2660 this information. Applications that define this SHOULD use CBOR 2661 to encode the data so that types and lengths are correctly 2662 included. 2664 The following CDDL fragment corresponds to the text above. 2666 PartyInfo = ( 2667 identity : bstr / nil, 2668 nonce : bstr / int / nil, 2669 other : bstr / nil, 2670 ) 2672 COSE_KDF_Context = [ 2673 AlgorithmID : int / tstr, 2674 PartyUInfo : [ PartyInfo ], 2675 PartyVInfo : [ PartyInfo ], 2676 SuppPubInfo : [ 2677 keyDataLength : uint, 2678 protected : empty_or_serialized_map, 2679 ? other : bstr 2680 ], 2681 ? SuppPrivInfo : bstr 2682 ] 2684 12. Content Key Distribution Methods 2686 Content key distribution methods (recipient algorithms) can be 2687 defined into a number of different classes. COSE has the ability to 2688 support many classes of recipient algorithms. In this section, a 2689 number of classes are listed and then a set of algorithms are 2690 specified for each of the classes. The names of the recipient 2691 algorithm classes used here are the same as are defined in [RFC7516]. 2692 Other specifications use different terms for the recipient algorithm 2693 classes or do not support some of the recipient algorithm classes. 2695 12.1. Direct Encryption 2697 The direct encryption class algorithms share a secret between the 2698 sender and the recipient that is used either directly or after 2699 manipulation as the CEK. When direct encryption mode is used, it 2700 MUST be the only mode used on the message. 2702 The COSE_Encrypt structure for the recipient is organized as follows: 2704 o The 'protected' field MUST be a zero length item unless it is used 2705 in the computation of the content key. 2707 o The 'alg' parameter MUST be present. 2709 o A parameter identifying the shared secret SHOULD be present. 2711 o The 'ciphertext' field MUST be a zero length item. 2713 o The 'recipients' field MUST be absent. 2715 12.1.1. Direct Key 2717 This recipient algorithm is the simplest; the identified key is 2718 directly used as the key for the next layer down in the message. 2719 There are no algorithm parameters defined for this algorithm. The 2720 algorithm identifier value is assigned in Table 15. 2722 When this algorithm is used, the protected field MUST be zero length. 2723 The key type MUST be 'Symmetric'. 2725 +--------+-------+-------------------+ 2726 | name | value | description | 2727 +--------+-------+-------------------+ 2728 | direct | -6 | Direct use of CEK | 2729 +--------+-------+-------------------+ 2731 Table 15: Direct Key 2733 12.1.1.1. Security Considerations 2735 This recipient algorithm has several potential problems that need to 2736 be considered: 2738 o These keys need to have some method to be regularly updated over 2739 time. All of the content encryption algorithms specified in this 2740 document have limits on how many times a key can be used without 2741 significant loss of security. 2743 o These keys need to be dedicated to a single algorithm. There have 2744 been a number of attacks developed over time when a single key is 2745 used for multiple different algorithms. One example of this is 2746 the use of a single key both for CBC encryption mode and CBC-MAC 2747 authentication mode. 2749 o Breaking one message means all messages are broken. If an 2750 adversary succeeds in determining the key for a single message, 2751 then the key for all messages is also determined. 2753 12.1.2. Direct Key with KDF 2755 These recipient algorithms take a common shared secret between the 2756 two parties and applies the HKDF function (Section 11.1), using the 2757 context structure defined in Section 11.2 to transform the shared 2758 secret into the CEK. The 'protected' field can be of non-zero 2759 length. Either the 'salt' parameter of HKDF or the partyU 'nonce' 2760 parameter of the context structure MUST be present. The salt/nonce 2761 parameter can be generated either randomly or deterministically. The 2762 requirement is that it be a unique value for the shared secret in 2763 question. 2765 If the salt/nonce value is generated randomly, then it is suggested 2766 that the length of the random value be the same length as the hash 2767 function underlying HKDF. While there is no way to guarantee that it 2768 will be unique, there is a high probability that it will be unique. 2769 If the salt/nonce value is generated deterministically, it can be 2770 guaranteed to be unique and thus there is no length requirement. 2772 A new IV must be used for each message if the same key is used. The 2773 IV can be modified in a predictable manner, a random manner or an 2774 unpredictable manner (i.e., encrypting a counter). 2776 The IV used for a key can also be generated from the same HKDF 2777 functionality as the key is generated. If HKDF is used for 2778 generating the IV, the algorithm identifier is set to "IV- 2779 GENERATION". 2781 When these algorithms are used, the key type MUST be 'symmetric'. 2783 The set of algorithms defined in this document can be found in 2784 Table 16. 2786 +---------------------+-------+-------------+-----------------------+ 2787 | name | value | KDF | description | 2788 +---------------------+-------+-------------+-----------------------+ 2789 | direct+HKDF-SHA-256 | -10 | HKDF | Shared secret w/ HKDF | 2790 | | | SHA-256 | and SHA-256 | 2791 | | | | | 2792 | direct+HKDF-SHA-512 | -11 | HKDF | Shared secret w/ HKDF | 2793 | | | SHA-512 | and SHA-512 | 2794 | | | | | 2795 | direct+HKDF-AES-128 | -12 | HKDF AES- | Shared secret w/ AES- | 2796 | | | MAC-128 | MAC 128-bit key | 2797 | | | | | 2798 | direct+HKDF-AES-256 | -13 | HKDF AES- | Shared secret w/ AES- | 2799 | | | MAC-256 | MAC 256-bit key | 2800 +---------------------+-------+-------------+-----------------------+ 2802 Table 16: Direct Key with KDF 2804 When using a COSE key for this algorithm, the following checks are 2805 made: 2807 o The 'kty' field MUST be present and it MUST be 'Symmetric'. 2809 o If the 'alg' field is present, it MUST match the algorithm being 2810 used. 2812 o If the 'key_ops' field is present, it MUST include 'deriveKey' or 2813 'deriveBits'. 2815 12.1.2.1. Security Considerations 2817 The shared secret needs to have some method to be regularly updated 2818 over time. The shared secret forms the basis of trust. Although not 2819 used directly, it should still be subject to scheduled rotation. 2821 While these methods do not provide for perfect forward secrecy, as 2822 the same shared secret is used for all of the keys generated, if the 2823 key for any single message is discovered only the message (or series 2824 of messages) using that derived key are compromised. A new key 2825 derivation step will generate a new key which requires the same 2826 amount of work to get the key. 2828 12.2. Key Wrapping 2830 In key wrapping mode, the CEK is randomly generated and that key is 2831 then encrypted by a shared secret between the sender and the 2832 recipient. All of the currently defined key wrapping algorithms for 2833 COSE are AE algorithms. Key wrapping mode is considered to be 2834 superior to direct encryption if the system has any capability for 2835 doing random key generation. This is because the shared key is used 2836 to wrap random data rather than data that has some degree of 2837 organization and may in fact be repeating the same content. The use 2838 of Key Wrapping loses the weak data origination that is provided by 2839 the direct encryption algorithms. 2841 The COSE_Encrypt structure for the recipient is organized as follows: 2843 o The 'protected' field MUST be absent if the key wrap algorithm is 2844 an AE algorithm. 2846 o The 'recipients' field is normally absent, but can be used. 2847 Applications MUST deal with a recipient field being present, not 2848 being able to decrypt that recipient is an acceptable way of 2849 dealing with it. Failing to process the message is not an 2850 acceptable way of dealing with it. 2852 o The plain text to be encrypted is the key from next layer down 2853 (usually the content layer). 2855 o At a minimum, the 'unprotected' field MUST contain the 'alg' 2856 parameter and SHOULD contain a parameter identifying the shared 2857 secret. 2859 12.2.1. AES Key Wrapping 2861 The AES Key Wrapping algorithm is defined in [RFC3394]. This 2862 algorithm uses an AES key to wrap a value that is a multiple of 64 2863 bits. As such, it can be used to wrap a key for any of the content 2864 encryption algorithms defined in this document. The algorithm 2865 requires a single fixed parameter, the initial value. This is fixed 2866 to the value specified in Section 2.2.3.1 of [RFC3394]. There are no 2867 public parameters that vary on a per invocation basis. The protected 2868 header field MUST be empty. 2870 Keys may be obtained either from a key structure or from a recipient 2871 structure. Implementations encrypting and decrypting MUST validate 2872 that the key type, key length and algorithm are correct and 2873 appropriate for the entities involved. 2875 When using a COSE key for this algorithm, the following checks are 2876 made: 2878 o The 'kty' field MUST be present and it MUST be 'Symmetric'. 2880 o If the 'alg' field is present, it MUST match the AES Key Wrap 2881 algorithm being used. 2883 o If the 'key_ops' field is present, it MUST include 'encrypt' or 2884 'wrap key' when encrypting. 2886 o If the 'key_ops' field is present, it MUST include 'decrypt' or 2887 'unwrap key' when decrypting. 2889 +--------+-------+----------+-----------------------------+ 2890 | name | value | key size | description | 2891 +--------+-------+----------+-----------------------------+ 2892 | A128KW | -3 | 128 | AES Key Wrap w/ 128-bit key | 2893 | | | | | 2894 | A192KW | -4 | 192 | AES Key Wrap w/ 192-bit key | 2895 | | | | | 2896 | A256KW | -5 | 256 | AES Key Wrap w/ 256-bit key | 2897 +--------+-------+----------+-----------------------------+ 2899 Table 17: AES Key Wrap Algorithm Values 2901 12.2.1.1. Security Considerations for AES-KW 2903 The shared secret needs to have some method to be regularly updated 2904 over time. The shared secret is the basis of trust. 2906 12.3. Key Transport 2908 Key transport mode is also called key encryption mode in some 2909 standards. Key transport mode differs from key wrap mode in that it 2910 uses an asymmetric encryption algorithm rather than a symmetric 2911 encryption algorithm to protect the key. This document does not 2912 define any key transport mode algorithms. 2914 When using a key transport algorithm, the COSE_Encrypt structure for 2915 the recipient is organized as follows: 2917 o The 'protected' field MUST be absent. 2919 o The plain text to be encrypted is the key from next layer down 2920 (usually the content layer). 2922 o At a minimum, the 'unprotected' field MUST contain the 'alg' 2923 parameter and SHOULD contain a parameter identifying the 2924 asymmetric key. 2926 12.4. Direct Key Agreement 2928 The 'direct key agreement' class of recipient algorithms uses a key 2929 agreement method to create a shared secret. A KDF is then applied to 2930 the shared secret to derive a key to be used in protecting the data. 2931 This key is normally used as a CEK or MAC key, but could be used for 2932 other purposes if more than two layers are in use (see Appendix B). 2934 The most commonly used key agreement algorithm is Diffie-Hellman, but 2935 other variants exist. Since COSE is designed for a store and forward 2936 environment rather than an on-line environment, many of the DH 2937 variants cannot be used as the receiver of the message cannot provide 2938 any dynamic key material. One side-effect of this is that perfect 2939 forward secrecy (see [RFC4949]) is not achievable. A static key will 2940 always be used for the receiver of the COSE object. 2942 Two variants of DH that are supported are: 2944 Ephemeral-Static DH: where the sender of the message creates a 2945 one-time DH key and uses a static key for the recipient. The use 2946 of the ephemeral sender key means that no additional random input 2947 is needed as this is randomly generated for each message. 2949 Static-Static DH: where a static key is used for both the sender 2950 and the recipient. The use of static keys allows for recipient to 2951 get a weak version of data origination for the message. When 2952 static-static key agreement is used, then some piece of unique 2953 data for the KDF is required to ensure that a different key is 2954 created for each message. 2956 When direct key agreement mode is used, there MUST be only one 2957 recipient in the message. This method creates the key directly and 2958 that makes it difficult to mix with additional recipients. If 2959 multiple recipients are needed, then the version with key wrap needs 2960 to be used. 2962 The COSE_Encrypt structure for the recipient is organized as follows: 2964 o At a minimum, headers MUST contain the 'alg' parameter and SHOULD 2965 contain a parameter identifying the recipient's asymmetric key. 2967 o The headers SHOULD identify the sender's key for the static-static 2968 versions and MUST contain the sender's ephemeral key for the 2969 ephemeral-static versions. 2971 12.4.1. ECDH 2973 The mathematics for Elliptic Curve Diffie-Hellman can be found in 2974 [RFC6090]. In this document, the algorithm is extended to be used 2975 with the two curves defined in [RFC7748]. 2977 ECDH is parameterized by the following: 2979 o Curve Type/Curve: The curve selected controls not only the size of 2980 the shared secret, but the mathematics for computing the shared 2981 secret. The curve selected also controls how a point in the curve 2982 is represented and what happens for the identity points on the 2983 curve. In this specification, we allow for a number of different 2984 curves to be used. A set of curves are defined in Table 22. 2985 The math used to obtain the computed secret is based on the curve 2986 selected and not on the ECDH algorithm. For this reason, a new 2987 algorithm does not need to be defined for each of the curves. 2989 o Computed Secret to Shared Secret: Once the computed secret is 2990 known, the resulting value needs to be converted to a byte string 2991 to run the KDF function. The X coordinate is used for all of the 2992 curves defined in this document. For curves X25519 and X448, the 2993 resulting value is used directly as it is a byte string of a known 2994 length. For the P-256, P-384 and P-521 curves, the X coordinate 2995 is run through the I2OSP function defined in [I-D.moriarty-pkcs1], 2996 using the same computation for n as is defined in Section 8.1. 2998 o Ephemeral-static or static-static: The key agreement process may 2999 be done using either a static or an ephemeral key for the sender's 3000 side. When using ephemeral keys, the sender MUST generate a new 3001 ephemeral key for every key agreement operation. The ephemeral 3002 key is placed in the 'ephemeral key' parameter and MUST be present 3003 for all algorithm identifiers that use ephemeral keys. When using 3004 static keys, the sender MUST either generate a new random value or 3005 otherwise create a unique value. For the KDF functions used, this 3006 means either in the 'salt' parameter for HKDF (Table 13) or in the 3007 'PartyU nonce' parameter for the context structure (Table 14) MUST 3008 be present. (Both may be present if desired.) The value in the 3009 parameter MUST be unique for the pair of keys being used. It is 3010 acceptable to use a global counter that is incremented for every 3011 static-static operation and use the resulting value. When using 3012 static keys, the static key should be identified to the recipient. 3013 The static key can be identified either by providing the key 3014 ('static key') or by providing a key identifier for the static key 3015 ('static key id'). Both of these parameters are defined in 3016 Table 19. 3018 o Key derivation algorithm: The result of an ECDH key agreement 3019 process does not provide a uniformly random secret. As such, it 3020 needs to be run through a KDF in order to produce a usable key. 3021 Processing the secret through a KDF also allows for the 3022 introduction of context material: how the key is going to be used, 3023 and one-time material for static-static key agreement. All of the 3024 algorithms defined in this document use one of the HKDF algorithms 3025 defined in Section 11.1 with the context structure defined in 3026 Section 11.2. 3028 o Key Wrap algorithm: No key wrap algorithm is used. This is 3029 represented in Table 18 as 'none'. The key size for the context 3030 structure is the content layer encryption algorithm size. 3032 The set of direct ECDH algorithms defined in this document are found 3033 in Table 18. 3035 +-----------+-------+---------+------------+--------+---------------+ 3036 | name | value | KDF | Ephemeral- | Key | description | 3037 | | | | Static | Wrap | | 3038 +-----------+-------+---------+------------+--------+---------------+ 3039 | ECDH-ES + | -25 | HKDF - | yes | none | ECDH ES w/ | 3040 | HKDF-256 | | SHA-256 | | | HKDF - | 3041 | | | | | | generate key | 3042 | | | | | | directly | 3043 | | | | | | | 3044 | ECDH-ES + | -26 | HKDF - | yes | none | ECDH ES w/ | 3045 | HKDF-512 | | SHA-512 | | | HKDF - | 3046 | | | | | | generate key | 3047 | | | | | | directly | 3048 | | | | | | | 3049 | ECDH-SS + | -27 | HKDF - | no | none | ECDH SS w/ | 3050 | HKDF-256 | | SHA-256 | | | HKDF - | 3051 | | | | | | generate key | 3052 | | | | | | directly | 3053 | | | | | | | 3054 | ECDH-SS + | -28 | HKDF - | no | none | ECDH SS w/ | 3055 | HKDF-512 | | SHA-512 | | | HKDF - | 3056 | | | | | | generate key | 3057 | | | | | | directly | 3058 +-----------+-------+---------+------------+--------+---------------+ 3060 Table 18: ECDH Algorithm Values 3062 +-----------+-------+----------+---------------------+--------------+ 3063 | name | label | type | algorithm | description | 3064 +-----------+-------+----------+---------------------+--------------+ 3065 | ephemeral | -1 | COSE_Key | ECDH-ES+HKDF-256, | Ephemeral | 3066 | key | | | ECDH-ES+HKDF-512, | Public key | 3067 | | | | ECDH-ES+A128KW, | for the | 3068 | | | | ECDH-ES+A192KW, | sender | 3069 | | | | ECDH-ES+A256KW | | 3070 | | | | | | 3071 | static | -2 | COSE_Key | ECDH-SS+HKDF-256, | Static | 3072 | key | | | ECDH-SS+HKDF-512, | Public key | 3073 | | | | ECDH-SS+A128KW, | for the | 3074 | | | | ECDH-SS+A192KW, | sender | 3075 | | | | ECDH-SS+A256KW | | 3076 | | | | | | 3077 | static | -3 | bstr | ECDH-SS+HKDF-256, | Static | 3078 | key id | | | ECDH-SS+HKDF-512, | Public key | 3079 | | | | ECDH-SS+A128KW, | identifier | 3080 | | | | ECDH-SS+A192KW, | for the | 3081 | | | | ECDH-SS+A256KW | sender | 3082 +-----------+-------+----------+---------------------+--------------+ 3084 Table 19: ECDH Algorithm Parameters 3086 This document defines these algorithms to be used with the curves 3087 P-256, P-384, P-521, X25519, and X448. Implementations MUST verify 3088 that the key type and curve are correct. Different curves are 3089 restricted to different key types. Implementations MUST verify that 3090 the curve and algorithm are appropriate for the entities involved. 3092 When using a COSE key for this algorithm, the following checks are 3093 made: 3095 o The 'kty' field MUST be present and it MUST be 'EC2' or 'OKP'. 3097 o If the 'alg' field is present, it MUST match the Key Agreement 3098 algorithm being used. 3100 o If the 'key_ops' field is present, it MUST include 'derive key' or 3101 'derive bits' for the private key. 3103 o If the 'key_ops' field is present, it MUST be empty for the public 3104 key. 3106 12.4.2. Security Considerations 3108 Some method of checking that points provided from external entities 3109 are valid. For the 'EC2' key format, this can be done by checking 3110 that the x and y values form a point on the curve. For the 'OKP' 3111 format, there is no simple way to do point validation. 3113 Consideration was given to requiring that the public keys of both 3114 entities be provided as part of the key derivation process. (As 3115 recommended in section 6.1 of [RFC7748].) This was not done as COSE 3116 is used in a store and forward format rather than in on line key 3117 exchange. In order for this to be a problem, either the receiver 3118 public key has to be chosen maliciously or the sender has to be 3119 malicious. In either case, all security evaporates anyway. 3121 A proof of possession of the private key associated with the public 3122 key is recommended when a key is moved from untrusted to trusted. 3123 (Either by the end user or by the entity that is responsible for 3124 making trust statements on keys.) 3126 12.5. Key Agreement with Key Wrap 3128 Key Agreement with Key Wrapping uses a randomly generated CEK. The 3129 CEK is then encrypted using a Key Wrapping algorithm and a key 3130 derived from the shared secret computed by the key agreement 3131 algorithm. The function for this would be: 3133 encryptedKey = KeyWrap(KDF(DH-Shared, context), CEK) 3135 The COSE_Encrypt structure for the recipient is organized as follows: 3137 o The 'protected' field is fed into the KDF context structure. 3139 o The plain text to be encrypted is the key from next layer down 3140 (usually the content layer). 3142 o The 'alg' parameter MUST be present in the layer. 3144 o A parameter identifying the recipient's key SHOULD be present. A 3145 parameter identifying the sender's key SHOULD be present. 3147 12.5.1. ECDH 3149 These algorithms are defined in Table 20. 3151 ECDH with Key Agreement is parameterized by the same parameters as 3152 for ECDH Section 12.4.1 with the following modifications: 3154 o Key Wrap Algorithm: Any of the key wrap algorithms defined in 3155 Section 12.2.1 are supported. The size of the key used for the 3156 key wrap algorithm is fed into the KDF function. The set of 3157 identifiers are found in Table 20. 3159 +-----------+-------+---------+------------+--------+---------------+ 3160 | name | value | KDF | Ephemeral- | Key | description | 3161 | | | | Static | Wrap | | 3162 +-----------+-------+---------+------------+--------+---------------+ 3163 | ECDH-ES + | -29 | HKDF - | yes | A128KW | ECDH ES w/ | 3164 | A128KW | | SHA-256 | | | Concat KDF | 3165 | | | | | | and AES Key | 3166 | | | | | | wrap w/ 128 | 3167 | | | | | | bit key | 3168 | | | | | | | 3169 | ECDH-ES + | -30 | HKDF - | yes | A192KW | ECDH ES w/ | 3170 | A192KW | | SHA-256 | | | Concat KDF | 3171 | | | | | | and AES Key | 3172 | | | | | | wrap w/ 192 | 3173 | | | | | | bit key | 3174 | | | | | | | 3175 | ECDH-ES + | -31 | HKDF - | yes | A256KW | ECDH ES w/ | 3176 | A256KW | | SHA-256 | | | Concat KDF | 3177 | | | | | | and AES Key | 3178 | | | | | | wrap w/ 256 | 3179 | | | | | | bit key | 3180 | | | | | | | 3181 | ECDH-SS + | -32 | HKDF - | no | A128KW | ECDH SS w/ | 3182 | A128KW | | SHA-256 | | | Concat KDF | 3183 | | | | | | and AES Key | 3184 | | | | | | wrap w/ 128 | 3185 | | | | | | bit key | 3186 | | | | | | | 3187 | ECDH-SS + | -33 | HKDF - | no | A192KW | ECDH SS w/ | 3188 | A192KW | | SHA-256 | | | Concat KDF | 3189 | | | | | | and AES Key | 3190 | | | | | | wrap w/ 192 | 3191 | | | | | | bit key | 3192 | | | | | | | 3193 | ECDH-SS + | -34 | HKDF - | no | A256KW | ECDH SS w/ | 3194 | A256KW | | SHA-256 | | | Concat KDF | 3195 | | | | | | and AES Key | 3196 | | | | | | wrap w/ 256 | 3197 | | | | | | bit key | 3198 +-----------+-------+---------+------------+--------+---------------+ 3200 Table 20: ECDH Algorithm Values with Key Wrap 3202 When using a COSE key for this algorithm, the following checks are 3203 made: 3205 o The 'kty' field MUST be present and it MUST be 'EC2' or 'OKP'. 3207 o If the 'alg' field is present, it MUST match the Key Agreement 3208 algorithm being used. 3210 o If the 'key_ops' field is present, it MUST include 'derive key' or 3211 'derive bits' for the private key. 3213 o If the 'key_ops' field is present, it MUST be empty for the public 3214 key. 3216 13. Key Object Parameters 3218 The COSE_Key object defines a way to hold a single key object. It is 3219 still required that the members of individual key types be defined. 3220 This section of the document is where we define an initial set of 3221 members for specific key types. 3223 For each of the key types, we define both public and private members. 3224 The public members are what is transmitted to others for their usage. 3225 Private members allow for the archival of keys by individuals. 3226 However, there are some circumstances in which private keys may be 3227 distributed to entities in a protocol. Examples include: entities 3228 that have poor random number generation, centralized key creation for 3229 multi-cast type operations, and protocols in which a shared secret is 3230 used as a bearer token for authorization purposes. 3232 Key types are identified by the 'kty' member of the COSE_Key object. 3233 In this document, we define four values for the member: 3235 +-----------+-------+--------------------------------------------+ 3236 | name | value | description | 3237 +-----------+-------+--------------------------------------------+ 3238 | OKP | 1 | Octet Key Pair | 3239 | | | | 3240 | EC2 | 2 | Elliptic Curve Keys w/ X,Y Coordinate pair | 3241 | | | | 3242 | Symmetric | 4 | Symmetric Keys | 3243 | | | | 3244 | Reserved | 0 | This value is reserved | 3245 +-----------+-------+--------------------------------------------+ 3247 Table 21: Key Type Values 3249 13.1. Elliptic Curve Keys 3251 Two different key structures could be defined for Elliptic Curve 3252 keys. One version uses both an x and a y coordinate, potentially 3253 with point compression ('EC2'). This is the traditional EC point 3254 representation that is used in [RFC5480]. The other version uses 3255 only the x coordinate as the y coordinate is either to be recomputed 3256 or not needed for the key agreement operation ('OKP'). 3258 Applications MUST check that the curve and the key type are 3259 consistent and reject a key if they are not. 3261 +---------+----------+-------+------------------------------------+ 3262 | name | key type | value | description | 3263 +---------+----------+-------+------------------------------------+ 3264 | P-256 | EC2 | 1 | NIST P-256 also known as secp256r1 | 3265 | | | | | 3266 | P-384 | EC2 | 2 | NIST P-384 also known as secp384r1 | 3267 | | | | | 3268 | P-521 | EC2 | 3 | NIST P-521 also known as secp521r1 | 3269 | | | | | 3270 | X25519 | OKP | 4 | X25519 for use w/ ECDH only | 3271 | | | | | 3272 | X448 | OKP | 5 | X448 for use w/ ECDH only | 3273 | | | | | 3274 | Ed25519 | OKP | 6 | Ed25519 for use w/ EdDSA only | 3275 | | | | | 3276 | Ed448 | OKP | 7 | Ed448 for use w/ EdDSA only | 3277 +---------+----------+-------+------------------------------------+ 3279 Table 22: EC Curves 3281 13.1.1. Double Coordinate Curves 3283 The traditional way of sending EC curves has been to send either both 3284 the x and y coordinates, or the x coordinate and a sign bit for the y 3285 coordinate. The latter encoding has not been recommended in the IETF 3286 due to potential IPR issues. However, for operations in constrained 3287 environments, the ability to shrink a message by not sending the y 3288 coordinate is potentially useful. 3290 For EC keys with both coordinates, the 'kty' member is set to 2 3291 (EC2). The key parameters defined in this section are summarized in 3292 Table 23. The members that are defined for this key type are: 3294 crv contains an identifier of the curve to be used with the key. 3295 The curves defined in this document for this key type can be found 3296 in Table 22. Other curves may be registered in the future and 3297 private curves can be used as well. 3299 x contains the x coordinate for the EC point. The integer is 3300 converted to an octet string as defined in [SEC1]. Leading zero 3301 octets MUST be preserved. 3303 y contains either the sign bit or the value of y coordinate for the 3304 EC point. When encoding the value y, the integer is converted to 3305 an octet string (as defined in [SEC1]) and encoded as a CBOR bstr. 3306 Leading zero octets MUST be preserved. The compressed point 3307 encoding is also supported. Compute the sign bit as laid out in 3308 the Elliptic-Curve-Point-to-Octet-String Conversion function of 3309 [SEC1]. If the sign bit is zero, then encode y as a CBOR false 3310 value, otherwise encode y as a CBOR true value. The encoding of 3311 the infinity point is not supported. 3313 d contains the private key. 3315 For public keys, it is REQUIRED that 'crv', 'x' and 'y' be present in 3316 the structure. For private keys, it is REQUIRED that 'crv' and 'd' 3317 be present in the structure. For private keys, it is RECOMMENDED 3318 that 'x' and 'y' also be present, but they can be recomputed from the 3319 required elements and omitting them saves on space. 3321 +------+-------+-------+---------+----------------------------------+ 3322 | name | key | label | type | description | 3323 | | type | | | | 3324 +------+-------+-------+---------+----------------------------------+ 3325 | crv | 2 | -1 | int / | EC Curve identifier - Taken from | 3326 | | | | tstr | the COSE Curves registry | 3327 | | | | | | 3328 | x | 2 | -2 | bstr | X Coordinate | 3329 | | | | | | 3330 | y | 2 | -3 | bstr / | Y Coordinate | 3331 | | | | bool | | 3332 | | | | | | 3333 | d | 2 | -4 | bstr | Private key | 3334 +------+-------+-------+---------+----------------------------------+ 3336 Table 23: EC Key Parameters 3338 13.2. Octet Key Pair 3340 A new key type is defined for Octet Key Pairs (OKP). Do not assume 3341 that keys using this type are elliptic curves. This key type could 3342 be used for other curve types (for example, mathematics based on 3343 hyper-elliptic surfaces). 3345 The key parameters defined in this section are summarized in 3346 Table 24. The members that are defined for this key type are: 3348 crv contains an identifier of the curve to be used with the key. 3349 The curves defined in this document for this key type can be found 3350 in Table 22. Other curves may be registered in the future and 3351 private curves can be used as well. 3353 x contains the x coordinate for the EC point. The octet string 3354 represents a little-endian encoding of x. 3356 d contains the private key. 3358 For public keys, it is REQUIRED that 'crv' and 'x' be present in the 3359 structure. For private keys, it is REQUIRED that 'crv' and 'd' be 3360 present in the structure. For private keys, it is RECOMMENDED that 3361 'x' also be present, but it can be recomputed from the required 3362 elements and omitting it saves on space. 3364 +------+------+-------+-------+-------------------------------------+ 3365 | name | key | label | type | description | 3366 | | type | | | | 3367 +------+------+-------+-------+-------------------------------------+ 3368 | crv | 1 | -1 | int / | EC Curve identifier - Taken from | 3369 | | | | tstr | the COSE Key Common Parameters | 3370 | | | | | registry | 3371 | | | | | | 3372 | x | 1 | -2 | bstr | X Coordinate | 3373 | | | | | | 3374 | d | 1 | -4 | bstr | Private key | 3375 +------+------+-------+-------+-------------------------------------+ 3377 Table 24: Octet Key Pair Parameters 3379 13.3. Symmetric Keys 3381 Occasionally it is required that a symmetric key be transported 3382 between entities. This key structure allows for that to happen. 3384 For symmetric keys, the 'kty' member is set to 3 (Symmetric). The 3385 member that is defined for this key type is: 3387 k contains the value of the key. 3389 This key structure does not have a form that contains only public 3390 members. As it is expected that this key structure is going to be 3391 transmitted, care must be taking that it is never transmitted 3392 accidentally or insecurely. For symmetric keys, it is REQUIRED that 3393 'k' be present in the structure. 3395 +------+----------+-------+------+-------------+ 3396 | name | key type | label | type | description | 3397 +------+----------+-------+------+-------------+ 3398 | k | 4 | -1 | bstr | Key Value | 3399 +------+----------+-------+------+-------------+ 3401 Table 25: Symmetric Key Parameters 3403 14. CBOR Encoder Restrictions 3405 There has been an attempt to limit the number of places where the 3406 document needs to impose restrictions on how the CBOR Encoder needs 3407 to work. We have managed to narrow it down to the following 3408 restrictions: 3410 o The restriction applies to the encoding the Sig_structure, the 3411 Enc_structure, and the MAC_structure. 3413 o The rules for Canonical CBOR (Section 3.9 of RFC 7049) MUST be 3414 used in these locations. The main rule that needs to be enforced 3415 is that all lengths in these structures MUST be encoded such that 3416 they are encoded using definite lengths and the minimum length 3417 encoding is used. 3419 o Applications MUST NOT generate messages with the same label used 3420 twice as a key in a single map. Applications MUST NOT parse and 3421 process messages with the same label used twice as a key in a 3422 single map. Applications can enforce the parse and process 3423 requirement by using parsers that will fail the parse step or by 3424 using parsers that will pass all keys to the application and the 3425 application can perform the check for duplicate keys. 3427 15. Application Profiling Considerations 3429 This document is designed to provide a set of security services, but 3430 not to provide implementation requirements for specific usage. The 3431 interoperability requirements are provided for how each of the 3432 individual services are used and how the algorithms are to be used 3433 for interoperability. The requirements about which algorithms and 3434 which services are needed are deferred to each application. 3436 An example of a profile can be found in 3437 [I-D.selander-ace-object-security] where two profiles are being 3438 developed. One is for carrying content by itself, and the other is 3439 for carrying content in combination with CoAP headers. 3441 It is intended that a profile of this document be created that 3442 defines the interoperability requirements for that specific 3443 application. This section provides a set of guidelines and topics 3444 that need to be considered when profiling this document. 3446 o Applications need to determine the set of messages defined in this 3447 document that they will be using. The set of messages corresponds 3448 fairly directly to the set of security services that are needed 3449 and to the security levels needed. 3451 o Applications may define new header parameters for a specific 3452 purpose. Applications will often times select specific header 3453 parameters to use or not to use. For example, an application 3454 would normally state a preference for using either the IV or the 3455 partial IV parameter. If the partial IV parameter is specified, 3456 then the application would also need to define how the fixed 3457 portion of the IV would be determined. 3459 o When applications use externally defined authenticated data, they 3460 need to define how that data is encoded. This document assumes 3461 that the data will be provided as a byte stream. More information 3462 can be found in Section 4.3. 3464 o Applications need to determine the set of security algorithms that 3465 are to be used. When selecting the algorithms to be used as the 3466 mandatory to implement set, consideration should be given to 3467 choosing different types of algorithms when two are chosen for a 3468 specific purpose. An example of this would be choosing HMAC- 3469 SHA512 and AES-CMAC as different MAC algorithms; the construction 3470 is vastly different between these two algorithms. This means that 3471 a weakening of one algorithm would be unlikely to lead to a 3472 weakening of the other algorithms. Of course, these algorithms do 3473 not provide the same level of security and thus may not be 3474 comparable for the desired security functionality. 3476 o Applications may need to provide some type of negotiation or 3477 discovery method if multiple algorithms or message structures are 3478 permitted. The method can be as simple as requiring 3479 preconfiguration of the set of algorithms to providing a discovery 3480 method built into the protocol. S/MIME provided a number of 3481 different ways to approach the problem that applications could 3482 follow: 3484 * Advertising in the message (S/MIME capabilities) [RFC5751]. 3486 * Advertising in the certificate (capabilities extension) 3487 [RFC4262]. 3489 * Minimum requirements for the S/MIME, which have been updated 3490 over time [RFC2633][RFC5751]. 3492 16. IANA Considerations 3494 16.1. CBOR Tag assignment 3496 It is requested that IANA assign the following tags from the "CBOR 3497 Tags" registry. It is requested that the tags for COSE_Sign1, 3498 COSE_Encrypt0, and COSE_Mac0 be assigned in the 1 to 23 value range 3499 (one byte long when encoded). It is requested that the tags for 3500 COSE_Sign, COSE_Encrypt and COSE_MAC be assigned in the 24 to 255 3501 value range (two bytes long when encoded). 3503 The tags to be assigned are in Table 1. 3505 16.2. COSE Header Parameters Registry 3507 It is requested that IANA create a new registry entitled "COSE Header 3508 Parameters". The registry should be created as Expert Review 3509 Required. Guidelines for the experts is provided Section 16.11. It 3510 should be noted that in additional to the expert review, some 3511 portions of the registry require a specification, potentially on 3512 standards track, be supplied as well. 3514 The columns of the registry are: 3516 name The name is present to make it easier to refer to and discuss 3517 the registration entry. The value is not used in the protocol. 3518 Names are to be unique in the table. 3520 label This is the value used for the label. The label can be either 3521 an integer or a string. Registration in the table is based on the 3522 value of the label requested. Integer values between 1 and 255 3523 and strings of length 1 are designated as Standards Track Document 3524 required. Integer values from 256 to 65535 and strings of length 3525 2 are designated as Specification Required. Integer values of 3526 greater than 65535 and strings of length greater than 2 are 3527 designated as expert review. Integer values in the range -1 to 3528 -65536 are delegated to the "COSE Header Algorithm Parameters" 3529 registry. Integer values less than -65536 are marked as private 3530 use. 3532 value This contains the CBOR type for the value portion of the 3533 label. 3535 value registry This contains a pointer to the registry used to 3536 contain values where the set is limited. 3538 description This contains a brief description of the header field. 3540 specification This contains a pointer to the specification defining 3541 the header field (where public). 3543 The initial contents of the registry can be found in Table 2 and 3544 Table 27. The specification column for all rows in that table should 3545 be this document. 3547 Additionally, the label of 0 is to be marked as 'Reserved'. 3549 16.3. COSE Header Algorithm Parameters Registry 3551 It is requested that IANA create a new registry entitled "COSE Header 3552 Algorithm Parameters". The registry is to be created as Expert 3553 Review Required. Expert review guidelines are provided in 3554 Section 16.11. 3556 The columns of the registry are: 3558 name The name is present to make it easier to refer to and discuss 3559 the registration entry. The value is not used in the protocol. 3561 algorithm The algorithm(s) that this registry entry is used for. 3562 This value is taken from the "COSE Algorithm Values" registry. 3563 Multiple algorithms can be specified in this entry. For the 3564 table, the algorithm, label pair MUST be unique. 3566 label This is the value used for the label. The label is an integer 3567 in the range of -1 to -65536. 3569 value This contains the CBOR type for the value portion of the 3570 label. 3572 description This contains a brief description of the header field. 3574 specification This contains a pointer to the specification defining 3575 the header field (where public). 3577 The initial contents of the registry can be found in Table 13, 3578 Table 14, and Table 19. The specification column for all rows in 3579 that table should be this document. 3581 16.4. COSE Algorithms Registry 3583 It is requested that IANA create a new registry entitled "COSE 3584 Algorithms Registry". The registry is to be created as Expert Review 3585 Required. Guidelines for the experts is provided Section 16.11. It 3586 should be noted that in additional to the expert review, some 3587 portions of the registry require a specification, potentially on 3588 standards track, be supplied as well. 3590 The columns of the registry are: 3592 value: The value to be used to identify this algorithm. Algorithm 3593 values MUST be unique. The value can be a positive integer, a 3594 negative integer or a string. Integer values between -256 and 255 3595 and strings of length 1 are designated as Standards Track Document 3596 required. Integer values from -65536 to 65535 and strings of 3597 length 2 are designated as Specification Required. Integer values 3598 of greater than 65535 and strings of length greater than 2 are 3599 designated as expert review. Integer values less than -65536 are 3600 marked as private use. 3602 description: A short description of the algorithm. 3604 specification: A document where the algorithm is defined (if 3605 publicly available). 3607 recommended: Does the IETF have a concensus recommendation to use 3608 the algorithm. The legal values are 'yes', 'no' and 'deprecated'. 3610 The initial contents of the registry can be found in Table 10, 3611 Table 9, Table 11, Table 5, Table 7, Table 8, Table 15, Table 16, 3612 Table 17, Table 6, Table 20 and Table 18. The specification column 3613 for all rows in the table should be this document. The recommneded 3614 column for all rows in the table are set to 'yes'. 3616 Additionally, the label of 0 is to be marked as 'Reserved'. 3618 NOTE: The assignment of algorithm identifiers in this document was 3619 done so that positive numbers were used for the first layer objects 3620 (COSE_Sign, COSE_Sign1, COSE_Encrypt, COSE_Encrypt0, COSE_Mac, and 3621 COSE_Mac0). Negative numbers were used for second layer objects 3622 (COSE_Signature and COSE_recipient). Expert reviewers should 3623 consider this practice, but are not expected to be restricted by this 3624 precedent. 3626 16.5. COSE Key Common Parameters Registry 3628 It is requested that IANA create a new registry entitled "COSE Key 3629 Common Parameters" registry. The registry is to be created as Expert 3630 Review Required. Guidelines for the experts is provided 3631 Section 16.11. It should be noted that in additional to the expert 3632 review, some portions of the registry require a specification, 3633 potentially on standards track, be supplied as well. 3635 The columns of the registry are: 3637 name This is a descriptive name that enables easier reference to the 3638 item. It is not used in the encoding. 3640 label The value to be used to identify this algorithm. Key map 3641 labels MUST be unique. The label can be a positive integer, a 3642 negative integer or a string. Integer values between 0 and 255 3643 and strings of length 1 are designated as Standards Track Document 3644 required. Integer values from 256 to 65535 and strings of length 3645 2 are designated as Specification Required. Integer values of 3646 greater than 65535 and strings of length greater than 2 are 3647 designated as expert review. Integer values in the range -1 to 3648 -65536 are used for key parameters specific to a single algorithm 3649 delegated to the "COSE Key Type Parameter Labels" registry. 3650 Integer values less than -65536 are marked as private use. 3652 CBOR Type This field contains the CBOR type for the field. 3654 registry This field denotes the registry that values come from, if 3655 one exists. 3657 description This field contains a brief description for the field. 3659 specification This contains a pointer to the public specification 3660 for the field if one exists 3662 This registry will be initially populated by the values in Table 3. 3663 The specification column for all of these entries will be this 3664 document. 3666 16.6. COSE Key Type Parameters Registry 3668 It is requested that IANA create a new registry "COSE Key Type 3669 Parameters". The registry is to be created as Expert Review 3670 Required. Expert review guidelines are provided in Section 16.11. 3672 The columns of the table are: 3674 key type This field contains a descriptive string of a key type. 3675 This should be a value that is in the COSE Key Common Parameters 3676 table and is placed in the 'kty' field of a COSE Key structure. 3678 name This is a descriptive name that enables easier reference to the 3679 item. It is not used in the encoding. 3681 label The label is to be unique for every value of key type. The 3682 range of values is from -256 to -1. Labels are expected to be 3683 reused for different keys. 3685 CBOR type This field contains the CBOR type for the field. 3687 description This field contains a brief description for the field. 3689 specification This contains a pointer to the public specification 3690 for the field if one exists. 3692 This registry will be initially populated by the values in Table 23, 3693 Table 24, and Table 25. The specification column for all of these 3694 entries will be this document. 3696 16.7. COSE Key Type Registry 3698 It is requested that IANA create a new registry "COSE Key Type 3699 Registry". The registry is to be created as Expert Review Required. 3700 Expert review guidelines are provided in Section 16.11. 3702 The columns of this table are: 3704 name This is a descriptive name that enables easier reference to the 3705 item. The name MUST be unique. It is not used in the encoding. 3707 value This is the value used to identify the curve. These values 3708 MUST be unique. The value can be a positive integer, a negative 3709 integer or a string. 3711 description This field contains a brief description of the curve. 3713 specification This contains a pointer to the public specification 3714 for the curve if one exists. 3716 This registry will be initially populated by the values in Table 21. 3717 The specification column for all of these entries will be this 3718 document. 3720 16.8. COSE Elliptic Curve Parameters Registry 3722 It is requested that IANA create a new registry "COSE Elliptic Curve 3723 Parameters". The registry is to be created as Expert Review 3724 Required. Guidelines for the experts is provided Section 16.11. It 3725 should be noted that in additional to the expert review, some 3726 portions of the registry require a specification, potentially on 3727 standards track, be supplied as well. 3729 The columns of the table are: 3731 name This is a descriptive name that enables easier reference to the 3732 item. It is not used in the encoding. 3734 value This is the value used to identify the curve. These values 3735 MUST be unique. The integer values from -256 to 255 are 3736 designated as Standards Track Document Required. The integer 3737 values from 256 to 65535 and -65536 to -257 are designated as 3738 Specification Required. Integer values over 65535 are designated 3739 as expert review. Integer values less than -65536 are marked as 3740 private use. 3742 key type This designates the key type(s) that can be used with this 3743 curve. 3745 description This field contains a brief description of the curve. 3747 specification This contains a pointer to the public specification 3748 for the curve if one exists. 3750 recommended: Does the IETF have a concensus recommendation to use 3751 the algorithm. The legal values are 'yes', 'no' and 'deprecated'. 3753 This registry will be initially populated by the values in Table 22. 3754 The specification column for all of these entries will be this 3755 document. The recommended column for all of the inital entries will 3756 be 'yes'. 3758 16.9. Media Type Registrations 3760 16.9.1. COSE Security Message 3762 This section registers the "application/cose" media type in the 3763 "Media Types" registry. These media types are used to indicate that 3764 the content is a COSE message. 3766 Type name: application 3768 Subtype name: cose 3770 Required parameters: N/A 3772 Optional parameters: cose-type 3774 Encoding considerations: binary 3775 Security considerations: See the Security Considerations section 3776 of RFC TBD. 3778 Interoperability considerations: N/A 3780 Published specification: RFC TBD 3782 Applications that use this media type: IoT applications sending 3783 security content over HTTP(S) transports. 3785 Fragment identifier considerations: N/A 3787 Additional information: 3789 * Magic number(s): N/A 3791 * File extension(s): cbor 3793 * Macintosh file type code(s): N/A 3795 Person & email address to contact for further information: 3796 iesg@ietf.org 3798 Intended usage: COMMON 3800 Restrictions on usage: N/A 3802 Author: Jim Schaad, ietf@augustcellars.com 3804 Change Controller: IESG 3806 Provisional registration? No 3808 16.9.2. COSE Key media type 3810 This section registers the "application/cose-key" and "application/ 3811 cose-key-set" media types in the "Media Types" registry. These media 3812 types are used to indicate, respectively, that content is a COSE_Key 3813 or COSE_KeySet object. 3815 The template for registering "application/cose-key" is: 3817 Type name: application 3819 Subtype name: cose-key 3821 Required parameters: N/A 3822 Optional parameters: N/A 3824 Encoding considerations: binary 3826 Security considerations: See the Security Considerations section 3827 of RFC TBD. 3829 Interoperability considerations: N/A 3831 Published specification: RFC TBD 3833 Applications that use this media type: Distribution of COSE based 3834 keys for IoT applications. 3836 Fragment identifier considerations: N/A 3838 Additional information: 3840 * Magic number(s): N/A 3842 * File extension(s): cbor 3844 * Macintosh file type code(s): N/A 3846 Person & email address to contact for further information: 3847 iesg@ietf.org 3849 Intended usage: COMMON 3851 Restrictions on usage: N/A 3853 Author: Jim Schaad, ietf@augustcellars.com 3855 Change Controller: IESG 3857 Provisional registration? No 3859 The template for registering "application/cose-key-set" is: 3861 Type name: application 3863 Subtype name: cose-key-set 3865 Required parameters: N/A 3867 Optional parameters: N/A 3869 Encoding considerations: binary 3870 Security considerations: See the Security Considerations section 3871 of RFC TBD. 3873 Interoperability considerations: N/A 3875 Published specification: RFC TBD 3877 Applications that use this media type: Distribution of COSE based 3878 keys for IoT applications. 3880 Fragment identifier considerations: N/A 3882 Additional information: 3884 * Magic number(s): N/A 3886 * File extension(s): cbor 3888 * Macintosh file type code(s): N/A 3890 Person & email address to contact for further information: 3891 iesg@ietf.org 3893 Intended usage: COMMON 3895 Restrictions on usage: N/A 3897 Author: Jim Schaad, ietf@augustcellars.com 3899 Change Controller: IESG 3901 Provisional registration? No 3903 16.10. CoAP Content-Format Registrations 3905 IANA is requested to add the following entries to the "CoAP Content- 3906 Format" registry. ID assignment in the 24-255 range is requested. 3908 +---------------------------------+----------+-------+--------------+ 3909 | Media Type | Encoding | ID | Reference | 3910 +---------------------------------+----------+-------+--------------+ 3911 | application/cose; cose-type | | TBD10 | [This | 3912 | ="cose-sign" | | | Document] | 3913 | | | | | 3914 | application/cose; cose-type | | TBD11 | [This | 3915 | ="cose-sign1" | | | Document] | 3916 | | | | | 3917 | application/cose; cose-type | | TBD12 | [This | 3918 | ="cose-encrypt" | | | Document] | 3919 | | | | | 3920 | application/cose; cose-type | | TBD13 | [This | 3921 | ="cose-encrypt0" | | | Document] | 3922 | | | | | 3923 | application/cose; cose-type | | TBD14 | [This | 3924 | ="cose-mac" | | | Document] | 3925 | | | | | 3926 | application/cose; cose-type | | TBD15 | [This | 3927 | ="cose-mac0" | | | Document] | 3928 | | | | | 3929 | application/cose-key | | TBD16 | [This | 3930 | | | | Document] | 3931 | | | | | 3932 | application/cose-key-set | | TBD17 | [This | 3933 | | | | Document | 3934 +---------------------------------+----------+-------+--------------+ 3936 Table 26 3938 16.11. Expert Review Instructions 3940 All of the IANA registries established in this document are defined 3941 as expert review. This section gives some general guidelines for 3942 what the experts should be looking for, but they are being designated 3943 as experts for a reason so they should be given substantial latitude. 3945 Expert reviewers should take into consideration the following points: 3947 o Point squatting should be discouraged. Reviewers are encouraged 3948 to get sufficient information for registration requests to ensure 3949 that the usage is not going to duplicate one that is already 3950 registered and that the point is likely to be used in deployments. 3951 The zones tagged as private use are intended for testing purposes 3952 and closed environments, code points in other ranges should not be 3953 assigned for testing. 3955 o Specifications are required for the standards track range of point 3956 assignment. Specifications should exist for specification 3957 required ranges, but early assignment before a specification is 3958 available is considered to be permissible. Specifications are 3959 needed for the first-come, first-serve range if they are expected 3960 to be used outside of closed environments in an interoperable way. 3961 When specifications are not provided, the description provided 3962 needs to have sufficient information to identify what the point is 3963 being used for. 3965 o Experts should take into account the expected usage of fields when 3966 approving point assignment. The fact that there is a range for 3967 standards track documents does not mean that a standards track 3968 document cannot have points assigned outside of that range. The 3969 length of the encoded value should be weighed against how many 3970 code points of that length are left, the size of device it will be 3971 used on, and the number of code points left that encode to that 3972 size. 3974 o When algorithms are registered, vanity registrations should be 3975 discouraged. One way to do this is to require registrations to 3976 provide additional documentation on security analysis of the 3977 algorithm. Another thing that should be considered is to request 3978 for an opinion on the algorithm from the Crypto Forum Research 3979 Group (CFRG). Algorithms that do not meet the security 3980 requirements of the community and the messages structures should 3981 not be registered. 3983 17. Implementation Status 3985 This section records the status of known implementations of the 3986 protocol defined by this specification at the time of posting of this 3987 Internet-Draft, and is based on a proposal described in [RFC7942]. 3988 The description of implementations in this section is intended to 3989 assist the IETF in its decision processes in progressing drafts to 3990 RFCs. Please note that the listing of any individual implementation 3991 here does not imply endorsement by the IETF. Furthermore, no effort 3992 has been spent to verify the information presented here that was 3993 supplied by IETF contributors. This is not intended as, and must not 3994 be construed to be, a catalog of available implementations or their 3995 features. Readers are advised to note that other implementations may 3996 exist. 3998 According to [RFC7942], "this will allow reviewers and working groups 3999 to assign due consideration to documents that have the benefit of 4000 running code, which may serve as evidence of valuable experimentation 4001 and feedback that have made the implemented protocols more mature. 4003 It is up to the individual working groups to use this information as 4004 they see fit". 4006 17.1. Author's Versions 4008 There are three different implementations that have been created by 4009 the author of the document both to create the examples that are 4010 included in the document and to validate the structures and 4011 methodology used in the design of COSE. 4013 Implementation Location: https://github.com/cose-wg 4015 Primary Maintainer: Jim Schaad 4017 Languages: There are three different languages that are currently 4018 supported: Java, C# and C. 4020 Cryptography: The Java and C# libraries use Bouncy Castle to 4021 provide the required cryptography. The C version uses OPENSSL 4022 Version 1.0 for the cryptography. 4024 Coverage: The libraries currently do not have full support for 4025 counter signatures of either variety. They do have support to 4026 allow for implicit algorithm support as they allow for the 4027 application to set attributes that are not to be sent in the 4028 message. 4030 Testing: All of the examples in the example library are generated 4031 by the C# library and then validated using the Java and C 4032 libraries. All three libraries have tests to allow for the 4033 creating of the same messages that are in the example library 4034 followed by validating them. These are not compared against the 4035 example library. The Java and C# libraries have unit testing 4036 included. Not all of the MUST statements in the document have 4037 been implemented as part of the libraries. One such statement is 4038 the requirement that unique labels be present. 4040 Licensing: Revised BSD License 4042 17.2. COSE Testing Library 4044 Implementation Location: https://github.com/cose-wg/Examples 4046 Primary Maintainer: Jim Schaad 4048 Description: A set of tests for the COSE library is provided as 4049 part of the implementation effort. Both success and fail tests 4050 have been provided. All of the examples in this document are part 4051 of this example set. 4053 Coverage: An attempt has been made to have test cases for every 4054 message type and algorithm in the document. Currently examples 4055 dealing with counter signatures, EdDSA, and ECDH with Curve24459 4056 and Goldilocks are missing. 4058 Licensing: Public Domain 4060 18. Security Considerations 4062 There are a number of security considerations that need to be taken 4063 into account by implementers of this specification. The security 4064 considerations that are specific to an individual algorithm are 4065 placed next to the description of the algorithm. While some 4066 considerations have been highlighted here, additional considerations 4067 may be found in the documents listed in the references. 4069 Implementations need to protect the private key material for any 4070 individuals. There are some cases in this document that need to be 4071 highlighted on this issue. 4073 o Using the same key for two different algorithms can leak 4074 information about the key. It is therefore recommended that keys 4075 be restricted to a single algorithm. 4077 o Use of 'direct' as a recipient algorithm combined with a second 4078 recipient algorithm, exposes the direct key to the second 4079 recipient. 4081 o Several of the algorithms in this document have limits on the 4082 number of times that a key can be used without leaking information 4083 about the key. 4085 The use of ECDH and direct plus KDF (with no key wrap) will not 4086 directly lead to the private key being leaked; the one way function 4087 of the KDF will prevent that. There is however, a different issue 4088 that needs to be addressed. Having two recipients requires that the 4089 CEK be shared between two recipients. The second recipient therefore 4090 has a CEK that was derived from material that can be used for the 4091 weak proof of origin. The second recipient could create a message 4092 using the same CEK and send it to the first recipient, the first 4093 recipient would, for either static-static ECDH or direct plus KDF, 4094 make an assumption that the CEK could be used for proof of origin 4095 even though it is from the wrong entity. If the key wrap step is 4096 added, then no proof of origin is implied and this is not an issue. 4098 Although it has been mentioned before, the use of a single key for 4099 multiple algorithms has been demonstrated in some cases to leak 4100 information about a key, provide for attackers to forge integrity 4101 tags, or gain information about encrypted content. Binding a key to 4102 a single algorithm prevents these problems. Key creators and key 4103 consumers are strongly encouraged not only to create new keys for 4104 each different algorithm, but to include that selection of algorithm 4105 in any distribution of key material and strictly enforce the matching 4106 of algorithms in the key structure to algorithms in the message 4107 structure. In addition to checking that algorithms are correct, the 4108 key form needs to be checked as well. Do not use an 'EC2' key where 4109 an 'OKP' key is expected. 4111 Before using a key for transmission, or before acting on information 4112 received, a trust decision on a key needs to be made. Is the data or 4113 action something that the entity associated with the key has a right 4114 to see or a right to request? A number of factors are associated 4115 with this trust decision. Some of the ones that are highlighted here 4116 are: 4118 o What are the permissions associated with the key owner? 4120 o Is the cryptographic algorithm acceptable in the current context? 4122 o Have the restrictions associated with the key, such as algorithm 4123 or freshness, been checked and are correct? 4125 o Is the request something that is reasonable, given the current 4126 state of the application? 4128 o Have any security considerations that are part of the message been 4129 enforced (as specified by the application or 'crit' parameter)? 4131 There are a large number of algorithms presented in this document 4132 that use nonce values. For all of the nonces defined in this 4133 document, there is some type of restriction on the nonce being a 4134 unique value either for a key or for some other conditions. In all 4135 of these cases, there is no known requirement on the nonce being both 4136 unique and unpredictable, under these circumstances it reasonable to 4137 use a counter for creation of the nonce. In cases where one wants 4138 the pattern of the nonce to be unpredictable as well as unique, one 4139 can use a key created for that purpose and encrypt the counter to 4140 produce the nonce value. 4142 One area that has been starting to get exposure is doing traffic 4143 analysis of encrypted messages based on the length of the message. 4144 This specification does not provide for a uniform method of providing 4145 padding as part of the message structure. An observer can 4146 distinguish between two different strings (for example, 'YES' and 4147 'NO') based on length for all of the content encryption algorithms 4148 that are defined in this document. This means that it is up to 4149 applications to document how content padding is to be done in order 4150 to prevent or discourage such analysis. (For example, the strings 4151 could be defined as 'YES' and 'NO '.) 4153 19. References 4155 19.1. Normative References 4157 [AES-GCM] Dworkin, M., "NIST Special Publication 800-38D: 4158 Recommendation for Block Cipher Modes of Operation: 4159 Galois/Counter Mode (GCM) and GMAC.", Nov 2007. 4161 [COAP.Formats] 4162 IANA, , "CoAP Content-Formats". 4164 [DSS] U.S. National Institute of Standards and Technology, 4165 "Digital Signature Standard (DSS)", July 2013. 4167 [I-D.irtf-cfrg-eddsa] 4168 Josefsson, S. and I. Liusvaara, "Edwards-curve Digital 4169 Signature Algorithm (EdDSA)", draft-irtf-cfrg-eddsa-08 4170 (work in progress), August 2016. 4172 [MAC] NiST, N., "FIPS PUB 113: Computer Data Authentication", 4173 May 1985. 4175 [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- 4176 Hashing for Message Authentication", RFC 2104, 4177 DOI 10.17487/RFC2104, February 1997, 4178 . 4180 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 4181 Requirement Levels", BCP 14, RFC 2119, 4182 DOI 10.17487/RFC2119, March 1997, 4183 . 4185 [RFC3394] Schaad, J. and R. Housley, "Advanced Encryption Standard 4186 (AES) Key Wrap Algorithm", RFC 3394, DOI 10.17487/RFC3394, 4187 September 2002, . 4189 [RFC3610] Whiting, D., Housley, R., and N. Ferguson, "Counter with 4190 CBC-MAC (CCM)", RFC 3610, DOI 10.17487/RFC3610, September 4191 2003, . 4193 [RFC5869] Krawczyk, H. and P. Eronen, "HMAC-based Extract-and-Expand 4194 Key Derivation Function (HKDF)", RFC 5869, 4195 DOI 10.17487/RFC5869, May 2010, 4196 . 4198 [RFC6090] McGrew, D., Igoe, K., and M. Salter, "Fundamental Elliptic 4199 Curve Cryptography Algorithms", RFC 6090, 4200 DOI 10.17487/RFC6090, February 2011, 4201 . 4203 [RFC6979] Pornin, T., "Deterministic Usage of the Digital Signature 4204 Algorithm (DSA) and Elliptic Curve Digital Signature 4205 Algorithm (ECDSA)", RFC 6979, DOI 10.17487/RFC6979, August 4206 2013, . 4208 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 4209 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 4210 October 2013, . 4212 [RFC7539] Nir, Y. and A. Langley, "ChaCha20 and Poly1305 for IETF 4213 Protocols", RFC 7539, DOI 10.17487/RFC7539, May 2015, 4214 . 4216 [RFC7748] Langley, A., Hamburg, M., and S. Turner, "Elliptic Curves 4217 for Security", RFC 7748, DOI 10.17487/RFC7748, January 4218 2016, . 4220 [SEC1] Standards for Efficient Cryptography Group, "SEC 1: 4221 Elliptic Curve Cryptography", May 2009. 4223 19.2. Informative References 4225 [I-D.greevenbosch-appsawg-cbor-cddl] 4226 Vigano, C. and H. Birkholz, "CBOR data definition language 4227 (CDDL): a notational convention to express CBOR data 4228 structures", draft-greevenbosch-appsawg-cbor-cddl-09 (work 4229 in progress), September 2016. 4231 [I-D.moriarty-pkcs1] 4232 Moriarty, K., Kaliski, B., Jonsson, J., and A. Rusch, 4233 "PKCS #1 Version 2.2: RSA Cryptography Specifications", 4234 draft-moriarty-pkcs1-03 (work in progress), September 4235 2016. 4237 [I-D.moriarty-pkcs5-v2dot1] 4238 Moriarty, K., Kaliski, B., and A. Rusch, "PKCS #5: 4239 Password-Based Cryptography Specification Version 2.1", 4240 draft-moriarty-pkcs5-v2dot1-04 (work in progress), 4241 September 2016. 4243 [I-D.selander-ace-object-security] 4244 Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 4245 "Object Security of CoAP (OSCOAP)", draft-selander-ace- 4246 object-security-05 (work in progress), July 2016. 4248 [PVSig] Brown, D. and D. Johnson, "Formal Security Proofs for a 4249 Signature Scheme with Partial Message Recover", February 4250 2000. 4252 [RFC2633] Ramsdell, B., Ed., "S/MIME Version 3 Message 4253 Specification", RFC 2633, DOI 10.17487/RFC2633, June 1999, 4254 . 4256 [RFC4231] Nystrom, M., "Identifiers and Test Vectors for HMAC-SHA- 4257 224, HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512", 4258 RFC 4231, DOI 10.17487/RFC4231, December 2005, 4259 . 4261 [RFC4262] Santesson, S., "X.509 Certificate Extension for Secure/ 4262 Multipurpose Internet Mail Extensions (S/MIME) 4263 Capabilities", RFC 4262, DOI 10.17487/RFC4262, December 4264 2005, . 4266 [RFC4493] Song, JH., Poovendran, R., Lee, J., and T. Iwata, "The 4267 AES-CMAC Algorithm", RFC 4493, DOI 10.17487/RFC4493, June 4268 2006, . 4270 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", 4271 FYI 36, RFC 4949, DOI 10.17487/RFC4949, August 2007, 4272 . 4274 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 4275 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 4276 . 4278 [RFC5480] Turner, S., Brown, D., Yiu, K., Housley, R., and T. Polk, 4279 "Elliptic Curve Cryptography Subject Public Key 4280 Information", RFC 5480, DOI 10.17487/RFC5480, March 2009, 4281 . 4283 [RFC5652] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, 4284 RFC 5652, DOI 10.17487/RFC5652, September 2009, 4285 . 4287 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 4288 Mail Extensions (S/MIME) Version 3.2 Message 4289 Specification", RFC 5751, DOI 10.17487/RFC5751, January 4290 2010, . 4292 [RFC5752] Turner, S. and J. Schaad, "Multiple Signatures in 4293 Cryptographic Message Syntax (CMS)", RFC 5752, 4294 DOI 10.17487/RFC5752, January 2010, 4295 . 4297 [RFC5990] Randall, J., Kaliski, B., Brainard, J., and S. Turner, 4298 "Use of the RSA-KEM Key Transport Algorithm in the 4299 Cryptographic Message Syntax (CMS)", RFC 5990, 4300 DOI 10.17487/RFC5990, September 2010, 4301 . 4303 [RFC6151] Turner, S. and L. Chen, "Updated Security Considerations 4304 for the MD5 Message-Digest and the HMAC-MD5 Algorithms", 4305 RFC 6151, DOI 10.17487/RFC6151, March 2011, 4306 . 4308 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 4309 Specifications and Registration Procedures", BCP 13, 4310 RFC 6838, DOI 10.17487/RFC6838, January 2013, 4311 . 4313 [RFC7159] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 4314 Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March 4315 2014, . 4317 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 4318 Application Protocol (CoAP)", RFC 7252, 4319 DOI 10.17487/RFC7252, June 2014, 4320 . 4322 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 4323 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 4324 2015, . 4326 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 4327 RFC 7516, DOI 10.17487/RFC7516, May 2015, 4328 . 4330 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 4331 DOI 10.17487/RFC7517, May 2015, 4332 . 4334 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 4335 DOI 10.17487/RFC7518, May 2015, 4336 . 4338 [RFC7942] Sheffer, Y. and A. Farrel, "Improving Awareness of Running 4339 Code: The Implementation Status Section", BCP 205, 4340 RFC 7942, DOI 10.17487/RFC7942, July 2016, 4341 . 4343 [SP800-56A] 4344 Barker, E., Chen, L., Roginsky, A., and M. Smid, "NIST 4345 Special Publication 800-56A: Recommendation for Pair-Wise 4346 Key Establishment Schemes Using Discrete Logarithm 4347 Cryptography", May 2013. 4349 [W3C.WebCrypto] 4350 Watson, M., "Web Cryptography API", July 2016. 4352 Appendix A. Making Mandatory Algorithm Header Optional 4354 There has been a portion of the working group who have expressed a 4355 strong desire to relax the rule that the algorithm identifier be 4356 required to appear in each level of a COSE object. There are two 4357 basic reasons that have been advanced to support this position. 4358 First, the resulting message will be smaller if the algorithm 4359 identifier is omitted from the most common messages in a CoAP 4360 environment. Second, there is a potential bug that will arise if 4361 full checking is not done correctly between the different places that 4362 an algorithm identifier could be placed (the message itself, an 4363 application statement, the key structure that the sender possesses 4364 and the key structure the recipient possesses). 4366 This appendix lays out how such a change can be made and the details 4367 that an application needs to specify in order to use this option. 4368 Two different sets of details are specified: Those needed to omit an 4369 algorithm identifier and those needed to use a variant on the counter 4370 signature attribute that contains no attributes about itself. 4372 A.1. Algorithm Identification 4374 In this section are laid out three sets of recommendations. The 4375 first set of recommendations apply to having an implicit algorithm 4376 identified for a single layer of a COSE object. The second set of 4377 recommendations apply to having multiple implicit algorithms 4378 identified for multiple layers of a COSE object. The third set of 4379 recommendations apply to having implicit algorithms for multiple COSE 4380 object constructs. 4382 RFC 2119 language is deliberately not used here. This specification 4383 can provide recommendations, but it cannot enforce them. 4385 This set of recommendations applies to the case where an application 4386 is distributing a fixed algorithm along with the key information for 4387 use in a single COSE object. This normally applies to the smallest 4388 of the COSE objects, specifically COSE_Sign1, COSE_Mac0, and 4389 COSE_Encrypt0, but could apply to the other structures as well. 4391 The following items should be taken into account: 4393 o Applications need to list the set of COSE structures that implicit 4394 algorithms are to be used in. Applications need to require that 4395 the receipt of an explicit algorithm identifier in one of these 4396 structures will lead to the message being rejected. This 4397 requirement is stated so that there will never be a case where 4398 there is any ambiguity about the question of which algorithm 4399 should be used, the implicit or the explicit one. This applies 4400 even if the transported algorithm identifier is a protected 4401 attribute. This applies even if the transported algorithm is the 4402 same as the implicit algorithm. 4404 o Applications need to define the set of information that is to be 4405 considered to be part of a context when omitting algorithm 4406 identifiers. At a minimum, this would be the key identifier (if 4407 needed), the key, the algorithm, and the COSE structure it is used 4408 with. Applications should restrict the use of a single key to a 4409 single algorithm. As noted for some of the algorithms in this 4410 document, the use of the same key in different related algorithms 4411 can lead to leakage of information about the key, leakage about 4412 the data or the ability to perform forgeries. 4414 o In many cases, applications that make the algorithm identifier 4415 implicit will also want to make the context identifier implicit 4416 for the same reason. That is, omitting the context identifier 4417 will decrease the message size (potentially significantly 4418 depending on the length of the identifier). Applications that do 4419 this will need to describe the circumstances where the context 4420 identifier is to be omitted and how the context identifier is to 4421 be inferred in these cases. (Exhaustive search over all of the 4422 keys would normally not be considered to be acceptable.) An 4423 example of how this can be done is to tie the context to a 4424 transaction identifier. Both would be sent on the original 4425 message, but only the transaction identifier would need to be sent 4426 after that point as the context is tied into the transaction 4427 identifier. Another way would be to associate a context with a 4428 network address. All messages coming from a single network 4429 address can be assumed to be associated with a specific context. 4430 (In this case the address would normally be distributed as part of 4431 the context.) 4433 o Applications cannot rely on key identifiers being unique unless 4434 they take significant efforts to ensure that they are computed in 4435 such a way as to create this guarantee. Even when an application 4436 does this, the uniqueness might be violated if the application is 4437 run in different contexts (i.e., with a different context 4438 provider) or if the system combines the security contexts from 4439 different applications together into a single store. 4441 o Applications should continue the practice of protecting the 4442 algorithm identifier. Since this is not done by placing it in the 4443 protected attributes field, applications should define an 4444 application specific external data structure that includes this 4445 value. This external data field can be used as such for content 4446 encryption, MAC, and signature algorithms. It can be used in the 4447 SuppPrivInfo field for those algorithms which use a KDF function 4448 to derive a key value. Applications may also want to protect 4449 other information that is part of the context structure as well. 4450 It should be noted that those fields, such as the key or a base 4451 IV, are protected by virtue of being used in the cryptographic 4452 computation and do not need to be included in the external data 4453 field. 4455 The second case is having multiple implicit algorithm identifiers 4456 specified for a multiple layer COSE object. An example of how this 4457 would work is the encryption context that an application specifies 4458 contains a content encryption algorithm, a key wrap algorithm, a key 4459 identifier, and a shared secret. The sender omits sending the 4460 algorithm identifier for both the content layer and the recipient 4461 layer leaving only the key identifier. The receiver then uses the 4462 key identifier to get the implicit algorithm identifiers. 4464 The following additional items need to be taken into consideration: 4466 o Applications that want to support this will need to define a 4467 structure that allows for, and clearly identifies, both the COSE 4468 structure to be used with a given key and the structure and 4469 algorithm to be used for the secondary layer. The key for the 4470 secondary layer is computed per normal from the recipient layer. 4472 The third case is having multiple implicit algorithm identifiers, but 4473 targeted at potentially unrelated layers or different COSE objects. 4475 There are a number of different scenarios where this might be 4476 applicable. Some of these scenarios are: 4478 o Two contexts are distributed as a pair. Each of the contexts is 4479 for use with a COSE_Encrypt message. Each context will consist of 4480 distinct secret keys and IVs and potentially even different 4481 algorithms. One context is for sending messages from party A to 4482 party B, the second context is for sending messages from party B 4483 to party A. This means that there is no chance for a reflection 4484 attack to occur as each party uses different secret keys to send 4485 its messages, a message that is reflected back to it would fail to 4486 decrypt. 4488 o Two contexts are distributed as a pair. The first context is used 4489 for encryption of the message; the second context is used to place 4490 a counter signature on the message. The intention is that the 4491 second context can be distributed to other entities independently 4492 of the first context. This allows these entities to validate that 4493 the message came from an individual without being able to decrypt 4494 the message and see the content. 4496 o Two contexts are distributed as a pair. The first context 4497 contains a key for dealing with MACed messages, the second context 4498 contains a key for dealing with encrypted messages. This allows 4499 for a unified distribution of keys to participants for different 4500 types of messages that have different keys, but where the keys may 4501 be used in coordinated manner. 4503 For these cases, the following additional items need to be 4504 considered: 4506 o Applications need to ensure that the multiple contexts stay 4507 associated. If one of the contexts is invalidated for any reason, 4508 all of the contexts associated with it should also be invalidated. 4510 A.2. Counter Signature Without Headers 4512 There is a group of people who want to have a counter signature 4513 parameter that is directly tied to the value being signed and thus 4514 the authenticated and unauthenticated buckets can be removed from the 4515 message being sent. The focus on this is an even smaller size, as 4516 all of the information on the process of creating the counter 4517 signature is implicit rather than being explicitly carried in the 4518 message. This includes not only the algorithm identifier as 4519 presented above, but also items such as the key identification is 4520 always external to the signature structure. This means that the 4521 entities that are doing the validation of the counter signature are 4522 required to infer which key is to be used from context rather than 4523 being explicit. One way of doing this would be to presume that all 4524 data coming from a specific port (or to a specific URL) is to be 4525 validated by a specific key. (Note that this does not require that 4526 the key identifier be part of the value signed as it does not serve a 4527 cryptographic purpose. If the key validates the counter signature, 4528 then it should be presumed that the entity associated with that key 4529 produced the signature.) 4531 When computing the signature for the bare counter signature header, 4532 the same Sig_structure defined in Section 4.4 is used. The 4533 sign_protected field is omitted, as there is no protected header 4534 field in in this counter signature header. The value of 4535 "CounterSignature0" is placed in the context field of the 4536 Sig_stucture. 4538 +-------------------+-------+-------+-------+-----------------------+ 4539 | name | label | value | value | description | 4540 | | | type | | | 4541 +-------------------+-------+-------+-------+-----------------------+ 4542 | CounterSignature0 | 9 | bstr | | Counter signature | 4543 | | | | | with implied signer | 4544 | | | | | and headers | 4545 +-------------------+-------+-------+-------+-----------------------+ 4547 Table 27 4549 Appendix B. Two Layers of Recipient Information 4551 All of the currently defined recipient algorithms classes only use 4552 two layers of the COSE_Encrypt structure. The first layer is the 4553 message content and the second layer is the content key encryption. 4554 However, if one uses a recipient algorithm such as RSA-KEM (see 4555 Appendix A of RSA-KEM [RFC5990]), then it makes sense to have three 4556 layers of the COSE_Encrypt structure. 4558 These layers would be: 4560 o Layer 0: The content encryption layer. This layer contains the 4561 payload of the message. 4563 o Layer 1: The encryption of the CEK by a KEK. 4565 o Layer 2: The encryption of a long random secret using an RSA key 4566 and a key derivation function to convert that secret into the KEK. 4568 This is an example of what a triple layer message would look like. 4569 The message has the following layers: 4571 o Layer 0: Has a content encrypted with AES-GCM using a 128-bit key. 4573 o Layer 1: Uses the AES Key wrap algorithm with a 128-bit key. 4575 o Layer 2: Uses ECDH Ephemeral-Static direct to generate the layer 1 4576 key. 4578 In effect, this example is a decomposed version of using the ECDH- 4579 ES+A128KW algorithm. 4581 Size of binary file is 184 bytes 4582 992( 4583 [ 4584 / protected / h'a10101' / { 4585 \ alg \ 1:1 \ AES-GCM 128 \ 4586 } / , 4587 / unprotected / { 4588 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 4589 }, 4590 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e2852948658f0 4591 811139868826e89218a75715b', 4592 / recipients / [ 4593 [ 4594 / protected / h'', 4595 / unprotected / { 4596 / alg / 1:-3 / A128KW / 4597 }, 4598 / ciphertext / h'dbd43c4e9d719c27c6275c67d628d493f090593db82 4599 18f11', 4600 / recipients / [ 4601 [ 4602 / protected / h'a1013818' / { 4603 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 4604 } / , 4605 / unprotected / { 4606 / ephemeral / -1:{ 4607 / kty / 1:2, 4608 / crv / -1:1, 4609 / x / -2:h'b2add44368ea6d641f9ca9af308b4079aeb519f11 4610 e9b8a55a600b21233e86e68', 4611 / y / -3:false 4612 }, 4613 / kid / 4:'meriadoc.brandybuck@buckland.example' 4614 }, 4615 / ciphertext / h'' 4616 ] 4617 ] 4618 ] 4619 ] 4620 ] 4621 ) 4623 Appendix C. Examples 4625 This appendix includes a set of examples that show the different 4626 features and message types that have been defined in this document. 4627 To make the examples easier to read, they are presented using the 4628 extended CBOR diagnostic notation (defined in 4629 [I-D.greevenbosch-appsawg-cbor-cddl]) rather than as a binary dump. 4631 A GitHub project has been created at https://github.com/cose-wg/ 4632 Examples that contains not only the examples presented in this 4633 document, but a more complete set of testing examples as well. Each 4634 example is found in a JSON file that contains the inputs used to 4635 create the example, some of the intermediate values that can be used 4636 in debugging the example and the output of the example presented in 4637 both a hex and a CBOR diagnostic notation format. Some of the 4638 examples at the site are designed failure testing cases; these are 4639 clearly marked as such in the JSON file. If errors in the examples 4640 in this document are found, the examples on github will be updated 4641 and a note to that effect will be placed in the JSON file. 4643 As noted, the examples are presented using the CBOR's diagnostic 4644 notation. A Ruby based tool exists that can convert between the 4645 diagnostic notation and binary. This tool can be installed with the 4646 command line: 4648 gem install cbor-diag 4650 The diagnostic notation can be converted into binary files using the 4651 following command line: 4653 diag2cbor.rb < inputfile > outputfile 4655 The examples can be extracted from the XML version of this document 4656 via an XPath expression as all of the artwork is tagged with the 4657 attribute type='CBORdiag'. (Depending on the XPath evaluator one is 4658 using, it may be necessary to deal with > as an entity.) 4660 //artwork[@type='CDDL']/text() 4662 C.1. Examples of Signed Message 4664 C.1.1. Single Signature 4666 This example uses the following: 4668 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 4670 Size of binary file is 104 bytes 4671 991( 4672 [ 4673 / protected / h'', 4674 / unprotected / {}, 4675 / payload / 'This is the content.', 4676 / signatures / [ 4677 [ 4678 / protected / h'a10126' / { 4679 \ alg \ 1:-7 \ ECDSA 256 \ 4680 } / , 4681 / unprotected / { 4682 / kid / 4:'11' 4683 }, 4684 / signature / h'eae868ecc176883766c5dc5ba5b8dca25dab3c2e56a5 4685 51ce5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64327 4686 be470355c9657ce0' 4687 ] 4688 ] 4689 ] 4690 ) 4692 C.1.2. Multiple Signers 4694 This example uses the following: 4696 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 4698 o Signature Algorithm: ECDSA w/ SHA-512, Curve P-521 4700 Size of binary file is 278 bytes 4701 991( 4702 [ 4703 / protected / h'', 4704 / unprotected / {}, 4705 / payload / 'This is the content.', 4706 / signatures / [ 4707 [ 4708 / protected / h'a10126' / { 4709 \ alg \ 1:-7 \ ECDSA 256 \ 4710 } / , 4711 / unprotected / { 4712 / kid / 4:'11' 4713 }, 4714 / signature / h'0dc1c5e62719d8f3cce1468b7c881eee6a8088b46bf8 4715 36ae956dd38fe93199199951a6a5e02a24aed5edde3509748366b1c539aaef7dea34 4716 f2cd618fe19fe55d' 4717 ], 4718 [ 4719 / protected / h'a1013823' / { 4720 \ alg \ 1:-36 4721 } / , 4722 / unprotected / { 4723 / kid / 4:'bilbo.baggins@hobbiton.example' 4724 }, 4725 / signature / h'012ce5b1dfe8b5aa6eaa09a54c58a84ad0900e4fdf27 4726 59ec22d1c861cccd75c7e1c4025a2da35e512fc2874d6ac8fd862d09ad07ed2deac2 4727 97b897561e04a8d42476017c11a4a34e26c570c9eff22c1dc84d56cdf6e03ed34bc9 4728 e934c5fdf676c7948d79e97dfe161730217c57748aadb364a0207cee811e9dde65ae 4729 37942e8a8348cc91' 4730 ] 4731 ] 4732 ] 4733 ) 4735 C.1.3. Counter Signature 4737 This example uses the following: 4739 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 4741 o The same parameters are used for both the signature and the 4742 counter signature. 4744 Size of binary file is 181 bytes 4745 991( 4746 [ 4747 / protected / h'', 4748 / unprotected / { 4749 / countersign / 7:[ 4750 / protected / h'a10126' / { 4751 \ alg \ 1:-7 \ ECDSA 256 \ 4752 } / , 4753 / unprotected / { 4754 / kid / 4:'11' 4755 }, 4756 / signature / h'c9d3402485aa585cee3efc69b14496c0b00714584b26 4757 0f8e05764b7dbc70ae2b23b89812f5895b805f07a792f7ce77ef6d63875dc37d6a78 4758 ef4d175da45c9a51' 4759 ] 4760 }, 4761 / payload / 'This is the content.', 4762 / signatures / [ 4763 [ 4764 / protected / h'a10126' / { 4765 \ alg \ 1:-7 \ ECDSA 256 \ 4766 } / , 4767 / unprotected / { 4768 / kid / 4:'11' 4769 }, 4770 / signature / h'eae868ecc176883766c5dc5ba5b8dca25dab3c2e56a5 4771 51ce5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64327 4772 be470355c9657ce0' 4773 ] 4774 ] 4775 ] 4776 ) 4778 C.1.4. Signature w/ Criticality 4780 This example uses the following: 4782 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 4784 o There is a criticality marker on the "reserved" header parameter 4786 Size of binary file is 126 bytes 4787 991( 4788 [ 4789 / protected / h'a2687265736572766564f40281687265736572766564' / 4790 { 4791 "reserved":false, 4792 \ crit \ 2:[ 4793 "reserved" 4794 ] 4795 } / , 4796 / unprotected / {}, 4797 / payload / 'This is the content.', 4798 / signatures / [ 4799 [ 4800 / protected / h'a10126' / { 4801 \ alg \ 1:-7 \ ECDSA 256 \ 4802 } / , 4803 / unprotected / { 4804 / kid / 4:'11' 4805 }, 4806 / signature / h'eae868ecc176883766c5dc5ba5b8dca25dab3c2e56a5 4807 51ce5705b793914348e1ff259ead2c38d8a7d8a9c87c2ce534d762dab059773115a6 4808 176fa780e85b6b25' 4809 ] 4810 ] 4811 ] 4812 ) 4814 C.2. Single Signer Examples 4816 C.2.1. Single ECDSA signature 4818 This example uses the following: 4820 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 4822 Size of binary file is 100 bytes 4823 997( 4824 [ 4825 / protected / h'a10126' / { 4826 \ alg \ 1:-7 \ ECDSA 256 \ 4827 } / , 4828 / unprotected / { 4829 / kid / 4:'11' 4830 }, 4831 / payload / 'This is the content.', 4832 / signature / h'eae868ecc176883766c5dc5ba5b8dca25dab3c2e56a551ce 4833 5705b793914348e19f43d6c6ba654472da301b645b293c9ba939295b97c4bdb84778 4834 2bff384c5794' 4835 ] 4836 ) 4838 C.3. Examples of Enveloped Messages 4840 C.3.1. Direct ECDH 4842 This example uses the following: 4844 o CEK: AES-GCM w/ 128-bit key 4846 o Recipient class: ECDH Ephemeral-Static, Curve P-256 4848 Size of binary file is 152 bytes 4849 992( 4850 [ 4851 / protected / h'a10101' / { 4852 \ alg \ 1:1 \ AES-GCM 128 \ 4853 } / , 4854 / unprotected / { 4855 / iv / 5:h'c9cf4df2fe6c632bf7886413' 4856 }, 4857 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 4858 c52a357da7a644b8070a151b0', 4859 / recipients / [ 4860 [ 4861 / protected / h'a1013818' / { 4862 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 4863 } / , 4864 / unprotected / { 4865 / ephemeral / -1:{ 4866 / kty / 1:2, 4867 / crv / -1:1, 4868 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 4869 bf054e1c7b4d91d6280', 4870 / y / -3:true 4871 }, 4872 / kid / 4:'meriadoc.brandybuck@buckland.example' 4873 }, 4874 / ciphertext / h'' 4875 ] 4876 ] 4877 ] 4878 ) 4880 C.3.2. Direct plus Key Derivation 4882 This example uses the following: 4884 o CEK: AES-CCM w/128-bit key, truncate the tag to 64 bits 4886 o Recipient class: Use HKDF on a shared secret with the following 4887 implicit fields as part of the context. 4889 * salt: "aabbccddeeffgghh" 4891 * APU identity: "lighting-client" 4893 * APV identity: "lighting-server" 4895 * Supplementary Public Other: "Encryption Example 02" 4897 Size of binary file is 92 bytes 4899 992( 4900 [ 4901 / protected / h'a1010a' / { 4902 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 4903 } / , 4904 / unprotected / { 4905 / iv / 5:h'89f52f65a1c580933b5261a76c' 4906 }, 4907 / ciphertext / h'753548a19b1307084ca7b2056924ed95f2e3b17006dfe93 4908 1b687b847', 4909 / recipients / [ 4910 [ 4911 / protected / h'a10129' / { 4912 \ alg \ 1:-10 4913 } / , 4914 / unprotected / { 4915 / salt / -20:'aabbccddeeffgghh', 4916 / kid / 4:'our-secret' 4917 }, 4918 / ciphertext / h'' 4919 ] 4920 ] 4921 ] 4922 ) 4924 C.3.3. Counter Signature on Encrypted Content 4926 This example uses the following: 4928 o CEK: AES-GCM w/ 128-bit key 4930 o Recipient class: ECDH Ephemeral-Static, Curve P-256 4932 Size of binary file is 327 bytes 4933 992( 4934 [ 4935 / protected / h'a10101' / { 4936 \ alg \ 1:1 \ AES-GCM 128 \ 4937 } / , 4938 / unprotected / { 4939 / iv / 5:h'c9cf4df2fe6c632bf7886413', 4940 / countersign / 7:[ 4941 / protected / h'a1013823' / { 4942 \ alg \ 1:-36 4943 } / , 4944 / unprotected / { 4945 / kid / 4:'bilbo.baggins@hobbiton.example' 4946 }, 4947 / signature / h'00aa98cbfd382610a375d046a275f30266e8d0faacb9 4948 069fde06e37825ae7825419c474f416ded0c8e3e7b55bff68f2a704135bdf99186f6 4949 6659461c8cf929cc7fb300f5e2b33c3b433655042ff719804ff73b0be3e988ecebc0 4950 c70ef6616996809c6eb59a918dbe0a5edb0d15137ece0aba2a0b0f68ad2631cb62f2 4951 ea4d7099804218b0' 4952 ] 4953 }, 4954 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 4955 c52a357da7a644b8070a151b0', 4956 / recipients / [ 4957 [ 4958 / protected / h'a1013818' / { 4959 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 4960 } / , 4961 / unprotected / { 4962 / ephemeral / -1:{ 4963 / kty / 1:2, 4964 / crv / -1:1, 4965 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 4966 bf054e1c7b4d91d6280', 4967 / y / -3:true 4968 }, 4969 / kid / 4:'meriadoc.brandybuck@buckland.example' 4970 }, 4971 / ciphertext / h'' 4972 ] 4973 ] 4974 ] 4975 ) 4977 C.3.4. Encrypted Content with External Data 4979 This example uses the following: 4981 o CEK: AES-GCM w/ 128-bit key 4983 o Recipient class: ECDH static-Static, Curve P-256 with AES Key Wrap 4985 o Externally Supplied AAD: h'0011bbcc22dd44ee55ff660077' 4987 Size of binary file is 174 bytes 4989 992( 4990 [ 4991 / protected / h'a10101' / { 4992 \ alg \ 1:1 \ AES-GCM 128 \ 4993 } / , 4994 / unprotected / { 4995 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 4996 }, 4997 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e28529d8f5335 4998 e5f0165eee976b4a5f6c6f09d', 4999 / recipients / [ 5000 [ 5001 / protected / h'a101381f' / { 5002 \ alg \ 1:-32 \ ECHD-SS+A128KW \ 5003 } / , 5004 / unprotected / { 5005 / static kid / -3:'peregrin.took@tuckborough.example', 5006 / kid / 4:'meriadoc.brandybuck@buckland.example', 5007 / U nonce / -22:h'0101' 5008 }, 5009 / ciphertext / h'41e0d76f579dbd0d936a662d54d8582037de2e366fd 5010 e1c62' 5011 ] 5012 ] 5013 ] 5014 ) 5016 C.4. Examples of Encrypted Messages 5018 C.4.1. Simple Encrypted Message 5020 This example uses the following: 5022 o CEK: AES-CCM w/ 128-bit key and a 64-bit tag 5024 Size of binary file is 54 bytes 5025 993( 5026 [ 5027 / protected / h'a1010a' / { 5028 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 5029 } / , 5030 / unprotected / { 5031 / iv / 5:h'89f52f65a1c580933b5261a78c' 5032 }, 5033 / ciphertext / h'5974e1b99a3a4cc09a659aa2e9e7fff161d38ce7edd5617 5034 388e77baf' 5035 ] 5036 ) 5038 C.4.2. Encrypted Message w/ a Partial IV 5040 This example uses the following: 5042 o CEK: AES-CCM w/ 128-bit key and a 64-bit tag 5044 o Prefix for IV is 89F52F65A1C580933B52 5046 Size of binary file is 43 bytes 5048 993( 5049 [ 5050 / protected / h'a1010a' / { 5051 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 5052 } / , 5053 / unprotected / { 5054 / partial iv / 6:h'61a7' 5055 }, 5056 / ciphertext / h'252a8911d465c125b6764739700f0141ed09192da5c69e5 5057 33abf852b' 5058 ] 5059 ) 5061 C.5. Examples of MACed messages 5063 C.5.1. Shared Secret Direct MAC 5065 This example uses the following: 5067 o MAC: AES-CMAC, 256-bit key, truncated to 64 bits 5069 o Recipient class: direct shared secret 5071 Size of binary file is 58 bytes 5072 994( 5073 [ 5074 / protected / h'a1010f' / { 5075 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 5076 } / , 5077 / unprotected / {}, 5078 / payload / 'This is the content.', 5079 / tag / h'9e1226ba1f81b848', 5080 / recipients / [ 5081 [ 5082 / protected / h'', 5083 / unprotected / { 5084 / alg / 1:-6 / direct /, 5085 / kid / 4:'our-secret' 5086 }, 5087 / ciphertext / h'' 5088 ] 5089 ] 5090 ] 5091 ) 5093 C.5.2. ECDH Direct MAC 5095 This example uses the following: 5097 o MAC: HMAC w/SHA-256, 256-bit key 5099 o Recipient class: ECDH key agreement, two static keys, HKDF w/ 5100 context structure 5102 Size of binary file is 215 bytes 5103 994( 5104 [ 5105 / protected / h'a10105' / { 5106 \ alg \ 1:5 \ HMAC 256//256 \ 5107 } / , 5108 / unprotected / {}, 5109 / payload / 'This is the content.', 5110 / tag / h'81a03448acd3d305376eaa11fb3fe416a955be2cbe7ec96f012c99 5111 4bc3f16a41', 5112 / recipients / [ 5113 [ 5114 / protected / h'a101381a' / { 5115 \ alg \ 1:-27 \ ECDH-SS + HKDF-256 \ 5116 } / , 5117 / unprotected / { 5118 / static kid / -3:'peregrin.took@tuckborough.example', 5119 / kid / 4:'meriadoc.brandybuck@buckland.example', 5120 / U nonce / -22:h'4d8553e7e74f3c6a3a9dd3ef286a8195cbf8a23d 5121 19558ccfec7d34b824f42d92bd06bd2c7f0271f0214e141fb779ae2856abf585a583 5122 68b017e7f2a9e5ce4db5' 5123 }, 5124 / ciphertext / h'' 5125 ] 5126 ] 5127 ] 5128 ) 5130 C.5.3. Wrapped MAC 5132 This example uses the following: 5134 o MAC: AES-MAC, 128-bit key, truncated to 64 bits 5136 o Recipient class: AES keywrap w/ a pre-shared 256-bit key 5138 Size of binary file is 110 bytes 5139 994( 5140 [ 5141 / protected / h'a1010e' / { 5142 \ alg \ 1:14 \ AES-CBC-MAC-128//64 \ 5143 } / , 5144 / unprotected / {}, 5145 / payload / 'This is the content.', 5146 / tag / h'36f5afaf0bab5d43', 5147 / recipients / [ 5148 [ 5149 / protected / h'', 5150 / unprotected / { 5151 / alg / 1:-5 / A256KW /, 5152 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 5153 }, 5154 / ciphertext / h'711ab0dc2fc4585dce27effa6781c8093eba906f227 5155 b6eb0' 5156 ] 5157 ] 5158 ] 5159 ) 5161 C.5.4. Multi-recipient MACed message 5163 This example uses the following: 5165 o MAC: HMAC w/ SHA-256, 128-bit key 5167 o Recipient class: Uses three different methods 5169 1. ECDH Ephemeral-Static, Curve P-521, AES-Key Wrap w/ 128-bit 5170 key 5172 2. AES-Key Wrap w/ 256-bit key 5174 Size of binary file is 310 bytes 5175 994( 5176 [ 5177 / protected / h'a10105' / { 5178 \ alg \ 1:5 \ HMAC 256//256 \ 5179 } / , 5180 / unprotected / {}, 5181 / payload / 'This is the content.', 5182 / tag / h'bf48235e809b5c42e995f2b7d5fa13620e7ed834e337f6aa43df16 5183 1e49e9323e', 5184 / recipients / [ 5185 [ 5186 / protected / h'a101381c' / { 5187 \ alg \ 1:-29 \ ECHD-ES+A128KW \ 5188 } / , 5189 / unprotected / { 5190 / ephemeral / -1:{ 5191 / kty / 1:2, 5192 / crv / -1:3, 5193 / x / -2:h'0043b12669acac3fd27898ffba0bcd2e6c366d53bc4db 5194 71f909a759304acfb5e18cdc7ba0b13ff8c7636271a6924b1ac63c02688075b55ef2 5195 d613574e7dc242f79c3', 5196 / y / -3:true 5197 }, 5198 / kid / 4:'bilbo.baggins@hobbiton.example' 5199 }, 5200 / ciphertext / h'339bc4f79984cdc6b3e6ce5f315a4c7d2b0ac466fce 5201 a69e8c07dfbca5bb1f661bc5f8e0df9e3eff5' 5202 ], 5203 [ 5204 / protected / h'', 5205 / unprotected / { 5206 / alg / 1:-5 / A256KW /, 5207 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 5208 }, 5209 / ciphertext / h'0b2c7cfce04e98276342d6476a7723c090dfdd15f9a 5210 518e7736549e998370695e6d6a83b4ae507bb' 5211 ] 5212 ] 5213 ] 5214 ) 5216 C.6. Examples of MAC0 messages 5218 C.6.1. Shared Secret Direct MAC 5220 This example uses the following: 5222 o MAC: AES-CMAC, 256-bit key, truncated to 64 bits 5223 o Recipient class: direct shared secret 5225 Size of binary file is 39 bytes 5227 996( 5228 [ 5229 / protected / h'a1010f' / { 5230 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 5231 } / , 5232 / unprotected / {}, 5233 / payload / 'This is the content.', 5234 / tag / h'726043745027214f' 5235 ] 5236 ) 5238 Note that this example uses the same inputs as Appendix C.5.1. 5240 C.7. COSE Keys 5242 C.7.1. Public Keys 5244 This is an example of a COSE Key set. This example includes the 5245 public keys for all of the previous examples. 5247 In order the keys are: 5249 o An EC key with a kid of "meriadoc.brandybuck@buckland.example" 5251 o An EC key with a kid of "peregrin.took@tuckborough.example" 5253 o An EC key with a kid of "bilbo.baggins@hobbiton.example" 5255 o An EC key with a kid of "11" 5257 Size of binary file is 481 bytes 5259 [ 5260 { 5261 -1:1, 5262 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 5263 8551d', 5264 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 5265 4d19c', 5266 1:2, 5267 2:'meriadoc.brandybuck@buckland.example' 5268 }, 5269 { 5270 -1:1, 5271 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 5272 09eff', 5273 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 5274 c117e', 5275 1:2, 5276 2:'11' 5277 }, 5278 { 5279 -1:3, 5280 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 5281 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 5282 f42ad', 5283 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 5284 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 5285 d9475', 5286 1:2, 5287 2:'bilbo.baggins@hobbiton.example' 5288 }, 5289 { 5290 -1:1, 5291 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 5292 d6280', 5293 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 5294 822bb', 5295 1:2, 5296 2:'peregrin.took@tuckborough.example' 5297 } 5298 ] 5300 C.7.2. Private Keys 5302 This is an example of a COSE Key set. This example includes the 5303 private keys for all of the previous examples. 5305 In order the keys are: 5307 o An EC key with a kid of "meriadoc.brandybuck@buckland.example" 5309 o A shared-secret key with a kid of "our-secret" 5311 o An EC key with a kid of "peregrin.took@tuckborough.example" 5313 o A shared-secret key with a kid of "018c0ae5-4d9b-471b- 5314 bfd6-eef314bc7037" 5316 o An EC key with a kid of "bilbo.baggins@hobbiton.example" 5318 o An EC key with a kid of "11" 5320 Size of binary file is 816 bytes 5322 [ 5323 { 5324 1:2, 5325 2:'meriadoc.brandybuck@buckland.example', 5326 -1:1, 5327 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 5328 8551d', 5329 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 5330 4d19c', 5331 -4:h'aff907c99f9ad3aae6c4cdf21122bce2bd68b5283e6907154ad911840fa 5332 208cf' 5333 }, 5334 { 5335 1:2, 5336 2:'11', 5337 -1:1, 5338 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 5339 09eff', 5340 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 5341 c117e', 5342 -4:h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850 5343 7b4d3' 5344 }, 5345 { 5346 1:2, 5347 2:'bilbo.baggins@hobbiton.example', 5348 -1:3, 5349 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 5350 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 5351 f42ad', 5352 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 5353 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 5354 d9475', 5355 -4:h'00085138ddabf5ca975f5860f91a08e91d6d5f9a76ad4018766a476680b 5356 55cd339e8ab6c72b5facdb2a2a50ac25bd086647dd3e2e6e99e84ca2c3609fdf177f 5357 eb26d' 5358 }, 5359 { 5360 1:4, 5361 2:'our-secret', 5362 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 5363 27188' 5364 }, 5365 { 5366 1:2, 5367 -1:1, 5368 2:'peregrin.took@tuckborough.example', 5369 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 5370 d6280', 5371 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 5372 822bb', 5373 -4:h'02d1f7e6f26c43d4868d87ceb2353161740aacf1f7163647984b522a848 5374 df1c3' 5375 }, 5376 { 5377 1:4, 5378 2:'our-secret2', 5379 -1:h'849b5786457c1491be3a76dcea6c4271' 5380 }, 5381 { 5382 1:4, 5383 2:'018c0ae5-4d9b-471b-bfd6-eef314bc7037', 5384 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 5385 27188' 5386 } 5387 ] 5389 Acknowledgments 5391 This document is a product of the COSE working group of the IETF. 5393 The following individuals are to blame for getting me started on this 5394 project in the first place: Richard Barnes, Matt Miller, and Martin 5395 Thomson. 5397 The initial version of the draft was based to some degree on the 5398 outputs of the JOSE and S/MIME working groups. 5400 The following individuals provided input into the final form of the 5401 document: Carsten Bormann, John Bradley, Brain Campbell, Michael B. 5403 Jones, Ilari Liusvaara, Francesca Palombini, Goran Selander, and 5404 Ludwig Seitz. 5406 Author's Address 5408 Jim Schaad 5409 August Cellars 5411 Email: ietf@augustcellars.com