Skip to content

Commit 3347124

Browse files
committed
feat: add strandlock protocol to smp and messages
1 parent b5a50e6 commit 3347124

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

logic/smp.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
generate_kem_keys,
2121
encap_shared_secret,
2222
decap_shared_secret,
23-
23+
one_time_pad
2424
)
2525
from core.trad_crypto import (
2626
derive_key_argon2id,
@@ -244,13 +244,11 @@ def smp_step_4_request_answer(user_data, user_data_lock, contact_id, message, ui
244244
with user_data_lock:
245245
tmp_key = b64decode(user_data["contacts"][contact_id]["lt_sign_key_smp"]["tmp_key"])
246246

247-
our_next_strand_nonce = user_data["contacts"][contact_id]["our_next_strand_nonce"]
248247
contact_next_strand_nonce = user_data["contacts"][contact_id]["contact_next_strand_nonce"]
249248

250249

251250
ciphertext_blob = b64decode(message["ciphertext_blob"], validate = True)
252251

253-
254252
smp_plaintext = decrypt_xchacha20poly1305(tmp_key, contact_next_strand_nonce, ciphertext_blob)
255253

256254
contact_new_strand_nonce = smp_plaintext[:XCHACHA20POLY1305_NONCE_LEN]
@@ -264,11 +262,9 @@ def smp_step_4_request_answer(user_data, user_data_lock, contact_id, message, ui
264262
question = smp_plaintext[SMP_NONCE_LENGTH + XCHACHA20POLY1305_NONCE_LEN + SMP_PROOF_LENGTH + ML_DSA_87_PK_LEN:].decode("utf-8")
265263

266264

267-
268265
with user_data_lock:
269266
user_data["contacts"][contact_id]["lt_sign_key_smp"]["question"] = question
270267
user_data["contacts"][contact_id]["lt_sign_key_smp"]["tmp_proof"] = contact_proof
271-
# user_data["contacts"][contact_id]["lt_sign_key_smp"]["smp_step"] = 5
272268

273269
user_data["contacts"][contact_id]["contact_next_strand_nonce"] = contact_new_strand_nonce
274270

@@ -326,7 +322,7 @@ def smp_step_4_answer_provided(user_data, user_data_lock, contact_id, answer, ui
326322
return
327323

328324

329-
# We compute proof for contact's public key (signing public key, and the question public key)
325+
# We compute proof for contact's public key (signing public key, and the kem public key)
330326
contact_key_fingerprint = sha3_512(contact_signing_public_key + contact_kem_public_key)
331327

332328
our_proof = contact_nonce + our_nonce + contact_key_fingerprint
@@ -355,6 +351,10 @@ def smp_step_4_answer_provided(user_data, user_data_lock, contact_id, answer, ui
355351
return
356352

357353

354+
our_strand_key, _ = one_time_pad(sha3_512(answer_secret)[:32], our_strand_key)
355+
contact_strand_key, _ = one_time_pad(sha3_512(answer_secret)[:32], contact_strand_key)
356+
357+
358358
# We call smp_success at very end to ensure if the requests step fail, we don't alter our local state
359359
smp_success(user_data, user_data_lock, contact_id, ui_queue)
360360

@@ -413,12 +413,15 @@ def smp_step_5(user_data, user_data_lock, contact_id, message, ui_queue) -> None
413413

414414

415415
# Verify Contact's version of our public-key fingerprint matches our actual public-key fingerprint
416-
# We compare using compare_digest to prevent timing analysis by avoiding content-based short circuiting behaviour
417416
if not hmac.compare_digest(our_proof, contact_proof):
418417
logger.warning("SMP Verification failed at step 5")
419418
smp_failure_notify_contact(user_data, user_data_lock, contact_id, ui_queue)
420419
return
421420

421+
422+
our_strand_key, _ = one_time_pad(sha3_512(answer_secret)[:32], our_strand_key)
423+
contact_strand_key, _ = one_time_pad(sha3_512(answer_secret)[:32], contact_strand_key)
424+
422425
with user_data_lock:
423426
user_data["contacts"][contact_id]["contact_next_strand_nonce"] = contact_new_strand_nonce
424427

0 commit comments

Comments
 (0)