concrete_shortint/lib.rs
1#![allow(clippy::excessive_precision)]
2//! Welcome the the `concrete-shortint` documentation!
3//!
4//! # Description
5//!
6//! This library makes it possible to execute modular operations over encrypted short integer.
7//!
8//! It allows to execute an integer circuit on an untrusted server because both circuit inputs and
9//! outputs are kept private.
10//!
11//! Data are encrypted on the client side, before being sent to the server.
12//! On the server side every computation is performed on ciphertexts.
13//!
14//! The server however, has to know the integer circuit to be evaluated.
15//! At the end of the computation, the server returns the encryption of the result to the user.
16//!
17//! # Keys
18//!
19//! This crates exposes two type of keys:
20//! * The [ClientKey] is used to encrypt and decrypt and has to be kept secret;
21//! * The [ServerKey] is used to perform homomorphic operations on the server side and it is meant
22//! to be published (the client sends it to the server).
23//!
24//!
25//! # Quick Example
26//!
27//! The following piece of code shows how to generate keys and run a small integer circuit
28//! homomorphically.
29//!
30//! ```rust
31//! use concrete_shortint::{gen_keys, Parameters};
32//!
33//! // We generate a set of client/server keys, using the default parameters:
34//! let (mut client_key, mut server_key) = gen_keys(Parameters::default());
35//!
36//! let msg1 = 1;
37//! let msg2 = 0;
38//!
39//! // We use the client key to encrypt two messages:
40//! let ct_1 = client_key.encrypt(msg1);
41//! let ct_2 = client_key.encrypt(msg2);
42//!
43//! // We use the server public key to execute an integer circuit:
44//! let ct_3 = server_key.unchecked_add(&ct_1, &ct_2);
45//!
46//! // We use the client key to decrypt the output of the circuit:
47//! let output = client_key.decrypt(&ct_3);
48//! assert_eq!(output, 1);
49//! ```
50pub mod ciphertext;
51pub mod client_key;
52pub mod engine;
53#[cfg(any(test, feature = "internal-keycache"))]
54pub mod keycache;
55pub mod parameters;
56pub mod server_key;
57#[cfg(doctest)]
58mod test_user_docs;
59pub mod wopbs;
60
61pub use ciphertext::Ciphertext;
62pub use client_key::ClientKey;
63pub use parameters::Parameters;
64pub use server_key::{CheckError, ServerKey};
65
66/// Generate a couple of client and server keys.
67///
68/// # Example
69///
70/// Generating a pair of [ClientKey] and [ServerKey] using the default parameters.
71///
72/// ```rust
73/// use concrete_shortint::gen_keys;
74///
75/// // generate the client key and the server key:
76/// let (cks, sks) = gen_keys(Default::default());
77/// ```
78pub fn gen_keys(parameters_set: Parameters) -> (ClientKey, ServerKey) {
79 let cks = ClientKey::new(parameters_set);
80 let sks = ServerKey::new(&cks);
81
82 (cks, sks)
83}