Skip to content

Commit f273338

Browse files
authored
Version 3.0.0 (#6)
1 parent c32ea76 commit f273338

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1280
-699
lines changed

.github/workflows/Build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
name: Build
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
- '!master'
48

59
jobs:
610
build:
11+
name: Release
712
runs-on: ubuntu-latest
813

914
steps:

.github/workflows/Checks.yml

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
11
name: Checks
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
- '!master'
48

59
jobs:
6-
build:
10+
documentation:
11+
name: Documentation
712
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Setup
17+
run: sudo apt-get install -y doxygen
18+
19+
- name: Documentation
20+
shell: bash
21+
run: ./scripts/build_documentation.sh
822

23+
headers:
24+
name: Header files
25+
runs-on: ubuntu-latest
926
steps:
10-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v2
1128

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

15-
- name: Documentation
16-
shell: bash
17-
run: ./scripts/build_documentation.sh
32+
- name: Header Guards
33+
run: ./scripts/check_header_guards.py
1834

19-
- name: Copyright
20-
run: ./scripts/check_copyright_headers.py
35+
style:
36+
name: Code style
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v2
2140

22-
- name: Header Guards
23-
run: ./scripts/check_header_guards.py
41+
- name: Setup
42+
run: sudo apt-get install -y clang-format-12
2443

25-
- name: Style
26-
shell: bash
27-
run: |
28-
find . -type f \( -iname "*.h" -o -iname "*.cc" \) -exec clang-format -n --style=Google {} \; &> checks.txt
29-
cat checks.txt
30-
test ! -s checks.txt
44+
- name: Check
45+
shell: bash
46+
run: |
47+
find . -type f \( -iname "*.h" -o -iname "*.cc" \) -exec clang-format -n --style=Google {} \; &> checks.txt
48+
cat checks.txt
49+
test ! -s checks.txt

.github/workflows/Test.yml

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,57 @@
11
name: Test
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
- '!master'
48

59
env:
610
BUILD_TYPE: Debug
711

812
jobs:
913
build:
14+
name: Coverage and Linting
1015
runs-on: ubuntu-latest
1116

1217
steps:
1318
- uses: actions/checkout@v2
1419

15-
- name: Setup catch2
20+
- name: Setup
1621
run: |
17-
sudo apt-get install -y lcov
22+
sudo apt-get install -y lcov bear
1823
curl -L https://github.com/catchorg/Catch2/archive/v2.13.0.tar.gz -o c.tar.gz
1924
tar xvf c.tar.gz
2025
cd Catch2-2.13.0/
21-
cmake -Bbuild -H. -DBUILD_TESTING=OFF
22-
sudo cmake --build build/ --target install
26+
cmake -B catch -DBUILD_TESTING=OFF
27+
cmake --build catch
28+
sudo cmake --install catch
2329
24-
- name: Create build directory
25-
run: cmake -E make_directory ${{runner.workspace}}/build
26-
27-
- name: Configure CMake
28-
shell: bash
29-
working-directory: ${{runner.workspace}}/build
30-
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
30+
- name: CMake
31+
run: cmake -B ${{runner.workspace}}/build -DCMAKE_BUILD_TYPE=$BUILD_TYPE .
3132

3233
- name: Build
3334
working-directory: ${{runner.workspace}}/build
3435
shell: bash
35-
run: cmake --build . --config $BUILD_TYPE
36+
run: bear make -s -j4
3637

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

4243
- name: Coverage
43-
working-directory: ${{runner.workspace}}/build
4444
shell: bash
4545
run: |
46-
make coverage
47-
lcov --summary coverage.info >> summary.txt
46+
cmake --build ${{runner.workspace}}/build --target coverage
47+
lcov --summary ${{runner.workspace}}/build/coverage.info >> ${{runner.workspace}}/summary.txt
48+
./scripts/check_coverage.py ${{runner.workspace}}/summary.txt
4849
49-
- name: Check
50+
- name: Lint
5051
shell: bash
51-
run: ./scripts/check_coverage.py ${{runner.workspace}}/build/summary.txt
52+
run: |
53+
find include/ src/ test/ -type f \( -iname "*.h" -o -iname "*.cc" \) \
54+
-exec clang-tidy -p ${{runner.workspace}}/build/compile_commands.json --quiet {} \; 1>> lint.txt 2>/dev/null
55+
cat lint.txt
56+
test ! -s lint.txt
57+

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
cmake_minimum_required( VERSION 3.14 )
1818

19-
project( scl VERSION 2.1.0 DESCRIPTION "Secure Computation Library" )
19+
project( scl VERSION 3.0.0 DESCRIPTION "Secure Computation Library" )
2020

2121
if(NOT CMAKE_BUILD_TYPE)
2222
set(CMAKE_BUILD_TYPE Release)
@@ -120,7 +120,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
120120
add_compile_definitions(SCL_ENABLE_EC_TESTS)
121121
endif()
122122

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

152152
endif()
153+
154+
message(STATUS "CXX_FLAGS=" ${CMAKE_CXX_FLAGS})

RELEASE.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
3.0: More features, build changes
2+
- Add method for returning a point as a pair of affine coordinates
3+
- Add method to check if a channel has data available
4+
- Allow sending and receiving STL vectors without specifying the size
5+
- Extend Vec with a SubVector, operator== and operator!= methods
6+
- Begin Shamir code refactor and move all of it into details namespace
7+
- bugs:
8+
- fix scalar multiplication for secp256k1_order
9+
- fix compilation error on g++12
10+
- build:
11+
- build tests with -fsanitize=address
12+
- disable actions for master branch
13+
- add clang-tidy action
14+
115
2.1: More Finite Fields
216
- Provide a FF implementation for computations modulo the order of Secp256k1
317
- Extend EC with support for scalar multiplications with scalars from a finite

examples/03_secret_sharing.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,36 @@ int main() {
4646
* correction. Lets see error detection at work first
4747
*/
4848

49+
scl::details::ShamirSSFactory<Fp> factory(
50+
1, prg, scl::details::SecurityLevel::CORRECT);
4951
/* We create 4 shamir shares with a threshold of 1.
5052
*/
51-
auto shamir_shares = scl::CreateShamirShares(secret, 4, 1, prg);
53+
auto shamir_shares = factory.Share(secret);
5254
std::cout << shamir_shares << "\n";
5355

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

6064
/* If we introduce an error, then reconstruction fails
6165
*/
6266
shamir_shares[2] = Fp(123);
6367
try {
64-
std::cout << scl::ReconstructShamir(shamir_shares, 1) << "\n";
68+
std::cout << recon.Reconstruct(shamir_shares,
69+
scl::details::SecurityLevel::DETECT)
70+
<< "\n";
6571
} catch (std::logic_error& e) {
6672
std::cout << e.what() << "\n";
6773
}
6874

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

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

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

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

97103
/* Lastly, if there's too many errors, then correction is not possible
98104
*/
99105
shamir_shares[1] = Fp(22);
100106
try {
101-
scl::ReconstructShamirRobust(shamir_shares, 1);
107+
recon.Reconstruct(shamir_shares);
102108
} catch (std::logic_error& e) {
103109
std::cout << e.what() << "\n";
104110
}

include/scl/hash.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,17 @@ Hash<B> &Hash<B>::Update(const unsigned char *bytes, std::size_t nbytes) {
130130
const unsigned char *p = bytes;
131131

132132
if (nbytes < old_tail) {
133-
while (nbytes--) mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
133+
while (nbytes-- > 0) {
134+
mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
135+
}
134136
return *this;
135137
}
136138

137-
if (old_tail) {
139+
if (old_tail != 0) {
138140
nbytes -= old_tail;
139-
while (old_tail--) mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
141+
while (old_tail-- != 0) {
142+
mSaved |= (uint64_t)(*(p++)) << ((mByteIndex++) * 8);
143+
}
140144

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

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

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

195201
// truncate
196202
DigestType digest = {0};
197-
for (std::size_t i = 0; i < digest.size(); ++i) digest[i] = mStateBytes[i];
203+
for (std::size_t i = 0; i < digest.size(); ++i) {
204+
digest[i] = mStateBytes[i];
205+
}
198206

199207
return digest;
200208
}
@@ -208,7 +216,9 @@ template <typename D>
208216
std::string DigestToString(const D &digest) {
209217
std::stringstream ss;
210218
ss << std::setw(2) << std::setfill('0') << std::hex;
211-
for (const auto &c : digest) ss << (int)c;
219+
for (const auto &c : digest) {
220+
ss << (int)c;
221+
}
212222
return ss.str();
213223
}
214224

include/scl/math/ec.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ class EC {
271271
return details::CurveIsPointAtInfinity<Curve>(mValue);
272272
};
273273

274+
/**
275+
* @brief Return this point as a pair of affine coordinates.
276+
* @return this point as a pair of affine coordinates.
277+
*/
278+
std::array<Field, 2> ToAffine() const {
279+
return details::CurveToAffine<Curve>(mValue);
280+
};
281+
274282
/**
275283
* @brief Output this point as a string.
276284
*/

include/scl/math/ec_ops.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ template <typename C>
5959
void CurveSetAffine(typename C::ValueType& out, const FF<typename C::Field>& x,
6060
const FF<typename C::Field>& y);
6161

62+
/**
63+
* @brief Convert a point to a pair of affine coordinates.
64+
* @param point the point to convert.
65+
* @return a set of affine coordinates.
66+
*/
67+
template <typename C>
68+
std::array<scl::FF<typename C::Field>, 2> CurveToAffine(
69+
const typename C::ValueType& point);
70+
6271
/**
6372
* @brief Add two elliptic curve points in-place.
6473
* @param out the first point and output
@@ -135,11 +144,11 @@ void CurveToBytes(unsigned char* dest, const typename C::ValueType& in,
135144

136145
/**
137146
* @brief Convert an elliptic curve point to a string
138-
* @param in the point
147+
* @param point the point
139148
* @return an STL string representation of \p in.
140149
*/
141150
template <typename C>
142-
std::string CurveToString(const typename C::ValueType& in);
151+
std::string CurveToString(const typename C::ValueType& point);
143152

144153
} // namespace details
145154
} // namespace scl

include/scl/math/ff_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace details {
3737
* @param value the integer to convert
3838
*/
3939
template <typename F>
40-
void FieldConvertIn(typename F::ValueType& out, const int value);
40+
void FieldConvertIn(typename F::ValueType& out, int value);
4141

4242
/**
4343
* @brief Add two field elements in-place.

0 commit comments

Comments
 (0)