11 #ifndef BUILD_BITCOIN_INTERNAL 61 impl = bls::PrivateKey::FromBytes((
const uint8_t*)buf);
70 impl.Serialize((uint8_t*)buf);
77 impl = bls::PrivateKey::AggregateInsecure({
impl, o.
impl});
87 std::vector<bls::PrivateKey> v;
88 v.reserve(sks.size());
89 for (
auto& sk : sks) {
90 v.emplace_back(sk.impl);
93 auto agg = bls::PrivateKey::AggregateInsecure(v);
101 #ifndef BUILD_BITCOIN_INTERNAL 104 unsigned char buf[32];
108 impl = bls::PrivateKey::FromBytes((
const uint8_t*)buf);
127 std::vector<bls::PrivateKey> mskVec;
128 mskVec.reserve(msk.size());
133 mskVec.emplace_back(sk.impl);
137 impl = bls::BLS::PrivateKeyShare(mskVec, (
const uint8_t*)_id.
impl.
begin());
167 sigRet.
impl =
impl.SignInsecurePrehashed((
const uint8_t*)hash.
begin());
178 impl = bls::PublicKey::FromBytes((
const uint8_t*)buf);
187 impl.Serialize((uint8_t*)buf);
194 impl = bls::PublicKey::AggregateInsecure({
impl, o.
impl});
204 std::vector<bls::PublicKey> v;
205 v.reserve(pks.size());
206 for (
auto& pk : pks) {
207 v.emplace_back(pk.impl);
210 auto agg = bls::PublicKey::AggregateInsecure(v);
227 std::vector<bls::PublicKey> mpkVec;
228 mpkVec.reserve(mpk.size());
233 mpkVec.emplace_back(pk.impl);
237 impl = bls::BLS::PublicKeyShare(mpkVec, (
const uint8_t*)_id.
impl.
begin());
264 impl = bls::InsecureSignature::FromBytes((
const uint8_t*)buf);
273 impl.Serialize((uint8_t*)buf);
280 impl = bls::InsecureSignature::Aggregate({
impl, o.
impl});
290 std::vector<bls::InsecureSignature> v;
291 v.reserve(sigs.size());
292 for (
auto& pk : sigs) {
293 v.emplace_back(pk.impl);
296 auto agg = bls::InsecureSignature::Aggregate(v);
305 const std::vector<CBLSPublicKey>& pks,
308 if (sigs.size() != pks.size() || sigs.empty()) {
312 std::vector<bls::Signature> v;
313 v.reserve(sigs.size());
315 for (
size_t i = 0; i < sigs.size(); i++) {
316 bls::AggregationInfo aggInfo = bls::AggregationInfo::FromMsgHash(pks[i].
impl, hash.
begin());
317 v.emplace_back(bls::Signature::FromInsecureSig(sigs[i].
impl, aggInfo));
320 auto aggSig = bls::Signature::AggregateSigs(v);
322 ret.
impl = aggSig.GetInsecureSig();
342 return impl.Verify({(
const uint8_t*)hash.
begin()}, {pubKey.
impl});
353 assert(!pubKeys.empty() && !hashes.empty() && pubKeys.size() == hashes.size());
355 std::vector<bls::PublicKey> pubKeyVec;
356 std::vector<const uint8_t*> hashes2;
357 hashes2.reserve(hashes.size());
358 pubKeyVec.reserve(pubKeys.size());
359 for (
size_t i = 0; i < pubKeys.size(); i++) {
360 auto& p = pubKeys[i];
364 pubKeyVec.push_back(p.impl);
365 hashes2.push_back((uint8_t*)hashes[i].begin());
369 return impl.Verify(hashes2, pubKeyVec);
381 std::vector<bls::AggregationInfo> v;
382 v.reserve(pks.size());
383 for (
auto& pk : pks) {
384 auto aggInfo = bls::AggregationInfo::FromMsgHash(pk.impl, hash.
begin());
385 v.emplace_back(aggInfo);
388 bls::AggregationInfo aggInfo = bls::AggregationInfo::MergeInfos(v);
389 bls::Signature aggSig = bls::Signature::FromInsecureSig(
impl, aggInfo);
390 return aggSig.Verify();
398 if (sigs.empty() || ids.empty() || sigs.size() != ids.size()) {
402 std::vector<bls::InsecureSignature> sigsVec;
403 std::vector<const uint8_t*> idsVec;
404 sigsVec.reserve(sigs.size());
405 idsVec.reserve(sigs.size());
407 for (
size_t i = 0; i < sigs.size(); i++) {
408 if (!sigs[i].
IsValid() || !ids[i].IsValid()) {
411 sigsVec.emplace_back(sigs[i].
impl);
412 idsVec.emplace_back(ids[i].
impl.begin());
416 impl = bls::BLS::RecoverSig(sigsVec, idsVec);
426 #ifndef BUILD_BITCOIN_INTERNAL 451 return ptr +
sizeof(
size_t);
460 uint8_t* ptr = (uint8_t*)p -
sizeof(
size_t);
461 size_t n = *(
size_t*)ptr;
468 #ifndef BUILD_BITCOIN_INTERNAL bool InternalSetBuf(const void *buf)
bool SecretKeyShare(const std::vector< CBLSSecretKey > &msk, const CBLSId &id)
static CBLSId FromInt(int64_t i)
bool InternalGetBuf(void *buf) const
static LockedPoolManager & Instance()
Return the current instance, or create it once.
static CBLSSignature AggregateSecure(const std::vector< CBLSSignature > &sigs, const std::vector< CBLSPublicKey > &pks, const uint256 &hash)
void SubInsecure(const CBLSSignature &o)
static void create_secure_allocator()
void GetStrongRandBytes(unsigned char *out, int num)
Function to gather random data from multiple sources, failing whenever any of those source fail to pr...
bool VerifyInsecure(const CBLSPublicKey &pubKey, const uint256 &hash) const
void AggregateInsecure(const CBLSSecretKey &o)
static CBLSId FromHash(const uint256 &hash)
bool VerifyInsecureAggregated(const std::vector< CBLSPublicKey > &pubKeys, const std::vector< uint256 > &hashes) const
static void secure_free(void *p)
void SetHash(const uint256 &hash)
static std::once_flag init_flag
bool InternalSetBuf(const void *buf)
friend class CBLSSignature
static mt_pooled_secure_allocator< uint8_t > * secure_allocator_instance
bool PublicKeyShare(const std::vector< CBLSPublicKey > &mpk, const CBLSId &id)
bool InternalSetBuf(const void *buf)
bool DHKeyExchange(const CBLSSecretKey &sk, const CBLSPublicKey &pk)
void AggregateInsecure(const CBLSPublicKey &o)
void AggregateInsecure(const CBLSSignature &o)
void * memcpy(void *a, const void *b, size_t c)
CBLSPublicKey GetPublicKey() const
bool InternalGetBuf(void *buf) const
bool InternalSetBuf(const void *buf)
bool InternalGetBuf(void *buf) const
static mt_pooled_secure_allocator< uint8_t > & get_secure_allocator()
bool Recover(const std::vector< CBLSSignature > &sigs, const std::vector< CBLSId > &ids)
bool InternalGetBuf(void *buf) const
void SetHex(const char *psz)
friend class CBLSPublicKey
bool VerifySecureAggregated(const std::vector< CBLSPublicKey > &pks, const uint256 &hash) const
CBLSSignature Sign(const uint256 &hash) const
static void * secure_allocate(size_t n)