@@ -0,0 +1,95 @@ | |||
############################################################################ | |||
# CMakeLists.txt | |||
# | |||
# Released under the MIT License. See LICENSE.txt for license information. | |||
# | |||
############################################################################ | |||
cmake_minimum_required(VERSION 3.0) | |||
project(DECAF VERSION 0.9.4 LANGUAGES C CXX) | |||
set(DECAF_SO_VERSION "0") | |||
option(ENABLE_SHARED "Build shared library." ON) | |||
option(ENABLE_STATIC "Build static library." ON) | |||
option(ENABLE_STRICT "Build with strict compile options." YES) | |||
option(ENABLE_TESTS "Enable compilation of tests." YES) | |||
if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX) | |||
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) | |||
message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}") | |||
endif() | |||
include(GNUInstallDirs) | |||
include(CheckSymbolExists) | |||
include(CMakePushCheckState) | |||
include_directories( | |||
src/GENERATED/include/ | |||
src/include/ | |||
src/ | |||
${CMAKE_CURRENT_BINARY_DIR} | |||
) | |||
set(STRICT_OPTIONS_CPP ) | |||
set(STRICT_OPTIONS_C ) | |||
set(STRICT_OPTIONS_CXX ) | |||
if(MSVC) | |||
if(ENABLE_STRICT) | |||
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} /WX") | |||
endif() | |||
else() | |||
set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -std=c++11 -O2 ") | |||
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wall -Wuninitialized -Wno-deprecated-declarations -Wno-missing-field-initializers ") | |||
set(STRICT_OPTIONS_C "${STRICT_OPTIONS_C} -std=c99 -O2 -Wstrict-prototypes -Wno-error=strict-prototypes -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer ") | |||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang") | |||
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Qunused-arguments -Wno-array-bounds ") | |||
endif() | |||
if(APPLE) | |||
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wno-error=unknown-warning-option -Qunused-arguments -Wno-tautological-compare -Wno-unused-function -Wno-array-bounds ") | |||
set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -stdlib=libc++ ") | |||
endif() | |||
if(ENABLE_STRICT) | |||
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Werror -Wextra -Wno-unused-parameter -fno-strict-aliasing ") | |||
endif() | |||
endif() | |||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STRICT_OPTIONS_C}") | |||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRICT_OPTIONS_CXX}") | |||
add_subdirectory(src) | |||
if(ENABLE_TESTS) | |||
enable_testing() | |||
add_subdirectory(test) | |||
endif() | |||
include(CMakePackageConfigHelpers) | |||
export(EXPORT ${EXPORT_TARGETS_NAME}Targets | |||
FILE "${CMAKE_CURRENT_BINARY_DIR}/DecafTargets.cmake" | |||
) | |||
configure_file(cmake/DecafConfig.cmake.in | |||
"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake" | |||
@ONLY | |||
) | |||
set(ConfigPackageLocation share/decaf/cmake) | |||
install(EXPORT ${EXPORT_TARGETS_NAME}Targets | |||
FILE DecafTargets.cmake | |||
DESTINATION ${ConfigPackageLocation} | |||
) | |||
install(FILES | |||
"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake" | |||
DESTINATION ${ConfigPackageLocation} | |||
) | |||
# CPack settings | |||
set(CPACK_PACKAGE_NAME "decaf") | |||
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) | |||
set(CPACK_SOURCE_GENERATOR "TGZ") | |||
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") | |||
set(CPACK_SOURCE_IGNORE_FILES | |||
"^${CMAKE_BINARY_DIR}" | |||
"/\\\\..+" | |||
) | |||
include(CPack) |
@@ -0,0 +1,50 @@ | |||
############################################################################ | |||
# decafConfig.cmake | |||
# Copyright (C) 2017 Belledonne Communications, Grenoble France | |||
# | |||
############################################################################ | |||
# | |||
# This program is free software; you can redistribute it and/or | |||
# modify it under the terms of the GNU General Public License | |||
# as published by the Free Software Foundation; either version 2 | |||
# of the License, or (at your option) any later version. | |||
# | |||
# This program is distributed in the hope that it will be useful, | |||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
# GNU General Public License for more details. | |||
# | |||
# You should have received a copy of the GNU General Public License | |||
# along with this program; if not, write to the Free Software | |||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
# | |||
############################################################################ | |||
# | |||
# Config file for the decaf package. | |||
# It defines the following variables: | |||
# | |||
# DECAF_FOUND - system has decaf | |||
# DECAF_INCLUDE_DIRS - the decaf include directory | |||
# DECAF_LIBRARIES - The libraries needed to use decaf | |||
# DECAF_CPPFLAGS - The compilation flags needed to use decaf | |||
if(@ENABLE_SHARED@) | |||
set(DECAF_TARGETNAME decaf) | |||
set(DECAF_LIBRARIES ${DECAF_TARGETNAME}) | |||
else() | |||
set(DECAF_TARGETNAME decaf-static) | |||
if(TARGET ${DECAF_TARGETNAME}) | |||
get_target_property(DECAF_LIBRARIES ${DECAF_TARGETNAME} LOCATION) | |||
get_target_property(DECAF_LINK_LIBRARIES ${DECAF_TARGETNAME} INTERFACE_LINK_LIBRARIES) | |||
if(DECAF_LINK_LIBRARIES) | |||
list(APPEND DECAF_LIBRARIES ${DECAF_LINK_LIBRARIES}) | |||
endif() | |||
endif() | |||
endif() | |||
get_target_property(DECAF_INCLUDE_DIRS ${DECAF_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES) | |||
list(INSERT DECAF_INCLUDE_DIRS 0 "@CMAKE_INSTALL_FULL_INCLUDEDIR@") | |||
list(REMOVE_DUPLICATES DECAF_INCLUDE_DIRS) | |||
set(DECAF_CPPFLAGS @DECAF_CPPFLAGS@) | |||
set(DECAF_FOUND 1) |
@@ -0,0 +1,112 @@ | |||
############################################################################ | |||
# CMakeLists.txt | |||
# | |||
# Released under the MIT License. See LICENSE.txt for license information. | |||
# | |||
############################################################################ | |||
set(DECAF_HEADER_FILES | |||
include/constant_time.h | |||
include/field.h | |||
include/keccak_internal.h | |||
include/portable_endian.h | |||
include/word.h | |||
) | |||
set(DECAF_SOURCE_FILES_C | |||
utils.c | |||
shake.c | |||
sha512.c | |||
spongerng.c | |||
) | |||
# default target arch is arch_32 which shall be generic enough to compile mostly on anything | |||
# target arch dirs: | |||
# global one to get the include/arch_intrinsics.h | |||
# availables: arch_32, arch_arm_32, arch_neon, arch_ref64, arch_x86_64 | |||
set(TARGET_ARCH_DIR arch_32) | |||
# specific to p25519, to get f_impl.c/h in p25519 | |||
#availables: arch_32, arch_ref64, arch_x86_64 | |||
set(TARGET_ARCH_DIR_P25519 arch_32) | |||
# specific to p448, to get f_impl.c/h in p448 | |||
# availables: arch_32, arch_arm_32, arch_neon, arch_ref64, arch_x86_64 | |||
set(TARGET_ARCH_DIR_P448 arch_32) | |||
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") # x86_64 | |||
message("Target architecture is x86_64") | |||
set(TARGET_ARCH_DIR arch_x86_64) | |||
set(TARGET_ARCH_DIR_P25519 arch_x86_64) | |||
set(TARGET_ARCH_DIR_P448 arch_x86_64) | |||
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arch64") # shall be arm64 bits, stick to ref64 | |||
message("Target architecture is 64 bits general purpose(arm64 shall use this)") | |||
set(TARGET_ARCH_DIR arch_ref64) | |||
set(TARGET_ARCH_DIR_P25519 arch_ref64) | |||
set(TARGET_ARCH_DIR_P448 arch_ref64) | |||
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") # is an arm 32 bits, TODO: detect neon features? | |||
message("Target architecture is arm32 no NEON") | |||
set(TARGET_ARCH_DIR arch_arm_32) | |||
set(TARGET_ARCH_DIR_P25519 arch_32) # nothing specific for arm32 on p25519 | |||
set(TARGET_ARCH_DIR_P448 arch_arm_32) | |||
else() # nothing picked yet, stick to the | |||
message("Target architecture is general purpose 32bits") | |||
endif() | |||
include_directories( | |||
${PROJECT_SOURCE_DIR}/src/include/${TARGET_ARCH_DIR} | |||
) | |||
set(DECAF_SOURCE_FILES_CXX | |||
) | |||
add_subdirectory(GENERATED/c/p25519) | |||
add_subdirectory(GENERATED/c/p448) | |||
add_subdirectory(GENERATED/c/curve25519) | |||
add_subdirectory(GENERATED/c/ed448goldilocks) | |||
if(ENABLE_STATIC) | |||
add_library(decaf-static STATIC ${DECAF_HEADER_FILES} ${DECAF_SOURCE_FILES_C} ${DECAF_SOURCE_FILES_CXX} $<TARGET_OBJECTS:p25519> $<TARGET_OBJECTS:p448> $<TARGET_OBJECTS:CURVE25519> $<TARGET_OBJECTS:CURVE448>) | |||
set_target_properties(decaf-static PROPERTIES OUTPUT_NAME decaf) | |||
target_include_directories(decaf-static PUBLIC) | |||
target_link_libraries(decaf-static INTERFACE) | |||
endif() | |||
if(ENABLE_SHARED) | |||
add_library(decaf SHARED ${DECAF_HEADER_FILES} ${DECAF_SOURCE_FILES_C} ${DECAF_SOURCE_FILES_CXX} $<TARGET_OBJECTS:p25519> $<TARGET_OBJECTS:p448> $<TARGET_OBJECTS:CURVE25519> $<TARGET_OBJECTS:CURVE448>) | |||
if(APPLE) | |||
set_target_properties(decaf PROPERTIES LINK_FLAGS "-stdlib=libc++") | |||
endif() | |||
set_target_properties(decaf PROPERTIES VERSION ${DECAF_SO_VERSION}) | |||
target_include_directories(decaf PUBLIC) | |||
target_link_libraries(decaf PRIVATE) | |||
if(MSVC) | |||
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") | |||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/decaf.pdb | |||
DESTINATION ${CMAKE_INSTALL_BINDIR} | |||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE | |||
) | |||
endif() | |||
endif() | |||
endif() | |||
if(ENABLE_STATIC) | |||
install(TARGETS decaf-static EXPORT ${EXPORT_TARGETS_NAME}Targets | |||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | |||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | |||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | |||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE | |||
) | |||
endif() | |||
if(ENABLE_SHARED) | |||
install(TARGETS decaf EXPORT ${EXPORT_TARGETS_NAME}Targets | |||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | |||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | |||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | |||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE | |||
) | |||
endif() | |||
install(DIRECTORY GENERATED/include/ | |||
DESTINATION include/decaf | |||
FILES_MATCHING PATTERN "*.h*" | |||
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ | |||
) |
@@ -0,0 +1,26 @@ | |||
############################################################################ | |||
# CMakeLists.txt | |||
# | |||
# Released under the MIT License. See LICENSE.txt for license information. | |||
# | |||
############################################################################ | |||
include_directories( | |||
${PROJECT_SOURCE_DIR}/src/p25519 | |||
${PROJECT_SOURCE_DIR}/src/GENERATED/c/p25519 | |||
) | |||
include_directories( | |||
${PROJECT_SOURCE_DIR}/src/p25519/${TARGET_ARCH_DIR_P25519} | |||
) | |||
set(CURVE25519_SOURCE_FILES_C | |||
decaf.c | |||
elligator.c | |||
scalar.c | |||
eddsa.c | |||
decaf_tables.c | |||
) | |||
add_library(CURVE25519 OBJECT ${CURVE25519_SOURCE_FILES_C}) | |||
set_target_properties(CURVE25519 PROPERTIES POSITION_INDEPENDENT_CODE True) |
@@ -0,0 +1,26 @@ | |||
############################################################################ | |||
# CMakeLists.txt | |||
# | |||
# Released under the MIT License. See LICENSE.txt for license information. | |||
# | |||
############################################################################ | |||
include_directories( | |||
${PROJECT_SOURCE_DIR}/src/p448 | |||
${PROJECT_SOURCE_DIR}/src/GENERATED/c/p448 | |||
) | |||
include_directories( | |||
${PROJECT_SOURCE_DIR}/src/p448/${TARGET_ARCH_DIR_P448} | |||
) | |||
set(CURVE448_SOURCE_FILES_C | |||
decaf.c | |||
elligator.c | |||
scalar.c | |||
eddsa.c | |||
decaf_tables.c | |||
) | |||
add_library(CURVE448 OBJECT ${CURVE448_SOURCE_FILES_C}) | |||
set_target_properties(CURVE448 PROPERTIES POSITION_INDEPENDENT_CODE True) |
@@ -0,0 +1,28 @@ | |||
############################################################################ | |||
# CMakeLists.txt | |||
# | |||
# Released under the MIT License. See LICENSE.txt for license information. | |||
# | |||
############################################################################ | |||
include_directories( | |||
${PROJECT_SOURCE_DIR}/src/p25519 | |||
${PROJECT_SOURCE_DIR}/src/GENERATED/c/p25519 | |||
) | |||
include_directories( | |||
${PROJECT_SOURCE_DIR}/src/p25519/${TARGET_ARCH_DIR_P25519} | |||
) | |||
set(P25519_HEADER_FILES | |||
f_field.h | |||
${PROJECT_SOURCE_DIR}/src/p25519/${TARGET_ARCH_DIR_P25519}/f_impl.h | |||
) | |||
set(P25519_SOURCE_FILES_C | |||
${PROJECT_SOURCE_DIR}/src/p25519/${TARGET_ARCH_DIR_P25519}/f_impl.c | |||
${PROJECT_SOURCE_DIR}/src/p25519/f_arithmetic.c | |||
f_generic.c | |||
) | |||
add_library(p25519 OBJECT ${P25519_HEADER_FILES} ${P25519_SOURCE_FILES_C}) | |||
set_target_properties(p25519 PROPERTIES POSITION_INDEPENDENT_CODE True) |
@@ -0,0 +1,29 @@ | |||
############################################################################ | |||
# CMakeLists.txt | |||
# | |||
# Released under the MIT License. See LICENSE.txt for license information. | |||
# | |||
############################################################################ | |||
include_directories( | |||
${PROJECT_SOURCE_DIR}/src/p448 | |||
${PROJECT_SOURCE_DIR}/src/GENERATED/c/p448 | |||
) | |||
include_directories( | |||
${PROJECT_SOURCE_DIR}/src/p448/${TARGET_ARCH_DIR_P448} | |||
) | |||
set(P448_HEADER_FILES | |||
f_field.h | |||
${PROJECT_SOURCE_DIR}/src/p448/${TARGET_ARCH_DIR_P448}/f_impl.h | |||
) | |||
set(P448_SOURCE_FILES_C | |||
${PROJECT_SOURCE_DIR}/src/p448/${TARGET_ARCH_DIR_P448}/f_impl.c | |||
${PROJECT_SOURCE_DIR}/src/p448/f_arithmetic.c | |||
f_generic.c | |||
) | |||
add_library(p448 OBJECT ${P448_HEADER_FILES} ${P448_SOURCE_FILES_C}) | |||
set_target_properties(p448 PROPERTIES POSITION_INDEPENDENT_CODE True) |
@@ -0,0 +1,31 @@ | |||
############################################################################ | |||
# CMakeLists.txt | |||
# | |||
# Released under the MIT License. See LICENSE.txt for license information. | |||
# | |||
############################################################################ | |||
if(ENABLE_SHARED) | |||
set(DECAF_LIBRARIES_FOR_TESTER decaf) | |||
else() | |||
set(DECAF_LIBRARIES_FOR_TESTER decaf-static) | |||
endif() | |||
add_executable(decaf_tester test_decaf.cxx) | |||
set_target_properties(decaf_tester PROPERTIES LINKER_LANGUAGE CXX) | |||
target_link_libraries(decaf_tester ${DECAF_LIBRARIES_FOR_TESTER}) | |||
add_executable(ristretto_tester ristretto.cxx) | |||
set_target_properties(ristretto_tester PROPERTIES LINKER_LANGUAGE CXX) | |||
target_link_libraries(ristretto_tester ${DECAF_LIBRARIES_FOR_TESTER}) | |||
add_executable(shakesum_tester shakesum.c) | |||
set_target_properties(shakesum_tester PROPERTIES LINKER_LANGUAGE C) | |||
target_link_libraries(shakesum_tester ${DECAF_LIBRARIES_FOR_TESTER}) | |||
add_executable(bench bench_decaf.cxx) | |||
set_target_properties(bench PROPERTIES LINKER_LANGUAGE CXX) | |||
target_link_libraries(bench ${DECAF_LIBRARIES_FOR_TESTER}) | |||
add_test(NAME decaf COMMAND decaf_tester) | |||
add_test(NAME bench COMMAND bench) | |||