About ckks_engine
`ckks_engine` is a Rust crate that provides an implementation of the CKKS (Cheon-Kim-Kim-Song) homomorphic encryption scheme. This scheme enables encrypted computations on real numbers and strings while preserving the privacy of the underlying data. With `ckks_engine`, you can perform a wide range of mathematical operations on encrypted data, including addition, subtraction, multiplication, division, exponentiation, and more, with some error accumulation due to the nature of approximate homomorphic encryption.
Key Features
- CKKS Algorithm: Full implementation of CKKS for encrypted computations on real numbers and strings.
- Homomorphic Arithmetic: Secure operations such as addition, subtraction, multiplication, and negation.
- String Operations: Supports encrypted string operations like length calculation, concatenation, and substring extraction.
- Floating-Point Operations: Functions for ceil, floor, round, and truncate on encrypted floating-point numbers.
- Advanced Arithmetic: Division and exponentiation for encrypted data.
- Secure Key Generation: Robust public and secret key management for secure encryption and decryption.
- Utility Functions: Tools for encoding and decoding real numbers and managing polynomial arithmetic.
Version History
- Version 1.0: Initial release with basic CKKS encryption and arithmetic operations.
- Version 2.0: Added floating-point operations and basic string functions.
- Version 3.0: Enhanced with advanced string and arithmetic features.
- Version 4.0: Introduced significant enhancements, robust testing, and improved usability.
Project Architecture
The crate has a modular architecture to support scalability and separation of concerns. Major components include:
- `ckks.rs`: Core CKKS encryption and decryption functions.
- `keygen.rs`: Key generation for public and secret keys.
- `polynomial.rs`: Polynomial structures and operations.
- `utils.rs`: Encoding/decoding of real numbers into polynomials.
- `arithmetic.rs`: Homomorphic arithmetic operations on encrypted data.
- `stringfn.rs`: String processing on encrypted data.
Examples: Encryption and Decryption
Below are examples demonstrating how to encrypt and decrypt both collections and individual values using the ckks_engine
crate.
Encrypt and Decrypt Collections
// Import necessary modules
use ckks_engine::*;
fn encrypt_decrypt_collection_example() {
// Set CKKS parameters
let params = CkksParameters::new(2048, 1000000000000007);
// Key generation
let keygen = KeyGenerator::new();
let (public_key, secret_key) = keygen.generate_keys();
// Initialize encryptor and decryptor
let encryptor = CKKSEncryptor::new(public_key.clone(), params.clone());
let decryptor = CKKSDecryptor::new(secret_key.clone(), params.clone());
// Collection to encrypt
let collection = [1.23, 4.56, 7.89];
// Encrypt the collection
let encrypted_collection = encryptor.encrypt_collection(&collection);
// Decrypt the collection
let decrypted_collection = decryptor.decrypt(&encrypted_collection);
// Output the result
println!("Original: {:?}", collection);
println!("Encrypted: {:?}", encrypted_collection);
println!("Decrypted: {:?}",decrypted_collection);
}
Encrypt and Decrypt a Single Value
// Import necessary modules
use ckks_engine::*;
fn encrypt_decrypt_value_example() {
// Set CKKS parameters
let params = CkksParameters::new(2048, 1000000000000007);
// Key generation
let keygen = KeyGenerator::new();
let (public_key, secret_key) = keygen.generate_keys();
// Initialize encryptor and decryptor
let encryptor = CKKSEncryptor::new(public_key.clone(), params.clone());
let decryptor = CKKSDecryptor::new(secret_key.clone(), params.clone());
// Value to encrypt
let value = 3.14159;
// Encrypt the value
let encrypted_value = encryptor.encrypt_value(value);
// Decrypt the value
let decrypted_value = decryptor.decrypt(&encrypted_value);
// Output the result
println!("Original: {:?}", value);
println!("Encrypted: {:?}", encrypted_value);
println!("Decrypted: {:?}", decrypted_value);
}
Copy and run the above examples in your Rust project to see how ckks_engine
handles encryption and decryption for both collections and individual values.