Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from blakehartin/main
Browse files Browse the repository at this point in the history
Hybrid ed25519 Dilithium
  • Loading branch information
DogeProtocol authored Nov 25, 2023
2 parents 3a49e02 + 1b5ba99 commit 7343f48
Show file tree
Hide file tree
Showing 66 changed files with 8,182 additions and 79 deletions.
24 changes: 15 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ if(POLICY CMP0066)
endif()
if(POLICY CMP0067)
cmake_policy(SET CMP0067 NEW)
endif()


endif()

project(hybridpqc C ASM)


option(OQS_DIST_BUILD "Build distributable library with optimized code for several CPU microarchitectures. Enables run-time CPU feature detection." ON)
option(OQS_BUILD_ONLY_LIB "Build only hybridpqc and do not expose build targets for tests, documentation, and pretty-printing available." OFF)
set(OQS_MINIMAL_BUILD "" CACHE STRING "Only build specifically listed algorithms.")
Expand All @@ -41,6 +39,8 @@ set(HYBRIDPQC_VERSION_TEXT "0.0.1-dev")
set(HYBRIDPQC_COMPILE_BUILD_TARGET "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_HOST_SYSTEM}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set( CMAKE_C_FLAGS "-fstack-protector -fstack-protector-all" )
set( CMAKE_CXX_FLAGS "-fstack-protector -fstack-protector-all" )

if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
set(ARCH "x86_64")
Expand Down Expand Up @@ -107,7 +107,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInf
else()
set(OQS_DEBUG_BUILD OFF)
endif()

option(OQS_SPEED_USE_ARM_PMU "Use ARM Performance Monitor Unit during benchmarking" OFF)
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_VENDOR "www.dogeprotocol.org")
Expand All @@ -132,9 +132,10 @@ endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

add_library(hybridpqc SHARED falcon512/codec.c falcon512/common.c falcon512/fft.c falcon512/fpr.c falcon512/keygen.c falcon512/nist.c falcon512/rng.c falcon512/shake.c falcon512/sign.c falcon512/vrfy.c random/randombytes.c "tweetnacl/tweetnacl.c" "hybrid/hybrid.h" "hybrid/hybrid.c")
add_executable(hybridpqctest falcon512/codec.c falcon512/common.c falcon512/fft.c falcon512/fpr.c falcon512/keygen.c falcon512/nist.c falcon512/rng.c falcon512/shake.c falcon512/sign.c falcon512/vrfy.c random/randombytes.c "tweetnacl/tweetnacl.c" "hybrid/hybrid.h" "hybrid/hybrid.c" "tests/test_hybrid.c")

set(SOURCE_FILES falcon512/codec.c falcon512/common.c falcon512/fft.c falcon512/fpr.c falcon512/keygen.c falcon512/nist.c falcon512/rng.c falcon512/shake.c falcon512/sign.c falcon512/vrfy.c dilithium2/ntt.c dilithium2/ntt.h dilithium2/packing.c dilithium2/packing.h dilithium2/params.h dilithium2/poly.c dilithium2/poly.h dilithium2/polyvec.c dilithium2/polyvec.h dilithium2/reduce.c dilithium2/reduce.h dilithium2/rounding.c dilithium2/rounding.h dilithium2/sign.c dilithium2/sign.h dilithium2/symmetric.h dilithium2/symmetric-shake.c sphincs/address.c sphincs/context_shake.c sphincs/fors.c sphincs/hash_shake.c sphincs/merkle.c sphincs/sign.c sphincs/thash_shake_simple.c sphincs/utils.c sphincs/utilsx1.c sphincs/wots.c sphincs/wotsx1.c random/randombytes.c common/fips202.c "common/hybrid-common.c" "tweetnacl/tweetnacl.c" "hybrid-falcon/hybrid.h" "hybrid-falcon/hybrid.c" "hybrid-dilithium/hybrid.h" "hybrid-dilithium/hybrid.c" "hybrid-dilithium-sphincs/hybrid.h" "hybrid-dilithium-sphincs/hybrid.c")
add_library(hybridpqc SHARED ${SOURCE_FILES})
add_executable(hybridpqctest ${SOURCE_FILES} "tests/test_hybrid.c")

set_target_properties(hybridpqc
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
Expand Down Expand Up @@ -220,4 +221,9 @@ install(FILES ${HYBRIDPQC_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hybridpqc)

execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/include/hybridpqc)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${HYBRIDPQC_HEADERS} ${PROJECT_BINARY_DIR}/include/hybridpqc)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${HYBRIDPQC_HEADERS} ${PROJECT_BINARY_DIR}/include/hybridpqc)

# enable testing functionality
enable_testing()

add_test(NAME hybridpqctest COMMAND $<TARGET_FILE:hybridpqctest>)
57 changes: 57 additions & 0 deletions common/compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef PQCLEAN_COMMON_COMPAT_H
#define PQCLEAN_COMMON_COMPAT_H

/* This file serves to solve compatibility issues between different
* versions of compilers.
*
* This file is allowed to use #ifdefs and toggle things by compiler versions.
*/

// From https://github.com/gcc-mirror/gcc/blob/af73a8b2027d9ab64944d7dbbb48e207d7790ce6/gcc/config/i386/avxintrin.h#L62-L71
/* Unaligned versions of the vector types */
#define UNALIGNED_VECTOR_POLYFILL_GCC \
typedef float __m256_u __attribute__ ((__vector_size__ (32), __may_alias__, __aligned__ (1))); \
typedef double __m256d_u __attribute__ ((__vector_size__ (32), __may_alias__, __aligned__ (1))); \
typedef long long __m256i_u __attribute__ ((__vector_size__ (32), __may_alias__, __aligned__ (1)));

#if defined(__GNUC__) && !defined(__clang__)
#include <features.h>

# if !__GNUC_PREREQ(7, 1) // at least GCC 7.1
/* Versions of the GCC pre-7.1 don't have __m256*_u types */
UNALIGNED_VECTOR_POLYFILL_GCC
# endif // __GNUC_PREREQ(7,1)

#elif defined(__GNUC__) && defined(__clang__)

# if __clang__major__ < 9
/* Versions of Clang pre-9.0 don't have __m256*_u types */
UNALIGNED_VECTOR_POLYFILL_GCC
# endif

#elif defined(_MSC_VER)
// MSVC simply doesn't have these types
#define __m256_u __m256
#define __m256d_u __m256d
#define __m256i_u __m256i

#else
#error UNSUPPORTED COMPILER!?!?
#endif // compiler selector

/************************
* Portable VLA support *
************************/

/* To support MSVC use alloca() instead of VLAs. */
#ifdef _MSC_VER
/* MSVC defines _alloca in malloc.h */
# include <malloc.h>
/* Note: _malloca(), which is recommended over deprecated _alloca,
requires that you call _freea(). So we stick with _alloca */
# define PQCLEAN_VLA(__t,__x,__s) __t *__x = (__t*)_alloca((__s)*sizeof(__t))
#else
# define PQCLEAN_VLA(__t,__x,__s) __t __x[__s]
#endif

#endif // PQCLEAN_COMMON_COMPAT_H
Loading

0 comments on commit 7343f48

Please sign in to comment.