Skip to content

Commit 443b57f

Browse files
committed
refactor: Replace hard-coded numbers with shared constants
1 parent 1ce7d85 commit 443b57f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

core/constants.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
OTP_PADDING_LENGTH = 2
1717
OTP_PADDING_LIMIT = 1024
1818

19-
SMP_NONCE_LENGTH = 64
20-
SMP_PROOF_LENGTH = 64
21-
SMP_QUESTION_MAX_LEN = 500
19+
SMP_NONCE_LENGTH = 64
20+
SMP_PROOF_LENGTH = 64
21+
SMP_ANSWER_OUTPUT_LEN = 64
22+
SMP_QUESTION_MAX_LEN = 500
2223

2324
# NIST-specified key sizes (bytes) and metadata
2425
ML_KEM_1024_NAME = "ML-KEM-1024"

logic/smp.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
Step 4 user receive this proof and try to compute an identical one
2828
If we succeed, the verification process is complete and we mark contact's as verified
2929
30-
This provides a mathematical guarantee of authenticity and integrity for our long-term public keys
30+
This provides a strong guarantee of authenticity and integrity for our long-term public keys
3131
IF the answer has enough entropy to be uncrackable *just* for the duration of the process
3232
3333
"""
@@ -40,7 +40,8 @@
4040
from core.trad_crypto import derive_key_argon2id, sha3_512
4141
from base64 import b64encode, b64decode
4242
from core.constants import (
43-
SMP_NONCE_LENGTH
43+
SMP_NONCE_LENGTH,
44+
SMP_ANSWER_OUTPUT_LEN
4445
)
4546
import hashlib
4647
import secrets
@@ -91,7 +92,7 @@ def initiate_smp(user_data: dict, user_data_lock, contact_id: str, question: str
9192
user_data["contacts"][contact_id]["lt_sign_key_smp"]["smp_step"] = 1
9293

9394
user_data["contacts"][contact_id]["lt_sign_keys"]["our_keys"]["private_key"] = private_key
94-
user_data["contacts"][contact_id]["lt_sign_keys"]["our_keys"]["public_key"] = public_key
95+
user_data["contacts"][contact_id]["lt_sign_keys"]["our_keys"]["public_key"] = public_key
9596

9697

9798

@@ -120,7 +121,7 @@ def smp_step_2_answer_provided(user_data, user_data_lock, contact_id, answer, ui
120121

121122
# Derieve a high-entropy secret key from the low-entropy answer
122123
argon2id_salt = sha3_512(our_nonce + contact_nonce)
123-
answer_secret, _ = derive_key_argon2id(answer.encode(), salt=argon2id_salt, output_length=64)
124+
answer_secret, _ = derive_key_argon2id(answer.encode(), salt=argon2id_salt, output_length=SMP_ANSWER_OUTPUT_LEN)
124125

125126
# Compute our proof
126127
our_message = contact_nonce + our_nonce + contact_key_fingerprint
@@ -191,7 +192,7 @@ def smp_step_3(user_data, user_data_lock, contact_id, message, ui_queue) -> None
191192

192193
# Derieve a high-entropy secret key from the low-entropy answer
193194
argon2id_salt = sha3_512(contact_nonce + our_nonce)
194-
answer_secret, _ = derive_key_argon2id(answer.encode(), salt=argon2id_salt, output_length=64)
195+
answer_secret, _ = derive_key_argon2id(answer.encode(), salt=argon2id_salt, output_length=SMP_ANSWER_OUTPUT_LEN)
195196

196197
# Compute the proof
197198
our_message = our_nonce + contact_nonce + our_key_fingerprint

0 commit comments

Comments
 (0)