Browse Source

Documents updated, examples synchronized

Hovsep Papoyan 1 year ago
parent
commit
b74e9e9324

+ 3 - 3
docs/source/base_types_and_alg.rst

@@ -21,13 +21,13 @@ Params
 
 The Params policy type stores flags and parameters for the FHE algorithms to use.
 
-There are different ways to generate a Params type instance, but the main way is to create a mutable object by calling ``GetParams%scheme_name%`` and setting the options after that. For the CKKS scheme, it will be ``GetParamsCKKSRNS``.
+There are different ways to generate a Params type instance, but the main way is to create a mutable object by calling ``GenParams%scheme_name%`` and setting the options after that. For the CKKS scheme, it will be ``GenParamsCKKSRNS``.
 
 CryptoContext
 -------------
 
 CryptoContext type, as its name stands, stores the metadata of your FHE context. You usually create its instance using one of the following functions:
 
-- By generating the CryptoContext directly - ``ffi::GenCryptoContextByParamsCKKSRNS``
-- By deserializing a CryptoContext generated somewhere else - ``ffi::DeserializeCryptoContextFromFile``
+- By generating the CryptoContext directly - ``ffi::DCRTPolyGenCryptoContextByParams%scheme_name%``
+- By deserializing a CryptoContext generated somewhere else - ``ffi::DCRTPolyDeserializeCryptoContextFromFile``
 

+ 7 - 8
docs/source/function_evaluation.rst

@@ -26,18 +26,17 @@ Our Rust wrapper is based on the original OpenFHE interface; `EvalLogistic` func
   A higher degree gives a more precise estimate but takes longer to run.
 
 Running the example
--------------------
+~~~~~~~~~~~~~~~~~~~~
 
-1. Ensure the `openfhe-rs` library is installed and properly configured, see the `Installation guide <../getting-started/installation.md>`.
-2. Go to the `examples` directory and make sure that the needed example is there - `function_evaluation.rs`.
-3. Compile and run the Rust file:
+1. Ensure the `openfhe-rs` library is installed and properly configured, see the :doc:`intro` section.
+2. Go to the `openfhe-rs` directory.
+3. Compile and run the `function_evaluation.rs` example:
 
-   .. code-block:: sh
+.. code-block:: sh
 
-      rustc function_evaluation.rs -o function_evaluation
-      ./function_evaluation
+    cargo run --example function_evaluation
 
-   This should output the results of the homomorphic computations to the console.
+This should output the results of the homomorphic computations to the console.
 
 How to choose a multiplicative depth
 -------------------------------------

+ 14 - 13
docs/source/intro.rst

@@ -22,19 +22,10 @@ Prerequisites
 Ensure you have the following dependencies installed:
 
 - `CMake >= 3.5.1`
-- `Clang >= 12.0` or `GCC >= 11.4`
+- `G++ >= 11.4`
 - `Rust >= 1.78`
 - `Git`
 
-Unix
-~~~~
-
-On Debian-based systems, you can install the necessary dependencies using:
-
-.. code-block:: bash
-
-    sudo apt install build-essential libssl-dev cmake clang git
-
 Installation process
 ---------------------
 
@@ -95,10 +86,20 @@ You also need to add a small piece of code for the core dependencies' configurat
         println!("cargo::rustc-link-arg=-Wl,-rpath=/usr/local/lib");
     }
 
-Template repository
-~~~~~~~~~~~~~~~~~~~
+To build and run a complete working example, go to the `crate_usage <https://github.com/fairmath/openfhe-rs/tree/master/crate_usage>`_ directory
+(assuming that the OpenFHE library is already installed),
+
+1. Build the application
+
+.. code-block:: bash
+
+    cargo build
+
+2. Run
+
+.. code-block:: bash
 
-Instead of doing it manually, you can start your project by forking our `template repository <https://github.com/fairmath/openfhe-rs-template/tree/main>`_.
+    cargo run
 
 Custom crate installation from the source
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 7 - 8
docs/source/polynomial_evaluation.rst

@@ -28,15 +28,14 @@ Our Rust wrapper is based on the original OpenFHE interface; `EvalPoly` function
 For this example, we set the multiplicative depth at 6 and the scaling mod size at 50.
 
 Running the example
--------------------
+~~~~~~~~~~~~~~~~~~~~
 
-1. Ensure the `openfhe-rs` library is installed and properly configured, see the `Installation guide <../getting-started/installation.md>`.
-2. Go to the `examples` directory and make sure that the needed example is there - `polynomial_evaluation.rs`.
-3. Compile and run the Rust file:
+1. Ensure the `openfhe-rs` library is installed and properly configured, see the :doc:`intro` section.
+2. Go to the `openfhe-rs` directory.
+3. Compile and run the `polynomial_evaluation.rs` example:
 
-   .. code-block:: sh
+.. code-block:: sh
 
-      rustc polynomial_evaluation.rs -o polynomial_evaluation
-      ./polynomial_evaluation
+    cargo run --example polynomial_evaluation
 
-   This should output the results of the homomorphic computations to the console.
+This should output the results of the homomorphic computations to the console.

+ 9 - 10
docs/source/simple_integers.rst

@@ -4,7 +4,7 @@ Homomorphic additions, multiplications, and rotations for vectors of integers vi
 Overview
 --------
 
-This Rust example demonstrates basic homomorphic encryption operations such as addition, multiplication, and rotation on vectors of integers using the BFVrns3 scheme provided by the `openfhe` library. The example walks through the setup of cryptographic parameters, key generation, encryption of plaintext vectors, performing homomorphic operations, and decrypting the results. The example for this code is located in :code:`examples/simple_integers.rs`.
+This Rust example demonstrates basic homomorphic encryption operations such as addition, multiplication, and rotation on vectors of integers using the BFVrns3 scheme provided by the `openfhe` library. The example walks through the setup of cryptographic parameters, key generation, encryption of plaintext vectors, performing homomorphic operations, and decrypting the results. The example for this code is located in :code:`examples/simple_integers.rs <https://github.com/fairmath/openfhe-rs/blob/master/examples/simple_integers.rs>`_.
 
 Code breakdown
 --------------
@@ -42,10 +42,10 @@ We create a crypto context based on the defined parameters and enable necessary
 
 .. code-block:: rust
 
-    let _cc = ffi::GenCryptoContextByParamsBFVRNS(&_cc_params_bfvrns);
-    _cc.Enable(ffi::PKESchemeFeature::PKE);
-    _cc.Enable(ffi::PKESchemeFeature::KEYSWITCH);
-    _cc.Enable(ffi::PKESchemeFeature::LEVELEDSHE);
+    let _cc = ffi::DCRTPolyGenCryptoContextByParamsBFVRNS(&_cc_params_bfvrns);
+    _cc.EnableByFeature(ffi::PKESchemeFeature::PKE);
+    _cc.EnableByFeature(ffi::PKESchemeFeature::KEYSWITCH);
+    _cc.EnableByFeature(ffi::PKESchemeFeature::LEVELEDSHE);
 
 Key Generation
 ~~~~~~~~~~~~~~
@@ -62,7 +62,7 @@ We generate the necessary keys for encryption, including evaluation keys for mul
     _index_list.pin_mut().push(2);
     _index_list.pin_mut().push(-1);
     _index_list.pin_mut().push(-2);
-    _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::GenNullPublicKey());
+    _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::DCRTPolyGenNullPublicKey());
 
 Plaintext Vector Creation
 ~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -110,12 +110,11 @@ Running the example
 ~~~~~~~~~~~~~~~~~~~~
 
 1. Ensure the `openfhe-rs` library is installed and properly configured, see the :doc:`intro` section.
-2. Go to the `examples` directory and make sure that the needed example is there - `simple_integers.rs`.
-3. Compile and run the Rust file:
+2. Go to the `openfhe-rs` directory.
+3. Compile and run the `simple_integers.rs` example:
 
 .. code-block:: sh
 
-    rustc simple_integers.rs -o simple_integers
-    ./simple_integers
+    cargo run --example simple_integers
 
 This should output the results of the homomorphic computations to the console.

+ 17 - 16
docs/source/simple_real_numbers.rst

@@ -6,7 +6,7 @@ Overview
 
 Homomorphic encryption allows computations on encrypted data without decrypting it. The CKKS (Cheon-Kim-Kim-Song) scheme supports approximate arithmetic operations on encrypted data, making it suitable for real number calculations.
 
-The example walks through the setup of cryptographic parameters, key generation, encryption of plaintext vectors, performing homomorphic operations, and decrypting the results. The example for this code is located in :code:`examples/simple_real_numbers.rs`.
+The example walks through the setup of cryptographic parameters, key generation, encryption of plaintext vectors, performing homomorphic operations, and decrypting the results. The example for this code is located in :code:`examples/simple_real_numbers.rs <https://github.com/fairmath/openfhe-rs/blob/master/examples/simple_real_numbers.rs>`_.
 
 Code breakdown
 --------------
@@ -18,7 +18,7 @@ We start by importing the necessary libraries and modules:
 
 .. code-block:: rust
 
-    use openfhe::cxx::{CxxVector, SharedPtr};
+    use openfhe::cxx::{CxxVector};
     use openfhe::ffi as ffi;
 
 The code example
@@ -28,7 +28,8 @@ The :code:`main` function contains the entire workflow for setting up the CKKS s
 
 .. code-block:: rust
 
-    fn main() {
+    fn main()
+    {
         // Define cryptographic parameters for CKKS
         let _mult_depth: u32 = 1;
         let _scale_mod_size: u32 = 50;
@@ -55,10 +56,10 @@ We create a crypto context based on the defined parameters and enable necessary
 .. code-block:: rust
 
     // Create crypto context based on parameters
-    let _cc = ffi::GenCryptoContextByParamsCKKSRNS(&_cc_params_ckksrns);
-    _cc.Enable(ffi::PKESchemeFeature::PKE);
-    _cc.Enable(ffi::PKESchemeFeature::KEYSWITCH);
-    _cc.Enable(ffi::PKESchemeFeature::LEVELEDSHE);
+    let _cc = ffi::DCRTPolyGenCryptoContextByParamsCKKSRNS(&_cc_params_ckksrns);
+    _cc.EnableByFeature(ffi::PKESchemeFeature::PKE);
+    _cc.EnableByFeature(ffi::PKESchemeFeature::KEYSWITCH);
+    _cc.EnableByFeature(ffi::PKESchemeFeature::LEVELEDSHE);
 
     // Outputing the ring dimension for clarity
     println!("CKKS scheme is using ring dimension {}\n", _cc.GetRingDimension());
@@ -78,7 +79,7 @@ We generate the necessary keys for encryption, including evaluation keys for mul
     let mut _index_list = CxxVector::<i32>::new();
     _index_list.pin_mut().push(1);
     _index_list.pin_mut().push(-2);
-    _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::GenNullPublicKey());
+    _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::DCRTPolyGenNullPublicKey());
 
 Creating Input Vectors
 ~~~~~~~~~~~~~~~~~~~~~~
@@ -106,8 +107,9 @@ We convert the input vectors into plaintext objects.
 .. code-block:: rust
 
     // Create plaintext objects from vectors
-    let _p_txt_1 = _cc.MakeCKKSPackedPlaintext(&_x_1, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
-    let _p_txt_2 = _cc.MakeCKKSPackedPlaintext(&_x_2, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
+    let _dcrt_poly_params = ffi::DCRTPolyGenNullParams();
+    let _p_txt_1 = _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_1, 1, 0, &_dcrt_poly_params, 0);
+    let _p_txt_2 = _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_2, 1, 0, &_dcrt_poly_params, 0);
 
     // Outputing the vectors for clarity
     println!("Input x1: {}", _p_txt_1.GetString());
@@ -181,15 +183,14 @@ Finally, we decrypt the results of the homomorphic computations and print them.
     println!("x1 rotate by -2 = {}", _result.GetString());
 
 Running the example
---------------------
+~~~~~~~~~~~~~~~~~~~~
 
-1. Ensure the `openfhe-rs` library is installed and properly configured, see the `Installation guide <../getting-started/installation.md>`_.
-2. Go to the `examples` directory and make sure that the needed example is there - `simple_real_numbers.rs`.
-3. Compile and run the Rust file:
+1. Ensure the `openfhe-rs` library is installed and properly configured, see the :doc:`intro` section.
+2. Go to the `openfhe-rs` directory.
+3. Compile and run the `simple_real_numbers.rs` example:
 
 .. code-block:: sh
 
-    rustc simple_real_numbers.rs -o simple_real_numbers
-    ./simple_real_numbers
+    cargo run --example simple_real_numbers
 
 This should output the results of the homomorphic computations to the console.