Skip to content

Commit

Permalink
Merge 7dfcca2 into 256562a
Browse files Browse the repository at this point in the history
  • Loading branch information
rbost committed Feb 13, 2019
2 parents 256562a + 7dfcca2 commit a665b2f
Show file tree
Hide file tree
Showing 23 changed files with 235 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@ build_test
build_bench
bin
static_analysis
Ubuntu

debug_crypto
check
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -7,3 +7,6 @@
[submodule "externals/googletest"]
path = externals/googletest
url = https://github.com/google/googletest.git
[submodule "externals/cmake-flag-manager"]
path = externals/cmake-flag-manager
url = https://github.com/rbost/cmake-flag-manager.git
100 changes: 70 additions & 30 deletions CMakeLists.txt
Expand Up @@ -19,16 +19,24 @@ list(
APPEND
CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/externals/sanitizers-cmake/cmake"
)

list(
APPEND
CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/externals/cmake-flag-manager/cmake"
)
# Build in Debug mode by default
set(default_build_type "Debug")

# Options
option(opensse_ENABLE_WALL "Enable all warnings" ON)
option(opensse_ENABLE_WEXTRA "Enable extra warnings" ON)
option(opensse_ENABLE_WSHADOW "Enable shadow warning" OFF)
option(opensse_ENABLE_PEDANTIC "Enable pedantic warning" OFF)
option(opensse_ENABLE_PEDANTIC "Enable pedantic warning" ON)
option(opensse_ENABLE_WERROR "Make all warnings into errors" ON)
option(opensse_ENABLE_BASIC_WARNINGS "Enable basic additional warnings" ON)
option(
opensse_ENABLE_ADVANCED_WARNINGS "Enable advanced additional warnings" ON
)
option(
opensse_OPTIMIZE_FOR_NATIVE_ARCH
"Enable compiler optimizations for the native processor architecture (if available)"
Expand All @@ -40,6 +48,8 @@ option(
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

include(FlagManager)

# enable code coverage
find_package(codecov)

Expand All @@ -50,51 +60,77 @@ find_package(Sanitizers)
enable_testing()

if(opensse_ENABLE_WALL)
check_cxx_compiler_flag("-Wall" COMPILER_OPT_WALL_SUPPORTED)
if(COMPILER_OPT_WALL_SUPPORTED)
add_compile_options(-Wall)
endif()
save_compile_option(-Wall)
endif()

if(opensse_ENABLE_WEXTRA)
check_cxx_compiler_flag("-Wextra" COMPILER_OPT_WEXTRA_SUPPORTED)
if(COMPILER_OPT_WEXTRA_SUPPORTED)
add_compile_options(-Wextra)
endif()
save_compile_option(-Wextra)
endif()

if(opensse_ENABLE_WSHADOW)
check_cxx_compiler_flag("-Wshadow" COMPILER_OPT_WSHADOW_SUPPORTED)
if(COMPILER_OPT_WEXTRA_SUPPORTED)
add_compile_options(-Wshadow)
endif()
save_compile_option(-Wshadow)
endif()

if(opensse_ENABLE_PEDANTIC)
check_cxx_compiler_flag("-pedantic" COMPILER_OPT_PEDANTIC_SUPPORTED)
if(COMPILER_OPT_WEXTRA_SUPPORTED)
add_compile_options(-pedantic)
endif()
save_compile_option(-pedantic)
endif()

if(opensse_ENABLE_WERROR)
check_cxx_compiler_flag("-Werror" COMPILER_OPT_WERROR_SUPPORTED)
if(COMPILER_OPT_WERROR_SUPPORTED)
add_compile_options(-Werror -Wno-error=unknown-pragmas)
endif()
save_compile_option(-Wno-error=unknown-pragmas -Werror)
endif()

if(opensse_OPTIMIZE_FOR_NATIVE_ARCH)
check_cxx_compiler_flag("-march=native" COMPILER_OPT_ARCH_NATIVE_SUPPORTED)
if(COMPILER_OPT_ARCH_NATIVE_SUPPORTED)
add_compile_options(-march=native)
endif()
save_compile_option(-march=native)
endif()

if(opensse_ENABLE_BASIC_WARNINGS)

save_compile_option(
-Wmissing-include-dirs
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
-Wctor-dtor-privacy
-Wunsafe-loop-optimizations
-Wuseless-cast
-Wformat=2
-Wcast-qual
-Wcast-align
)
save_compile_option(
-fno-rtti
# -fstack-protector -Wstack-protector
)
endif()

check_c_compiler_flag("-Wpsabi" WARNING_PSABI)
if(WARNING_PSABI)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=psabi")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=psabi")
if(opensse_ENABLE_ADVANCED_WARNINGS)
save_compile_option(
LIST_NAME "Lib_Warnings"
# -Weffc++ # Weffc++ is too annoying on gcc
-Wextra-semi # Extra, unnecessary semicolumns
# -Wsign-conversion # To be enabled
# -Wconversion # Extremely strict on gcc
-Wno-c++98-compat # No need to be C++98 compatible: we require C++11
-Wno-c++98-compat-pedantic
-Wno-error=padded
-Wno-error=source-uses-openmp
-Wno-unused-macros
-Wno-padded
)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")

save_compile_option(
LIST_NAME
"Clang_Lib_Warnings"
-Weverything # All Clang warnings
-Wno-covered-switch-default
-Wno-exit-time-destructors
-Wno-weak-vtables
-Wno-weak-template-vtables
-Wno-documentation-unknown-command
)
endif()
endif()

# This might be redundant with what is done in the main source CMakeLists.txt
Expand Down Expand Up @@ -125,12 +161,16 @@ if(NOT TARGET gtest)
endif()

add_subdirectory(src)
target_apply_saved_options(sse_crypto)
target_apply_saved_options(LIST_NAME "Lib_Warnings" sse_crypto)
target_apply_saved_options(LIST_NAME "Clang_Lib_Warnings" sse_crypto)
add_sanitizers(sse_crypto)
add_coverage(sse_crypto)

# Tests

add_subdirectory(tests)
target_apply_saved_options(check)
add_sanitizers(check)
add_coverage(check)

Expand Down
1 change: 1 addition & 0 deletions externals/cmake-flag-manager
Submodule cmake-flag-manager added at 171ad4
2 changes: 2 additions & 0 deletions fuzzing/CMakeLists.txt
Expand Up @@ -22,6 +22,7 @@ function(add_fuzz_target target_name target_source)
sanitizer_add_flags(${target_name} "libFuzzer" "libFuzzer")

add_dependencies(fuzz ${target_name})
target_apply_saved_options(${target_name})

if(libFuzzer_standalone_FLAG_DETECTED)

Expand All @@ -31,6 +32,7 @@ function(add_fuzz_target target_name target_source)
${target_source}
${ARGN}
)
target_apply_saved_options(${target_name}_standalone)

target_link_libraries(${target_name}_standalone OpenSSE::crypto)
add_sanitizers(${target_name}_standalone)
Expand Down
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -64,6 +64,7 @@ add_library(
mbedtls/rsa.c
)


# Generate PIC for the library
set_target_properties(sse_crypto PROPERTIES POSITION_INDEPENDENT_CODE ON)

Expand All @@ -87,6 +88,12 @@ target_compile_features(
cxx_lambdas
)

target_compile_features(
sse_crypto
PRIVATE
c_std_99
)

target_include_directories(
sse_crypto
PUBLIC
Expand Down
70 changes: 45 additions & 25 deletions src/include/sse/crypto/rcprf.hpp
Expand Up @@ -153,33 +153,49 @@ class RCPrfBase : public RCPrfParams
///
/// @brief Copy constructor
///
RCPrfBase(const RCPrfBase<NBYTES>& rcprf) noexcept = default;
RCPrfBase(const RCPrfBase<NBYTES>& rcprf) noexcept
: tree_height_(rcprf.tree_height_)
{
}
/* LCOV_EXCL_STOP */

///
/// @brief Destructor
///
virtual ~RCPrfBase() = default;

///
//
/// @brief Return the height of the represented tree
///
inline depth_type tree_height() const
{
return tree_height_;
}

///
/// @brief Copy assignment operator
///
/// @param base The object to be copied
///
RCPrfBase<NBYTES>& operator=(const RCPrfBase<NBYTES>& base) noexcept
{
tree_height_ = base.tree_height_;
return *this;
}

protected:
///
/// @brief Compute the direction of the root-to-leaf path at a given depth
/// @brief Compute the direction of the root-to-leaf path at a given
/// depth
///
/// When following the root-to-leaf path, return which of the left of the
/// right child of the node at the given depth we have to take next.
/// When following the root-to-leaf path, return which of the left of
/// the right child of the node at the given depth we have to take next.
///
/// @param leaf The leaf to go to from the tree's root
/// @param node_depth The depth of the node on the root-to-leaf path (a 0
/// node-depth points to the root, a tree_height-1 depth
/// is the leaf).
/// @param node_depth The depth of the node on the root-to-leaf path
/// (a 0
/// node-depth points to the root, a tree_height-1
/// depth is the leaf).
///
/// @return The child to go to in the root-to-leaf path.
///
Expand Down Expand Up @@ -337,7 +353,9 @@ std::array<uint8_t, NBYTES> RCPrfBase<NBYTES>::derive_leaf(
depth_type base_depth,
uint64_t leaf) const
{
assert(this->tree_height() > base_depth + 1);
assert(this->tree_height() >= 2); // this has to be an inner node
// with the previous check, we can substract 1 without risking an underflow
assert(this->tree_height() - 1 > base_depth);

if (this->tree_height() == base_depth + 2) {
// only one derivation to do
Expand All @@ -351,7 +369,9 @@ std::array<uint8_t, NBYTES> RCPrfBase<NBYTES>::derive_leaf(
return result;
}

assert(this->tree_height() - base_depth > 2);
// the previous test ensures that the tree_height is >= 2
assert(this->tree_height() - 2 > base_depth);

// the first step is done from the base PRG
RCPrfTreeNodeChild child = get_child(leaf, base_depth);
Key<kKeySize> subkey
Expand Down Expand Up @@ -484,7 +504,7 @@ class ConstrainedRCPrfElement : public RCPrfBase<NBYTES>
/// height and spanning over the specified leaves range.
///
/// @param height The height of the tree.
/// @param subtree_height The height of the subtree represented by the
/// @param st_height The height of the subtree represented by the
/// element.
/// @param min The minimum leaf index spanned by the
/// subtree.
Expand All @@ -500,20 +520,20 @@ class ConstrainedRCPrfElement : public RCPrfBase<NBYTES>
/// minimum leaf index.
///
ConstrainedRCPrfElement(RCPrfParams::depth_type height,
RCPrfParams::depth_type subtree_height,
RCPrfParams::depth_type st_height,
uint64_t min,
uint64_t max)
: RCPrfBase<NBYTES>(height), subtree_height_(subtree_height),
min_leaf_(min), max_leaf_(max)
: RCPrfBase<NBYTES>(height), subtree_height_(st_height), min_leaf_(min),
max_leaf_(max)
{
if (subtree_height == 0) {
if (st_height == 0) {
/* LCOV_EXCL_START */
// already covered by the subclasses
throw std::invalid_argument("Subtree height should be strictly "
"larger than 0.");
/* LCOV_EXCL_STOP */
}
if (subtree_height >= this->tree_height()) {
if (st_height >= this->tree_height()) {
throw std::invalid_argument(
"Subtree height is not smaller than the tree height");
}
Expand Down Expand Up @@ -668,7 +688,7 @@ class ConstrainedRCPrfInnerElement : public ConstrainedRCPrfElement<NBYTES>
///
/// @param key The value of the subtree's node. The key given as
/// input is moved, and is invalidated.
/// @param subtree_height The height of the subtree represented by the
/// @param st_height The height of the subtree represented by the
/// element.
/// @param min The minimum leaf index spanned by the subtree.
/// @param max The maximum leaf index spanned by the subtree.
Expand All @@ -682,13 +702,13 @@ class ConstrainedRCPrfInnerElement : public ConstrainedRCPrfElement<NBYTES>
///
ConstrainedRCPrfInnerElement(Key<RCPrfParams::kKeySize>&& key,
RCPrfParams::depth_type height,
RCPrfParams::depth_type subtree_height,
RCPrfParams::depth_type st_height,
uint64_t min,
uint64_t max)
: ConstrainedRCPrfElement<NBYTES>(height, subtree_height, min, max),
: ConstrainedRCPrfElement<NBYTES>(height, st_height, min, max),
base_prg_(std::move(key))
{
if (subtree_height <= 1) {
if (st_height <= 1) {
throw std::invalid_argument("Subtree height should be strictly "
"larger than 1 for an inner element.");
}
Expand All @@ -703,7 +723,7 @@ class ConstrainedRCPrfInnerElement : public ConstrainedRCPrfElement<NBYTES>
/// @param subtree_prg The Prg representing the subtree's root. The Prg
/// object is moved by the constructor, and is
/// invalidated.
/// @param subtree_height The height of the subtree represented by the
/// @param st_height The height of the subtree represented by the
/// element.
/// @param min The minimum leaf index spanned by the subtree.
/// @param max The maximum leaf index spanned by the subtree.
Expand All @@ -717,13 +737,13 @@ class ConstrainedRCPrfInnerElement : public ConstrainedRCPrfElement<NBYTES>
///
ConstrainedRCPrfInnerElement(Prg&& subtree_prg,
RCPrfParams::depth_type height,
RCPrfParams::depth_type subtree_height,
RCPrfParams::depth_type st_height,
uint64_t min,
uint64_t max)
: ConstrainedRCPrfElement<NBYTES>(height, subtree_height, min, max),
: ConstrainedRCPrfElement<NBYTES>(height, st_height, min, max),
base_prg_(std::move(subtree_prg))
{
if (subtree_height <= 1) {
if (st_height <= 1) {
throw std::invalid_argument("Subtree height should be strictly "
"larger than 1 for an inner element.");
}
Expand Down Expand Up @@ -1184,7 +1204,7 @@ class ConstrainedRCPrf : public RCPrfBase<NBYTES>
ConstrainedRCPrf& operator=(ConstrainedRCPrf<NBYTES>&& cprf) noexcept
{
static_cast<RCPrfBase<NBYTES>&>(*this)
= std::move(static_cast<RCPrfBase<NBYTES>&&>(cprf));
= static_cast<RCPrfBase<NBYTES>&>(cprf);
elements_ = std::move(cprf.elements_);

return *this;
Expand Down

0 comments on commit a665b2f

Please sign in to comment.