ckks_engine

Module keygen

Source

About the `keygen` Module

The `keygen` module in the ckks_engine crate is responsible for generating the public and secret keys required for the Cheon-Kim-Kim-Song (CKKS) encryption scheme. It provides a robust and secure mechanism to generate key pairs, ensuring privacy and integrity in encrypted computations.

Key Features

  • Public Key: Contains two polynomials (pk_0 and pk_1) that are used for encrypting plaintext data.
  • Secret Key: A single polynomial that is used to decrypt ciphertexts back to their original plaintext values.
  • Random Polynomial Generation: Securely generates random polynomials for keys using a customizable degree and modulus.
  • Noise Injection: Adds controlled noise to the public key for enhanced security.

How It Works

The `keygen` module uses a random number generator to create polynomials representing the secret key and public key. The public key consists of two polynomials: one derived from the secret key and a random polynomial, and another as a purely random polynomial. Noise is added to the public key to ensure security against cryptographic attacks.

The secret key is kept private and is used for decryption, while the public key is shared for encryption. Together, these keys enable secure homomorphic operations on encrypted data in the CKKS encryption scheme.

Usage

To generate a key pair, create an instance of the KeyGenerator struct and call the generate_keys() function. The returned key pair can then be used with the ckks module for encryption and decryption operations.

Example:

            
// Import the module
use ckks_engine::keygen::KeyGenerator;

fn main() {
    // Create a KeyGenerator
    let keygen = KeyGenerator::new();

    // Generate public and secret keys
    let (public_key, secret_key) = keygen.generate_keys();

    println!("Public Key: {:?}", public_key);
    println!("Secret Key: {:?}", secret_key);
}
            
          

Structsยง