File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import hmac
4+ from hashlib import sha256
5+
36from cryptography .hazmat .primitives import hashes
47from cryptography .hazmat .primitives .kdf .hkdf import HKDF
58
@@ -30,6 +33,25 @@ def derive_session_root(
3033 )
3134
3235
36+ def derive_key_confirmation (
37+ root_key : bytes ,
38+ transcript_hash : bytes ,
39+ * ,
40+ role : str ,
41+ ) -> bytes :
42+ if role not in {"initiator" , "responder" }:
43+ raise ValueError ("key confirmation role must be initiator or responder" )
44+ payload = b"" .join (
45+ (
46+ b"CypherSyntax/key-confirmation/v1|" ,
47+ role .encode ("ascii" ),
48+ b"|" ,
49+ transcript_hash ,
50+ )
51+ )
52+ return hmac .new (root_key , payload , sha256 ).digest ()
53+
54+
3355def _length_prefixed (value : bytes ) -> bytes :
3456 return len (value ).to_bytes (4 , "big" ) + value
3557
You can’t perform that action at this time.
0 commit comments