Skip to content

Commit

Permalink
Changes poly.* and vss.*
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptographer63 committed Sep 19, 2023
1 parent eaddf94 commit b081846
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
6 changes: 2 additions & 4 deletions yacl/crypto/primitives/vss/poly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace yacl::crypto {
// Generate a random polynomial with the given zero value, threshold, and
// modulus_.
void Polynomial::CreatePolynomial(const math::MPInt& zero_value,
const size_t threshold,
const math::MPInt& modulus) {
size_t threshold) {
// Create a vector to hold the polynomial coefficients.
std::vector<math::MPInt> coefficients(threshold);

Expand All @@ -21,11 +20,10 @@ void Polynomial::CreatePolynomial(const math::MPInt& zero_value,

// Generate a random integer less than modulus_ and assign it to
// coefficient_i.
math::MPInt::RandomLtN(modulus, &coefficient_i);
math::MPInt::RandomLtN(this->modulus_, &coefficient_i);

// Set the current coefficient to the generated random value.
coefficients[i] = coefficient_i;
modulus_ = modulus;
}

// Set the generated coefficients as the coefficients of the polynomial.
Expand Down
9 changes: 1 addition & 8 deletions yacl/crypto/primitives/vss/poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ namespace yacl::crypto {
// Polynomial class for polynomial manipulation and sharing.
class Polynomial {
public:
/**
* @brief Construct a new Polynomial object
*
*/
Polynomial(){};

/**
* @brief Construct a new Polynomial object with modulus
*
Expand All @@ -34,8 +28,7 @@ class Polynomial {
* @param threshold
* @param modulus
*/
void CreatePolynomial(const math::MPInt& zero_value, const size_t threshold,
const math::MPInt& modulus);
void CreatePolynomial(const math::MPInt& zero_value, size_t threshold);

/**
* @brief Horner's method, also known as Horner's rule or Horner's scheme, is
Expand Down
6 changes: 3 additions & 3 deletions yacl/crypto/primitives/vss/vss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ VerifiableSecretSharing::CreateShare(const math::MPInt& secret,
// Create a polynomial with the secret as the constant term and random
// coefficients.
std::vector<math::MPInt> coefficients(this->GetThreshold());
poly.CreatePolynomial(secret, this->GetThreshold(), this->GetPrime());
poly.CreatePolynomial(secret, this->GetThreshold());

std::vector<math::MPInt> xs(this->GetTotal());
std::vector<math::MPInt> ys(this->GetTotal());
Expand Down Expand Up @@ -43,7 +43,7 @@ VerifiableSecretSharing::CreateShareWithCommits(
const std::unique_ptr<yacl::crypto::EcGroup>& ecc_group, Polynomial& poly) {
// Create a polynomial with the secret as the constant term and random
// coefficients.
poly.CreatePolynomial(secret, this->threshold_, this->prime_);
poly.CreatePolynomial(secret, this->threshold_);

std::vector<math::MPInt> xs(this->total_);
std::vector<math::MPInt> ys(this->total_);
Expand All @@ -69,7 +69,7 @@ VerifiableSecretSharing::CreateShareWithCommits(

// Recover the secret from the shares using Lagrange interpolation.
math::MPInt VerifiableSecretSharing::RecoverSecret(
std::vector<VerifiableSecretSharing::Share> shares) {
absl::Span<const VerifiableSecretSharing::Share> shares) {
YACL_ENFORCE(shares.size() == threshold_);

math::MPInt secret(0);
Expand Down
2 changes: 1 addition & 1 deletion yacl/crypto/primitives/vss/vss.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class VerifiableSecretSharing {
* @param poly
* @return math::MPInt
*/
math::MPInt RecoverSecret(std::vector<Share> shares);
math::MPInt RecoverSecret(absl::Span<const Share> shares);

// New name for the type representing the result of GenerateShareWithCommits
// function.
Expand Down
3 changes: 1 addition & 2 deletions yacl/crypto/primitives/vss/vss_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST(VerifiableSecretSharingTest, TestCreateAndVerifyShares) {
yacl::crypto::VerifiableSecretSharing vss(20, 10, modulus);

// Initialize a polynomial for the secret sharing scheme
yacl::crypto::Polynomial polynomial;
yacl::crypto::Polynomial polynomial(modulus);

// Generate shares and commitments for the secret
using ShareAndCommitPair =
Expand All @@ -41,7 +41,6 @@ TEST(VerifiableSecretSharingTest, TestCreateAndVerifyShares) {

// Reconstruct the secret using the shares and the polynomial
math::MPInt reconstructed_secret = vss.RecoverSecret(shares);
SPDLOG_INFO("reconstructed_secret is : {}", reconstructed_secret);
// Check if the reconstructed secret matches the original secret
EXPECT_EQ(reconstructed_secret, original_secret);

Expand Down

0 comments on commit b081846

Please sign in to comment.