Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Commit 8ec79e3

Browse files
committed
fix: Fix pad sending error due to mismatching pad generation paramaters
1 parent 1f234dd commit 8ec79e3

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

core/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# crypto parameters
1010
AES_GCM_NONCE_LEN = 12 # bytes
1111

12-
OTP_PAD_SIZE = 10240 # bytes
12+
OTP_PAD_SIZE = 11264 # bytes
1313
OTP_PADDING_LENGTH = 2 # bytes
1414
OTP_PADDING_LIMIT = 1024 # bytes
1515

core/crypto.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def generate_kem_keys(algorithm: str = "Kyber1024"):
111111
return private_key, public_key
112112

113113

114-
def decrypt_kyber_shared_secrets(ciphertext_blob: bytes, private_key: bytes, otp_pad_size: int = 10240):
114+
def decrypt_kyber_shared_secrets(ciphertext_blob: bytes, private_key: bytes, otp_pad_size: int = OTP_PAD_SIZE):
115115
"""
116116
Decapsulates shared_secrets of size otp_pad_size and returns the resulting shared_secrets.
117117
The ciphertexts_blob is expected to be a concatenated sequence of Kyber ciphertexts,
@@ -123,9 +123,10 @@ def decrypt_kyber_shared_secrets(ciphertext_blob: bytes, private_key: bytes, otp
123123
split the blob and decapsulate in order.
124124
"""
125125

126+
cipher_size = 1568 # Kyber1024 ciphertext size
127+
126128
shared_secrets = b''
127-
cipher_size = 1568 # Kyber1024 ciphertext size
128-
cursor = 0
129+
cursor = 0
129130

130131
with oqs.KeyEncapsulation("Kyber1024", secret_key=private_key) as kem:
131132
while len(shared_secrets) < otp_pad_size:

logic/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def messages_data_handler(user_data, user_data_lock, user_data_copied, ui_queue,
263263
return
264264

265265

266-
# and immediately save the new pads and replay protection number
266+
# and immediately save the new pads and the hash chain
267267
with user_data_lock:
268268
user_data["contacts"][contact_id]["contact_pads"]["pads"] = contact_pads
269269
user_data["contacts"][contact_id]["contact_pads"]["hash_chain"] = next_hash_chain

0 commit comments

Comments
 (0)