forked from skalenetwork/libBLS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DKGBLSWrapper.cpp
84 lines (65 loc) · 3.13 KB
/
DKGBLSWrapper.cpp
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
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of libBLS.
libBLS is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libBLS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with libBLS. If not, see <https://www.gnu.org/licenses/>.
@file TEPrivateKeyShare.h
@author Sveta Rogova
@date 2019
*/
#include "DKGBLSWrapper.h"
#include <bls/BLSSignature.h>
#include <dkg/dkg.h>
DKGBLSWrapper::DKGBLSWrapper( size_t _requiredSigners, size_t _totalSigners )
: requiredSigners( _requiredSigners ), totalSigners( _totalSigners ) {
BLSSignature::checkSigners( _requiredSigners, _totalSigners );
DKGBLSSecret temp( _requiredSigners, _totalSigners );
dkg_secret_ptr = std::make_shared< DKGBLSSecret >( temp );
}
bool DKGBLSWrapper::VerifyDKGShare( size_t _signerIndex, const libff::alt_bn128_Fr& _share,
const std::shared_ptr< std::vector< libff::alt_bn128_G2 > >& _verification_vector ) {
if ( _share.is_zero() )
throw std::runtime_error( " Zero secret share" );
if ( _verification_vector == nullptr ) {
throw std::runtime_error( " Null verification vector" );
}
if ( _verification_vector->size() != requiredSigners )
throw std::runtime_error( "Wrong vector size" );
signatures::Dkg dkg( requiredSigners, totalSigners );
return dkg.Verification( _signerIndex, _share, *_verification_vector );
}
void DKGBLSWrapper::setDKGSecret(
std::shared_ptr< std::vector< libff::alt_bn128_Fr > > _poly_ptr ) {
if ( _poly_ptr == nullptr )
throw std::runtime_error( "Null polynomial ptr" );
dkg_secret_ptr->setPoly( *_poly_ptr );
}
std::shared_ptr< std::vector< libff::alt_bn128_Fr > > DKGBLSWrapper::createDKGSecretShares() {
return std::make_shared< std::vector< libff::alt_bn128_Fr > >(
dkg_secret_ptr->getDKGBLSSecretShares() );
}
std::shared_ptr< std::vector< libff::alt_bn128_G2 > > DKGBLSWrapper::createDKGPublicShares() {
return std::make_shared< std::vector< libff::alt_bn128_G2 > >(
dkg_secret_ptr->getDKGBLSPublicShares() );
}
BLSPrivateKeyShare DKGBLSWrapper::CreateBLSPrivateKeyShare(
std::shared_ptr< std::vector< libff::alt_bn128_Fr > > secret_shares_ptr ) {
if ( secret_shares_ptr == nullptr )
throw std::runtime_error( "Null secret_shares_ptr " );
if ( secret_shares_ptr->size() != totalSigners )
throw std::runtime_error( "Wrong number of secret key parts " );
signatures::Dkg dkg( requiredSigners, totalSigners );
libff::alt_bn128_Fr skey_share = dkg.SecretKeyShareCreate( *secret_shares_ptr );
return BLSPrivateKeyShare( skey_share, requiredSigners, totalSigners );
}
libff::alt_bn128_Fr DKGBLSWrapper::getValueAt0() {
return dkg_secret_ptr->getValueAt0();
}