Hybrid PQC

Kodium provides high-performance, pure Kotlin support for Post-Quantum Cryptography (PQC). Our implementation follows the Hybrid Approach, which is currently recommended by global cybersecurity agencies (such as NIST and ANSSI) for transitioning to a quantum-resistant future.

🛡 The Hybrid Approach

Quantum computers, while not yet powerful enough to break modern encryption, pose a future threat to classical asymmetric algorithms like RSA and Elliptic Curve Cryptography (including X25519).

To mitigate this risk without sacrificing the proven security of classical methods, Kodium's PQC suite uses a hybrid model:

  1. Classical Layer: Uses X25519 (Curve25519) Diffie-Hellman.

  2. Quantum Layer: Uses ML-KEM-768 (FIPS 203), formerly known as Kyber.

The secrets from both layers are mixed using HKDF-SHA256. This ensures that the resulting encryption is:

  • At least as secure as X25519 (if ML-KEM is ever found to have a flaw).

  • Secure against Quantum Computers (if X25519 is ever broken by a large-scale quantum machine).


🔑 Key Management

PQC keys are significantly larger than classical keys. Kodium uses dedicated classes to ensure type safety and prevent accidental misuse.

1. Generating Keys

// Generates a hybrid key pair
val myKeys: KodiumPqcPrivateKey = Kodium.pqc.generateKeyPair()

// Extract the public part to share with others
val myPublicKey: KodiumPqcPublicKey = myKeys.getPublicKey()

2. Exporting and Importing

Keys are exported as Base58-encoded strings with checksums for easy storage.

Key Size Reference:

Key Type
Raw Size (approx)
B58 Encoded Size

Classical PK

32 Bytes

~44 chars

Hybrid PQC PK

1,216 Bytes

~1,600 chars


📦 Basic Encryption & Decryption

The Kodium.pqc namespace mirrors the standard Kodium API but requires PQC-specific key types.


🔄 Double Ratchet & PQXDH Integration

The Double Ratchet algorithm in Kodium has been fully upgraded to support a Post-Quantum Cryptographic Suite. This allows you to establish end-to-end encrypted sessions that are resistant to "Harvest Now, Decrypt Later" attacks.

Example: P2P Secure Chat (Post-Quantum)

This example demonstrates how Alice and Bob can securely exchange messages using the PQDoubleRatchetSession across the typical phases of an E2EE chat application.

Phase 1: Account Creation & Key Publishing

Users Alice and Bob create their accounts. During registration, their devices generate the necessary cryptographic keys, including the new Hybrid PQC Keys, and publish them to a central server.

Phase 2: Alice Initiates Contact

Alice starts a chat with Bob. Her device fetches Bob's public bundle from the server and computes the quantum-resistant shared secret.

Phase 3: Bob Responds & Secure Chat Continues

Bob receives Alice's request. His device uses his private keys and Alice's provided payload to compute the identical shared secret and initialize his session.

Protocol Changes

When PQC is enabled in a Double Ratchet session via PQDoubleRatchetSession:

  • Handshake: The initial key exchange (PQXDH) includes an ML-KEM encapsulation alongside the standard X25519 prekeys.

  • Ratchet Steps: Every asymmetric ratchet step performs both an X25519 DH exchange and an ML-KEM encapsulation/decapsulation to the static long-term keys. The secrets are combined using HKDF to derive the new root key.

  • Header Size: Message headers are larger. A classical Double Ratchet header is 40 bytes. A PQRatchetHeader carries the ML-KEM ciphertext (1088 bytes for ML-KEM-768), bringing the header size to 1,128 bytes.


⚡️ Technical Specifications

  • Standard: NIST FIPS 203 (ML-KEM).

  • Security Level: ML-KEM-768 (equivalent to AES-192/RSA-4096 quantum security).

  • KDF: HKDF-SHA256 for secret mixing.

  • Cipher: XSalsa20-Poly1305 (via NaCl SecretBox).


Note: PQC is a rapidly evolving field. This implementation is based on the finalized FIPS 203 standard. As with all cryptography, ensure your library is kept up to date.

Last updated