Skip to content

Commit

Permalink
Merge pull request #184 from gaoweihe/develop
Browse files Browse the repository at this point in the history
FIX: fill `t` and `n` fields in BLSPublicKey constructors; fill `t` and `n` fields of BLS public keys while generate sample keys
  • Loading branch information
olehnikolaiev authored Jul 1, 2022
2 parents 3407b52 + b29f902 commit d157b07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion bls/BLSPrivateKeyShare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ BLSPrivateKeyShare::generateSampleKeys( size_t _requiredSigners, size_t _totalSi
std::vector< libff::alt_bn128_Fr > skeys = dkg_obj.SecretKeyContribution( pol );

libff::alt_bn128_Fr common_skey = pol.at( 0 );
std::shared_ptr< BLSPublicKey > pkey_ptr = std::make_shared< BLSPublicKey >( common_skey );
std::shared_ptr< BLSPublicKey > pkey_ptr = std::make_shared< BLSPublicKey >(
common_skey,
_requiredSigners,
_totalSigners
);

for ( size_t i = 0; i < _totalSigners; ++i ) {
std::string key_str = libBLS::ThresholdUtils::fieldElementToString( skeys.at( i ) );
Expand Down
12 changes: 10 additions & 2 deletions bls/BLSPublicKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,24 @@ BLSPublicKey::BLSPublicKey( const std::shared_ptr< std::vector< std::string > >
}
}

BLSPublicKey::BLSPublicKey( const libff::alt_bn128_G2& pkey ) {
BLSPublicKey::BLSPublicKey( const libff::alt_bn128_G2& pkey, size_t t, size_t n )
: t( t ), n( n ) {
libBLS::ThresholdUtils::initCurve();

// do not check signers for compatibility
// libBLS::ThresholdUtils::checkSigners( t, n );

libffPublicKey = std::make_shared< libff::alt_bn128_G2 >( pkey );
if ( libffPublicKey->is_zero() ) {
throw libBLS::ThresholdUtils::IsNotWellFormed( "Zero BLS Public Key" );
}
}

BLSPublicKey::BLSPublicKey( const libff::alt_bn128_Fr& skey ) {
BLSPublicKey::BLSPublicKey(const libff::alt_bn128_Fr& skey, size_t t, size_t n )
: t( t ), n( n ) {
// do not check signers for compatibility
// libBLS::ThresholdUtils::checkSigners( t, n );

libffPublicKey = std::make_shared< libff::alt_bn128_G2 >( skey * libff::alt_bn128_G2::one() );
if ( libffPublicKey->is_zero() ) {
throw libBLS::ThresholdUtils::IsNotWellFormed( "Public Key is equal to zero or corrupt" );
Expand Down
6 changes: 4 additions & 2 deletions bls/BLSPublicKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class BLSPublicKey {

public:
BLSPublicKey( const std::shared_ptr< std::vector< std::string > > );
BLSPublicKey( const libff::alt_bn128_Fr& skey );
BLSPublicKey( const libff::alt_bn128_G2& skey );
// default value set to 0 for compatibility
BLSPublicKey( const libff::alt_bn128_Fr& skey, size_t t = 0, size_t n = 0 );
// default value set to 0 for compatibility
BLSPublicKey( const libff::alt_bn128_G2& skey, size_t t = 0, size_t n = 0 );

BLSPublicKey(
std::shared_ptr< std::map< size_t, std::shared_ptr< BLSPublicKeyShare > > > map_pkeys_koefs,
Expand Down

0 comments on commit d157b07

Please sign in to comment.