Skip to content

Commit

Permalink
Added SEAL_AVOID_BRANCHING option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei Dai committed Mar 16, 2022
1 parent e49178a commit 354c6ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ set_property(CACHE SEAL_DEFAULT_PRNG PROPERTY
STRINGS "Blake2xb" "Shake256")
mark_as_advanced(FORCE SEAL_DEFAULT_PRNG)

# [option] SEAL_AVOID_BRANCHING (default: OFF)
# Avoid branching in conditional move operations if set to ON, use faster method if set to OFF.
set(SEAL_AVOID_BRANCHING_STR "Use an always branching-free conditional move")
option(SEAL_AVOID_BRANCHING ${SEAL_AVOID_BRANCHING_STR} OFF)
message(STATUS "SEAL_AVOID_BRANCHING: ${SEAL_AVOID_BRANCHING}")
mark_as_advanced(FORCE SEAL_AVOID_BRANCHING)

# [option] SEAL_USE_INTRIN (default: ON)
set(SEAL_USE_INTRIN_OPTION_STR "Use intrinsics")
option(SEAL_USE_INTRIN ${SEAL_USE_INTRIN_OPTION_STR} ON)
Expand Down
1 change: 1 addition & 0 deletions native/src/seal/util/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#cmakedefine SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT
#cmakedefine SEAL_USE_GAUSSIAN_NOISE
#cmakedefine SEAL_DEFAULT_PRNG @SEAL_DEFAULT_PRNG@
#cmakedefine SEAL_AVOID_BRANCHING

// Intrinsics
#cmakedefine SEAL_USE_INTRIN
Expand Down
5 changes: 5 additions & 0 deletions native/src/seal/util/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,9 @@ namespace seal

// Conditionally select the former if true and the latter if false
// This is a temporary solution that generates constant-time code with all compilers on all platforms.
#ifndef SEAL_AVOID_BRANCHING
#define SEAL_COND_SELECT(cond, if_true, if_false) (cond ? if_true : if_false)
#else
#define SEAL_COND_SELECT(cond, if_true, if_false) \
((if_false) ^ ((~static_cast<uint64_t>(cond) + 1) & ((if_true) ^ (if_false))))
#endif

0 comments on commit 354c6ba

Please sign in to comment.