Skip to main content

No project description provided

Project description

HomegrownDHE

HomegrownDHE is a Python package that provides an implementation of the Diffie-Hellman key exchange algorithm. It is designed for educational purposes and demonstrates how two participants can securely exchange cryptographic keys over an insecure channel.

Tests (Conda) CodeQL

Installation

To install the package from PyPI, use the following command:

pip install homegrowndhe

Usage

The package provides a main script to demonstrate the Diffie-Hellman key exchange, as well as utility functions for testing and debugging.

Running the Main Script

To run the main script, simply execute the __main__.py file:

python -m homegrowndhe

This will perform a Diffie-Hellman key exchange between two participants and print the results to the console.

Development Mode

To enable development mode, set the DEV_TEST environment variable to True. This will enable additional debug output and run the end-to-end tests:

export DEV_TEST=True
python -m homegrowndhe

Detailed Usage

Here is a detailed breakdown of the available functions and their usage:

main(test_iters=0) -> int

The main function to demonstrate the Diffie-Hellman key exchange between two participants.

  • test_iters: Number of test iterations to run. Defaults to TEST_ITERATIONS.
  • Returns an integer exit code. A non-zero exit code indicates an error.

test_end_to_end(iterations=1)

Function to perform end-to-end tests of the Diffie-Hellman key exchange.

  • iterations: Number of test iterations to run. Defaults to 1.

Utility Functions

The package includes several utility functions for terminal output and numeric operations:

  • twidth(): Returns the terminal width.
  • cprint(*args, padding=3, **kwargs): Centered print with padding.
  • blockprint(txt): Block print with centered text.
  • p_print(*args, **kwargs): Pretty print for development mode.
  • get_digits(s: str) -> str: Extracts digits from a string.
  • is_long_num(_s: str, min_d: int = 100) -> bool: Checks if a string contains a long numeric value.
  • get_long_numerics(s: str, min_d: int = 100) -> List[str]: Extracts long numeric values from a string.

Diffie-Hellman Key Exchange Classes

DiffieHellmanParticipant

A class representing a participant in the Diffie-Hellman key exchange.

  • __init__(self, parameters: DSA.DsaKey): Initializes a participant with given DSA parameters.
  • compute_shared_key(self, other_public_key: int) -> int: Computes the shared key using the other participant's public key.

generate_large_prime_parameters(bits: int = 2048) -> DSA.DsaKey

Generates large prime parameters for the Diffie-Hellman key exchange.

  • bits: The number of bits for the prime number. Defaults to 2048.

Testing

To run the tests, use the following command:

pytest

This will execute the tests defined in the test_homegrowndhe.py file.

License

This project is licensed under the MIT License.


Feel free to modify the README to suit your specific needs or add more sections if necessary.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

homegrowndhe-0.3.3.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

homegrowndhe-0.3.3-py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page