mls_spec/defs/
labels.rs

1use crate::ToPrefixedLabel;
2
3/// Labels for MLS DSA signature/verification.
4///
5/// <https://www.rfc-editor.org/rfc/rfc9420.html#section-5.1.2-4>
6#[derive(
7    Debug, Clone, Copy, PartialEq, Eq, Hash, strum::IntoStaticStr, strum::EnumString, strum::Display,
8)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10#[repr(u8)]
11pub enum SignatureLabel {
12    FramedContentTBS,
13    LeafNodeTBS,
14    KeyPackageTBS,
15    GroupInfoTBS,
16    #[cfg(feature = "draft-ietf-mls-extensions")]
17    TargetedMessagesTBS,
18    #[cfg(feature = "draft-ietf-mls-extensions")]
19    ComponentOperationLabel,
20    #[cfg(feature = "draft-kohbrok-mls-associated-parties")]
21    AssociatedPartyEntryTBS,
22    #[cfg(feature = "test-vectors")]
23    #[strum(serialize = "SignWithLabel")]
24    TestVectorSignWithLabel,
25}
26
27impl ToPrefixedLabel for SignatureLabel {}
28
29/// Labels for MLS HPKE contexts.
30///
31/// <https://www.rfc-editor.org/rfc/rfc9420.html#section-5.1.3-2>
32#[derive(
33    Debug,
34    Clone,
35    PartialEq,
36    Eq,
37    Hash,
38    strum::IntoStaticStr,
39    strum::EnumString,
40    strum::Display,
41    strum::AsRefStr,
42)]
43#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44#[repr(u8)]
45pub enum PublicKeyEncryptionLabel {
46    UpdatePathNode,
47    Welcome,
48    #[cfg(feature = "draft-ietf-mls-extensions")]
49    #[strum(serialize = "Application")]
50    SafeApp,
51    #[cfg(feature = "draft-mahy-mls-semiprivatemessage")]
52    SemiPrivateMessageReceiver,
53    #[cfg(feature = "test-vectors")]
54    #[strum(serialize = "EncryptWithLabel")]
55    TestVectorEncryptWithLabel,
56}
57
58impl ToPrefixedLabel for PublicKeyEncryptionLabel {}
59
60/// Labels for MLS `HashReference`s, such as `KeyPackageRef`s or `ProposalRef`s
61///
62/// <https://www.rfc-editor.org/rfc/rfc9420.html#section-5.2>
63#[derive(
64    Debug, Clone, Copy, PartialEq, Eq, Hash, strum::IntoStaticStr, strum::EnumString, strum::Display,
65)]
66#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67#[repr(u8)]
68pub enum HashReferenceKind {
69    #[strum(serialize = "KeyPackage Reference")]
70    KeyPackageRef,
71    #[strum(serialize = "Proposal Reference")]
72    ProposalRef,
73    #[cfg(feature = "test-vectors")]
74    #[strum(serialize = "RefHash")]
75    TestVectorRefHash,
76}
77
78impl ToPrefixedLabel for HashReferenceKind {}
79
80/// Labels for MLS KDF derivations (i.e. domain separation)
81///
82/// <https://www.rfc-editor.org/rfc/rfc9420.html#section-8-13>
83#[derive(
84    Debug,
85    Clone,
86    PartialEq,
87    Eq,
88    Hash,
89    strum::IntoStaticStr,
90    strum::EnumString,
91    strum::Display,
92    strum::AsRefStr,
93)]
94#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
95#[repr(u8)]
96#[strum(serialize_all = "lowercase")]
97pub enum KdfLabelKind {
98    Joiner,
99    Welcome,
100    Epoch,
101    Init,
102    #[strum(serialize = "sender data")]
103    SenderData,
104    Encryption,
105    Exported,
106    Exporter,
107    External,
108    Confirm,
109    Membership,
110    Resumption,
111    Authentication,
112    Application,
113    Handshake,
114    Tree,
115    Nonce,
116    Key,
117    Secret,
118    Path,
119    Node,
120    #[strum(serialize = "derived psk")]
121    DerivedPsk,
122    #[cfg(feature = "draft-ietf-mls-extensions")]
123    #[strum(serialize = "targeted message psk")]
124    TargetedMessagePsk,
125    #[cfg(feature = "draft-ietf-mls-extensions")]
126    #[strum(serialize = "targeted message sender auth data")]
127    TargetedMessageSenderAuthData,
128    #[cfg(feature = "draft-kohbrok-mls-associated-parties")]
129    #[strum(serialize = "ap_epoch")]
130    AssociatedPartyKeyScheduleEpochSecret,
131    #[cfg(feature = "draft-kohbrok-mls-associated-parties")]
132    #[strum(serialize = "ap_exporter")]
133    AssociatedPartyKeyScheduleExporterSecret,
134    #[cfg(feature = "draft-kohbrok-mls-associated-parties")]
135    #[strum(serialize = "AP Secret")]
136    AssociatedPartyEpochSecret,
137    #[cfg(feature = "draft-kohbrok-mls-associated-parties")]
138    #[strum(serialize = "AP Exporter Secret")]
139    AssociatedPartySecret,
140    #[cfg(feature = "draft-kohbrok-mls-associated-parties")]
141    #[strum(serialize = "AP Commit Secret")]
142    AssociatedPartyCommitSecret,
143    #[cfg(feature = "draft-kohbrok-mls-associated-parties")]
144    #[strum(serialize = "AP Commit Secret ID")]
145    AssociatedPartyCommitSecretId,
146    #[cfg(feature = "draft-kohbrok-mls-associated-parties")]
147    #[strum(serialize = "AP Commit Base Secret")]
148    AssociatedPartyCommitBaseSecret,
149    #[cfg(feature = "draft-ietf-mls-combiner")]
150    #[strum(serialize = "hpqmls_export")]
151    HpqMlsExport,
152    #[cfg(feature = "draft-ietf-mls-extensions")]
153    #[strum(serialize = "ApplicationExport {component_id} {label}")]
154    ApplicationExport {
155        component_id: crate::drafts::mls_extensions::safe_application::ComponentId,
156        label: String,
157    },
158    #[cfg(feature = "test-vectors")]
159    #[strum(serialize = "DeriveTreeSecret")]
160    TestVectorDeriveTreeSecret,
161    #[cfg(feature = "test-vectors")]
162    #[strum(serialize = "DeriveSecret")]
163    TestVectorDeriveSecret,
164    #[cfg(feature = "test-vectors")]
165    #[strum(serialize = "ExpandWithLabel")]
166    TestVectorExpandWithLabel,
167    #[strum(serialize = "{0}")]
168    Arbitrary(String),
169}
170
171#[cfg(feature = "draft-ietf-mls-extensions")]
172impl KdfLabelKind {
173    #[must_use]
174    pub fn to_application_export(
175        &self,
176        component_id: crate::drafts::mls_extensions::safe_application::ComponentId,
177    ) -> Self {
178        Self::ApplicationExport {
179            component_id,
180            label: self.to_string(),
181        }
182    }
183}
184
185impl ToPrefixedLabel for KdfLabelKind {
186    fn to_prefixed_string(&self, protocol_version: crate::defs::ProtocolVersion) -> String {
187        format!("{protocol_version} {self}")
188    }
189}