diff --git a/CMakeLists.txt b/CMakeLists.txt index 59387f7b..b66b286f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "~/.cmake/Modules") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "3rd/cmake-modules") set(CMAKE_CXX_STANDARD 11) +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) @@ -301,6 +303,14 @@ define_kem_alg( lightsaber_clean PQCLEAN_LIGHTSABER_CLEAN "${SRC_CLEAN_LIGHTSABER}" "${INC_CLEAN_LIGHTSABER}") +#function(define_frodo_src path) +#endif() +# -rw-r--r-- 1 kris kris 13783 Mar 1 12:35 kem.c +# -rw-r--r-- 1 kris kris 3343 Mar 1 12:35 matrix_shake.c +# -rw-r--r-- 1 kris kris 1426 Mar 1 12:35 noise.c +# -rw-r--r-- 1 kris kris 9202 Mar 1 12:35 util.c + + # AVX2 targets if(${ARCH} STREQUAL "ARCH_x86_64") diff --git a/src/sign/dilithium/dilithium2/clean/rounding.c b/src/sign/dilithium/dilithium2/clean/rounding.c index 9b49fb2f..23310cb1 100644 --- a/src/sign/dilithium/dilithium2/clean/rounding.c +++ b/src/sign/dilithium/dilithium2/clean/rounding.c @@ -1,6 +1,8 @@ #include "params.h" #include "rounding.h" #include +#include +#include /************************************************* * Name: PQCLEAN_DILITHIUM2_CLEAN_power2round @@ -37,14 +39,46 @@ int32_t PQCLEAN_DILITHIUM2_CLEAN_power2round(int32_t *a0, int32_t a) { * Returns a1. **************************************************/ int32_t PQCLEAN_DILITHIUM2_CLEAN_decompose(int32_t *a0, int32_t a) { - int32_t a1; + int32_t a1 = 0; + uint64_t r; + int32_t r0, r1; + + assert(a>0); assert(a>= 36; + r *= 2 * GAMMA2; + r = a - r; + + if (r>(2*GAMMA2)) { + r -= 2*GAMMA2; + } + + r1 = ((int32_t)r)*2*GAMMA2; + + // centrize + if (r > GAMMA2) { + *a0 = (int32_t)r - 2*GAMMA2; + } else { + *a0 = r; + } + + // CASE: r-r0 = q-1 => r1=0, r0 = r0-1 + + // OLD a1 = (a + 127) >> 7; a1 = (a1 * 11275 + (1 << 23)) >> 24; a1 ^= ((43 - a1) >> 31) & a1; - *a0 = a - a1 * 2 * GAMMA2; - *a0 -= (((Q - 1) / 2 - *a0) >> 31) & Q; + // TODO: ten sam trick co w barrett + int32_t a2 = ((uint64_t)a-*a0)/(2*GAMMA2); + + //*a0 = a - a1 * 2 * GAMMA2; + //*a0 -= (((Q - 1) / 2 - *a0) >> 31) & Q; + printf("(%d, %d,\n)", a1, a2); return a1; }