A simple test implementation of the Kyber-768 and sntrup761 post-quantum cryptographic algorithms using the liboqs library.
β‘ Kyber and sntrup761 are NIST-standardized key encapsulation mechanisms (KEM) designed to be secure against quantum computer attacks.
# Clone the repository
git clone https://github.com/SimedruF/simple_quantum_safe_algorithms.git
cd simple-kyber
# Compile and run
make
./simple_kyber
./simple_ntru_hps2048509
- Features
- Prerequisites
- Installation
- Usage
- API Reference
- Kyber-768 Specifications
- sntrup761 Specifications
- Example Output
- Security Considerations
- Contributing
- Resources
- License
- π Key Generation: Generate Kyber-768 and sntrup761 public/private key pairs
- π Encapsulation: Securely encapsulate shared secrets
- π Decapsulation: Decrypt and retrieve shared secrets
- β Verification: Built-in secret comparison and validation
- π§ͺ Testing: Complete test suite with example usage
- Operating System: Linux, macOS, or Windows (WSL)
- Compiler: GCC 7.0+ or Clang 6.0+
- Libraries: liboqs (Open Quantum Safe)
Ubuntu/Debian:
sudo apt update
sudo apt-get install cmake ninja-build libssl-dev python3-pytest python3-pytest-xdist unzip xsltproc doxygen graphviz astyle valgrind pip3 install pytest pytest-xdist pyyaml
macOS (Homebrew):
brew install liboqs
From Source:
git clone https://github.com/open-quantum-safe/liboqs.git
cd liboqs
mkdir build && cd build
cmake -GNinja -DCMAKE_INSTALL_PREFIX=/usr/local ..
ninja
sudo ninja install
Using Make:
make
Manual Compilation:
gcc -std=c99 -Wall -Wextra -O2 -o simple_kyber simple_kyber.c -loqs
./simple_kyber
./simple_ntru_hps2048509
#include "simple_kyber.h"
int main() {
// Initialize Kyber context
kyber_context_t ctx;
// Generate key pair
if (kyber_keygen(&ctx) != 0) {
fprintf(stderr, "Key generation failed\n");
return 1;
}
// Encapsulate secret
uint8_t shared_secret_a[32], shared_secret_b[32];
uint8_t ciphertext[KYBER768_CIPHERTEXT_BYTES];
kyber_encaps(&ctx, ciphertext, shared_secret_a);
kyber_decaps(&ctx, shared_secret_b, ciphertext);
// Verify secrets match
assert(memcmp(shared_secret_a, shared_secret_b, 32) == 0);
kyber_cleanup(&ctx);
return 0;
}
Function | Description | Returns |
---|---|---|
kyber_keygen(ctx) |
Generate public/private key pair | 0 on success |
kyber_encaps(ctx, ct, ss) |
Encapsulate shared secret | 0 on success |
kyber_decaps(ctx, ss, ct) |
Decapsulate shared secret | 0 on success |
kyber_cleanup(ctx) |
Free allocated memory | void |
typedef struct {
uint8_t public_key[KYBER768_PUBLICKEY_BYTES];
uint8_t secret_key[KYBER768_SECRETKEY_BYTES];
OQS_KEM *kem;
} kyber_context_t;
Parameter | Value | Description |
---|---|---|
Public Key Size | 1,184 bytes | Size of the public key |
Secret Key Size | 2,400 bytes | Size of the private key |
Ciphertext Size | 1,088 bytes | Size of encapsulated secret |
Shared Secret Size | 32 bytes | Size of shared secret |
Security Level | NIST Level 3 | Equivalent to AES-192 |
Base Problem | Module-LWE | Learning With Errors in modules |
Parameter | Value | Description |
---|---|---|
Public Key Size | 1,176 bytes | Size of the public key |
Secret Key Size | 1,416 bytes | Size of the private key |
Ciphertext Size | 1,028 bytes | Size of encapsulated secret |
Shared Secret Size | 32 bytes | Size of shared secret |
Security Level | NIST Level 1 | Equivalent to AES-128 |
Base Problem | NTRU Lattice | Security based on NTRU assumptions |
π Simple Kyber-768 Test Implementation
=====================================
β
Initializing Kyber-768...
β
Generating key pair... (1184B public, 2400B private)
β
Encapsulating shared secret... (32B secret β 1088B ciphertext)
β
Decapsulating shared secret... (1088B ciphertext β 32B secret)
β
Verifying shared secrets match...
π All tests passed successfully!
Performance Stats:
ββ Key Generation: 0.15ms
ββ Encapsulation: 0.09ms
ββ Decapsulation: 0.12ms
π Simple sntrup761 Test Implementation
=====================================
β
Initializing sntrup761...
β
Generating key pair... (1176B public, 1416B private)
β
Encapsulating shared secret... (32B secret β 1028B ciphertext)
β
Decapsulating shared secret... (1028B ciphertext β 32B secret)
β
Verifying shared secrets match...
π All tests passed successfully!
Performance Stats:
ββ Key Generation: 0.10ms
ββ Encapsulation: 0.08ms
ββ Decapsulation: 0.11ms
β οΈ Important: This is a demonstration implementation for educational purposes.
For production use:
- β Use cryptographically secure random number generators
- β Implement secure memory management (zero on free)
- β Add proper error handling and input validation
- β Use audited and certified implementations
- β Follow secure coding practices
Known Limitations:
- π¨ No side-channel attack protection
- π¨ Basic error handling only
- π¨ Not constant-time implementation
We welcome contributions! Please see our Contributing Guidelines.
# Clone with development dependencies
git clone --recursive https://github.com/SimedruF/simple_quantum_safe_algorithms.git
cd simple-kyber
# Install development tools
make dev-setup
# Run tests
make test
# Run static analysis
make lint
- π Bug Reports: Use the bug report template
- π‘ Feature Requests: Use the feature request template
- π Security Issues: Email [email protected]
- π liboqs Documentation
- π NIST Post-Quantum Standards
- π¬ Kyber Specification
- π¬ NTRUPrime/sntrup761 Specification
This project is licensed under the MIT License - see the LICENSE file for details.
- Open Quantum Safe Project for the liboqs library
- CRYSTALS Team for the Kyber algorithm
- NTRUPrime Team for the sntrup761 algorithm
- NIST for post-quantum cryptography standardization
Made with β€οΈ for the post-quantum future
β Star this repo β’ π Report Bug β’ π‘ Request Feature