Skip to content

Commit 5da7ddb

Browse files
authored
Version 2.0.0 (#4)
Version 2.0.0
1 parent 9d86510 commit 5da7ddb

Some content is hidden

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

89 files changed

+3297
-1055
lines changed

.gitignore

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
scutil.*
1+
# files related to build
22
build/
3+
.cache/
4+
5+
# do not track compiled documentation files
36
doc/
4-
/TAGS
5-
/GPATH
6-
/GRTAGS
7-
/GTAGS
8-
/.projectile
7+
8+
# build files for examples
99
examples/build/
10-
examples/libscl.*
10+
11+
# misc IDE stuff
1112
secure-computation-library.*
12-
/.cache/
13-
/compile_commands.json
14-
/lib/
15-
/install/
13+
compile_commands.json

CMakeLists.txt

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@
1616

1717
cmake_minimum_required( VERSION 3.14 )
1818

19-
project( scl VERSION 1.1.1 DESCRIPTION "Secure Computation Library" )
19+
project( scl VERSION 2.0.0 DESCRIPTION "Secure Computation Library" )
2020

2121
if(NOT CMAKE_BUILD_TYPE)
2222
set(CMAKE_BUILD_TYPE Release)
2323
endif()
2424

25+
option(WITH_EC "Include support for elliptic curves (requires GMP)" ON)
26+
2527
message(STATUS "CMAKE_BUILD_TYPE=" ${CMAKE_BUILD_TYPE})
28+
message(STATUS "WITH_EC=" ${WITH_EC})
29+
30+
if(WITH_EC MATCHES ON)
31+
find_library(GMP gmp libgmp REQUIRED)
32+
endif()
2633

2734
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
2835
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -pedantic -Werror -std=gnu++17")
@@ -44,6 +51,13 @@ set(SCL_SOURCE_FILES
4451
src/scl/net/discovery/server.cc
4552
src/scl/net/discovery/client.cc)
4653

54+
if(WITH_EC MATCHES ON)
55+
set(SCL_SOURCE_FILES ${SCL_SOURCE_FILES}
56+
src/scl/math/secp256k1_field.cc
57+
src/scl/math/secp256k1_curve.cc
58+
src/scl/math/number.cc)
59+
endif()
60+
4761
set(SCL_HEADERS "${CMAKE_SOURCE_DIR}/include")
4862

4963
include_directories(${SCL_HEADERS})
@@ -65,7 +79,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Release")
6579
FILES_MATCHING PATTERN "*.h")
6680

6781
endif()
68-
82+
6983
if(CMAKE_BUILD_TYPE MATCHES "Debug")
7084

7185
set(SCL_TEST_SOURCE_FILES
@@ -97,29 +111,40 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
97111

98112
test/scl/p/test_simple.cc)
99113

100-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
101-
find_package(Catch2 REQUIRED)
102-
include(CTest)
103-
include(Catch)
104-
include(${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake)
105-
106-
# Tests that check bounds for reading/writing are sped up considerably by
107-
# lowering said bounds.
108-
add_compile_definitions(MAX_VEC_READ_SIZE=1024)
109-
add_compile_definitions(MAX_MAT_READ_SIZE=1024)
110-
add_compile_definitions(SCL_TEST_DATA_DIR="${CMAKE_SOURCE_DIR}/test/data/")
111-
112-
add_executable(scl_test ${SCL_SOURCE_FILES} ${SCL_TEST_SOURCE_FILES})
113-
target_link_libraries(scl_test Catch2::Catch2 pthread)
114-
catch_discover_tests(scl_test)
115-
116-
append_coverage_compiler_flags()
117-
118-
# Tell lcov to ignore system STL headers in order to make the coverage
119-
# output more precise.
120-
setup_target_for_coverage_lcov(
121-
NAME coverage
122-
EXECUTABLE scl_test
123-
EXCLUDE "/usr/include/*" "test/*" "/usr/lib/*" "/usr/local/*")
114+
if(WITH_EC MATCHES ON)
115+
set(SCL_TEST_SOURCE_FILES ${SCL_TEST_SOURCE_FILES}
116+
test/scl/math/test_secp256k1.cc
117+
test/scl/math/test_number.cc)
118+
add_compile_definitions(SCL_ENABLE_EC_TESTS)
119+
endif()
120+
121+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
122+
find_package(Catch2 REQUIRED)
123+
include(CTest)
124+
include(Catch)
125+
include(${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake)
126+
127+
# Lower the max size of Vec/Mat reads to speed up tests
128+
add_compile_definitions(MAX_VEC_READ_SIZE=1024)
129+
add_compile_definitions(MAX_MAT_READ_SIZE=1024)
130+
add_compile_definitions(SCL_TEST_DATA_DIR="${CMAKE_SOURCE_DIR}/test/data/")
131+
132+
add_executable(scl_test ${SCL_SOURCE_FILES} ${SCL_TEST_SOURCE_FILES})
133+
target_link_libraries(scl_test Catch2::Catch2 pthread)
134+
135+
if(WITH_EC MATCHES ON)
136+
target_link_libraries(scl_test ${GMP})
137+
endif()
138+
139+
catch_discover_tests(scl_test)
140+
141+
append_coverage_compiler_flags()
142+
143+
# Tell lcov to ignore system STL headers in order to make the coverage
144+
# output more precise.
145+
setup_target_for_coverage_lcov(
146+
NAME coverage
147+
EXECUTABLE scl_test
148+
EXCLUDE "/usr/include/*" "test/*" "/usr/lib/*" "/usr/local/*")
124149

125150
endif()

DoxyConf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ WARN_LOGFILE =
100100
INPUT = ./include \
101101
./include/scl \
102102
./include/scl/math \
103-
./include/scl/math/z2k \
103+
./include/scl/math/fields \
104+
./include/scl/math/curves \
104105
./include/scl/ss \
105106
./include/scl/net \
106107
./include/scl/net/discovery \
@@ -111,7 +112,7 @@ RECURSIVE = NO
111112
EXCLUDE =
112113
EXCLUDE_SYMLINKS = NO
113114
EXCLUDE_PATTERNS =
114-
EXCLUDE_SYMBOLS = _SCL_*
115+
EXCLUDE_SYMBOLS = SCL_*
115116
EXAMPLE_PATH =
116117
EXAMPLE_PATTERNS = *
117118
EXAMPLE_RECURSIVE = NO
@@ -133,7 +134,6 @@ VERBATIM_HEADERS = YES
133134
CLANG_ASSISTED_PARSING = NO
134135
CLANG_OPTIONS =
135136
ALPHABETICAL_INDEX = YES
136-
COLS_IN_ALPHA_INDEX = 5
137137
IGNORE_PREFIX =
138138
GENERATE_HTML = YES
139139
HTML_OUTPUT = html

README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# SCL — Secure Computation Library
22

3-
SCL is a utilities library for prototyping Secure Multiparty Computation (MPC
4-
for short) protocols. The focus of SCL is usability, both in terms of the
5-
interfaces provided, but also the build process (SCL has no external
6-
dependencies, for example). SCL moreover attempts to provide functionality that
7-
abstracts away all the annoying "boilerplate" code that is needed for
8-
implementing a new and exciting MPC protocol, such as implementing a finite
9-
field, getting networking to work, or instantiating a PRG or hash function.
10-
11-
Hopefully, by using SCL, researches (and hobbyists) will find it a lot easier,
12-
and quicker!, to implement MPC protocols.
3+
SCL is a utilities library for prototyping Secure Multiparty Computation (_MPC_
4+
for short) protocols. The focus of SCL is usability, not necessarily speed. What
5+
this means is that SCL strives to provide an intuitive, easy to use and
6+
understand and well documented interface that helps the programmer prototype an
7+
MPC protocol faster (and nicer) than if they had to write everything themselves.
8+
9+
SCL provides high level interfaces and functionality for working with
10+
* Secret sharing, additive and Shamir.
11+
* Finite fields.
12+
* Networking.
13+
* Primitives, such as hash functions and PRGs.
1314

1415
### Disclaimer
1516

@@ -20,13 +21,11 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
2021
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
2122
PARTICULAR PURPOSE.
2223

23-
2424
# Building SCL
2525

26-
SCL has no external dependencies, except if you want to build the unittests. In
27-
that case, [catch2](https://github.com/catchorg/Catch2/tree/v2.x) is required as
28-
that's the framework used for testing, as well as ~lcov~ for generating test
29-
coverage.
26+
SCL uses [gmp](https://gmplib.org/) for working with Elliptic Curves, and
27+
[catch2](https://github.com/catchorg/Catch2/tree/v2.x) for testing and `lcov`
28+
for test coverage.
3029

3130
The CMake file recongnizes two different build types: `Debug` and `Release`, the
3231
latter being the default. In either case, building is straight forward and can
@@ -47,6 +46,10 @@ after the build command. By default, headers are install in `usr/local/include`
4746
and the shared library in `/usr/local/lib`. This location can be controlled by
4847
setting the `CMAKE_INSTALL_PREFIX` accordingly.
4948

49+
Support for Elliptic Curves can be disabled (and thus remove the need to have
50+
gmp installed) by passing `-DWITH_EC=OFF` to cmake.
51+
52+
5053
# Using SCL
5154

5255
To use SCL, link `libscl.so` when building your program and include the

RELEASE.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2.0: Elliptic curves and finite field refactoring
2+
- Make it simpler to define new finite fields
3+
- Include optional (but enabled by default) support for elliptic curves
4+
- Implement secp256k1
5+
- Include optional (but enabled by default) support for multi-precision integers
6+
- Significantly increase test coverage
7+
- Make header guards standard compliant
8+
- Rename FF<Bits> to Fp<Bits>.
9+
- Move class FF into scl namespace.
10+
111
1.1: Refactoring of finite field internals
212
- Finite field operations are now defined by individual specializations of
313
templated functions

examples/02_finite_fields.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main() {
3333
* which returns the actual size of a field element (so 61 bits in the below
3434
* case).
3535
*/
36-
using FF = scl::FF<32>;
36+
using Fp = scl::Fp<32>;
3737

3838
/* FF supports constructing an element from an int constant. The value input
3939
* is interpreted "modulo p" where p is the prime. This makes it possible to
@@ -42,9 +42,9 @@ int main() {
4242
* The default construtor of FF can be used to construct an element equal to
4343
* 0.
4444
*/
45-
auto a = FF(1);
46-
auto b = FF(1234);
47-
auto c = FF(555);
45+
auto a = Fp(1);
46+
auto b = Fp(1234);
47+
auto c = Fp(555);
4848

4949
/* FF supports all operations required for a field, so addition, subtraction,
5050
* multiplication and "division". Division is defined as multiplication by the
@@ -71,16 +71,16 @@ int main() {
7171

7272
/* Using a PRG (see the PRG example), we can generate random field elements.
7373
*/
74-
std::cout << FF::Random(prg) << "\n";
75-
std::cout << FF::Random(prg) << "\n";
76-
std::cout << FF::Random(prg) << "\n";
74+
std::cout << Fp::Random(prg) << "\n";
75+
std::cout << Fp::Random(prg) << "\n";
76+
std::cout << Fp::Random(prg) << "\n";
7777

7878
/* Serialization is also supported.
7979
*/
80-
unsigned char buffer[FF::ByteSize()];
80+
unsigned char buffer[Fp::ByteSize()];
8181

8282
a.Write(buffer);
83-
auto a_ = FF::Read(buffer);
83+
auto a_ = Fp::Read(buffer);
8484

8585
std::cout << (a_ == a) << "\n";
8686
}

examples/03_secret_sharing.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
#include <stdexcept>
2626

2727
int main() {
28-
using FF = scl::FF<32>;
29-
using Vec = scl::Vec<FF>;
28+
using Fp = scl::Fp<32>;
29+
using Vec = scl::Vec<Fp>;
3030
scl::PRG prg;
3131

3232
/* We can easily create an additive secret sharing of some secret value:
3333
*/
34-
FF secret(12345);
34+
Fp secret(12345);
3535
Vec shares = scl::CreateAdditiveShares(secret, 5, prg);
3636

3737
std::cout << "additive shares:\n" << shares << "\n";
@@ -59,7 +59,7 @@ int main() {
5959

6060
/* If we introduce an error, then reconstruction fails
6161
*/
62-
shamir_shares[2] = FF(123);
62+
shamir_shares[2] = Fp(123);
6363
try {
6464
std::cout << scl::ReconstructShamir(shamir_shares, 1) << "\n";
6565
} catch (std::logic_error& e) {
@@ -78,7 +78,7 @@ int main() {
7878
/* first we need the alphas that were used when generating the shares. By
7979
* default these are just the field elements 1 through 4.
8080
*/
81-
Vec alphas = {FF(1), FF(2), FF(3), FF(4)};
81+
Vec alphas = {Fp(1), Fp(2), Fp(3), Fp(4)};
8282
auto pe = scl::ReconstructShamirRobust(shamir_shares, alphas, 1);
8383

8484
/* pe is a pair of polynomials. The first is the original polynomial used for
@@ -87,16 +87,16 @@ int main() {
8787
*
8888
* The secret is embedded in the constant term.
8989
*/
90-
std::cout << pe[0].Evaluate(FF(0)) << "\n";
90+
std::cout << pe[0].Evaluate(Fp(0)) << "\n";
9191

9292
/* This will be 0, indicating that the share corresponding to party 3 had an
9393
* error.
9494
*/
95-
std::cout << pe[1].Evaluate(FF(3)) << "\n";
95+
std::cout << pe[1].Evaluate(Fp(3)) << "\n";
9696

9797
/* Lastly, if there's too many errors, then correction is not possible
9898
*/
99-
shamir_shares[1] = FF(22);
99+
shamir_shares[1] = Fp(22);
100100
try {
101101
scl::ReconstructShamirRobust(shamir_shares, 1);
102102
} catch (std::logic_error& e) {

examples/04_networking.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include <iostream>
2424

25+
#include "scl/net/tcp_channel.h"
26+
2527
scl::NetworkConfig RunServer(int n) {
2628
scl::DiscoveryServer server(n);
2729
scl::Party party{0, "127.0.0.1", 5000};
@@ -63,7 +65,7 @@ int main(int argc, char** argv) {
6365
* around.
6466
*/
6567

66-
auto network = scl::Network::Create(config);
68+
auto network = scl::Network::Create<scl::TcpChannel>(config);
6769

6870
for (std::size_t i = 0; i < 3; ++i) {
6971
// similar to the TCP channel example, send our ID to everyone:

examples/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@ project( scl_examples VERSION 1.0 DESCRIPTION "SCL example programs" )
2020

2121
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -O2 -std=gnu++17" )
2222

23+
find_library(GMP gmp libgmp REQUIRED)
24+
find_library(SCL scl libscl REQUIRED)
25+
2326
## primitives
2427
set( primitives "01_primitives" )
2528
add_executable( "${primitives}" "${primitives}.cc" )
26-
target_link_libraries( "${primitives}" scl pthread )
29+
target_link_libraries( "${primitives}" "${SCL}" "${GMP}" pthread )
2730

2831
## finite fields
2932
set( finite_fields "02_finite_fields" )
3033
add_executable( "${finite_fields}" "${finite_fields}.cc" )
31-
target_link_libraries( "${finite_fields}" scl pthread )
34+
target_link_libraries( "${finite_fields}" "${SCL}" "${GMP}" pthread )
3235

3336
## secret sharing
3437
set( secret_sharing "03_secret_sharing" )
3538
add_executable( "${secret_sharing}" "${secret_sharing}.cc" )
36-
target_link_libraries( "${secret_sharing}" scl pthread )
39+
target_link_libraries( "${secret_sharing}" "${SCL}" "${GMP}" pthread )
3740

3841
## simple networking
3942
set( networking "04_networking" )
4043
add_executable( "${networking}" "${networking}.cc" )
41-
target_link_libraries( "${networking}" scl pthread )
44+
target_link_libraries( "${networking}" "${SCL}" "${GMP}" pthread )

include/scl/hash.h

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

21-
#ifndef _SCL_HASH_H
22-
#define _SCL_HASH_H
21+
#ifndef SCL_HASH_H
22+
#define SCL_HASH_H
2323

2424
#include <array>
2525
#include <cstdint>
@@ -214,4 +214,4 @@ std::string DigestToString(const D &digest) {
214214

215215
} // namespace scl
216216

217-
#endif // _SCL_HASH_H
217+
#endif // SCL_HASH_H

0 commit comments

Comments
 (0)