Skip to content

Commit

Permalink
updated CI and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Floyd committed Mar 11, 2024
1 parent cb71517 commit 3bbbd9a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: arm

on: [push]


jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -21,7 +20,7 @@ jobs:
sudo apt-get install -y cmake make git autoconf libtool libgmp-dev libgmp10
git clone --depth=1 --single-branch --branch v1.7.1 https://github.com/google/benchmark.git benchmark && mkdir -p benchmark/build && cd ./benchmark/build && cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_GTEST_TESTS=OFF ../ && make -j
sudo apt-get install -y libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/libgtest.a /usr/lib && sudo cp lib/libgtest_main.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
cd /cryptanalysislib
cd /decoding
mkdir -p cmake-build-release
mkdir -p cmake-build-debug
cd cmake-build-debug
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/osx-x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ jobs:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install libomp llvm googletest google-benchmark
# - name: Install Google Benchmark
# run: git clone --depth=1 --single-branch --branch v1.8.3 https://github.com/google/benchmark.git benchmark && mkdir -p benchmark/build && cd ./benchmark/build && cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_GTEST_TESTS=OFF ../ && make -j
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -D CMAKE_CXX_COMPILER=$(brew --prefix llvm)/bin/clang++

Expand Down
85 changes: 68 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,31 @@ Currently the following algorithms are implemented on CPU:
- MMT/BJMM (F2/Fq)
- May-Ozerov (F2)

The Nearest-Neighbor subroutine see the [cryptanalysislib](https://github.com/FloydZ/cryptanalysislib).
For the Nearest-Neighbor subroutine see the [cryptanalysislib](https://github.com/FloydZ/cryptanalysislib).

Requirements:
=============

Arch Linux:
-----------
Note: `google-benchmark` is not really needed.

### Arch Linux:

```bash
sudo pacman -S cmake make clang gtest benchmark
```

Ubuntu 22.04:
-------------
### Ubuntu 22.04:

```bash
sudo apt install make cmake libomp-dev clang libgtest-dev googlebenchmark
```
Note: only Ubuntu 22.04 is supported, all older version specially Ubuntu 20.04
is not supported.

MacOS:
------
### MacOS:

```bash
brew insatll cmake make oogletest libomp llvm google-benchmark
brew install cmake make googletest libomp llvm google-benchmark
```

You need to have llvm first in your PATH, run:
Expand All @@ -49,24 +48,19 @@ export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
```

## NixOS
### NixOS

The installation on `nixos` is super easy:
```bash
nix-shell
mkdir build
cd build
cmake ..
make
```

Windows:
--------
### Windows:

You probably want to reevaluate some life decisions.


Python:
-------
### Python:

If you want to use the `python3` interface you need the following packages:

Expand All @@ -91,6 +85,63 @@ cmake ../
make -j8
```

Usage:
======

#C++ API:

You will find a lot of examples in the [test](./tests) folder. Here a little
example how to use `Sterns` algorithm
```c
#include "tests/mceliece/challenges/mce431.h"
#include "stern.h"

static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=2,.l=13,.c=0,.threads=1};
static constexpr ConfigStern config{isdConfig, .HM_bucketsize=16};

Stern<isdConfig, config> stern{};
stern.from_string(h, s);
stern.run();
assert(stern.correct());
```
All Implemented algorithms inherit from a base class called `ISD`. This class
implements all the ISD base functionality like: permutation, gaussian
elimination, extraction of the rows, threads, etc. Thus we first need to
initialize the configuration for this class with:
```c
static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=2,.l=13,.c=0,.threads=1};
```

Next the configuration of Sterns algorithms is initialized. Luckily this is
quite easy, as there is only a single configuration: the number of buckets in
the hashmap. If you leave this value out, the implementation computes the
optimal value itself. NOTE: this can lead to alignment issues.

Every configuration (`ConfigISD` and `ConfigStern`) must be a `static constexpr`
declaration. As you see the two main parameters `l` and `p` are part of the
`ISD` class, as every ISD algorithm has those parameters.

After this the main class for Stern is initialized via:
```c
Stern<isdConfig, config> stern{};
```

Now you can either pass the needed parity check matrix via
```c
stern.from_string(h, s);
```

see [here](./tests/mceliece/challenges/mce431.h) for an example of how the
strings should look like. Or you can generate a random instance via:
```c
stern.random();
```

And finally the algorithm is started via:
```c
stern.run();
```


Reproduction of Results EC'22 and EC'23:
Expand Down
3 changes: 3 additions & 0 deletions src/prange.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Prange : public ISDInstance<uint64_t, isd> {
constexpr static uint32_t l = isd.l;
constexpr static uint32_t q = isd.q;

static_assert(l == 0);
static_assert(p == 0);

using ISD = ISDInstance<uint64_t, isd>;
using PCMatrixOrg = ISD::PCMatrixOrg;
using PCMatrixOrg_T = ISD::PCMatrixOrg_T;
Expand Down
7 changes: 5 additions & 2 deletions src/stern.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ using namespace cryptanalysislib;

struct ConfigStern : public ConfigISD {
public:

// number of elements per bucket in the hashmap
const uint32_t HM_bucketsize = 0;
const uint32_t HM_bucketsize = bc((k+l)/2, p) >> l;

// number of elements which can be contained in the last list.
// this is only a tmp storage, after this many elements were added
Expand Down Expand Up @@ -56,6 +55,10 @@ class Stern : public ISDInstance<uint64_t, isd> {
constexpr static uint32_t l = config.l;
constexpr static uint32_t q = config.q;

static_assert(p > 0);
static_assert(l > 0);
static_assert(config.HM_bucketsize > 0);

using ISD = ISDInstance<uint64_t, isd>;
using Error = ISD::Error;
using Label = ISD::Label;
Expand Down

0 comments on commit 3bbbd9a

Please sign in to comment.