18
18
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
*/
20
20
21
- #include < scl/math.h>
22
- #include < scl/secret_sharing.h>
23
-
24
21
#include < iostream>
25
22
#include < stdexcept>
26
23
24
+ #include < scl/math.h>
25
+ #include < scl/secret_sharing.h>
26
+
27
27
int main () {
28
28
using Fp = scl::Fp<32 >;
29
29
using Vec = scl::Vec<Fp>;
30
- scl::PRG prg;
30
+
31
+ auto prg = scl::PRG::Create ();
31
32
32
33
/* We can easily create an additive secret sharing of some secret value:
33
34
*/
@@ -46,8 +47,8 @@ int main() {
46
47
* correction. Lets see error detection at work first
47
48
*/
48
49
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);
51
52
/* We create 4 shamir shares with a threshold of 1.
52
53
*/
53
54
auto shamir_shares = factory.Share (secret);
@@ -56,17 +57,15 @@ int main() {
56
57
/* Of course, these can be reconstructed. The second parameter is the
57
58
* threshold. This performs reconstruction with error detection.
58
59
*/
59
- auto recon = factory.GetInterpolator ();
60
60
auto shamir_reconstructed =
61
- recon. Reconstruct (shamir_shares, scl::details ::SecurityLevel::DETECT);
61
+ factory. Recover (shamir_shares, scl::SecurityLevel::DETECT);
62
62
std::cout << shamir_reconstructed << " \n " ;
63
63
64
64
/* If we introduce an error, then reconstruction fails
65
65
*/
66
66
shamir_shares[2 ] = Fp (123 );
67
67
try {
68
- std::cout << recon.Reconstruct (shamir_shares,
69
- scl::details::SecurityLevel::DETECT)
68
+ std::cout << factory.Recover (shamir_shares, scl::SecurityLevel::DETECT)
70
69
<< " \n " ;
71
70
} catch (std::logic_error& e) {
72
71
std::cout << e.what () << " \n " ;
@@ -75,7 +74,7 @@ int main() {
75
74
/* On the other hand, we can use the robust reconstruction since the threshold
76
75
* is low enough. I.e., because 4 >= 3*1 + 1.
77
76
*/
78
- auto r = recon. Reconstruct (shamir_shares);
77
+ auto r = factory. Recover (shamir_shares);
79
78
std::cout << r << " \n " ;
80
79
81
80
/* With a bit of extra work, we can even learn which share had the error.
@@ -104,7 +103,7 @@ int main() {
104
103
*/
105
104
shamir_shares[1 ] = Fp (22 );
106
105
try {
107
- recon. Reconstruct (shamir_shares);
106
+ factory. Recover (shamir_shares);
108
107
} catch (std::logic_error& e) {
109
108
std::cout << e.what () << " \n " ;
110
109
}
0 commit comments