Encryption
Public-Key Encryption
A public-key encryption scheme consists of three algorithms: key_gen, enc and dec.
key_gen(): outputs a tuple(pk, sk)of public key and secret key,enc(pk, m): takes in a messagemand a public keypk, and outputs a ciphertextc,dec(sk, c): takes in a ciphertextcand a secret keysk, and outputs a messagem.
This general behavior is captured by the PKEncryptionScheme trait.
Any explicit implementation fixes the domains of the public key, secret key, message and ciphertext.
When implementing the trait for a struct, then that struct can hold additional public parameters such as the security parameter.
With the provided functionality, it is easy to setup a scheme to encrypt and decrypt a bit:
use qfall_schemes::pk_encryption::{LPR, PKEncryptionScheme};
fn example_lpr() {
// setup public parameters and generate key-pair
let lpr = LPR::default();
let (pk, sk) = lpr.key_gen();
// encrypt and decrypt one bit
let cipher = lpr.enc(&pk, 1);
let m = lpr.dec(&sk, &cipher);
}
We implemented a generic trait to enable multi-bit encryption and decryption for schemes like LWE, Dual LWE, and LPR Encryption, which are in the implemented variant just capable of encrypting one bit.
use qfall_schemes::pk_encryption::{GenericMultiBitEncryption, LPR, PKEncryptionScheme};
fn example_lpr_multi_bit() {
// setup public parameters and generate key-pair
let scheme = LPR::default();
let (pk, sk) = scheme.key_gen();
// encrypt and decrypt multiple bits
let cipher = scheme.enc_multiple_bits(&pk, 15);
let message = scheme.dec_multiple_bits(&sk, &cipher);
}
The ring-based variant of LPR does not have this issue.
It can encrypt multiple bits at once, and is more efficient, as it is based on ideal lattices and thus, based on polynomial rings.
In this case, multiple bits can be encrypted at once with respect to the choice of n.
The implemented public-key encryption schemes can be found in qfall_schemes::pk_encryption.
Although not mandatory, several schemes provide functions to generate suitable public parameters via new_from_n(n) for some provided n, and a default parameter set.