A pure-Python hybrid cryptosystem featuring a novel Evolving-Key Chaining (EKC) mode.
Project description
DRES: Danish Resilient Encryption Scheme
A pure-Python hybrid cryptosystem, introducing a novel mode of operation called Evolving-Key Chaining (EKC).
1. The DRES Hybrid System
DRES is a "hybrid" cryptosystem, meaning it combines the best of asymmetric and symmetric cryptography to achieve a secure, authenticated pipeline:
- Asymmetric Key Exchange (DH): Alice and Bob use the Diffie-Hellman protocol to securely establish a
Shared Secretover an insecure channel. This provides Perfect Forward Secrecy (PFS). - Secure Key Derivation (HKDF): The
Shared Secretis fed into the HMAC-based Key Derivation Function (HKDF). This derives two separate, cryptographically isolated master keys:K_chain: For the novel EKC encryption.K_hmac: For the final message authentication.
- Symmetric Encryption (AES & EKC): The actual plaintext is encrypted using the novel Evolving-Key Chaining (EKC) mode, which uses AES-128 as its core primitive.
- Symmetric Authentication (HMAC): The entire resulting ciphertext is authenticated using HMAC-SHA256 (with
K_hmac) in an "Encrypt-then-MAC" scheme, making it impossible to tamper with the message.
2. Core Innovation: Evolving-Key Chaining (EKC)
This is the unique contribution of the DRES project. Instead of using a standard mode like CBC (which uses one static key), EKC is a new mode where the AES key evolves with every block of data.
This creates a strong, non-parallelizable dependency chain, offering unique security properties.
How EKC Works
For every 16-byte block of plaintext (P_i), the encryption process is as follows:
- Derive Block Key: A unique AES key (
K_i) is derived by hashing the masterK_chainwith the ciphertext of the previous block (C_i-1).K_i = HMAC(K_chain, C_i-1).digest()[:16]
- Chain Plaintext: The current plaintext block (
P_i) is XORed with the previous ciphertext block (C_i-1) for chaining.P_i_mod = P_i XOR C_i-1
- Encrypt Block: The modified plaintext is encrypted with the unique, single-use key
K_i.C_i = AES_Encrypt(K_i, P_i_mod)
Key Security Properties of EKC
- Resists Key-Reuse Attacks: The AES key is new for every single block. A key is never used more than once.
- Strong Avalanche Effect: A one-bit change in any ciphertext block (
C_i) will cause the next block's key (K_i+1) to become completely different, turning all subsequent blocks into random noise. - Sequential-Only Decryption: An attacker must decrypt Block 1 to derive the key for Block 2, and so on. This defeats parallel analysis and makes brute-force attacks exponentially harder.
- Academic Trade-off: This mode is (by design) much slower than standard CBC because it performs one HMAC operation per block. This is the core of the project's security-performance trade-off analysis.
3. Installation
The package is available on the Python Package Index (PyPI):
pip install DRES
4. Quick Start: Encrypt & Decrypt
This example shows a simple, secure encryption from Alice to Bob.
from dres import DRESCipher, KeyExchange
from dres.exceptions import AuthenticationError
# 1. Initialize the cipher engine
cipher = DRESCipher()
# 2. Both parties generate their long-term key pairs.
# (They would share their public keys beforehand)
alice_private, alice_public = KeyExchange.generate_keypair()
bob_private, bob_public = KeyExchange.generate_keypair()
# 3. Alice encrypts a message for Bob using his public key.
# The EKC mode is used automatically.
message = b"This message is secured by the Evolving-Key Chaining (EKC) mode!"
print("Encrypting...")
encrypted_package = cipher.encrypt(message, bob_public)
print(f"Package size: {len(encrypted_package)} bytes")
# 4. Bob receives the package and decrypts it with his private key.
print("Decrypting...")
try:
decrypted_message = cipher.decrypt(encrypted_package, bob_private)
print(f"\n✅ SUCCESS: Decrypted message matches original!")
print(f" '{decrypted_message.decode()}'")
assert message == decrypted_message
except AuthenticationError:
print("\n❌ FAILED: Message authentication failed! Package was tampered with.")
except Exception as e:
print(f"\n❌ FAILED: An unexpected error occurred: {e}")
5. Core Utilities (Pure Python)
This library is a self-contained tool. All major cryptographic components are implemented in pure Python, allowing for easy study and analysis:
KeyExchange: A pure-Python implementation of the Diffie-Hellman protocol, using the 2048-bit MODP group from RFC 3526.
AESCipher: A self-contained, pure-Python implementation of AES-128 (FIPS 197), including SubBytes, ShiftRows, MixColumns, and AddRoundKey.
HKDF: A pure-Python implementation of the RFC 5869 "Extract-and-Expand" Key Derivation Function.
Other Primitives: Utilizes the built-in hashlib (for SHA-256) and hmac modules as the secure foundation for HKDF and EKC.
This library was created by Danish as part of a Master of Technology project.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dres-0.2.2.tar.gz.
File metadata
- Download URL: dres-0.2.2.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28f48294c425be5082d4bd894bd29778a53e20f60a964d3bac5feac554ac77b1
|
|
| MD5 |
c45e00e57537864c64c714b198a1341a
|
|
| BLAKE2b-256 |
afc9b99dae29b0ad1bd06be771e5d154c9057818f6c4274bcf71f30730aa89a0
|
File details
Details for the file dres-0.2.2-py3-none-any.whl.
File metadata
- Download URL: dres-0.2.2-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37ad8d013f4a3c9867180b82d09656f13c278e68fe835e6623a2c2c418b29d82
|
|
| MD5 |
5059299246529414dc0ce2690a1ed307
|
|
| BLAKE2b-256 |
d007b77157e1df6afbdd0fb245c149fd2e4dec6539e25cfc9173d95d686d50a6
|