fixed autokey
This commit is contained in:
parent
493d31e3c6
commit
de98ad4268
2 changed files with 14 additions and 32 deletions
|
@ -38,12 +38,6 @@ def int_to_fixed_length_bytes(value: int, length_bits: int) -> bytes:
|
|||
|
||||
|
||||
def generate_keypair(p: int, g: int, private_bits: int = 256) -> tuple[int, int]:
|
||||
"""
|
||||
Generate a Diffie-Hellman private/public key pair.
|
||||
|
||||
- private_bits controls the size of the secret exponent for performance and security.
|
||||
256 bits is a common choice for Group 14.
|
||||
"""
|
||||
a = 0
|
||||
while a < 2:
|
||||
a = number.getRandomNBitInteger(private_bits)
|
||||
|
@ -52,10 +46,6 @@ def generate_keypair(p: int, g: int, private_bits: int = 256) -> tuple[int, int]
|
|||
|
||||
|
||||
def derive_shared_key(peer_public: int, private: int, p: int, key_len: int = 32) -> bytes:
|
||||
"""
|
||||
Compute the shared secret and derive a symmetric key using HKDF-SHA256.
|
||||
Returns key_len bytes (default 32 bytes = 256-bit key).
|
||||
"""
|
||||
shared_secret = pow(peer_public, private, p)
|
||||
# Use fixed-length big-endian encoding of the shared secret for KDF input
|
||||
shared_bytes = int_to_fixed_length_bytes(shared_secret, p.bit_length())
|
||||
|
@ -63,7 +53,6 @@ def derive_shared_key(peer_public: int, private: int, p: int, key_len: int = 32)
|
|||
return key
|
||||
|
||||
|
||||
@dataclass
|
||||
class TimingResult:
|
||||
alice_keygen_s: float
|
||||
bob_keygen_s: float
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue