1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! # Shamir's Secret Sharing (SSS) Module
//!
//! This module implements Shamir's Secret Sharing, a cryptographic algorithm to distribute
//! a secret amongst a group of participants, each of whom is allocated a share of the secret.
//! The unique property of SSS is that the secret can only be reconstructed when a sufficient
//! number of shares (threshold) are combined together; individually, shares do not reveal
//! any information about the secret.
//!
//! The scheme is based on polynomial interpolation over a finite field, ensuring security
//! and mathematical robustness. It has applications in secure key storage, distributed systems,
//! and wherever secret management is critical.
//!
//! ## Key Functionalities
//! - **Share Generation**: Divides a secret into multiple shares, ensuring that only a
//! specified number of shares can reconstruct the secret.
//! - **Secret Reconstruction**: Combines a sufficient number of shares to reconstruct
//! the original secret using Lagrange interpolation.
//!
//! ## Usage
//! This module is designed to be used where secure and distributed control over a secret
//! is necessary. It leverages the `Polynomial` and `lagrange_interpolation_zero` functions
//! from the `utils` module for its core operations, aligning with cryptographic best practices.
//!
use ;
use cratePolynomial;
use cratelagrange_interpolation_zero;
/// Generates shares for Shamir's Secret Sharing scheme.
///
/// # Arguments
///
/// * `secret` - The secret value to be shared.
/// * `threshold` - The threshold value for reconstructing the secret.
/// * `num_shares` - The number of shares to generate.
/// * `modulus` - The modulus for the polynomial operations.
///
/// # Returns
///
/// A vector of tuples representing the generated shares. Each tuple contains the x-coordinate
/// (share index) and the corresponding y-coordinate (share value).
/// Reconstructs the secret from shares using Lagrange interpolation.
///
/// # Arguments
///
/// * `shares` - A slice of tuples representing the shares. Each tuple contains the x-coordinate
/// (share index) and the corresponding y-coordinate (share value).
/// * `modulus` - The modulus used for the finite field operations.
///
/// # Returns
///
/// The reconstructed secret if successful, otherwise None.