Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary stuff from CMake #2

Merged
merged 6 commits into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build/
/.idea/
15 changes: 1 addition & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,9 @@ set(
)

find_path(GMP_INCLUDE_DIR NAMES gmp.h)
find_library(GMP_LIBRARIES NAMES gmp libgmp)
find_library(GMPXX_LIBRARIES NAMES gmpxx libgmpxx)
message(STATUS "GMP include dir: ${GMP_INCLUDE_DIR}")

include(FindPkgConfig)
pkg_check_modules(
CRYPTO
REQUIRED

libcrypto
)

if("${WITH_PROCPS}")
pkg_check_modules(
Expand All @@ -137,18 +130,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
Expand Down
7 changes: 5 additions & 2 deletions libff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ target_link_libraries(
ff

${GMP_LIBRARIES}
${GMPXX_LIBRARIES}
${CRYPTO_LIBRARIES}
${PROCPS_LIBRARIES}
${FF_EXTRALIBS}
)
target_include_directories(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for including over linking GMP? There's currently a linking error in this build: https://travis-ci.org/scipr-lab/libff/builds/269181457#L1262

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need both (unless you use CMake's imported targets).
I think the issue is the variable GMP_LIBRARIES is never set. I will check it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the builds are failing because the GMP was previously pulled by additional libcrypto library.

ff
PUBLIC ..
PRIVATE ${GMP_INCLUDE_DIR}
)

install(
DIRECTORY "" DESTINATION "include/libff"
Expand Down
2 changes: 1 addition & 1 deletion libff/algebra/curves/curve_utils.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GroupT scalar_mul(const GroupT &base, const bigint<m> &scalar)
GroupT result = GroupT::zero();

bool found_one = false;
for (long i = scalar.max_bits() - 1; i >= 0; --i)
for (long i = static_cast<long>(scalar.max_bits() - 1); i >= 0; --i)
{
if (found_one)
{
Expand Down
16 changes: 10 additions & 6 deletions libff/algebra/fields/bigint.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define BIGINT_TCC_
#include <cassert>
#include <cstring>
#include <random>

namespace libff {

Expand Down Expand Up @@ -158,18 +159,21 @@ bool bigint<n>::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<<bit));
return (this->data[part] & (one<<bit)) != 0;
}
}

template<mp_size_t n>
bigint<n>& bigint<n>::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<std::random_device::result_type*>(this->data);
for (size_t i = 0; i < num_random_words; ++i)
{
random_words[i] = rd();
}

return (*this);
}
Expand Down
2 changes: 1 addition & 1 deletion libff/algebra/fields/field_utils.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void batch_invert(std::vector<FieldT> &vec)

FieldT acc_inverse = acc.inverse();

for (long i = vec.size()-1; i >= 0; --i)
for (long i = static_cast<long>(vec.size()-1); i >= 0; --i)
{
const FieldT old_el = vec[i];
vec[i] = acc_inverse * prod[i];
Expand Down
2 changes: 1 addition & 1 deletion libff/algebra/fields/fp.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Fp_model<n,modulus>::Fp_model(const bigint<n> &b)
template<mp_size_t n, const bigint<n>& modulus>
Fp_model<n,modulus>::Fp_model(const long x, const bool is_unsigned)
{
static_assert(std::numeric_limits<mp_limb_t>::max() >= std::numeric_limits<long>::max(), "long won't fit in mp_limb_t");
static_assert(std::numeric_limits<mp_limb_t>::max() >= static_cast<unsigned long>(std::numeric_limits<long>::max()), "long won't fit in mp_limb_t");
if (is_unsigned || x >= 0)
{
this->mont_repr.data[0] = (mp_limb_t)x;
Expand Down
2 changes: 1 addition & 1 deletion libff/algebra/fields/fp4.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Fp4_model<n, modulus> Fp4_model<n,modulus>::cyclotomic_exp(const bigint<m> &expo
bool found_nonzero = false;
std::vector<long> NAF = find_wnaf(1, exponent);

for (long i = NAF.size() - 1; i >= 0; --i)
for (long i = static_cast<long>(NAF.size() - 1); i >= 0; --i)
{
if (found_nonzero)
{
Expand Down
2 changes: 1 addition & 1 deletion libff/algebra/fields/fp6_2over3.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Fp6_2over3_model<n, modulus> Fp6_2over3_model<n,modulus>::cyclotomic_exp(const b
bool found_nonzero = false;
std::vector<long> NAF = find_wnaf(1, exponent);

for (long i = NAF.size() - 1; i >= 0; --i)
for (long i = static_cast<long>(NAF.size() - 1); i >= 0; --i)
{
if (found_nonzero)
{
Expand Down
4 changes: 4 additions & 0 deletions libff/common/profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libff/common/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ size_t get_power_of_two(size_t n);
/// returns ceil(log2(n)), so 1ul<<log2(n) is the smallest power of 2, that is not less than n
size_t log2(size_t n);

inline size_t exp2(size_t k) { return 1ul << k; }
inline size_t exp2(size_t k) { return size_t(1) << k; }

size_t to_twos_complement(int i, size_t w);
int from_twos_complement(size_t i, size_t w);
Expand Down