Skip to content

Commit

Permalink
Check length of Commit in VSS Scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
sword03 committed Jan 4, 2024
1 parent 60c5e73 commit 5531ce4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/crypto-suites/crypto-sss/vsss.cpp
Expand Up @@ -29,7 +29,8 @@ void MakeSharesWithCommitsAndCoes(vector<Point> &shares, vector<CurvePoint> &com
poly.GetCommits(commits, g);
}

bool VerifyShare(const vector<CurvePoint> &commits, const BN &shareIndex, const BN &share, const CurvePoint &g, const BN &prime) {
bool VerifyShare(const vector<CurvePoint> &commits, int threshold, const BN &shareIndex, const BN &share, const CurvePoint &g, const BN &prime) {
if((int)commits.size() != threshold) return false;
return Polynomial::VerifyCommits(commits, shareIndex, share, g, prime);
}

Expand Down
3 changes: 2 additions & 1 deletion src/crypto-suites/crypto-sss/vsss.h
Expand Up @@ -78,13 +78,14 @@ MakeSharesWithCommitsAndCoes(std::vector<Point> &shares, std::vector<safeheron::
* Verify share in Feldman's scheme
*
* @param commits
* @param threshold
* @param shareIndex
* @param share
* @param curve
* @returns {boolean}
*/
bool
VerifyShare(const std::vector<safeheron::curve::CurvePoint> &commits, const safeheron::bignum::BN &shareIndex, const safeheron::bignum::BN &share, const safeheron::curve::CurvePoint &g, const safeheron::bignum::BN &prime);
VerifyShare(const std::vector<safeheron::curve::CurvePoint> &commits, int threshold, const safeheron::bignum::BN &shareIndex, const safeheron::bignum::BN &share, const safeheron::curve::CurvePoint &g, const safeheron::bignum::BN &prime);

/**
* Recover secret
Expand Down
4 changes: 2 additions & 2 deletions src/crypto-suites/crypto-sss/vsss_ed25519.cpp
Expand Up @@ -35,8 +35,8 @@ void MakeSharesWithCommitsAndCoes(vector<Point> &shares, vector<CurvePoint> &com
vsss::MakeSharesWithCommitsAndCoes(shares, commits, secret, threshold, shareIndexs, coeArray, curv->n, curv->g);
}

bool VerifyShare(const vector<CurvePoint> &commits, const BN &shareIndex, const BN &share) {
return vsss::VerifyShare(commits, shareIndex, share, curv->g, curv->n);
bool VerifyShare(const vector<CurvePoint> &commits, int threshold, const BN &shareIndex, const BN &share) {
return vsss::VerifyShare(commits, threshold, shareIndex, share, curv->g, curv->n);
}

void RecoverSecret(BN &secret, const vector<Point> &shares) {
Expand Down
3 changes: 2 additions & 1 deletion src/crypto-suites/crypto-sss/vsss_ed25519.h
Expand Up @@ -87,13 +87,14 @@ MakeSharesWithCommitsAndCoes(std::vector<Point> &shares, std::vector<safeheron::
* Verify share in Feldman's scheme
*
* @param commits
* @param threshold
* @param shareIndex
* @param share
* @param curve
* @returns {boolean}
*/
bool
VerifyShare(const std::vector<safeheron::curve::CurvePoint> &commits, const safeheron::bignum::BN &shareIndex,
VerifyShare(const std::vector<safeheron::curve::CurvePoint> &commits, int threshold, const safeheron::bignum::BN &shareIndex,
const safeheron::bignum::BN &share);

/**
Expand Down
4 changes: 2 additions & 2 deletions src/crypto-suites/crypto-sss/vsss_secp256k1.cpp
Expand Up @@ -36,8 +36,8 @@ void MakeSharesWithCommitsAndCoes(vector<Point> &shares, vector<CurvePoint> &com
vsss::MakeSharesWithCommitsAndCoes(shares, commits, secret, threshold, shareIndexs, coeArray, curv->n, curv->g);
}

bool VerifyShare(const vector<CurvePoint> &commits, const BN &shareIndex, const BN &share) {
return vsss::VerifyShare(commits, shareIndex, share, curv->g, curv->n);
bool VerifyShare(const vector<CurvePoint> &commits, int threshold, const BN &shareIndex, const BN &share) {
return vsss::VerifyShare(commits, threshold, shareIndex, share, curv->g, curv->n);
}

void RecoverSecret(BN &secret, const vector<Point> &shares) {
Expand Down
3 changes: 2 additions & 1 deletion src/crypto-suites/crypto-sss/vsss_secp256k1.h
Expand Up @@ -87,13 +87,14 @@ MakeSharesWithCommitsAndCoes(std::vector<Point> &shares, std::vector<safeheron::
* Verify share in Feldman's scheme
*
* @param commits
* @param threshold
* @param shareIndex
* @param share
* @param curve
* @returns {boolean}
*/
bool
VerifyShare(const std::vector<safeheron::curve::CurvePoint> &commits, const safeheron::bignum::BN &shareIndex,
VerifyShare(const std::vector<safeheron::curve::CurvePoint> &commits, int threshold, const safeheron::bignum::BN &shareIndex,
const safeheron::bignum::BN &share);

/**
Expand Down
8 changes: 4 additions & 4 deletions test/crypto-sss/sss-test.cpp
Expand Up @@ -87,7 +87,7 @@ TEST(Secret_Sharing_Scheme, Example2)
std::cout << "x: " << str << std::endl;
shares[i].y.ToHexStr(str);
std::cout << "y: " << str << std::endl;
EXPECT_TRUE(vsss_secp256k1::VerifyShare(cmts, shares[i].x, shares[i].y));
EXPECT_TRUE(vsss_secp256k1::VerifyShare(cmts, threshold, shares[i].x, shares[i].y));
}

BN recovered_secret;
Expand Down Expand Up @@ -120,7 +120,7 @@ TEST(Secret_Sharing_Scheme, Example3)
std::cout << "x: " << str << std::endl;
shares[i].y.ToHexStr(str);
std::cout << "y: " << str << std::endl;
EXPECT_TRUE(vsss_secp256k1::VerifyShare(cmts, shares[i].x, shares[i].y));
EXPECT_TRUE(vsss_secp256k1::VerifyShare(cmts, threshold, shares[i].x, shares[i].y));
}

BN recovered_secret;
Expand Down Expand Up @@ -149,7 +149,7 @@ TEST(Secret_Sharing_Scheme, Example4)
std::cout << "x: " << str << std::endl;
shares[i].y.ToHexStr(str);
std::cout << "y: " << str << std::endl;
EXPECT_TRUE(vsss_secp256k1::VerifyShare(cmts, shares[i].x, shares[i].y));
EXPECT_TRUE(vsss_secp256k1::VerifyShare(cmts, threshold, shares[i].x, shares[i].y));
}

BN recovered_secret;
Expand All @@ -174,7 +174,7 @@ TEST(Secret_Sharing_Scheme, Example5)
std::cout << "x: " << str << std::endl;
shares[i].y.ToHexStr(str);
std::cout << "y: " << str << std::endl;
EXPECT_TRUE(vsss_secp256k1::VerifyShare(cmts, shares[i].x, shares[i].y));
EXPECT_TRUE(vsss_secp256k1::VerifyShare(cmts, threshold, shares[i].x, shares[i].y));
}

BN recovered_secret;
Expand Down

0 comments on commit 5531ce4

Please sign in to comment.