skillfed

spake2

SPAKE2 password-authenticated key exchange (pure python)

spake2 v0.9 708.3K downloads/30d#5,264 on PyPI89
Permissive license MIT DORMANT released

What it is and what it does

SPAKE2 is a pure-Python implementation of the SPAKE2 password-authenticated key exchange protocol. It solves the problem of two parties who only share a weak password needing to establish a strong shared secret for encrypted communication without prior key exchange infrastructure. The protocol resists both passive eavesdropping and active man-in-the-middle attacks: a passive attacker learns nothing about the password or derived key, while an active attacker gets only one guess per protocol execution with no offline dictionary attack possible.

The library provides three main classes: SPAKE2_A and SPAKE2_B for asymmetric roles (typically client and server), and SPAKE2_Symmetric for peer-to-peer scenarios where roles cannot be predetermined. The protocol requires only one message round trip to establish the session key, with an optional second round trip for key confirmation. All messages are bytestrings, and the default security level (Ed25519) produces 33-byte messages. The derived key can be used directly for HMAC or authenticated encryption, or fed into HKDF for deriving additional session keys.

Use it for:

  • Device pairing protocols where one device generates a code and both devices use it as a one-time password to establish trust
  • Login systems where you want to avoid sending plaintext passwords over TLS by having both client and server derive a shared key from the password
  • Peer-to-peer applications needing symmetric key agreement without pre-established infrastructure or certificate authorities
  • Establishing encrypted channels between parties who have only memorized or shared a weak password out-of-band
  • Building key confirmation mechanisms to verify both parties derived the same key before using it for data encryption

Worth the install?

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

Implements SPAKE2, a password-authenticated key exchange (PAKE) algorithm that allows two parties sharing a weak password to derive a strong shared secret for encrypted communication.

Yes, if you need PAKE for password-based key exchange. The implementation is stable (no known vulnerabilities, low install friction), MIT-licensed, and suitable for production use in pairing and login protocols. Dormant maintenance is acceptable for a mature cryptographic algorithm. Verify that the implementation meets your security audit requirements and interoperability needs before deployment.

Install

spake2 on PyPI

pip

pip install spake2

uv

uv add spake2

poetry

poetry add spake2

Installing spake2

Before you install

Low install friction with a single cryptography dependency; dormant maintenance status (last commit 2024-09-25, no releases in 688 days) suggests stability over active development.

License in practice

MIT license permits free use, modification, and distribution with minimal restrictions, making it suitable for both open-source and proprietary projects.

Quickstart

from spake2 import SPAKE2_A, SPAKE2_B

# Client side
s = SPAKE2_A(b"shared_password")
msg_out = s.start()
# send msg_out to server
msg_in = receive_from_server()
key = s.finish(msg_in)

# Server side
q = SPAKE2_B(b"shared_password")
msg_out = q.start()
# send msg_out to client
msg_in = receive_from_client()
key = q.finish(msg_in)

Both parties must agree on their roles (A or B) before the exchange; use SPAKE2_Symmetric for symmetric peer scenarios.

Verify before relying

  • Whether the implementation has undergone formal cryptographic audit or review
  • Performance characteristics and suitability for high-throughput scenarios
  • Interoperability guarantees with other SPAKE2 implementations across languages

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 1 — cryptography
Maintenance dormant — 688 days since the last release
Last repo commit
First released
Downloads 708,346/month — #5,264 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: spake2-0.9-py3-none-any.whl

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Topic :: Security :: Cryptography

Tags

password authenticated key exchangePAKE protocol implementationSPAKE2 cryptographyshared secret from passwordweak password key derivationencrypted channel setupman-in-the-middle resistant auth
cryptographykey-exchangeauthentication

More Cryptography packages