A Python prototype demonstrating authenticated session establishment with:
- secp256k1 elliptic-curve Diffie-Hellman (ECDH)
- deterministic key derivation from a BIP39 mnemonic
- BIP32 extended public keys (xpubs)
- ECDSA signatures for authenticating ephemeral session keys
- AES-256-CBC encryption for an application message
This repository is intended for experimentation and protocol review. It is not production-ready cryptographic software.
The example in server-client.py follows this flow:
- Derive separate server and client keys from deterministic derivation paths.
- Derive an xpub that the client can use to verify server keys.
- Generate an ephemeral secp256k1 key pair for each side.
- Sign each ephemeral public key with the corresponding derived identity key.
- Verify the signatures using the derived or stored public keys.
- Derive a shared AES key with ECDH and a session identifier from the combined public keys.
- Encrypt a message on the client and decrypt it on the server.
- Python 3.9 or newer
- pip
Install the Python dependencies:
python -m pip install cryptography bip-utils bip32 ecdsaFrom the repository directory, run the end-to-end demonstration:
python server-client.pyGenerate and print a secp256k1 private/public key pair:
python test.pyThe output from server-client.py should show successful validation of both session public keys and the original message after decryption.
| File | Purpose |
|---|---|
server-client.py |
End-to-end authenticated ECDH and encrypted-message demonstration |
secp256k1.py |
secp256k1 curve and point arithmetic |
bip.py |
BIP39/BIP32 key derivation, xpub handling, and ECDSA helpers |
aes.py |
AES-CBC encryption and decryption helpers |
coords.py |
Coordinate-related elliptic-curve utilities |
a-ecdh.py |
Additional ECDH experiment |
test.py |
Basic key-generation exercise |
- The mnemonic embedded in
server-client.pyis public and must never be used for real credentials, devices, or funds. - The implementation is educational and has not been audited.
- AES-CBC does not provide message authentication. A production protocol should use an authenticated encryption mode such as AES-GCM or ChaCha20-Poly1305.
- Ephemeral randomness, key storage, key rotation, public-key validation, error handling, and replay protection require additional production design.
This project is distributed under the GNU General Public License v3.0. See LICENSE.