Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: Build

on: [push]
on:
push:
branches:
- '*'
- '!master'

jobs:
build:
name: Release
runs-on: ubuntu-latest

steps:
Expand Down
55 changes: 37 additions & 18 deletions .github/workflows/Checks.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
name: Checks

on: [push]
on:
push:
branches:
- '*'
- '!master'

jobs:
build:
documentation:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup
run: sudo apt-get install -y doxygen

- name: Documentation
shell: bash
run: ./scripts/build_documentation.sh

headers:
name: Header files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Setup
run: sudo apt-get install -y doxygen clang-format-12
- name: Copyright
run: ./scripts/check_copyright_headers.py

- name: Documentation
shell: bash
run: ./scripts/build_documentation.sh
- name: Header Guards
run: ./scripts/check_header_guards.py

- name: Copyright
run: ./scripts/check_copyright_headers.py
style:
name: Code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Header Guards
run: ./scripts/check_header_guards.py
- name: Setup
run: sudo apt-get install -y clang-format-12

- name: Style
shell: bash
run: |
find . -type f \( -iname "*.h" -o -iname "*.cc" \) -exec clang-format -n --style=Google {} \; &> checks.txt
cat checks.txt
test ! -s checks.txt
- name: Check
shell: bash
run: |
find . -type f \( -iname "*.h" -o -iname "*.cc" \) -exec clang-format -n --style=Google {} \; &> checks.txt
cat checks.txt
test ! -s checks.txt
42 changes: 24 additions & 18 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
name: Test

on: [push]
on:
push:
branches:
- '*'
- '!master'

env:
BUILD_TYPE: Debug

jobs:
build:
name: Coverage and Linting
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup catch2
- name: Setup
run: |
sudo apt-get install -y lcov
sudo apt-get install -y lcov bear
curl -L https://github.com/catchorg/Catch2/archive/v2.13.0.tar.gz -o c.tar.gz
tar xvf c.tar.gz
cd Catch2-2.13.0/
cmake -Bbuild -H. -DBUILD_TESTING=OFF
sudo cmake --build build/ --target install
cmake -B catch -DBUILD_TESTING=OFF
cmake --build catch
sudo cmake --install catch

- name: Create build directory
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
- name: CMake
run: cmake -B ${{runner.workspace}}/build -DCMAKE_BUILD_TYPE=$BUILD_TYPE .

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config $BUILD_TYPE
run: bear make -s -j4

- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
run: ctest -C $BUILD_TYPE

- name: Coverage
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
make coverage
lcov --summary coverage.info >> summary.txt
cmake --build ${{runner.workspace}}/build --target coverage
lcov --summary ${{runner.workspace}}/build/coverage.info >> ${{runner.workspace}}/summary.txt
./scripts/check_coverage.py ${{runner.workspace}}/summary.txt

- name: Check
- name: Lint
shell: bash
run: ./scripts/check_coverage.py ${{runner.workspace}}/build/summary.txt
run: |
find include/ src/ test/ -type f \( -iname "*.h" -o -iname "*.cc" \) \
-exec clang-tidy -p ${{runner.workspace}}/build/compile_commands.json --quiet {} \; 1>> lint.txt 2>/dev/null
cat lint.txt
test ! -s lint.txt

6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

cmake_minimum_required( VERSION 3.14 )

project( scl VERSION 2.1.0 DESCRIPTION "Secure Computation Library" )
project( scl VERSION 3.0.0 DESCRIPTION "Secure Computation Library" )

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
Expand Down Expand Up @@ -120,7 +120,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_compile_definitions(SCL_ENABLE_EC_TESTS)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -fsanitize=address")
find_package(Catch2 REQUIRED)
include(CTest)
include(Catch)
Expand Down Expand Up @@ -150,3 +150,5 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
EXCLUDE "/usr/include/*" "test/*" "/usr/lib/*" "/usr/local/*")

endif()

message(STATUS "CXX_FLAGS=" ${CMAKE_CXX_FLAGS})
14 changes: 14 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
3.0: More features, build changes
- Add method for returning a point as a pair of affine coordinates
- Add method to check if a channel has data available
- Allow sending and receiving STL vectors without specifying the size
- Extend Vec with a SubVector, operator== and operator!= methods
- Begin Shamir code refactor and move all of it into details namespace
- bugs:
- fix scalar multiplication for secp256k1_order
- fix compilation error on g++12
- build:
- build tests with -fsanitize=address
- disable actions for master branch
- add clang-tidy action

2.1: More Finite Fields
- Provide a FF implementation for computations modulo the order of Secp256k1
- Extend EC with support for scalar multiplications with scalars from a finite
Expand Down
22 changes: 14 additions & 8 deletions examples/03_secret_sharing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,36 @@ int main() {
* correction. Lets see error detection at work first
*/

scl::details::ShamirSSFactory<Fp> factory(
1, prg, scl::details::SecurityLevel::CORRECT);
/* We create 4 shamir shares with a threshold of 1.
*/
auto shamir_shares = scl::CreateShamirShares(secret, 4, 1, prg);
auto shamir_shares = factory.Share(secret);
std::cout << shamir_shares << "\n";

/* Of course, these can be reconstructed. The second parameter is the
* threshold. This performs reconstruction with error detection.
*/
auto shamir_reconstructed = scl::ReconstructShamir(shamir_shares, 1);
auto recon = factory.GetInterpolator();
auto shamir_reconstructed =
recon.Reconstruct(shamir_shares, scl::details::SecurityLevel::DETECT);
std::cout << shamir_reconstructed << "\n";

/* If we introduce an error, then reconstruction fails
*/
shamir_shares[2] = Fp(123);
try {
std::cout << scl::ReconstructShamir(shamir_shares, 1) << "\n";
std::cout << recon.Reconstruct(shamir_shares,
scl::details::SecurityLevel::DETECT)
<< "\n";
} catch (std::logic_error& e) {
std::cout << e.what() << "\n";
}

/* On the other hand, we can use the robust reconstruction since the threshold
* is low enough. I.e., because 4 >= 3*1 + 1.
*/
auto r = scl::ReconstructShamirRobust(shamir_shares, 1);
auto r = recon.Reconstruct(shamir_shares);
std::cout << r << "\n";

/* With a bit of extra work, we can even learn which share had the error.
Expand All @@ -79,26 +85,26 @@ int main() {
* default these are just the field elements 1 through 4.
*/
Vec alphas = {Fp(1), Fp(2), Fp(3), Fp(4)};
auto pe = scl::ReconstructShamirRobust(shamir_shares, alphas, 1);
auto pe = scl::details::ReconstructShamirRobust(shamir_shares, alphas, 1);

/* pe is a pair of polynomials. The first is the original polynomial used for
* generating the shares and the second is a polynomial whose roots tell which
* share had errors.
*
* The secret is embedded in the constant term.
*/
std::cout << pe[0].Evaluate(Fp(0)) << "\n";
std::cout << std::get<0>(pe).Evaluate(Fp(0)) << "\n";

/* This will be 0, indicating that the share corresponding to party 3 had an
* error.
*/
std::cout << pe[1].Evaluate(Fp(3)) << "\n";
std::cout << std::get<1>(pe).Evaluate(Fp(3)) << "\n";

/* Lastly, if there's too many errors, then correction is not possible
*/
shamir_shares[1] = Fp(22);
try {
scl::ReconstructShamirRobust(shamir_shares, 1);
recon.Reconstruct(shamir_shares);
} catch (std::logic_error& e) {
std::cout << e.what() << "\n";
}
Expand Down
22 changes: 16 additions & 6 deletions include/scl/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ Hash<B> &Hash<B>::Update(const unsigned char *bytes, std::size_t nbytes) {
const unsigned char *p = bytes;

if (nbytes < old_tail) {
while (nbytes--) mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
while (nbytes-- > 0) {
mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
}
return *this;
}

if (old_tail) {
if (old_tail != 0) {
nbytes -= old_tail;
while (old_tail--) mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
while (old_tail-- != 0) {
mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
}

mState[mWordIndex] ^= mSaved;
mByteIndex = 0;
Expand Down Expand Up @@ -167,7 +171,9 @@ Hash<B> &Hash<B>::Update(const unsigned char *bytes, std::size_t nbytes) {
p += sizeof(uint64_t);
}

while (tail--) mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
while (tail-- > 0) {
mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
}

return *this;
}
Expand All @@ -194,7 +200,9 @@ auto Hash<B>::Finalize() -> DigestType {

// truncate
DigestType digest = {0};
for (std::size_t i = 0; i < digest.size(); ++i) digest[i] = mStateBytes[i];
for (std::size_t i = 0; i < digest.size(); ++i) {
digest[i] = mStateBytes[i];
}

return digest;
}
Expand All @@ -208,7 +216,9 @@ template <typename D>
std::string DigestToString(const D &digest) {
std::stringstream ss;
ss << std::setw(2) << std::setfill('0') << std::hex;
for (const auto &c : digest) ss << (int)c;
for (const auto &c : digest) {
ss << (int)c;
}
return ss.str();
}

Expand Down
8 changes: 8 additions & 0 deletions include/scl/math/ec.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ class EC {
return details::CurveIsPointAtInfinity<Curve>(mValue);
};

/**
* @brief Return this point as a pair of affine coordinates.
* @return this point as a pair of affine coordinates.
*/
std::array<Field, 2> ToAffine() const {
return details::CurveToAffine<Curve>(mValue);
};

/**
* @brief Output this point as a string.
*/
Expand Down
13 changes: 11 additions & 2 deletions include/scl/math/ec_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ template <typename C>
void CurveSetAffine(typename C::ValueType& out, const FF<typename C::Field>& x,
const FF<typename C::Field>& y);

/**
* @brief Convert a point to a pair of affine coordinates.
* @param point the point to convert.
* @return a set of affine coordinates.
*/
template <typename C>
std::array<scl::FF<typename C::Field>, 2> CurveToAffine(
const typename C::ValueType& point);

/**
* @brief Add two elliptic curve points in-place.
* @param out the first point and output
Expand Down Expand Up @@ -135,11 +144,11 @@ void CurveToBytes(unsigned char* dest, const typename C::ValueType& in,

/**
* @brief Convert an elliptic curve point to a string
* @param in the point
* @param point the point
* @return an STL string representation of \p in.
*/
template <typename C>
std::string CurveToString(const typename C::ValueType& in);
std::string CurveToString(const typename C::ValueType& point);

} // namespace details
} // namespace scl
Expand Down
2 changes: 1 addition & 1 deletion include/scl/math/ff_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace details {
* @param value the integer to convert
*/
template <typename F>
void FieldConvertIn(typename F::ValueType& out, const int value);
void FieldConvertIn(typename F::ValueType& out, int value);

/**
* @brief Add two field elements in-place.
Expand Down
Loading