Skip to main content

DRES: Danish Resilient Encryption Scheme

PyPI version Python Version License

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:

  1. Asymmetric Key Exchange (DH): Alice and Bob use the Diffie-Hellman protocol to securely establish a Shared Secret over an insecure channel. This provides Perfect Forward Secrecy (PFS).
  2. Secure Key Derivation (HKDF): The Shared Secret is 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.
  3. 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.
  4. 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:

  1. Derive Block Key: A unique AES key (K_i) is derived by hashing the master K_chain with the ciphertext of the previous block (C_i-1).
    • K_i = HMAC(K_chain, C_i-1).digest()[:16]
  2. 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
  3. 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.

Download files

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

Source Distribution

dres-0.2.2.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dres-0.2.2-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

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

Hashes for dres-0.2.2.tar.gz
Algorithm Hash digest
SHA256 28f48294c425be5082d4bd894bd29778a53e20f60a964d3bac5feac554ac77b1
MD5 c45e00e57537864c64c714b198a1341a
BLAKE2b-256 afc9b99dae29b0ad1bd06be771e5d154c9057818f6c4274bcf71f30730aa89a0

See more details on using hashes here.

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

Hashes for dres-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 37ad8d013f4a3c9867180b82d09656f13c278e68fe835e6623a2c2c418b29d82
MD5 5059299246529414dc0ce2690a1ed307
BLAKE2b-256 d007b77157e1df6afbdd0fb245c149fd2e4dec6539e25cfc9173d95d686d50a6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page