Skip to content

Commit a22f73d

Browse files
authored
Version 4.0.0 (#7)
* Version 4.0.0
1 parent f273338 commit a22f73d

Some content is hidden

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

84 files changed

+1857
-736
lines changed

.clang-format

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Language: Cpp
2+
BasedOnStyle: Google
3+
DerivePointerAlignment: false
4+
AllowShortFunctionsOnASingleLine: Empty
5+
BinPackArguments: false
6+
BinPackParameters: false
7+
8+
# The include rules below structures includes as
9+
#
10+
# - STL headers (anything without an extension, tbp)
11+
# - Other headers (anything that ends with .h)
12+
# - External SCL headers (anything of the form <scl/...>)
13+
# - Internal SCL headers (anything of the form "scl/...")
14+
#
15+
# The only exception is when a .cc file includes a header file with the same
16+
# name at the same path.
17+
18+
IncludeCategories:
19+
- Regex: '^<scl/.*\.h*'
20+
Priority: 4
21+
SortPriority: 0
22+
- Regex: '^<.*\.h>'
23+
Priority: 2
24+
SortPriority: 0
25+
- Regex: '^<.*'
26+
Priority: 1
27+
SortPriority: 0
28+
- Regex: '^scl/.*'
29+
Priority: 5
30+
SortPriority: 0

.clang-tidy

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Checks: '-*,bugprone-*,performance-*,readability-*,google-global-names-in-headers,cert-dcl59-cpp,-bugprone-easily-swappable-parameters,-readability-identifier-length,-readability-magic-numbers,-readability-function-cognitive-complexity,-readability-function-size'
2+
3+
# Enabled checks:
4+
# - bugprone
5+
# - performance
6+
# - readability
7+
# - google-global-names-in-headers
8+
# - cert-dcl59-cpp
9+
#
10+
# Specific disabled checks
11+
#
12+
# bugprone-easily-swappable-parameters:
13+
# Doesn't make sense to exclude functions taking multiple ints in SCL.
14+
#
15+
# readability-identifier-length:
16+
# Short identifiers make sense.
17+
#
18+
# readability-magic-numbers:
19+
# Too strict.
20+
#
21+
# readability-function-cognitive-complexity
22+
# Catch2.
23+
#
24+
# readability-function-size
25+
# Catch2.
26+
27+
AnalyzeTemporaryDtors: false

.github/workflows/Checks.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
documentation:
1111
name: Documentation
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-20.04
1313
steps:
1414
- uses: actions/checkout@v2
1515

@@ -39,11 +39,11 @@ jobs:
3939
- uses: actions/checkout@v2
4040

4141
- name: Setup
42-
run: sudo apt-get install -y clang-format-12
42+
run: sudo apt-get install -y clang-format
4343

4444
- name: Check
4545
shell: bash
4646
run: |
47-
find . -type f \( -iname "*.h" -o -iname "*.cc" \) -exec clang-format -n --style=Google {} \; &> checks.txt
47+
find . -type f \( -iname "*.h" -o -iname "*.cc" \) -exec clang-format -n {} \; &> checks.txt
4848
cat checks.txt
4949
test ! -s checks.txt

.github/workflows/Test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
jobs:
1313
build:
1414
name: Coverage and Linting
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-20.04
1616

1717
steps:
1818
- uses: actions/checkout@v2

CMakeLists.txt

+10-6
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 3.0.0 DESCRIPTION "Secure Computation Library" )
19+
project( scl VERSION 4.0.0 DESCRIPTION "Secure Computation Library" )
2020

2121
if(NOT CMAKE_BUILD_TYPE)
2222
set(CMAKE_BUILD_TYPE Release)
@@ -35,10 +35,12 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
3535
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -pedantic -Werror -std=gnu++17")
3636

3737
set(SCL_SOURCE_FILES
38-
src/scl/prg.cc
39-
src/scl/hash.cc
38+
src/scl/util/str.cc
39+
40+
src/scl/primitives/prg.cc
41+
src/scl/primitives/sha3.cc
42+
src/scl/primitives/sha256.cc
4043

41-
src/scl/math/str.cc
4244
src/scl/math/mersenne61.cc
4345
src/scl/math/mersenne127.cc
4446

@@ -87,8 +89,9 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
8789
set(SCL_TEST_SOURCE_FILES
8890
test/scl/main.cc
8991

90-
test/scl/test_hash.cc
91-
test/scl/test_prg.cc
92+
test/scl/primitives/test_prg.cc
93+
test/scl/primitives/test_sha3.cc
94+
test/scl/primitives/test_sha256.cc
9295

9396
test/scl/gf7.cc
9497
test/scl/math/test_mersenne61.cc
@@ -102,6 +105,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
102105
test/scl/ss/test_additive.cc
103106
test/scl/ss/test_poly.cc
104107
test/scl/ss/test_shamir.cc
108+
test/scl/ss/test_feldman.cc
105109

106110
test/scl/net/util.cc
107111
test/scl/net/test_config.cc

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,15 @@ inspiration.
6262
SCL uses Doxygen for documentation. Run `./scripts/build_documentation.sh` to
6363
generate the documentation. This is placed in the `doc/` folder. Documentation
6464
uses `doxygen`, so make sure that's installed.
65+
66+
# Citing
67+
68+
I'd greatly appreciate any work that uses SCL include the below bibtex entry
69+
70+
```
71+
@misc{secure-computation-library,
72+
author = {Anders Dalskov},
73+
title = {{SCL (Secure Computation Library)---utility library for prototyping MPC applications}},
74+
howpublished = {\url{https://github.com/anderspkd/secure-computation-library}},
75+
}
76+
```

RELEASE.txt

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
4.0: Shamir, Feldman, SHA-256
2+
- Refactor Shamir to allow caching of Lagrange coefficients
3+
- Add support for Feldman Secret Sharing
4+
- Add support for SHA-256
5+
- Add bibtex blob for citing SCL
6+
- Refactor interface for hash functions
7+
- Refactor interface for Shamir
8+
- bugs:
9+
- Fix negation of 0 in Secp256k1::Field and Secp256k1::Order
10+
- Make serialization and deserialization of curve points behave more sanely
11+
112
3.0: More features, build changes
213
- Add method for returning a point as a pair of affine coordinates
314
- Add method to check if a channel has data available

examples/01_primitives.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ int main() {
4242

4343
/* The DigestToString can be used to print a hex representation of a digest.
4444
*/
45-
std::cout << scl::DigestToString(digest) << "\n";
45+
std::cout << scl::details::DigestToString(digest) << "\n";
4646
}

examples/02_finite_fields.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
*/
2020

21-
#include <scl/math.h>
22-
2321
#include <iostream>
2422

23+
#include <scl/math.h>
24+
2525
int main() {
2626
/* This defines a "Finite Field" with space for at least 32 bits of
2727
* computation. At the moment, SCL supports two primes: One that is 61 bits
@@ -67,7 +67,7 @@ int main() {
6767
std::cout << a << " ?= " << b << ": " << (a == b) << "\n";
6868
std::cout << a << " ?= " << a << ": " << (a == a) << "\n";
6969

70-
scl::PRG prg;
70+
auto prg = scl::PRG::Create();
7171

7272
/* Using a PRG (see the PRG example), we can generate random field elements.
7373
*/

examples/03_secret_sharing.cc

+11-12
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
*/
2020

21-
#include <scl/math.h>
22-
#include <scl/secret_sharing.h>
23-
2421
#include <iostream>
2522
#include <stdexcept>
2623

24+
#include <scl/math.h>
25+
#include <scl/secret_sharing.h>
26+
2727
int main() {
2828
using Fp = scl::Fp<32>;
2929
using Vec = scl::Vec<Fp>;
30-
scl::PRG prg;
30+
31+
auto prg = scl::PRG::Create();
3132

3233
/* We can easily create an additive secret sharing of some secret value:
3334
*/
@@ -46,8 +47,8 @@ int main() {
4647
* correction. Lets see error detection at work first
4748
*/
4849

49-
scl::details::ShamirSSFactory<Fp> factory(
50-
1, prg, scl::details::SecurityLevel::CORRECT);
50+
auto factory =
51+
scl::ShamirSSFactory<Fp>::Create(1, prg, scl::SecurityLevel::CORRECT);
5152
/* We create 4 shamir shares with a threshold of 1.
5253
*/
5354
auto shamir_shares = factory.Share(secret);
@@ -56,17 +57,15 @@ int main() {
5657
/* Of course, these can be reconstructed. The second parameter is the
5758
* threshold. This performs reconstruction with error detection.
5859
*/
59-
auto recon = factory.GetInterpolator();
6060
auto shamir_reconstructed =
61-
recon.Reconstruct(shamir_shares, scl::details::SecurityLevel::DETECT);
61+
factory.Recover(shamir_shares, scl::SecurityLevel::DETECT);
6262
std::cout << shamir_reconstructed << "\n";
6363

6464
/* If we introduce an error, then reconstruction fails
6565
*/
6666
shamir_shares[2] = Fp(123);
6767
try {
68-
std::cout << recon.Reconstruct(shamir_shares,
69-
scl::details::SecurityLevel::DETECT)
68+
std::cout << factory.Recover(shamir_shares, scl::SecurityLevel::DETECT)
7069
<< "\n";
7170
} catch (std::logic_error& e) {
7271
std::cout << e.what() << "\n";
@@ -75,7 +74,7 @@ int main() {
7574
/* On the other hand, we can use the robust reconstruction since the threshold
7675
* is low enough. I.e., because 4 >= 3*1 + 1.
7776
*/
78-
auto r = recon.Reconstruct(shamir_shares);
77+
auto r = factory.Recover(shamir_shares);
7978
std::cout << r << "\n";
8079

8180
/* With a bit of extra work, we can even learn which share had the error.
@@ -104,7 +103,7 @@ int main() {
104103
*/
105104
shamir_shares[1] = Fp(22);
106105
try {
107-
recon.Reconstruct(shamir_shares);
106+
factory.Recover(shamir_shares);
108107
} catch (std::logic_error& e) {
109108
std::cout << e.what() << "\n";
110109
}

examples/04_networking.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
*/
2020

21-
#include <scl/scl.h>
22-
2321
#include <iostream>
2422

25-
#include "scl/net/tcp_channel.h"
23+
#include <scl/net/tcp_channel.h>
24+
#include <scl/scl.h>
2625

2726
scl::NetworkConfig RunServer(int n) {
2827
scl::DiscoveryServer server(n);
@@ -67,7 +66,7 @@ int main(int argc, char** argv) {
6766

6867
auto network = scl::Network::Create<scl::TcpChannel>(config);
6968

70-
for (std::size_t i = 0; i < 3; ++i) {
69+
for (std::size_t i = 0; i < (std::size_t)n; ++i) {
7170
// similar to the TCP channel example, send our ID to everyone:
7271
network.Party(i)->Send(config.Id());
7372
unsigned received_id;

include/scl/math/ec.h

+14-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "scl/math/ec_ops.h"
2727
#include "scl/math/ff.h"
2828
#include "scl/math/number.h"
29-
#include "scl/prg.h"
29+
#include "scl/primitives/prg.h"
3030

3131
namespace scl {
3232

@@ -44,6 +44,11 @@ class EC {
4444
*/
4545
using Field = FF<typename Curve::Field>;
4646

47+
/**
48+
* @brief A large sub-group of this curve.
49+
*/
50+
using Order = FF<typename Curve::Order>;
51+
4752
/**
4853
* @brief The size of a curve point in bytes.
4954
* @param compressed
@@ -62,7 +67,9 @@ class EC {
6267
/**
6368
* @brief A string indicating which curve this is.
6469
*/
65-
constexpr static const char* Name() { return Curve::kName; };
70+
constexpr static const char* Name() {
71+
return Curve::kName;
72+
};
6673

6774
/**
6875
* @brief Get the generator of this curve.
@@ -96,7 +103,9 @@ class EC {
96103
/**
97104
* @brief Create a new point equal to the point at infinity.
98105
*/
99-
explicit constexpr EC() { details::CurveSetPointAtInfinity<Curve>(mValue); };
106+
explicit constexpr EC() {
107+
details::CurveSetPointAtInfinity<Curve>(mValue);
108+
};
100109

101110
/**
102111
* @brief Add another EC point to this.
@@ -173,7 +182,7 @@ class EC {
173182
* @param scalar the scalar
174183
* @return this.
175184
*/
176-
EC& operator*=(const FF<typename Curve::Order>& scalar) {
185+
EC& operator*=(const Order& scalar) {
177186
details::CurveScalarMultiply<Curve>(mValue, scalar);
178187
return *this;
179188
};
@@ -195,8 +204,7 @@ class EC {
195204
* @param scalar the scalar
196205
* @return the point multiplied with the scalar.
197206
*/
198-
friend EC operator*(const EC& point,
199-
const FF<typename Curve::Order>& scalar) {
207+
friend EC operator*(const EC& point, const Order& scalar) {
200208
EC copy(point);
201209
return copy *= scalar;
202210
};

include/scl/math/ec_ops.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ void CurveSetGenerator(typename C::ValueType& out);
5656
* @param y the y coordinate
5757
*/
5858
template <typename C>
59-
void CurveSetAffine(typename C::ValueType& out, const FF<typename C::Field>& x,
59+
void CurveSetAffine(typename C::ValueType& out,
60+
const FF<typename C::Field>& x,
6061
const FF<typename C::Field>& y);
6162

6263
/**
@@ -139,7 +140,8 @@ void CurveFromBytes(typename C::ValueType& out, const unsigned char* src);
139140
* @param compress whether to compress the point
140141
*/
141142
template <typename C>
142-
void CurveToBytes(unsigned char* dest, const typename C::ValueType& in,
143+
void CurveToBytes(unsigned char* dest,
144+
const typename C::ValueType& in,
143145
bool compress);
144146

145147
/**

0 commit comments

Comments
 (0)