diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..add2a728 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/build/ +/.idea/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b23f9b4a..b531dab0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,16 +113,21 @@ set( ) find_path(GMP_INCLUDE_DIR NAMES gmp.h) -find_library(GMP_LIBRARIES NAMES gmp libgmp) -find_library(GMPXX_LIBRARIES NAMES gmpxx libgmpxx) +find_library(GMP_LIBRARY gmp) +if(GMP_LIBRARY MATCHES ${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(gmp_library_type SHARED) +else() + set(gmp_library_type STATIC) +endif() +message(STATUS "GMP: ${GMP_LIBRARY}, ${GMP_INCLUDE_DIR}") +add_library(GMP::gmp ${gmp_library_type} IMPORTED) +set_target_properties( + GMP::gmp PROPERTIES + IMPORTED_LOCATION ${GMP_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${GMP_INCLUDE_DIR} +) include(FindPkgConfig) -pkg_check_modules( - CRYPTO - REQUIRED - - libcrypto -) if("${WITH_PROCPS}") pkg_check_modules( @@ -137,18 +142,12 @@ else() ) endif() -# Enable Boost for program_options -FIND_PACKAGE( Boost 1.40 COMPONENTS program_options REQUIRED ) -INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} ) - add_definitions( -DCURVE_${CURVE} ) enable_testing() -include_directories(.) - if(${CURVE} STREQUAL "BN128") add_definitions( -DBN_SUPPORT_SNARK=1 diff --git a/libff/CMakeLists.txt b/libff/CMakeLists.txt index ace1da7b..4961c976 100755 --- a/libff/CMakeLists.txt +++ b/libff/CMakeLists.txt @@ -54,12 +54,14 @@ add_library( target_link_libraries( ff - ${GMP_LIBRARIES} - ${GMPXX_LIBRARIES} - ${CRYPTO_LIBRARIES} + GMP::gmp ${PROCPS_LIBRARIES} ${FF_EXTRALIBS} ) +target_include_directories( + ff + PUBLIC .. +) install( DIRECTORY "" DESTINATION "include/libff" diff --git a/libff/algebra/curves/curve_utils.tcc b/libff/algebra/curves/curve_utils.tcc index 8bb4509d..275c0f61 100755 --- a/libff/algebra/curves/curve_utils.tcc +++ b/libff/algebra/curves/curve_utils.tcc @@ -16,7 +16,7 @@ GroupT scalar_mul(const GroupT &base, const bigint &scalar) GroupT result = GroupT::zero(); bool found_one = false; - for (long i = scalar.max_bits() - 1; i >= 0; --i) + for (long i = static_cast(scalar.max_bits() - 1); i >= 0; --i) { if (found_one) { diff --git a/libff/algebra/fields/bigint.tcc b/libff/algebra/fields/bigint.tcc index 9824544d..6a2b6f62 100755 --- a/libff/algebra/fields/bigint.tcc +++ b/libff/algebra/fields/bigint.tcc @@ -11,6 +11,7 @@ #define BIGINT_TCC_ #include #include +#include namespace libff { @@ -158,18 +159,21 @@ bool bigint::test_bit(const std::size_t bitno) const const std::size_t part = bitno/GMP_NUMB_BITS; const std::size_t bit = bitno - (GMP_NUMB_BITS*part); const mp_limb_t one = 1; - return (this->data[part] & (one<data[part] & (one< bigint& bigint::randomize() { - assert(GMP_NUMB_BITS == sizeof(mp_limb_t) * 8); - FILE *fp = fopen("/dev/urandom", "r"); //TODO Remove hard-coded use of /dev/urandom. - size_t bytes_read = fread(this->data, 1, sizeof(mp_limb_t) * n, fp); - assert(bytes_read == sizeof(mp_limb_t) * n); - fclose(fp); + static_assert(GMP_NUMB_BITS == sizeof(mp_limb_t) * 8, "Wrong GMP_NUMB_BITS value"); + std::random_device rd; + constexpr size_t num_random_words = sizeof(mp_limb_t) * n / sizeof(std::random_device::result_type); + auto random_words = reinterpret_cast(this->data); + for (size_t i = 0; i < num_random_words; ++i) + { + random_words[i] = rd(); + } return (*this); } diff --git a/libff/algebra/fields/field_utils.tcc b/libff/algebra/fields/field_utils.tcc index 812c34c2..258dd085 100755 --- a/libff/algebra/fields/field_utils.tcc +++ b/libff/algebra/fields/field_utils.tcc @@ -189,7 +189,7 @@ void batch_invert(std::vector &vec) FieldT acc_inverse = acc.inverse(); - for (long i = vec.size()-1; i >= 0; --i) + for (long i = static_cast(vec.size()-1); i >= 0; --i) { const FieldT old_el = vec[i]; vec[i] = acc_inverse * prod[i]; diff --git a/libff/algebra/fields/fp.tcc b/libff/algebra/fields/fp.tcc index 97b0fd92..17f9e7b8 100755 --- a/libff/algebra/fields/fp.tcc +++ b/libff/algebra/fields/fp.tcc @@ -196,7 +196,7 @@ Fp_model::Fp_model(const bigint &b) template& modulus> Fp_model::Fp_model(const long x, const bool is_unsigned) { - static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), "long won't fit in mp_limb_t"); + static_assert(std::numeric_limits::max() >= static_cast(std::numeric_limits::max()), "long won't fit in mp_limb_t"); if (is_unsigned || x >= 0) { this->mont_repr.data[0] = (mp_limb_t)x; diff --git a/libff/algebra/fields/fp4.tcc b/libff/algebra/fields/fp4.tcc index bd2d4646..608a5844 100755 --- a/libff/algebra/fields/fp4.tcc +++ b/libff/algebra/fields/fp4.tcc @@ -189,7 +189,7 @@ Fp4_model Fp4_model::cyclotomic_exp(const bigint &expo bool found_nonzero = false; std::vector NAF = find_wnaf(1, exponent); - for (long i = NAF.size() - 1; i >= 0; --i) + for (long i = static_cast(NAF.size() - 1); i >= 0; --i) { if (found_nonzero) { diff --git a/libff/algebra/fields/fp6_2over3.tcc b/libff/algebra/fields/fp6_2over3.tcc index ea75a82a..0b671d9d 100755 --- a/libff/algebra/fields/fp6_2over3.tcc +++ b/libff/algebra/fields/fp6_2over3.tcc @@ -219,7 +219,7 @@ Fp6_2over3_model Fp6_2over3_model::cyclotomic_exp(const b bool found_nonzero = false; std::vector NAF = find_wnaf(1, exponent); - for (long i = NAF.size() - 1; i >= 0; --i) + for (long i = static_cast(NAF.size() - 1); i >= 0; --i) { if (found_nonzero) { diff --git a/libff/common/profiling.cpp b/libff/common/profiling.cpp index 4de648f5..f2a19858 100755 --- a/libff/common/profiling.cpp +++ b/libff/common/profiling.cpp @@ -38,12 +38,16 @@ long long get_nsec_time() /* Return total CPU time consumsed by all threads of the process, in nanoseconds. */ long long get_nsec_cpu_time() { +#if _MSC_VER + return 0; +#else ::timespec ts; if ( ::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) ) throw ::std::runtime_error("clock_gettime(CLOCK_PROCESS_CPUTIME_ID) failed"); // If we expected this to work, don't silently ignore failures, because that would hide the problem and incur an unnecessarily system-call overhead. So if we ever observe this exception, we should probably add a suitable #ifdef . //TODO: clock_gettime(CLOCK_PROCESS_CPUTIME_ID) is not supported by native Windows. What about Cygwin? Should we #ifdef on CLOCK_PROCESS_CPUTIME_ID or on __linux__? return ts.tv_sec * 1000000000ll + ts.tv_nsec; +#endif } long long start_time, last_time; diff --git a/libff/common/utils.hpp b/libff/common/utils.hpp index c1aba970..dc77547e 100755 --- a/libff/common/utils.hpp +++ b/libff/common/utils.hpp @@ -25,7 +25,7 @@ size_t get_power_of_two(size_t n); /// returns ceil(log2(n)), so 1ul<