Skip to content

SimedruF/simple_quantum_safe_algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Simple Kyber & sntrup761 Implementation

License: MIT C Security

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.

πŸš€ Quick Start

# 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

πŸ“‹ Table of Contents

✨ Features

  • πŸ”‘ 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

πŸ“¦ Prerequisites

  • Operating System: Linux, macOS, or Windows (WSL)
  • Compiler: GCC 7.0+ or Clang 6.0+
  • Libraries: liboqs (Open Quantum Safe)

πŸ› οΈ Installation

Install liboqs

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

Compile the Project

Using Make:

make

Manual Compilation:

gcc -std=c99 -Wall -Wextra -O2 -o simple_kyber simple_kyber.c -loqs

🎯 Usage

Basic Example

./simple_kyber
./simple_ntru_hps2048509

Integration in Your Code

#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;
}

πŸ“š API Reference

Core Functions

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

Data Structures

typedef struct {
    uint8_t public_key[KYBER768_PUBLICKEY_BYTES];
    uint8_t secret_key[KYBER768_SECRETKEY_BYTES];
    OQS_KEM *kem;
} kyber_context_t;

πŸ“Š Kyber-768 Specifications

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

πŸ“Š sntrup761 Specifications

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

πŸ’» Example Output

πŸ” 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

πŸ”’ Security Considerations

⚠️ 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

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines.

Development Setup

# 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

Reporting Issues

πŸ“– Resources

Documentation

Related Projects

Academic Papers

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


Made with ❀️ for the post-quantum future

⭐ Star this repo β€’ πŸ› Report Bug β€’ πŸ’‘ Request Feature

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published