-
Notifications
You must be signed in to change notification settings - Fork 3
/
draft-ietf-cose-hpke.txt
1344 lines (837 loc) · 40.3 KB
/
draft-ietf-cose-hpke.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
COSE H. Tschofenig
Internet-Draft H-BRS
Intended status: Standards Track O. Steele, Ed.
Expires: 10 January 2025 Transmute
D. Ajitomi
bibital
L. Lundblade
Security Theory LLC
9 July 2024
Use of Hybrid Public-Key Encryption (HPKE) with CBOR Object Signing and
Encryption (COSE)
draft-ietf-cose-hpke-09
Abstract
This specification defines hybrid public-key encryption (HPKE) for
use with CBOR Object Signing and Encryption (COSE). HPKE offers a
variant of public-key encryption of arbitrary-sized plaintexts for a
recipient public key.
HPKE works for any combination of an asymmetric key encapsulation
mechanism (KEM), key derivation function (KDF), and authenticated
encryption with additional data (AEAD) function. Authentication for
HPKE in COSE is provided by COSE-native security mechanisms or by one
of the authenticated variants of HPKE.
This document defines the use of the HPKE with COSE.
Status of This Memo
This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet-
Drafts is at https://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."
This Internet-Draft will expire on 10 January 2025.
Tschofenig, et al. Expires 10 January 2025 [Page 1]
Internet-Draft COSE HPKE July 2024
Copyright Notice
Copyright (c) 2024 IETF Trust and the persons identified as the
document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents (https://trustee.ietf.org/
license-info) in effect on the date of publication of this document.
Please review these documents carefully, as they describe your rights
and restrictions with respect to this document. Code Components
extracted from this document must include Revised BSD License text as
described in Section 4.e of the Trust Legal Provisions and are
provided without warranty as described in the Revised BSD License.
This document may contain material from IETF Documents or IETF
Contributions published or made publicly available before November
10, 2008. The person(s) controlling the copyright in some of this
material may not have granted the IETF Trust the right to allow
modifications of such material outside the IETF Standards Process.
Without obtaining an adequate license from the person(s) controlling
the copyright in such materials, this document may not be modified
outside the IETF Standards Process, and derivative works of it may
not be created outside the IETF Standards Process, except to format
it for publication as an RFC or to translate it into languages other
than English.
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3
2. Conventions and Terminology . . . . . . . . . . . . . . . . . 3
3. HPKE for COSE . . . . . . . . . . . . . . . . . . . . . . . . 3
3.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . 4
3.1.1. HPKE Direct Encryption Mode . . . . . . . . . . . . . 4
3.1.2. HPKE Key Encryption Mode . . . . . . . . . . . . . . 5
3.2. Key Representation . . . . . . . . . . . . . . . . . . . 9
4. Ciphersuite Registration . . . . . . . . . . . . . . . . . . 9
4.1. COSE_Keys for COSE-HPKE Ciphersuites . . . . . . . . . . 11
5. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.1. HPKE Direct Encryption Mode . . . . . . . . . . . . . . . 12
5.2. HPKE Key Encryption Mode . . . . . . . . . . . . . . . . 13
5.2.1. COSE_Encrypt . . . . . . . . . . . . . . . . . . . . 13
5.2.2. COSE_MAC . . . . . . . . . . . . . . . . . . . . . . 15
5.3. Key Representation . . . . . . . . . . . . . . . . . . . 18
5.3.1. KEM Public Key for HPKE-Base-P256-SHA256-A128GCM . . 18
5.3.2. KEM Private Key for HPKE-Base-P256-SHA256-A128GCM . . 18
5.3.3. KEM Public Key for
HPKE-Base-X25519-SHA256-CHACHA20POLY1305 . . . . . . 19
6. Security Considerations . . . . . . . . . . . . . . . . . . . 19
Tschofenig, et al. Expires 10 January 2025 [Page 2]
Internet-Draft COSE HPKE July 2024
7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 20
7.1. COSE Algorithms Registry . . . . . . . . . . . . . . . . 20
7.2. COSE Header Parameters . . . . . . . . . . . . . . . . . 22
8. References . . . . . . . . . . . . . . . . . . . . . . . . . 22
8.1. Normative References . . . . . . . . . . . . . . . . . . 22
8.2. Informative References . . . . . . . . . . . . . . . . . 23
Appendix A. Contributors . . . . . . . . . . . . . . . . . . . . 23
Appendix B. Acknowledgements . . . . . . . . . . . . . . . . . . 24
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 24
1. Introduction
Hybrid public-key encryption (HPKE) [RFC9180] is a scheme that
provides public key encryption of arbitrary-sized plaintexts given a
recipient's public key.
This document defines the use of the HPKE with COSE ([RFC9052],
[RFC9053]).
2. Conventions and Terminology
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in
BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all
capitals, as shown here.
This specification uses the following abbreviations and terms:
* Content-encryption key (CEK), a term defined in CMS [RFC2630].
* Hybrid Public Key Encryption (HPKE) is defined in [RFC9180].
* pkR is the public key of the recipient, as defined in [RFC9180].
* skR is the private key of the recipient, as defined in [RFC9180].
* Key Encapsulation Mechanism (KEM), see [RFC9180].
* Key Derivation Function (KDF), see [RFC9180].
* Authenticated Encryption with Associated Data (AEAD), see
[RFC9180].
* Additional Authenticated Data (AAD), see [RFC9180].
3. HPKE for COSE
Tschofenig, et al. Expires 10 January 2025 [Page 3]
Internet-Draft COSE HPKE July 2024
3.1. Overview
This specification supports two modes of HPKE in COSE, namely
* HPKE Direct Encryption mode, where HPKE is used to encrypt the
plaintext. This mode can only be used with a single recipient.
Section 3.1.1 provides the details.
* HPKE Key Encryption mode, where HPKE is used to encrypt a content
encryption key (CEK) and the CEK is subsequently used to encrypt
the plaintext. This mode supports multiple recipients.
Section 3.1.2 provides the details.
In both cases a new COSE header parameter, called 'ek', is used to
convey the content of the enc structure defined in the HPKE
specification. "Enc" represents the serialized public key.
For use with HPKE the 'ek' header parameter MUST be present in the
unprotected header parameter and MUST contain the encapsulated key,
which is output of the HPKE KEM, and it is a bstr.
3.1.1. HPKE Direct Encryption Mode
With the HPKE Direct Encryption mode the information carried inside
the COSE_recipient structure is embedded inside the COSE_Encrypt0.
HPKE is used to directly encrypt the plaintext and the resulting
ciphertext is either included in the COSE_Encrypt0 or is detached.
If a payload is transported separately then it is called "detached
content". A nil CBOR object is placed in the location of the
ciphertext. See Section 5 of [RFC9052] for a description of detached
payloads.
The sender MUST set the alg parameter in the protected header, which
indicates the use of HPKE.
The sender MUST place the 'ek' (encapsulated key) parameter into the
unprotected header. Although the use of the 'kid' parameter in
COSE_Encrypt0 is discouraged by RFC 9052, this documents RECOMMENDS
the use of the 'kid' parameter (or other parameters) to explicitly
identify the static recipient public key used by the sender. If the
COSE_Encrypt0 contains the 'kid' then the recipient may use it to
select the appropriate private key.
The HPKE specification describes an API and this API uses an "aad"
parameter as input. When COSE_Encrypt0 is used then there is no AEAD
function executed by COSE natively and HPKE offers this
functionality.
Tschofenig, et al. Expires 10 January 2025 [Page 4]
Internet-Draft COSE HPKE July 2024
The "aad" parameter provided to the HPKE API is constructed as
follows (and the design has been re-used from [RFC9052]):
Enc_structure = [
context : "Encrypt0",
protected : empty_or_serialized_map,
external_aad : bstr
]
empty_or_serialized_map = bstr .cbor header_map / bstr .size 0
The protected field in the Enc_structure contains the protected
attributes from the COSE_Encrypt0 structure at layer 0, encoded in a
bstr type.
Figure 1 shows the COSE_Encrypt0 CDDL structure.
COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0)
; Layer 0
COSE_Encrypt0 = [
Headers,
ciphertext : bstr / nil,
]
Figure 1: CDDL used for the HPKE Direct Encryption Mode
The COSE_Encrypt0 MAY be tagged or untagged.
An example is shown in Section 5.1.
3.1.2. HPKE Key Encryption Mode
With the HPKE Key Encryption mode information is conveyed in the
COSE_recipient structure, i.e. one COSE_recipient structure per
recipient.
In this approach the following layers are involved:
* Layer 0 (corresponding to the COSE_Encrypt structure) contains the
content (plaintext) encrypted with the CEK. This ciphertext may
be detached, and if not detached, then it is included in the
COSE_Encrypt structure.
* Layer 1 (corresponding to a recipient structure) contains
parameters needed for HPKE to generate a shared secret used to
encrypt the CEK. This layer conveys the encrypted CEK in the
encCEK structure. The protected header MUST contain the HPKE alg
Tschofenig, et al. Expires 10 January 2025 [Page 5]
Internet-Draft COSE HPKE July 2024
parameter and the unprotected header MUST contain the 'ek'
parameter. The unprotected header MAY contain the kid parameter
to identify the static recipient public key the sender has been
using with HPKE.
This two-layer structure is used to encrypt content that can also be
shared with multiple parties at the expense of a single additional
encryption operation. As stated above, the specification uses a CEK
to encrypt the content at layer 0.
3.1.2.1. Recipient Encryption
This describes the Recipient_structure. It serves instead of
COSE_KDF_Context for COSE-HPKE recipients (and possibly other COSE
algorithms defined outside this document). It MUST be used for COSE-
HPKE recipients as it provides the protection for recipient protected
headers. It is patterned after the Enc_structure in [RFC9052], but
is specifically for a COSE_recipient, never a COSE_Encrypt. The
COSE_KDF_Context MUST NOT be used in COSE-HPKE.
Recipient_structure = [
context: "Recipient",
next_layer_alg: int/tstr,
recipient_protected_header: empty_or_serialize_map,
recipient_aad: bstr
]
* "next_layer_alg" is the algorithm ID of the COSE layer for which
the COSE_recipient is encrypting a key. It is the algorithm that
the key MUST be used with. This value MUST match the alg
parameter in the next lower COSE layer. (This serves the same
purpose as the alg ID in the COSE_KDF_Context. It also mitigates
attacks where a person-in-the-middle changes the following layer
algorithm from an AEAD algorithm to one that is not foiling the
protection of the following layer headers).
* "recipient_protected_header" contains the protected headers from
the COSE_recipient CBOR-encoded deterministically with the "Core
Deterministic Encoding Requirements", specified in Section 4.2.1
of RFC 8949 [STD94].
* "recipient_aad" contains any additional context the application
wishes to protect. If none, it is a zero-length string. This is
distinct from the external_aad for the whole COSE encrypt. It is
per-recipient. Since it is not a header, it may be secret data
that is not transmitted. It provides a means to convey many of
the fields in COSE_KDF_Context.
Tschofenig, et al. Expires 10 January 2025 [Page 6]
Internet-Draft COSE HPKE July 2024
3.1.2.2. COSE-HPKE Recipient Construction
This is the procedure for creating a COSE_recipient for COSE-HPKE.
When a COSE_recipeint is constructed for a COSE-HPKE recipient, this
is given as the "aad" parameter to the HPKE Seal() API. The "info"
parameter to HPKE_Seal is not used with COSE_HPKE.
The creation of the COSE_recipient is as follows:
1. Prepare a Recipient_structure
2. Obtain the key To used use by the next lowest layer
3. Pass in the following parameters to HPKE Seal API
1. Public key of recipient for "pKR"
2. Empty string for "info"
3. CBOR-encoded Recipient_structure for "aad"
4. The key for next lowest COSE layer for "pt"
4. The following are returned from the HPKE Seal API
1. The "enc" is placed in the "ek" header of the COSE_recipient
2. The "ct" is placed in the "ciphertext" field of the
COSE_recipient
The decoding and decryption of a COSE_recipient is as follows:
1. Prepare a Recipient_structure
2. Pass in the following parameters to HPKE Open API
1. The "ek" header for "enc"
2. Secret key for recipient for "sKR"
3. Empty string for "info"
4. CBOR-encoded Recipient_structure for "aad"
5. The cipher text from the COSE_recipient as "ct"
Tschofenig, et al. Expires 10 January 2025 [Page 7]
Internet-Draft COSE HPKE July 2024
3. What is returned from HPKE Open API is the key for the next
lowest COSE layer
It is not necessary to fill in recipient_aad as HPKE itself covers
the attacks that recipient_aad (and COSE_KDF_Context (and SP800-56A))
are used to mitigate. COSE-HPKE use cases may use it for any purpose
they wish, but it should generally be for small identifiers, context
or secrets, not to protect bulk external data. Bulk external data
should be protected at layer 0 with external_aad.
The COSE_recipient structure, shown in Figure 2, is repeated for each
recipient.
COSE_Encrypt_Tagged = #6.96(COSE_Encrypt)
/ Layer 0 /
COSE_Encrypt = [
Headers,
ciphertext : bstr / nil,
recipients : + COSE_recipient
]
/ Layer 1 /
COSE_recipient = [
protected : bstr .cbor header_map,
unprotected : header_map,
encCEK : bstr,
]
header_map = {
Generic_Headers,
* label => values,
}
Figure 2: CDDL used for the HPKE Key Encryption Mode
The COSE_Encrypt MAY be tagged or untagged.
When encrypting the content at layer 0 then the instructions in
Section 5.3 of [RFC9052] MUST to be followed, which includes the
calculation of the authenticated data strcture.
An example is shown in Section 5.2.
Tschofenig, et al. Expires 10 January 2025 [Page 8]
Internet-Draft COSE HPKE July 2024
3.2. Key Representation
The COSE_Key with the existing key types can be used to represent KEM
private or public keys. When using a COSE_Key for COSE-HPKE, the
following checks are made:
* The "kty" field MUST be present, and it MUST be one of the key
types for HPKE KEM.
* If the "kty" field is "OKP" or "EC2", the "crv" field MUST be
present and it MUST be a curve for HPKE KEM.
* If the "alg" field is present, it MUST be one of the supported
COSE-HPKE "alg" values and the key type of its KEM MUST match the
"kty" field. If the "kty" field is "OKP" or "EC2", the curve of
the KEM MUST match the "crv" field. The valid combinations of the
"alg", "kty" and "crv" are shown in Figure 3.
* If the "key_ops" field is present, it MUST include only "derive
bits" for the private key and MUST be empty for the public key.
Examples of the COSE_Key for COSE-HPKE are shown in Section 5.3.
4. Ciphersuite Registration
A ciphersuite is a group of algorithms, often sharing component
algorithms such as hash functions, targeting a security level. An
HPKE ciphersuite, is composed of the following choices:
* HPKE Mode
* KEM Algorithm
* KDF Algorithm
* AEAD Algorithm
The "KEM", "KDF", and "AEAD" values are chosen from the HPKE IANA
registry [HPKE-IANA].
For readability the algorithm ciphersuites labels are built according
to the following scheme:
HPKE-<Version>-<Mode>-<KEM>-<KDF>-<AEAD>
The "Mode" indicator may be populated with the following values from
Table 1 of [RFC9180]:
Tschofenig, et al. Expires 10 January 2025 [Page 9]
Internet-Draft COSE HPKE July 2024
* "Base" refers to "mode_base" described in Section 5.1.1 of
[RFC9180], which only enables encryption to the holder of a given
KEM private key.
* "PSK" refers to "mode_psk", described in Section 5.1.2 of
[RFC9180], which authenticates using a pre-shared key.
* "Auth" refers to "mode_auth", described in Section 5.1.3 of
[RFC9180], which authenticates using an asymmetric key.
* "Auth_Psk" refers to "mode_auth_psk", described in Section 5.1.4
of [RFC9180], which authenticates using both a PSK and an
asymmetric key.
For a list of ciphersuite registrations, please see Section 7. The
following table summarizes the relationship between the ciphersuites
registered in this document, which all use the "Base" mode and the
values registered in the HPKE IANA registry [HPKE-IANA].
+--------------------------------------------------+------------------+
| COSE-HPKE | HPKE |
| Cipher Suite Label | KEM | KDF | AEAD |
+--------------------------------------------------+-----+-----+------+
| HPKE-Base-P256-SHA256-A128GCM |0x10 | 0x1 | 0x1 |
| HPKE-Base-P384-SHA384-AS256GCM |0x11 | 0x2 | 0x2 |
| HPKE-Base-P521-SHA512-AS256GCM |0x12 | 0x3 | 0x2 |
| HPKE-Base-X25519-SHA256-A128GCM |0x20 | 0x1 | 0x1 |
| HPKE-Base-X25519-SHA256-ChaCha20Poly1305 |0x20 | 0x1 | 0x3 |
| HPKE-Base-X448-SHA512-AS256GCM |0x21 | 0x3 | 0x2 |
| HPKE-Base-X448-SHA512-ChaCha20Poly1305 |0x21 | 0x3 | 0x3 |
+--------------------------------------------------+-----+-----+------+
As the list indicates, the ciphersuite labels have been abbreviated
at least to some extend to maintain the tradeoff between readability
and length.
The ciphersuite list above is a minimal starting point. Additional
ciphersuites can be registered into the already existing registry.
For example, once post-quantum cryptographic algorithms have been
standardized it might be beneficial to register ciphersuites for use
with COSE-HPKE. Additionally, ciphersuites utilizing the compact
encoding of the public keys, as defined in [I-D.irtf-cfrg-dnhpke],
may be standardized for use in constrained environments.
Tschofenig, et al. Expires 10 January 2025 [Page 10]
Internet-Draft COSE HPKE July 2024
As a guideline for ciphersuite submissions to the IANA CoSE algorithm
registry, the designated experts must only register combinations of
(KEM, KDF, AEAD) triple that consitute valid combinations for use
with HPKE, the KDF used should (if possible) match one internally
used by the KEM, and components should not be mixed between global
and national standards.
4.1. COSE_Keys for COSE-HPKE Ciphersuites
The COSE-HPKE ciphersuite uniquely determines the type of KEM for
which a COSE_Key is used. The following mapping table shows the
valid combinations of the COSE-HPKE ciphersuite, COSE_Key type and
its curve.
+---------------------+--------------+
| COSE-HPKE | COSE_Key |
| Ciphersuite Label | kty | crv |
+---------------------+-----+--------+
| HPKE-Base-P256-\* | EC2 | P-256 |
| HPKE-Base-P384-\* | EC2 | P-384 |
| HPKE-Base-P521-\* | EC2 | P-521 |
| HPKE-Base-X25519-\* | OKP | X25519 |
| HPKE-Base-X448-\* | OKP | X448 |
| HPKE-Base-CP256-\* | EC2 | P-256 |
| HPKE-Base-CP384-\* | EC2 | P-384 |
| HPKE-Base-CP521-\* | EC2 | P-521 |
+---------------------+-----+--------+
Figure 3: COSE_Key Types and Curves for COSE-HPKE Ciphersuites
5. Examples
This section provides a set of examples that shows all COSE message
types (COSE_Encrypt0, COSE_Encrypt and COSE_MAC) to which the COSE-
HPKE can be applied, and also provides some examples of key
representation for HPKE KEM.
Each example of the COSE message includes the following information
that can be used to check the interoperability of COSE-HPKE
implementations:
* plaintext: Original data of the encrypted payload.
* external_aad: Externally supplied AAD.
* skR: A recipient private key.
Tschofenig, et al. Expires 10 January 2025 [Page 11]
Internet-Draft COSE HPKE July 2024
* skE: An ephemeral sender private key paired with the encapsulated
key.
5.1. HPKE Direct Encryption Mode
This example assumes that a sender wants to communicate an encrypted
payload to a single recipient in the most efficient way.
An example of the HPKE Direct Encryption Mode is shown in Figure 4.
Line breaks and comments have been inserted for better readability.
This example uses the following:
* alg: HPKE-Base-P256-SHA256-A128GCM
* plaintext: "This is the content."
* external_aad: "COSE-HPKE app"
* skR: h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850
7b4d3'
* skE: h'42dd125eefc409c3b57366e721a40043fb5a58e346d51c133128a772371
60218'
16([
/ alg = HPKE-Base-P256-SHA256-A128GCM (Assumed: 35) /
h'a1011823',
{
/ kid /
4: h'3031',
/ ek /
-4: h'045df24272faf43849530db6be01f42708b3c3a9
df8e268513f0a996ed09ba7840894a3fb946cb28
23f609c59463093d8815a7400233b75ca8ecb177
54d241973e',
},
/ encrypted plaintext /
h'35aa3d98739289b83751125abe44e3b977e4b9abbf2c8cfaade
b15f7681eef76df88f096',
])
Figure 4: COSE_Encrypt0 Example for HPKE
Tschofenig, et al. Expires 10 January 2025 [Page 12]
Internet-Draft COSE HPKE July 2024
5.2. HPKE Key Encryption Mode
In this example we assume that a sender wants to transmit a payload
to two recipients using the HPKE Key Encryption mode. Note that it
is possible to send two single-layer payloads, although it will be
less efficient.
5.2.1. COSE_Encrypt
An example of the COSE_Encrypt structure using the HPKE scheme is
shown in Figure 5. Line breaks and comments have been inserted for
better readability.
This example uses the following:
TODO: recompute this for Recipient_structure
* Encryption alg: AES-128-GCM
* plaintext: "This is the content."
* detatched ciphertext: h'cc168c4e148c52a83010a75250935a47ccb8682dee
bcef8fce5d60c161e849f53a2dc664'
* kid:"01"
- alg: HPKE-Base-P256-SHA256-A128GCM
- external_aad: "COSE-HPKE app"
- skR: h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030
8507b4d3'
- skE: h'97ad883f949f4cdcb1301b9446950efd4eb519e16c4a3d78304eec83
2692f9f6'
* kid:"02"
- alg: HPKE-Base-X25519-SHA256-CHACHA20POLY1305
- external_aad: "COSE-HPKE app"
- skR: h'bec275a17e4d362d0819dc0695d89a73be6bf94b66ab726ae0b1afe3
c43f41ce'
- skE: h'b8ed3f4df56c230e36fa6620a47f24d08856d242ea547c5521ff7bd6
9af8fd6f'
Tschofenig, et al. Expires 10 January 2025 [Page 13]
Internet-Draft COSE HPKE July 2024
96_0([
/ alg = AES-128-GCM (1) /
h'a10101',
{
/ iv /
5: h'b3fb95dde18c6f90a9f0ae55',
},
/ detached ciphertext /
null,
[
[
/ alg = HPKE-Base-P256-SHA256-A128GCM (Assumed: 35) /
h'a1011823',
{
/ kid /
4: h'3031',
/ ek /
-4: h'04d97b79486fe2e7b98fb1bd43
c4faee316ff38d28609a1cf568
40a809298a91e601f1cc0c2ba4
6cb67b41f4651b769cafd9df78
e58aa7f5771291bd4f0f420ba6',
},
/ ciphertext containing encrypted CEK /
h'24450f54ae93375351467d17aa7a795cfede2
c03eced1ad21fcb7e7c2fe64397',
],
[
/ alg = HPKE-Base-X25519-SHA256-CHACHA20POLY1305 (Assumed: 42) /
h'a101182a',
{
/ kid /
4: h'3032',
/ ek /
-4: h'd1afbdc95b0e735676f6bca34f
be50f2822259ac09bfc3c500f1
4a05de9b2833',
},
/ ciphertext containing encrypted CEK /
h'079b443ec6dfcda6a5f8748aff3875146a8ed
40359e1279b545166385d8d9b59',
],
],
])
Figure 5: COSE_Encrypt Example for HPKE
Tschofenig, et al. Expires 10 January 2025 [Page 14]
Internet-Draft COSE HPKE July 2024
To offer authentication of the sender the payload in Figure 5 is
signed with a COSE_Sign1 wrapper, which is outlined in Figure 6. The
payload in Figure 6 is meant to contain the content of Figure 5.
18(
[
/ protected / h'a10126' / {
\ alg \ 1:-7 \ ECDSA 256 \
} / ,
/ unprotected / {
/ kid / 4:'[email protected]'
},
/ payload / h'AA19...B80C',
/ signature / h'E3B8...25B8'
]
)
Figure 6: COSE_Encrypt Example for HPKE
5.2.2. COSE_MAC
An example of the COSE_MAC structure using the HPKE scheme is shown
in Figure 7.
This example uses the following:
* MAC alg: HMAC 256/256
* payload: "This is the content."
* kid:"01"
- alg: HPKE-Base-P256-SHA256-A128GCM
- external_aad: "COSE-HPKE app"
- skR: h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030
8507b4d3'
- skE: h'e5dd9472b5807636c95be0ba2575020ba91cbb3561b52be141da8967
8c664307'
* kid:"02"
- alg: HPKE-Base-X25519-SHA256-CHACHA20POLY1305
- external_aad: "COSE-HPKE app"
Tschofenig, et al. Expires 10 January 2025 [Page 15]
Internet-Draft COSE HPKE July 2024
- skR: h'bec275a17e4d362d0819dc0695d89a73be6bf94b66ab726ae0b1afe3
c43f41ce'
- skE: h'78a49d7af71b5244498e943f361aa0250184afc48b8098a68ae97ccd
2cd7e56f'
Tschofenig, et al. Expires 10 January 2025 [Page 16]
Internet-Draft COSE HPKE July 2024
97_0([
/ alg = HMAC 256/256 (5) /
h'a10105',
{},
/ payload = 'This is the content.' /
h'546869732069732074686520636f6e74656e742e',
/ tag /
h'5cdcf6055fcbdb53b4001d8fb88b2a46b200ed28e1ed77e16ddf43fb3cac3a98',
[
[
/ alg = HPKE-Base-P256-SHA256-A128GCM (Assumed: 35) /
h'a1011823',
{
/ kid = '01' /
4: h'3031',
/ ek /
-4: h'043ac21632e45e1fbd733f002a
621aa4f3d94737adc395d5a7cb
6e9554bd1ad273aec991493786
d72616d9759bf8526e6e20c1ed
c41ba5739f2b2e441781aa0eb4',
},
/ ciphertext containing encrypted MAC key /
h'5cee2b4235a7ff695164f7a8d1e79ccf3ca3d
e8b22f3592626020a95b2a8d3fb4d7aa7fe37
432426ee70073a368f29d1',
],
[
/ alg = HPKE-Base-X25519-SHA256-CHACHA20POLY1305 (Assumed: 42) /
h'a101182a',
{
/ kid = '02' /
4: h'3032',
/ ek /
-4: h'02cffacc60def3bb3d0a1c3661
227c9de8dc2b1d3939dd2c07d4
49ebb0bba324',
},
/ ciphertext containing encrypted MAC key /
h'3f5b8b60271d5234dbea554dc1461d0239e9f
4589f6415e8563b061dbcb37795a616111b78
2b4c589b534309327ffadc',
],
],
])
Figure 7: COSE_MAC Example for HPKE
Tschofenig, et al. Expires 10 January 2025 [Page 17]
Internet-Draft COSE HPKE July 2024
5.3. Key Representation
Examples of private and public KEM key representation are shown
below.
5.3.1. KEM Public Key for HPKE-Base-P256-SHA256-A128GCM
{
/ kty = 'EC2' /
1: 2,
/ kid = '01' /
2: h'3031',
/ alg = HPKE-Base-P256-SHA256-A128GCM (Assumed: 35) /
3: 35,
/ crv = 'P-256' /
-1: 1,
/ x /
-2: h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d',
/ y /
-3: h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd0084d19c'
}
Figure 8: Key Representation Example for HPKE-Base-
P256-SHA256-A128GCM
5.3.2. KEM Private Key for HPKE-Base-P256-SHA256-A128GCM
{
/ kty = 'EC2' /
1: 2,
/ kid = '01' /
2: h'3031',
/ alg = HPKE-Base-P256-SHA256-A128GCM (Assumed: 35) /
3: 35,
/ key_ops = ['derive_bits'] /
4: [8],
/ crv = 'P-256' /
-1: 1,
/ x /
-2: h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a09eff',
/ y /
-3: h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbfc117e',
/ d /
-4: h'57c92077664146e876760c9520d054aa93c3afb04e306705db6090308507b4d3',