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

Commit ad81148

Browse files
committed
fix: xchacha nonce size
1 parent ee83cdc commit ad81148

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

logic/storage.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pathlib import Path
22
from base64 import b64encode, b64decode
33
from core.constants import (
4+
XCHACHA20POLY1305_NONCE_LEN,
45
ML_KEM_1024_NAME,
56
CLASSIC_MCELIECE_8_F_NAME,
67
ACCOUNT_FILE_PATH,
@@ -29,13 +30,13 @@ def load_account_data(password = None) -> dict:
2930
with open(ACCOUNT_FILE_PATH, "rb") as f:
3031
blob = f.read()
3132

32-
# first 12 bytes is nonce, and last 32 bytes is the password salt,
33+
# first XCHACHA20POLY13055_NONCE_LEN bytes is nonce, and last 32 bytes is the password salt,
3334
# and the ciphertext is inbetween.
3435
password_kdf, _ = crypto.derive_key_argon2id(password.encode(), salt=blob[-ARGON2_SALT_LEN:])
3536

3637
blob = blob[:-ARGON2_SALT_LEN]
3738

38-
user_data = json.loads(crypto.decrypt_xchacha20poly1305(password_kdf, blob[:12], blob[12:]))
39+
user_data = json.loads(crypto.decrypt_xchacha20poly1305(password_kdf[:32], blob[:XCHACHA20POLY1305_NONCE_LEN], blob[XCHACHA20POLY1305_NONCE_LEN:]))
3940

4041

4142
with open(Path("assets") / "browsers_headers.json", "r") as f:
@@ -258,7 +259,7 @@ def save_account_data(user_data: dict, user_data_lock, password = None) -> None:
258259
password_kdf, password_salt = crypto.derive_key_argon2id(password.encode())
259260

260261

261-
nonce, ciphertext = crypto.encrypt_xchacha20poly1305(password_kdf, json.dumps(user_data).encode("utf-8"))
262+
nonce, ciphertext = crypto.encrypt_xchacha20poly1305(password_kdf[:32], json.dumps(user_data).encode("utf-8"))
262263
with open(ACCOUNT_FILE_PATH, "wb") as f:
263264
f.write(nonce + ciphertext + password_salt)
264265

0 commit comments

Comments
 (0)