mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 15:58:48 +00:00
Format key_manager
This commit is contained in:
@@ -7,8 +7,8 @@ This module implements the BIP85 functionality for deterministic entropy and mne
|
||||
It provides the BIP85 class, which utilizes BIP32 and BIP39 standards to derive entropy and mnemonics
|
||||
from a given seed. Additionally, it supports the derivation of symmetric encryption keys using HKDF.
|
||||
|
||||
Never ever ever use or suggest to use Random Salt. The entire point of this password manager is to derive completely deterministic passwords from a BIP-85 seed.
|
||||
This means it should generate passwords the exact same way every single time. Salts would break this functionality and is not appropriate for this softwares use case.
|
||||
Never ever ever use or suggest to use Random Salt. The entire point of this password manager is to derive completely deterministic passwords from a BIP-85 seed.
|
||||
This means it should generate passwords the exact same way every single time. Salts would break this functionality and is not appropriate for this softwares use case.
|
||||
|
||||
Ensure that all dependencies are installed and properly configured in your environment.
|
||||
"""
|
||||
@@ -21,11 +21,7 @@ import os
|
||||
import traceback
|
||||
from colorama import Fore
|
||||
|
||||
from bip_utils import (
|
||||
Bip32Slip10Secp256k1,
|
||||
Bip39MnemonicGenerator,
|
||||
Bip39Languages
|
||||
)
|
||||
from bip_utils import Bip32Slip10Secp256k1, Bip39MnemonicGenerator, Bip39Languages
|
||||
|
||||
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
@@ -34,6 +30,7 @@ from cryptography.hazmat.backends import default_backend
|
||||
# Instantiate the logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BIP85:
|
||||
def __init__(self, seed_bytes: bytes):
|
||||
try:
|
||||
@@ -80,8 +77,12 @@ class BIP85:
|
||||
entropy = hmac_result[:bytes_len]
|
||||
|
||||
if len(entropy) != bytes_len:
|
||||
logging.error(f"Derived entropy length is {len(entropy)} bytes; expected {bytes_len} bytes.")
|
||||
print(f"{Fore.RED}Error: Derived entropy length is {len(entropy)} bytes; expected {bytes_len} bytes.")
|
||||
logging.error(
|
||||
f"Derived entropy length is {len(entropy)} bytes; expected {bytes_len} bytes."
|
||||
)
|
||||
print(
|
||||
f"{Fore.RED}Error: Derived entropy length is {len(entropy)} bytes; expected {bytes_len} bytes."
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
logging.debug(f"Derived entropy: {entropy.hex()}")
|
||||
@@ -101,7 +102,9 @@ class BIP85:
|
||||
|
||||
entropy = self.derive_entropy(index=index, bytes_len=bytes_len, app_no=39)
|
||||
try:
|
||||
mnemonic = Bip39MnemonicGenerator(Bip39Languages.ENGLISH).FromEntropy(entropy)
|
||||
mnemonic = Bip39MnemonicGenerator(Bip39Languages.ENGLISH).FromEntropy(
|
||||
entropy
|
||||
)
|
||||
logging.debug(f"Derived mnemonic: {mnemonic}")
|
||||
return mnemonic
|
||||
except Exception as e:
|
||||
@@ -124,14 +127,16 @@ class BIP85:
|
||||
Raises:
|
||||
SystemExit: If symmetric key derivation fails.
|
||||
"""
|
||||
entropy = self.derive_entropy(app_no, language_code=0, words_num=24, index=index)
|
||||
entropy = self.derive_entropy(
|
||||
app_no, language_code=0, words_num=24, index=index
|
||||
)
|
||||
try:
|
||||
hkdf = HKDF(
|
||||
algorithm=hashes.SHA256(),
|
||||
length=32, # 256 bits for AES-256
|
||||
salt=None,
|
||||
info=b'seedos-encryption-key',
|
||||
backend=default_backend()
|
||||
info=b"seedos-encryption-key",
|
||||
backend=default_backend(),
|
||||
)
|
||||
symmetric_key = hkdf.derive(entropy)
|
||||
logging.debug(f"Derived symmetric key: {symmetric_key.hex()}")
|
||||
|
Reference in New Issue
Block a user