secret_tree.mx raw
1 package mls
2
3 // MLS secret tree (RFC 9420 §9).
4 // Type definitions — crypto derivation methods go in secret_tree_crypto.mx.
5
6 type ratchetLabel []byte
7
8 var (
9 ratchetLabelHandshake = ratchetLabel("handshake")
10 ratchetLabelApplication = ratchetLabel("application")
11 )
12
13 func ratchetLabelFromContentType(ct contentType) ratchetLabel {
14 switch ct {
15 case contentTypeApplication:
16 return ratchetLabelApplication
17 case contentTypeProposal, contentTypeCommit:
18 return ratchetLabelHandshake
19 default:
20 panic("unreachable")
21 }
22 }
23
24 // secretTree holds tree node secrets for encryption key/nonce generation.
25 type secretTree [][]byte
26
27 func (tree secretTree) get(ni nodeIndex) []byte {
28 secret := tree[int(ni)]
29 if secret == nil {
30 panic("empty node in secret tree")
31 }
32 return secret
33 }
34
35 func (tree secretTree) set(ni nodeIndex, secret []byte) {
36 tree[int(ni)] = secret
37 }
38
39 type ratchetSecret struct {
40 secret []byte
41 generation uint32
42 }
43