Skip to content

Commit d1c5151

Browse files
authored
new version (#17)
1 parent 7d6384b commit d1c5151

Some content is hidden

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

68 files changed

+2595
-1720
lines changed

CMakeLists.txt

+5-2
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 6.2.0 DESCRIPTION "Secure Computation Library" )
19+
project( scl VERSION 0.7.0 DESCRIPTION "Secure Computation Library" )
2020

2121
if(NOT CMAKE_BUILD_TYPE)
2222
set(CMAKE_BUILD_TYPE Release)
@@ -64,7 +64,7 @@ if(WITH_EC MATCHES ON)
6464
src/scl/math/ops_gmp_ff.cc
6565
src/scl/math/secp256k1_field.cc
6666
src/scl/math/secp256k1_curve.cc
67-
src/scl/math/secp256k1_order.cc
67+
src/scl/math/secp256k1_scalar.cc
6868
src/scl/math/number.cc)
6969
endif()
7070

@@ -102,6 +102,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
102102
test/scl/util/test_sha256.cc
103103
test/scl/util/test_ecdsa.cc
104104
test/scl/util/test_cmdline.cc
105+
test/scl/util/test_merkle.cc
105106

106107
test/scl/gf7.cc
107108
test/scl/math/test_mersenne61.cc
@@ -137,7 +138,9 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
137138
test/scl/simulation/test_result.cc
138139
test/scl/simulation/test_measurement.cc
139140
test/scl/simulation/test_mem_channel_buffer.cc
141+
test/scl/simulation/test_channel.cc
140142
test/scl/simulation/test_env.cc
143+
test/scl/simulation/test_manager.cc
141144

142145
test/scl/serialization/test_serializer.cc)
143146

RELEASE.txt

+29-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
6.2.0: More functionality for Number
1+
0.7.0:
2+
- Exponentiation for field elements
3+
- Various bug fixes. Especially in the simulation code
4+
- Change versioning. Make all releases start with 0 (to mark them as pre-release).
5+
- Merkle tree hashing.
6+
- Make it possible to hash anything which has a Serializer specialization.
7+
- Vec::ScalarMultiply now allows multiplying a Vec of curve points with a
8+
scalar. Same for Mat.
9+
- Make it possible to prematurely terminate a party in a simulation.
10+
- Introduce a "Manager" class that contains the parameters of a simulation.
11+
- Rename EC::Order to EC::ScalarField.
12+
- Introduce a function for acquiring the order of a field.
13+
- Make utility functions in ECDSA public.
14+
- Various optimizations for the elliptic curve code.
15+
- Simplify the measurement class.
16+
17+
0.6.2: More functionality for Number
218
- Add modulo operator to Number.
319
- Add some mathematical functions that operate on numbers.
420
- Make Number serializable; add Serializer specialization.
521
- Add a simple command-line argument parser.
622

7-
6.1.0: Extend serialization functionality
23+
0.6.1: Extend serialization functionality
824
- Make Write methods return the number of bytes written.
925
- Make it possible to serialize vectors with arbitrary content.
1026

11-
6.0.0: Improvements to serialization and Channels.
27+
0.6.0: Improvements to serialization and Channels.
1228
- Added a Serializer type that can be specialized in order to specify how
1329
various objects are converted to bytes.
1430
- Added a Packet type that allows reading and writing almost arbitrary objects,
@@ -17,37 +33,33 @@
1733
Packets. Remove old Send/Recv overloads.
1834
- Remove proto::ProtocolEnvironment.
1935

20-
5.3.0: ECDSA
36+
0.5.3: ECDSA
2137
- Added functionality for creating ECDSA signatures.
2238

23-
5.2.0: Protocol environment extensions
39+
0.5.2: Protocol environment extensions
2440
- Make it possible to create "checkpoints" through the protocol environment
2541
clock.
2642
- fix a bug that prevented the documentation from being buildt
2743
- Rename ProtocolEnvironment to Env, and introduce a typedef for backwards
2844
compatability.
2945

30-
5.1.2: Style changes
46+
0.5.1: Style changes
3147
- Change naming style of private field members.
32-
33-
5.1.1: Bug fixes and simplifications
3448
- Simplifed the NextToRun logic because a greedy strategy too often results in
3549
rollbacks.
3650
- Fixed a bug in the Rollback logic where WriteOps weren't rolled back
3751
correctly.
38-
39-
5.1: Vec-Mat multiplication
4052
- Add a Vec Mat to Vec multiplication function to Mat
4153
- Minor refactoring of test_mat.cc
4254

43-
5.0: Simulation
55+
0.5.0: Simulation
4456
- Added a new module for simulating protocol executions under different network
4557
conditions.
4658
- Refactored layout with respect to namespaces. details no longer exists, and
4759
the different modules have gotten their own namespace.
4860
- Up test coverage to 100%. Minor refactoring to the actions.
4961

50-
4.0: Shamir, Feldman, SHA-256
62+
0.4.0: Shamir, Feldman, SHA-256
5163
- Refactor Shamir to allow caching of Lagrange coefficients
5264
- Add support for Feldman Secret Sharing
5365
- Add support for SHA-256
@@ -58,7 +70,7 @@
5870
- Fix negation of 0 in Secp256k1::Field and Secp256k1::Order
5971
- Make serialization and deserialization of curve points behave more sanely
6072

61-
3.0: More features, build changes
73+
0.3.0: More features, build changes
6274
- Add method for returning a point as a pair of affine coordinates
6375
- Add method to check if a channel has data available
6476
- Allow sending and receiving STL vectors without specifying the size
@@ -72,12 +84,12 @@
7284
- disable actions for master branch
7385
- add clang-tidy action
7486

75-
2.1: More Finite Fields
87+
0.2.1: More Finite Fields
7688
- Provide a FF implementation for computations modulo the order of Secp256k1
7789
- Extend EC with support for scalar multiplications with scalars from a finite
7890
field of size the order of a subgroup.
7991

80-
2.0: Elliptic curves and finite field refactoring
92+
0.2.0: Elliptic curves and finite field refactoring
8193
- Make it simpler to define new finite fields
8294
- Include optional (but enabled by default) support for elliptic curves
8395
- Implement secp256k1
@@ -87,13 +99,13 @@
8799
- Rename FF<Bits> to Fp<Bits>.
88100
- Move class FF into scl namespace.
89101

90-
1.1: Refactoring of finite field internals
102+
0.1.1: Refactoring of finite field internals
91103
- Finite field operations are now defined by individual specializations of
92104
templated functions
93105
- Remove DEFINE_FINITE_FIELD macro
94106
- Move Mersenne61 and Mersenne127 definitions into ff.h
95107

96-
1.0: Initial public version of SCL.
108+
0.1.0: Initial public version of SCL.
97109
- Features:
98110
- Math:
99111
- Finite Field class with two instantiations based on Mersenne primes

include/scl/math/curves/secp256k1.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct Secp256k1 {
5757
/**
5858
* @brief Finite field modulo a Secp256k1 prime order sub-group.
5959
*/
60-
struct Order {
60+
struct Scalar {
6161
/**
6262
* @brief Internal type of elements.
6363
*/

include/scl/math/ec.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class EC final : Add<EC<Curve>>, Eq<EC<Curve>>, Print<EC<Curve>> {
4747
/**
4848
* @brief A large sub-group of this curve.
4949
*/
50-
using Order = FF<typename Curve::Order>;
50+
using ScalarField = FF<typename Curve::Scalar>;
5151

5252
/**
5353
* @brief The size of a curve point in bytes.
@@ -165,7 +165,7 @@ class EC final : Add<EC<Curve>>, Eq<EC<Curve>>, Print<EC<Curve>> {
165165
* @param scalar the scalar
166166
* @return this.
167167
*/
168-
EC& operator*=(const Order& scalar) {
168+
EC& operator*=(const ScalarField& scalar) {
169169
CurveScalarMultiply<Curve>(m_value, scalar);
170170
return *this;
171171
}
@@ -187,7 +187,7 @@ class EC final : Add<EC<Curve>>, Eq<EC<Curve>>, Print<EC<Curve>> {
187187
* @param scalar the scalar
188188
* @return the point multiplied with the scalar.
189189
*/
190-
friend EC operator*(const EC& point, const Order& scalar) {
190+
friend EC operator*(const EC& point, const ScalarField& scalar) {
191191
EC copy(point);
192192
return copy *= scalar;
193193
}
@@ -208,10 +208,9 @@ class EC final : Add<EC<Curve>>, Eq<EC<Curve>>, Print<EC<Curve>> {
208208
* @param scalar the scalar
209209
* @return the point multiplied with the scalar.
210210
*/
211-
friend EC operator*(const FF<typename Curve::Order>& scalar,
212-
const EC& point) {
211+
friend EC operator*(const ScalarField& scalar, const EC& point) {
213212
return point * scalar;
214-
}
213+
} // LCOV_EXCL_LINE
215214

216215
/**
217216
* @brief Negate this point.
@@ -229,30 +228,30 @@ class EC final : Add<EC<Curve>>, Eq<EC<Curve>>, Print<EC<Curve>> {
229228
*/
230229
bool Equal(const EC& other) const {
231230
return CurveEqual<Curve>(m_value, other.m_value);
232-
}
231+
} // LCOV_EXCL_LINE
233232

234233
/**
235234
* @brief Check if this point is equal to the point at inifity.
236235
* @return true if this point is equal to the point at inifity.
237236
*/
238237
bool PointAtInfinity() const {
239238
return CurveIsPointAtInfinity<Curve>(m_value);
240-
}
239+
} // LCOV_EXCL_LINE
241240

242241
/**
243242
* @brief Return this point as a pair of affine coordinates.
244243
* @return this point as a pair of affine coordinates.
245244
*/
246245
std::array<Field, 2> ToAffine() const {
247246
return CurveToAffine<Curve>(m_value);
248-
}
247+
} // LCOV_EXCL_LINE
249248

250249
/**
251250
* @brief Output this point as a string.
252251
*/
253252
std::string ToString() const {
254253
return CurveToString<Curve>(m_value);
255-
}
254+
} // LCOV_EXCL_LINE
256255

257256
/**
258257
* @brief Write this point to a buffer.
@@ -261,7 +260,7 @@ class EC final : Add<EC<Curve>>, Eq<EC<Curve>>, Print<EC<Curve>> {
261260
*/
262261
void Write(unsigned char* dest, bool compress = true) const {
263262
CurveToBytes<Curve>(dest, m_value, compress);
264-
}
263+
} // LCOV_EXCL_LINE
265264

266265
private:
267266
typename Curve::ValueType m_value;

include/scl/math/ec_ops.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void CurveScalarMultiply(typename C::ValueType& out, const Number& scalar);
110110
*/
111111
template <typename C>
112112
void CurveScalarMultiply(typename C::ValueType& out,
113-
const FF<typename C::Order>& scalar);
113+
const FF<typename C::Scalar>& scalar);
114114

115115
/**
116116
* @brief Check if two elliptic curve points are equal.

include/scl/math/ff.h

+30
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,36 @@ class FF final : Add<FF<Field>>,
255255
friend class FFAccess;
256256
};
257257

258+
/**
259+
* @brief Returns the order of a finite field.
260+
*/
261+
template <typename F>
262+
Number Order();
263+
264+
/**
265+
* @brief Raise an element to a power.
266+
* @param base the base.
267+
* @param exp the exponent.
268+
* @return \p base raised to the \p exp th power.
269+
*/
270+
template <typename T>
271+
FF<T> Exp(const FF<T>& base, std::size_t exp) {
272+
if (exp == 0) {
273+
return FF<T>::One();
274+
}
275+
276+
const auto n = sizeof(std::size_t) * 8 - __builtin_clzll(exp);
277+
FF r = FF<T>::One();
278+
for (std::size_t i = n; i-- > 0;) {
279+
r *= r;
280+
if (((exp >> i) & 1) == 1) {
281+
r *= base;
282+
}
283+
}
284+
285+
return r;
286+
}
287+
258288
} // namespace scl::math
259289

260290
#endif // SCL_MATH_FF_H

include/scl/math/ff_ops.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <string>
2424
#include <type_traits>
2525

26+
#include "scl/math/number.h"
27+
2628
namespace scl::math {
2729

2830
/**

include/scl/math/lagrange.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ namespace scl::math {
5252
* @see https://en.wikipedia.org/wiki/Lagrange_polynomial
5353
*/
5454
template <typename T>
55-
Vec<T> ComputeLagrangeBasis(const math::Vec<T>& nodes, int x) {
56-
const auto _x = T{x};
55+
Vec<T> ComputeLagrangeBasis(const math::Vec<T>& nodes, const T& x) {
5756
const auto n = nodes.Size();
5857
std::vector<T> b;
5958
b.reserve(n);
@@ -63,14 +62,25 @@ Vec<T> ComputeLagrangeBasis(const math::Vec<T>& nodes, int x) {
6362
for (std::size_t j = 0; j < n; ++j) {
6463
if (i != j) {
6564
const auto xj = nodes[j];
66-
ell *= (_x - xj) / (xi - xj);
65+
ell *= (x - xj) / (xi - xj);
6766
}
6867
}
6968
b.emplace_back(ell);
7069
}
7170
return b;
7271
}
7372

73+
/**
74+
* @brief Computes a lagrange basis for a set of nodes.
75+
* @param nodes the set of nodes.
76+
* @param x the evaluation point x.
77+
* @see ComputeLagrangeBasis
78+
*/
79+
template <typename T>
80+
Vec<T> ComputeLagrangeBasis(const math::Vec<T>& nodes, int x) {
81+
return ComputeLagrangeBasis(nodes, T{x});
82+
}
83+
7484
} // namespace scl::math
7585

7686
#endif // SCL_MATH_LAGRANGE_H

include/scl/math/mat.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,10 @@ class Mat : Print<Mat<Elem>> {
332332
* @param scalar the scalar
333333
* @return this scaled by \p scalar.
334334
*/
335-
Mat ScalarMultiply(const Elem& scalar) const {
335+
template <
336+
typename Scalar,
337+
std::enable_if_t<util::HasOperatorMul<Elem, Scalar>::value, bool> = true>
338+
Mat ScalarMultiply(const Scalar& scalar) const {
336339
Mat copy(m_rows, m_cols, m_values);
337340
return copy.ScalarMultiplyInPlace(scalar);
338341
}
@@ -342,7 +345,10 @@ class Mat : Print<Mat<Elem>> {
342345
* @param scalar the scalar
343346
* @return this scaled by \p scalar.
344347
*/
345-
Mat& ScalarMultiplyInPlace(const Elem& scalar) {
348+
template <
349+
typename Scalar,
350+
std::enable_if_t<util::HasOperatorMul<Elem, Scalar>::value, bool> = true>
351+
Mat& ScalarMultiplyInPlace(const Scalar& scalar) {
346352
for (auto& v : m_values) {
347353
v *= scalar;
348354
}

0 commit comments

Comments
 (0)