Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved schemeswitching-data-serializer.h from pke/include/scheme/ckksrns to pke/unittest as it is a collection of special utilities #916

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/pke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ if( BUILD_UNITTESTS )
endif()
add_executable (pke_tests ${PKE_TEST_SRC_FILES} ${UNITTESTMAIN})
set_property(TARGET pke_tests PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/unittest)
target_include_directories(pke_tests PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/unittest")
target_include_directories(pke_tests PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils")
target_include_directories(pke_tests PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils")
target_link_libraries ( pke_tests ${PKELIBS} ${ADDITIONAL_LIBS})
if (NOT ${WITH_OPENMP} )
target_link_libraries ( pke_tests PRIVATE Threads::Threads)
Expand All @@ -80,7 +79,14 @@ if ( BUILD_EXAMPLES)
file (GLOB PKE_EXAMPLES_SRC_FILES CONFIGURE_DEPENDS examples/*.cpp)
foreach (app ${PKE_EXAMPLES_SRC_FILES})
get_filename_component ( exe ${app} NAME_WE )
add_executable ( ${exe} ${app} )
if(${exe} STREQUAL "scheme-switching-serial")
# add schemeswitching-data-serializer.cpp to link line and
# include the unittest/utils directory where schemeswitching-data-serializer.h is
add_executable ( ${exe} ${app} "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils/schemeswitching-data-serializer.cpp")
target_include_directories( ${exe} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils")
else()
add_executable ( ${exe} ${app} )
endif()
set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/pke)
set( PKEAPPS ${PKEAPPS} ${exe} )
target_link_libraries ( ${exe} ${PKELIBS} ${ADDITIONAL_LIBS})
Expand Down
8 changes: 8 additions & 0 deletions src/pke/examples/SCHEME_SWITCHING_CAPABILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,11 @@ respectively, `EvalMaxSchemeSwitching` or `EvalMaxSchemeSwitchingAlt` to obtain
- Computing the min/max via scheme switching is only implemented for vectors of size a power of two.
- Large memory consumption for large number of slots (because of the linear transform required in the switching and that the keys are created with the maximum number of levels)
- Only GINX with uniform ternary secrets is currently supported for scheme switching.


Additional example demonstrating serialization
================================================

The code for this example is located in [scheme-switching-serial.cpp](scheme-switching-serial.cpp). The file provides a simple setup for real number serialization before progressing into the next logical step - serialization and communication between 2 separate entities.
All generated files containing serialized data are stored in the DATAFOLDER directory, which is defined in [scheme-switching-serial.cpp](scheme-switching-serial.cpp). If you want to rename any of those files, you can do so in [src/pke/unittest/utils/schemeswitching-data-serializer.h](src/pke/unittest/utils/schemeswitching-data-serializer.h).

23 changes: 6 additions & 17 deletions src/pke/examples/scheme-switching-serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@
2 separate entities
*/

#include <iomanip>
#include <tuple>
#include <unistd.h>

#include "openfhe.h"
#include "binfhecontext.h"
#include "scheme/ckksrns/schemeswitching-data-serializer.h"

// header files needed for serialization
#include "ciphertext-ser.h"
#include "cryptocontext-ser.h"
#include "key/key-ser.h"
#include "scheme/ckksrns/ckksrns-ser.h"
#include "schemeswitching-data-serializer.h"

#include <iomanip>
#include <tuple>
#include <unistd.h>


using namespace lbcrypto;

Expand All @@ -61,18 +62,6 @@ using namespace lbcrypto;

// Save-Load locations for keys
const std::string DATAFOLDER = "demoData";
std::string ccLocation = "/cryptocontext.txt"; // cc
std::string pubKeyLocation = "/key_pub.txt"; // Pub key
std::string multKeyLocation = "/key_mult.txt"; // relinearization key
std::string rotKeyLocation = "/key_rot.txt"; // automorphism / rotation key
std::string paramssLocation = "/paramss.txt"; // cc
std::string binccLocation = "/bincryptocontext.txt"; // binfhe cc
std::string btRkLocation = "/bt_rk.txt"; // binfhe bootstrapping refreshing key
std::string btSwkLocation = "/bt_swk.txt"; // binfhe bootstrapping rotation key
std::string FHEWtoCKKSKeyLocation = "/key_swkFC.txt"; // switching key from FHEW to CKKS

// Save-load locations for RAW ciphertexts
std::string cipherLocation = "/ciphertext.txt";

// Save-load locations for evaluated ciphertext
std::string cipherArgminLocation = "/ciphertextArgmin.txt";
Expand Down
2 changes: 1 addition & 1 deletion src/pke/unittest/utckksrns/UnitTestSchemeSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
#include "scheme/ckksrns/ckksrns-utils.h"
#include "cryptocontext-ser.h"
#include "scheme/ckksrns/ckksrns-ser.h"
#include "scheme/ckksrns/schemeswitching-data-serializer.h"
#include "ciphertext-ser.h"
#include "key/key-ser.h"
#include "schemeswitching-data-serializer.h"

#include <iostream>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//==================================================================================
#include "scheme/ckksrns/schemeswitching-data-serializer.h"
#include "schemeswitching-data-serializer.h"

#include "ciphertext-ser.h"
#include "cryptocontext-ser.h"
Expand Down