This repository contains a simple, interactive web-based demonstration of the workflow of two fundamental types of Quantum-Resistant Cryptography (PQC) algorithms: a Key Encapsulation Mechanism (KEM) and a Digital Signature Scheme. These algorithms are designed to run on classical computers but are mathematically resistant to attacks from future quantum computers.
Important Disclaimer: This demo uses highly simplified, non-cryptographic operations for illustrative purposes only. It is NOT cryptographically secure and should NEVER be used for real-world encryption or signing. Its sole purpose is to help visualize the conceptual steps involved in PQC.
Post-Quantum Cryptography (PQC), also known as Quantum-Resistant Cryptography, refers to cryptographic algorithms that are believed to be secure against attacks by both classical and quantum computers. Unlike Quantum Key Distribution (QKD), which relies on quantum physics and specialized hardware for key exchange, PQC algorithms are mathematical constructions designed to run on existing classical computing infrastructure. The development of PQC is crucial to protect current and future sensitive data from the threat of sufficiently powerful quantum computers.
This demo illustrates the operational flow of two key PQC primitives:
-
Purpose: KEMs are used to securely establish a shared secret key between two parties (e.g., Alice and Bob) over an insecure communication channel. This shared secret can then be used as a symmetric key for encrypting and decrypting bulk data (e.g., using AES). PQC KEMs are designed to ensure that even a quantum computer cannot break the encapsulation and discover the shared secret.
-
Workflow:
-
Key Generation: Alice generates a public/private key pair (
PK_A,SK_A).PK_Ais made public, whileSK_Aremains secret. -
Encapsulation (by Bob): Bob generates a random session key. He then "encapsulates" this session key using Alice's
PK_A, producing aCiphertext. ThisCiphertextis sent to Alice. -
Decapsulation (by Alice): Alice receives the
Ciphertext. She uses herSK_Ato "decapsulate" theCiphertext, which should yield the same session key that Bob generated. -
Shared Secret: If successful, Alice and Bob now securely share the same session key, which they can use for symmetric encryption.
-
-
Purpose: Digital signatures provide assurance of the authenticity (who sent the message) and integrity (that the message hasn't been altered) of a message. PQC signature schemes are designed so that a quantum computer cannot forge a signature or alter a signed message without detection.
-
Workflow:
-
Key Generation: Alice generates a public/private key pair for signing (
PK_Sig_A,SK_Sig_A).PK_Sig_Ais made public, whileSK_Sig_Aremains secret. -
Signing (by Alice): Alice takes a message and uses her
SK_Sig_Ato compute aSignaturefor that message. -
Verification (by Bob): Bob receives the message, the signature, and Alice's
PK_Sig_A. He usesPK_Sig_Ato verify that theSignatureis valid for that specificMessage. If verification passes, he knows the message came from Alice and has not been tampered with.
-
The HTML and JavaScript code simulate the interactions between Alice and Bob for both KEM and Digital Signature processes.
-
generateSimpleKey(length): A non-cryptographic function that generates a random string of a specifiedlength. This simulates cryptographic keys for demonstration purposes. -
simpleHash(str): A non-cryptographic function that computes a simple hash of a string. This simulates cryptographic hash functions. -
showMessage(element, message, type): A utility to display status messages to the user in the UI, with different styles for success, warning, and error.
-
"Generate Alice's KEM Keys" Button:
-
Action: When clicked, Alice's conceptual public (
kemAlicePk) and private (kemAliceSk) keys are generated as random strings. -
Display: These keys are shown in the respective output boxes.
-
Outcome: Alice is ready to receive encapsulated keys.
-
-
"Bob Encapsulate Key" Button:
-
Prerequisite: Alice's KEM public key must be generated.
-
Action: Bob generates a random
kemBobSessionKey. This key is then "encapsulated" using Alice'skemAlicePk. The encapsulation is simulated bysimpleHash(kemBobSessionKey + kemAlicePk), producingkemCiphertext. -
Display: Bob's generated session key and the ciphertext are shown.
-
Outcome: Bob has created a ciphertext containing a shared secret, ready to be sent to Alice.
-
-
"Alice Decapsulate Key" Button:
-
Prerequisite: Alice's KEM keys must be generated, and Bob must have encapsulated a key.
-
Action: Alice attempts to "decapsulate" the
kemCiphertextusing herkemAliceSk. The demo simulates this by checking if a re-derived hash (simpleHash(kemBobSessionKey + kemAlicePk)) matches thekemCiphertext. -
Display: If successful, Alice's
aliceDecapsulatedKeyDivshows the recovered session key. -
Outcome: A message indicates whether the decapsulation was successful and if Alice and Bob now share the same session key.
-
-
"Generate Alice's Signature Keys" Button:
-
Action: Alice's conceptual public (
sigAlicePk) and private (sigAliceSk) keys for signing are generated as random strings. -
Display: These keys are shown in the respective output boxes.
-
Outcome: Alice is ready to sign messages.
-
-
"Alice Sign Message" Button:
-
Prerequisite: Alice's signature keys must be generated, and a message must be entered in the
messageToSigntextarea. -
Action: Alice "signs" the entered message using her
sigAliceSk. The signing process is simulated bysimpleHash(message + sigAliceSk), producingcurrentSignature. -
Display: The generated signature is shown.
-
Outcome: Alice has created a signature for her message.
-
-
"Copy Alice's Sig Public Key to Bob" Button:
-
Prerequisite: Alice's signature keys must be generated and a message signed.
-
Action: This button simulates sending Alice's
sigAlicePk, themessageToSign, and thegeneratedSignatureto Bob's side for verification. The values are copied to Bob's corresponding input fields. -
Outcome: Bob has all the necessary information to attempt verification.
-
-
"Bob Verify Signature" Button:
-
Prerequisite: All fields on Bob's side (
messageToVerify,signatureToVerify,bobSigPublicKey) must be populated. -
Action: Bob attempts to "verify" the signature. In this simplified demo, verification passes if the
message,signature, andpublicKeyon Bob's side exactly match the original values Alice generated. This illustrates that any tampering with the message or signature would cause verification to fail. -
Outcome: A message indicates whether the signature was successfully verified (confirming authenticity and integrity) or if verification failed (indicating tampering or incorrect keys).
-
-
Access the Canvas: Open the "Conceptual Quantum-Resistant Cryptography (PQC) Demo" Canvas in your environment.
-
Explore KEM:
-
Click "Generate Alice's KEM Keys". Observe Alice's Public and Private Keys.
-
Click "Bob Encapsulate Key". Observe Bob's generated session key and the ciphertext.
-
Click "Alice Decapsulate Key". Observe Alice's decapsulated key and the success message.
-
-
Explore Digital Signatures:
-
Click "Generate Alice's Signature Keys". Observe Alice's Public and Private Keys.
-
Enter a message in the "Message to Sign" textarea.
-
Click "Alice Sign Message". Observe the generated signature.
-
Click "Copy Alice's Sig Public Key to Bob". This populates Bob's verification fields.
-
Click "Bob Verify Signature". Observe the verification result.
-
Test Tampering: Try changing the message or signature on Bob's side before clicking "Bob Verify Signature" to see verification fail.
-
-
HTML5: Provides the structural elements of the web page.
-
Tailwind CSS: Used for responsive design and modern styling, ensuring a clean and intuitive user interface.
-
JavaScript: Implements all the interactive logic for key generation, encapsulation, decapsulation, signing, and verification. It uses simple string operations and hashing for conceptual demonstration, not actual cryptographic primitives.