Skip to content

Commit

Permalink
mergerd
Browse files Browse the repository at this point in the history
  • Loading branch information
Floyd committed Jun 5, 2024
2 parents 43ce372 + 6b95fa5 commit 5015cc4
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 102 deletions.
16 changes: 4 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ check_cxx_compiler_flag(-march=native COMPILER_SUPPORTS_MARCH_NATIVE)
check_cxx_compiler_flag(-fno-inline COMPILER_SUPPORTS_NO_INLINE)
check_cxx_compiler_flag(-fsanitize=address COMPILER_SUPPORTS_SANITIZE_ADDRESS) # TODO support not recognized
check_cxx_compiler_flag(-fsanitize=memory COMPILER_SUPPORTS_SANITIZE_MEMORY)
check_cxx_compiler_flag(-fconstexpr-steps=91 COMPILER_SUPPORTS_CONSTEXPR_COST)
check_cxx_compiler_flag(-fconstexpr-steps=9999999 COMPILER_SUPPORTS_CONSTEXPR_COST)
check_cxx_compiler_flag(-fno-exceptions COMPILER_SUPPORTS_NO_EXCEPTION)
check_ipo_supported(RESULT lto_supported OUTPUT error)
check_cxx_compiler_flag(-latomic LINKER_SUPPORTS_ATOMIC) # TODO
Expand Down Expand Up @@ -113,18 +113,18 @@ if(lto_supported AND USE_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

set(ALLOWED_WARNINGS " -Wno-c99-designator -Wno-invalid-constexpr -Wno-unused-function -Wno-zero-length-array")
set(ALLOWED_WARNINGS " -Wno-unknown-pragmas -Wno-c99-designator -Wno-invalid-constexpr -Wno-unused-function -Wno-zero-length-array")

message(STATUS "System Processor: ${CMAKE_SYSTEM_PROCESSOR}")

IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
message(STATUS "ARM CPU detected")
set(ADDITIONAL_FLAGS "-DUSE_ARM -flax-vector-conversions -march=native")
set(DEBUG_FLAGS "-g -Wall -Wextra -Wpedantic -fpermissive -DDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${SANITIZER_FLAGS} ${ADDITIONAL_FLAGS}")
set(DEBUG_FLAGS "-g -Wall -Wextra -fpermissive -DDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${SANITIZER_FLAGS} ${ADDITIONAL_FLAGS}")
set(OPTIMIZE_FLAGS "-O3 -DNDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${ADDITIONAL_FLAGS}")
else()

set(DEBUG_FLAGS "-g -O0 -Wall -Wextra -Wpedantic -DDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${SANITIZER_FLAGS} ${ADDITIONAL_FLAGS}")
set(DEBUG_FLAGS "-g -O0 -Wall -Wextra -DDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${SANITIZER_FLAGS} ${ADDITIONAL_FLAGS}")
set(OPTIMIZE_FLAGS "-g -march=native -DNDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${ADDITIONAL_FLAGS}")
endif()

Expand Down Expand Up @@ -189,7 +189,6 @@ if(CMAKE_CUDA_COMPILER)
# again only for arch... fuck NVIDIA
include_directories(/opt/cuda/samples/cuda-samples/Common)
include_directories(/usr/local/cuda/samples/cuda-samples/Common)
include_directories(/home/floyd.zweydinger/cuda-samples/Common)
include_directories(/opt/cuda/include)
include_directories(deps/cudacommon)
include_directories(deps/cuCollections/include)
Expand Down Expand Up @@ -225,21 +224,14 @@ if(CMAKE_CUDA_COMPILER)
endif()

# include every subpackage which is included in `cryptanalysislib`
include_directories("deps/cryptanalysislib/deps/fplll/")
include_directories("deps/cryptanalysislib/deps/b63/include/b63")
include_directories("deps/cryptanalysislib/deps/m4ri/m4ri")
include_directories("deps/cryptanalysislib/deps/m4ri")
include_directories("deps/cryptanalysislib/deps/ska_sort")
include_directories("deps/cryptanalysislib/deps/Static-Sort/include")
include_directories("deps/cryptanalysislib/src")

include_directories("src")
include_directories("test/decoding/challenges")
include_directories("test/mceliece/challenges")
include_directories("/usr/local/include")

link_directories("deps/cryptanalysislib/build")
link_directories("deps/cryptanalysislib/deps/m4ri/.libs")
link_directories("/usr/local/lib")

#TODO
Expand Down
37 changes: 26 additions & 11 deletions src/bjmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ class BJMM : public ISDInstance<uint64_t, isd> {
constexpr static uint32_t gaus_c = config.c;

using ISD = ISDInstance<uint64_t, isd>;
using PCMatrixOrg = ISD::PCMatrixOrg;
using PCMatrixOrg_T = ISD::PCMatrixOrg_T;
using PCMatrix = ISD::PCMatrix;
using PCMatrix_T = ISD::PCMatrix_T;
using PCSubMatrix = ISD::PCSubMatrix;
using PCSubMatrix_T = ISD::PCSubMatrix_T;
using Syndrome = ISD::Syndrome;
using Error = ISD::Error;
using Label = ISD::Label;
using PCMatrixOrg = typename ISD::PCMatrixOrg;
using PCMatrixOrg_T = typename ISD::PCMatrixOrg_T;
using PCMatrix = typename ISD::PCMatrix;
using PCMatrix_T = typename ISD::PCMatrix_T;
using PCSubMatrix = typename ISD::PCSubMatrix;
using PCSubMatrix_T = typename ISD::PCSubMatrix_T;
using Syndrome = typename ISD::Syndrome;
using Error = typename ISD::Error;
using Label = typename ISD::Label;
using ISD::A,ISD::H,ISD::wA,ISD::wAT,ISD::HT,ISD::s,ISD::ws,ISD::e,ISD::syndrome,ISD::P,ISD::not_found,ISD::loops,ISD::ghz;
using ISD::cycles,ISD::periodic_print,ISD::packed,ISD::simd;

using l_type = ISD::l_type;
using l_type = typename ISD::l_type;
using keyType = LogTypeTemplate<l>;
// using valueType = TypeTemplate<bc(n, p)>[1];

Expand Down Expand Up @@ -125,7 +125,7 @@ class BJMM : public ISDInstance<uint64_t, isd> {
HM1 *hm1; HM2 *hm2;

constexpr static ConfigEnumHashMap configEnum{config};
constexpr static ConfigEnumHashMapD2 configEnumD2{config, .l1=l1, .l2=l2};
constexpr static ConfigEnumHashMapD2 configEnumD2{config, l1, l2};
EnumHashMap<configEnum, HM1> *bEnum;
CollisionHashMap<configEnum, HM1> *cEnum;
CollisionHashMapD2<configEnumD2, HM1, HM2> *cEnumD2;
Expand Down Expand Up @@ -257,10 +257,19 @@ class BJMM : public ISDInstance<uint64_t, isd> {
ISD::extract_pHT(pHT);


/// TODO describe the parameters
/// \param a1
/// \param a2
/// \param index1
/// \param index2
/// \param nr_cols
auto f1 = [&, this](const l_type a1, const l_type a2,
const uint16_t *index1, const uint16_t *index2,
const uint32_t nr_cols) __attribute__((always_inline)) {
// NOTE: iT1 curently unknown in the global scope
// ASSERT(bEnum->check_hashmap2(iT1, index1, 2*p, l1));
(void) index2;
(void) nr_cols;
const l_type a = a1 ^ a2;
hm2->insert(a>>l1, V2::create(a, index1));
};
Expand All @@ -269,6 +278,11 @@ class BJMM : public ISDInstance<uint64_t, isd> {
const uint16_t *index1, const uint16_t *index2,
const uint32_t nr_cols) __attribute__((always_inline)) {
ASSERT(bEnum->check_hashmap2(syndrome, index1, 4*p, l));
(void) index2;
(void) nr_cols;
(void) a1;
(void) a2;

for (uint32_t i = 0; i < 4; ++i) {
final_list[final_list_current_size][i] = index1[i];
}
Expand All @@ -294,6 +308,7 @@ class BJMM : public ISDInstance<uint64_t, isd> {
while ((iT1 ^ syndrome) < iT1) {
iT1 += 1;
}

const l_type iT2 = iT1 ^ syndrome;

cEnum->step(iT1, f1, tid, simd);
Expand Down
4 changes: 2 additions & 2 deletions src/fq/sieving.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class FqSieving : public ISDInstance<uint64_t, isd>{

/// NOTE: the compressor negates the data, needed to be able
/// to search for exact matches.
l_type data1 = this->NegateCompress
l_type data1 = this->template NegateCompress
<lower_l>(L1->at(i).label);
IndexType pos1 = hm1->find(data1, load1);

Expand Down Expand Up @@ -277,7 +277,7 @@ class FqSieving : public ISDInstance<uint64_t, isd>{
HM_LoadType load1;

/// NOTE: the compressor negates the data
l_type data1 = this->NegateCompress
l_type data1 = this->template NegateCompress
<lower_l_bit>(L1->at(i).label);

/// NOTE: maybe I can prepare data1 before hand?
Expand Down
30 changes: 15 additions & 15 deletions src/mitm.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,10 @@ class CollisionHashMap {
constexpr static size_t enumeration_size = bc(enumeration_length, enumeration_weight);
constexpr static size_t enumeration_size_per_thread = enumeration_size/threads;

using HM_LoadType = HashMap::load_type;
using HM_DataType = HashMap::data_type;

using HM_DataType_IndexType = HM_DataType::index_type;
using l_type = HM_DataType::data_type;
using HM_LoadType = typename HashMap::load_type;
using HM_DataType = typename HashMap::data_type;
using HM_DataType_IndexType = typename HM_DataType::index_type;
using l_type = typename HM_DataType::data_type;
constexpr static size_t HM1_BUCKETSIZE = HashMap::bucketsize;

using cle = std::pair<uint16_t, uint16_t>;
Expand All @@ -395,8 +394,8 @@ class CollisionHashMap {
*lHTr = nullptr;

public:
constexpr CollisionHashMap(const l_type *lHT, HashMap *hm, cle *cL = nullptr) noexcept :
cL(cL), hm(hm), lHT(lHT), lHTr(lHT + n_half - config.epsilon) {
constexpr CollisionHashMap(const l_type *_lHT, HashMap *hm, cle *cL = nullptr) noexcept :
cL(cL), hm(hm), lHT(_lHT), lHTr(_lHT + n_half - config.epsilon) {
}

///
Expand Down Expand Up @@ -600,26 +599,27 @@ class CollisionHashMapD2 {
constexpr static size_t enumeration_size = bc(enumeration_length,enumeration_weigth);
constexpr static size_t enumeration_size_per_thread = enumeration_size/threads;

using HM_LoadType = HashMap2::load_type;
using HM_DataType = HashMap2::data_type;
using HM_DataType_IndexType = HM_DataType::index_type;
using l_type = HM_DataType::data_type;
using HM_LoadType = typename HashMap2::load_type;
using HM_DataType = typename HashMap2::data_type;
using HM_DataType_IndexType = typename HM_DataType::index_type;
using l_type = typename HM_DataType::data_type;

const l_type *lHT, *lHTr;
HashMap1 *hm1;
HashMap2 *hm2;
const l_type *lHT = nullptr, *lHTr = nullptr;


public:
CollisionHashMapD2(const l_type *lHT,
CollisionHashMapD2(const l_type *_lHT,
HashMap1 *hm1,
HashMap2 *hm2) noexcept :
lHT(lHT), lHTr(lHT + n_half - config.epsilon), hm1(hm1), hm2(hm2) {
}
lHT(_lHT), lHTr(_lHT + n_half - config.epsilon),
hm1(hm1), hm2(hm2) {}

template<typename F>
bool step(const l_type iT, F &&f, const uint32_t tid = 0, const bool simd=true) {
/// TODO simd
(void)simd;
return coll_hashmap_simple(iT, tid, f);
}

Expand Down
10 changes: 5 additions & 5 deletions src/stern.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ConfigStern : public ConfigISD {


// returns the expected number of iterations
[[nodiscard]] consteval uint64_t compute_loops() const noexcept {
[[nodiscard]] constexpr uint64_t compute_loops() const noexcept {
#ifdef EXPECTED_PERMUTATIONS
return EXPECTED_PERMUTATIONS;
#else
Expand Down Expand Up @@ -60,15 +60,15 @@ class Stern : public ISDInstance<uint64_t, isd> {
static_assert(config.HM_bucketsize > 0);

using ISD = ISDInstance<uint64_t, isd>;
using Error = ISD::Error;
using Label = ISD::Label;
using limb_type = ISD::limb_type;
using Error = typename ISD::Error;
using Label = typename ISD::Label;
using limb_type = typename ISD::limb_type;
using ISD::A,ISD::H,ISD::wA,ISD::wAT,ISD::HT,ISD::s,ISD::ws,ISD::e,ISD::syndrome,ISD::P,ISD::not_found,ISD::loops,ISD::ghz,ISD::expected_loops;
using ISD::cycles,ISD::periodic_print,ISD::packed,ISD::simd;


// base datatype of the hashmap
using l_type = ISD::l_type;
using l_type = typename ISD::l_type;

constexpr static uint32_t kl_half = (k+l)/2;

Expand Down
5 changes: 2 additions & 3 deletions tests/fq/sieving/50.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <gtest/gtest.h>
#include <iostream>

#include "../challenges/50_20_4.h"
#include "fq/sieving.h"
Expand All @@ -15,7 +14,7 @@ using ::testing::UnitTest;

TEST(Sieving, t1p2) {
static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=q,.w=w,.p=2,.l=3,.c=0,.threads=1};
static constexpr ConfigFqSieving config{isdConfig, .HM_bs=20, .sieving_steps=5, .enumeration_q=3};
static constexpr ConfigFqSieving config{isdConfig, 20, 5, 3};

FqSieving<isdConfig, config> sieve{};
sieve.from_string(h, s);
Expand All @@ -31,4 +30,4 @@ int main(int argc, char **argv) {
srand(time(NULL));
random_seed(rand());
return RUN_ALL_TESTS();
}
}
4 changes: 2 additions & 2 deletions tests/mceliece/bjmm/1284.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using ::testing::UnitTest;

TEST(BJMM, t1284t1p1) {
static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=19,.c=0,.threads=1};
static constexpr ConfigBJMM config{isdConfig, .l1=2, .HM1_bucketsize=1<<6, .HM2_bucketsize=4};
static constexpr ConfigBJMM config{isdConfig, 2, 1<<6, 4};

BJMM<isdConfig, config> bjmm{};
bjmm.from_string(h, s);
Expand All @@ -29,4 +29,4 @@ int main(int argc, char **argv) {
srand(time(NULL));
random_seed(rand());
return RUN_ALL_TESTS();
}
}
2 changes: 1 addition & 1 deletion tests/mceliece/bjmm/240.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST(Bjmm, t240) {
constexpr uint32_t bucketsize2 = 8;

static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=10,.c=0,.threads=1};
static constexpr ConfigBJMM config{isdConfig, .l1=4, .HM1_bucketsize=bucketsize1, .HM2_bucketsize=bucketsize2};
static constexpr ConfigBJMM config{isdConfig, 4, bucketsize1, bucketsize2};

BJMM<isdConfig, config> bjmm{};
bjmm.from_string(h, s);
Expand Down
31 changes: 16 additions & 15 deletions tests/mceliece/bjmm/431.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST(BJMM, t431t1p2) {
constexpr uint32_t bucketsize2 = 8;

static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=16,.c=0,.threads=1};
static constexpr ConfigBJMM config{isdConfig, .l1=2, .HM1_bucketsize=bucketsize1, .HM2_bucketsize=bucketsize2};
static constexpr ConfigBJMM config{isdConfig, 2, bucketsize1, bucketsize2};

BJMM<isdConfig, config> bjmm{};
bjmm.from_string(h, s);
Expand All @@ -30,27 +30,28 @@ TEST(BJMM, t431t1p2c20) {
constexpr uint32_t bucketsize2 = 8;

static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=16,.c=20,.threads=1};
static constexpr ConfigBJMM config{isdConfig, .l1=2, .HM1_bucketsize=bucketsize1, .HM2_bucketsize=bucketsize2};
static constexpr ConfigBJMM config{isdConfig, 2, bucketsize1, bucketsize2};

BJMM<isdConfig, config> bjmm{};
bjmm.from_string(h, s);
bjmm.run();
EXPECT_EQ(bjmm.correct(), true);
}

TEST(EB, t431t1p2) {
constexpr uint32_t bucketsize1 = 16;
constexpr uint32_t bucketsize2 = 8;

static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=16,.c=0,.threads=1};
static constexpr ConfigBJMM configBJMM{isdConfig, .l1=2, .HM1_bucketsize=bucketsize1, .HM2_bucketsize=bucketsize2};
static constexpr ConfigEB config{isdConfig, .l1=2, .HM1_bucketsize=bucketsize1, .HM2_bucketsize=bucketsize2, .p2=1};

EB<isdConfig, configBJMM, config> bjmm{};
bjmm.from_string(h, s);
bjmm.run();
EXPECT_EQ(bjmm.correct(), true);
}
// TODO
//TEST(EB, t431t1p2) {
// constexpr uint32_t bucketsize1 = 16;
// constexpr uint32_t bucketsize2 = 8;
//
// static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=16,.c=0,.threads=1};
// static constexpr ConfigBJMM configBJMM{isdConfig, 2, bucketsize1, bucketsize2};
// static constexpr ConfigEB config{isdConfig, .l1=2, .HM1_bucketsize=bucketsize1, .HM2_bucketsize=bucketsize2, .p2=1};
//
// EB<isdConfig, configBJMM, config> bjmm{};
// bjmm.from_string(h, s);
// bjmm.run();
// EXPECT_EQ(bjmm.correct(), true);
//}
int main(int argc, char **argv) {
InitGoogleTest(&argc, argv);
ident();
Expand Down
6 changes: 3 additions & 3 deletions tests/mceliece/bjmm/640.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using ::testing::UnitTest;

TEST(BJMM, t640t1p2) {
static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=16,.c=0,.threads=1};
static constexpr ConfigBJMM config{isdConfig, .l1=2, .HM1_bucketsize=1<<6, .HM2_bucketsize=20};
static constexpr ConfigBJMM config{isdConfig, 2, 1<<6, 20};

BJMM<isdConfig, config> bjmm{};
bjmm.from_string(h, s);
Expand All @@ -25,7 +25,7 @@ TEST(BJMM, t640t1p2) {

TEST(BJMM, t640t1p2c20) {
static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=16,.c=20,.threads=1};
static constexpr ConfigBJMM config{isdConfig, .l1=2, .HM1_bucketsize=1<<6, .HM2_bucketsize=20};
static constexpr ConfigBJMM config{isdConfig, 2, 1<<6, 20};

BJMM<isdConfig, config> bjmm{};
bjmm.from_string(h, s);
Expand All @@ -39,4 +39,4 @@ int main(int argc, char **argv) {
srand(time(NULL));
random_seed(rand());
return RUN_ALL_TESTS();
}
}
Loading

0 comments on commit 5015cc4

Please sign in to comment.