Skip to content

Commit 36941a5

Browse files
authored
Implement key confirmation derivation function
Added a function to derive key confirmation using HMAC and SHA-256.
1 parent d91a6c6 commit 36941a5

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/cyphersyntax/kdf.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from __future__ import annotations
22

3+
import hmac
4+
from hashlib import sha256
5+
36
from cryptography.hazmat.primitives import hashes
47
from 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+
3355
def _length_prefixed(value: bytes) -> bytes:
3456
return len(value).to_bytes(4, "big") + value
3557

0 commit comments

Comments
 (0)