skillfed

diffiehellmanlib

Diffie-Hellman key exchange library

diffiehellmanlib v5.0.1 73.8K downloads/30d#14,925 on PyPI
Permissive license MIT AGING released

What it is and what it does

DiffieHellmanLib is a Python cryptography library that implements the Diffie-Hellman key exchange protocol, with core functions written in Rust for performance. It generates cryptographically secure parameters (a large prime p and primitive root g), creates private and public key pairs for two parties, and computes a shared secret that both parties can derive independently. The library supports prime sizes from 512 to 8192 bits, with 2048 bits recommended for production use; it includes caching of generated primes with a 1-hour TTL and applies SHA-256 hashing plus HKDF to the final shared secret for additional security.

The package has no runtime dependencies and is designed for scenarios where two parties need to establish a shared encryption key over an untrusted channel. It requires Python 3.7 or higher and depends on precompiled wheels for most users, though source builds require Rust and the maturin build tool.

Use it for:

  • Establishing encrypted communication channels between two peers in a distributed system
  • Generating shared encryption keys for secure message exchange protocols
  • Testing cryptographic implementations that require Diffie-Hellman parameter generation
  • Building key agreement mechanisms for IoT or embedded systems requiring lightweight crypto
  • Implementing forward-secret session key derivation in custom authentication schemes

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Generates Diffie-Hellman key exchange parameters and performs shared secret computation using cryptographically secure operations with Rust-backed performance.

Yes, if you need a straightforward Diffie-Hellman implementation with Rust-backed performance and no external crypto dependencies. The MIT license and zero runtime dependencies make it low-friction to integrate. However, note that the project shows aging maintenance (last release 533 days ago) and prebuilt wheels are limited to Linux x64 and Windows x64; other platforms require a source build with Rust tooling. For production use, verify that 2048-bit or larger primes are enforced and that parameter transmission is authenticated.

Install

diffiehellmanlib on PyPI

pip

pip install diffiehellmanlib

uv

uv add diffiehellmanlib

poetry

poetry add diffiehellmanlib

Installing diffiehellmanlib

Before you install

Medium install friction due to compiled wheels; prebuilt binaries available for Linux x64 and Windows, but source builds require Rust and maturin. Last release 533 days ago; maintenance status is aging.

License in practice

MIT license permits commercial and private use with minimal restrictions; attribution appreciated but not legally required.

Quickstart

import diffiehellmanlib as dh

# Generate parameters
p, g = dh.generate_p_g(2048)

# Generate Alice's keys
a = dh.generate_a_or_b(p)
A = dh.generate_A_or_B(p, g, a)

# Generate Bob's keys
b = dh.generate_a_or_b(p)
B = dh.generate_A_or_B(p, g, b)

# Compute shared secret
shared_key = dh.generate_shared_key(B, p, a)

Requires Python 3.7 or higher; prebuilt wheels available only for Linux x64 and Windows x64—other platforms need Rust and maturin installed to build from source.

Verify before relying

  • Whether prebuilt wheels cover all target platforms beyond Linux x64 and Windows x64
  • Current state of the repository and whether it remains actively maintained
  • Performance characteristics on systems other than the documented Intel Core i3-7gen baseline

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.7)
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance aging — 533 days since the last release
First released
Downloads 73,822/month — #14,925 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: diffiehellmanlib-5.0.1-cp312-cp312-manylinux_2_34_x86_64.whl; diffiehellmanlib-5.0.1-cp312-cp312-win_amd64.whl

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Rust

Tags

diffie-hellman key exchangeshared secret generationcryptographic key agreementDH protocol implementationkey exchange librarypublic key cryptographysecure parameter generation
key-exchangecryptographyrust-backed

More Cryptography packages