Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions src/bls/bls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@
#include <assert.h>
#include <string.h>

bool CBLSId::InternalSetBuf(const void* buf)
{
memcpy(impl.begin(), buf, sizeof(uint256));
return true;
}

bool CBLSId::InternalGetBuf(void* buf) const
{
memcpy(buf, impl.begin(), sizeof(uint256));
return true;
}

void CBLSId::SetInt(int x)
{
impl.SetHex(strprintf("%x", x));
Expand Down Expand Up @@ -54,22 +42,6 @@ CBLSId CBLSId::FromHash(const uint256& hash)
return id;
}

bool CBLSSecretKey::InternalSetBuf(const void* buf)
{
try {
impl = bls::PrivateKey::FromBytes((const uint8_t*)buf);
return true;
} catch (...) {
return false;
}
}

bool CBLSSecretKey::InternalGetBuf(void* buf) const
{
impl.Serialize((uint8_t*)buf);
return true;
}

void CBLSSecretKey::AggregateInsecure(const CBLSSecretKey& o)
{
assert(IsValid() && o.IsValid());
Expand Down Expand Up @@ -171,22 +143,6 @@ CBLSSignature CBLSSecretKey::Sign(const uint256& hash) const
return sigRet;
}

bool CBLSPublicKey::InternalSetBuf(const void* buf)
{
try {
impl = bls::PublicKey::FromBytes((const uint8_t*)buf);
return true;
} catch (...) {
return false;
}
}

bool CBLSPublicKey::InternalGetBuf(void* buf) const
{
impl.Serialize((uint8_t*)buf);
return true;
}

void CBLSPublicKey::AggregateInsecure(const CBLSPublicKey& o)
{
assert(IsValid() && o.IsValid());
Expand Down Expand Up @@ -257,22 +213,6 @@ bool CBLSPublicKey::DHKeyExchange(const CBLSSecretKey& sk, const CBLSPublicKey&
return true;
}

bool CBLSSignature::InternalSetBuf(const void* buf)
{
try {
impl = bls::InsecureSignature::FromBytes((const uint8_t*)buf);
return true;
} catch (...) {
return false;
}
}

bool CBLSSignature::InternalGetBuf(void* buf) const
{
impl.Serialize((uint8_t*)buf);
return true;
}

void CBLSSignature::AggregateInsecure(const CBLSSignature& o)
{
assert(IsValid() && o.IsValid());
Expand Down
48 changes: 25 additions & 23 deletions src/bls/bls.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ class CBLSWrapper

inline constexpr size_t GetSerSize() const { return SerSize; }

virtual bool InternalSetBuf(const void* buf) = 0;
virtual bool InternalGetBuf(void* buf) const = 0;

public:
static const size_t SerSize = _SerSize;

Expand Down Expand Up @@ -106,8 +103,10 @@ class CBLSWrapper
if (std::all_of((const char*)buf, (const char*)buf + SerSize, [](char c) { return c == 0; })) {
Reset();
} else {
fValid = InternalSetBuf(buf);
if (!fValid) {
try {
impl = ImplType::FromBytes((const uint8_t*)buf);
fValid = true;
} catch (...) {
Reset();
}
}
Expand All @@ -126,8 +125,7 @@ class CBLSWrapper
if (!fValid) {
memset(buf, 0, SerSize);
} else {
bool ok = InternalGetBuf(buf);
assert(ok);
impl.Serialize(static_cast<uint8_t*>(buf));
}
}

Expand Down Expand Up @@ -215,7 +213,26 @@ class CBLSWrapper
}
};

class CBLSId : public CBLSWrapper<uint256, BLS_CURVE_ID_SIZE, CBLSId>
struct CBLSIdImplicit : public uint256
{
CBLSIdImplicit() {}
CBLSIdImplicit(const uint256& id)
{
memcpy(begin(), id.begin(), sizeof(uint256));
}
static CBLSIdImplicit FromBytes(const uint8_t* buffer)
{
CBLSIdImplicit instance;
memcpy(instance.begin(), buffer, sizeof(CBLSIdImplicit));
return instance;
}
void Serialize(uint8_t* buffer) const
{
memcpy(buffer, data, sizeof(CBLSIdImplicit));
}
};

class CBLSId : public CBLSWrapper<CBLSIdImplicit, BLS_CURVE_ID_SIZE, CBLSId>
{
public:
using CBLSWrapper::operator=;
Expand All @@ -229,10 +246,6 @@ class CBLSId : public CBLSWrapper<uint256, BLS_CURVE_ID_SIZE, CBLSId>

static CBLSId FromInt(int64_t i);
static CBLSId FromHash(const uint256& hash);

protected:
bool InternalSetBuf(const void* buf);
bool InternalGetBuf(void* buf) const;
};

class CBLSSecretKey : public CBLSWrapper<bls::PrivateKey, BLS_CURVE_SECKEY_SIZE, CBLSSecretKey>
Expand All @@ -254,10 +267,6 @@ class CBLSSecretKey : public CBLSWrapper<bls::PrivateKey, BLS_CURVE_SECKEY_SIZE,

CBLSPublicKey GetPublicKey() const;
CBLSSignature Sign(const uint256& hash) const;

protected:
bool InternalSetBuf(const void* buf);
bool InternalGetBuf(void* buf) const;
};

class CBLSPublicKey : public CBLSWrapper<bls::PublicKey, BLS_CURVE_PUBKEY_SIZE, CBLSPublicKey>
Expand All @@ -278,9 +287,6 @@ class CBLSPublicKey : public CBLSWrapper<bls::PublicKey, BLS_CURVE_PUBKEY_SIZE,
bool PublicKeyShare(const std::vector<CBLSPublicKey>& mpk, const CBLSId& id);
bool DHKeyExchange(const CBLSSecretKey& sk, const CBLSPublicKey& pk);

protected:
bool InternalSetBuf(const void* buf);
bool InternalGetBuf(void* buf) const;
};

class CBLSSignature : public CBLSWrapper<bls::InsecureSignature, BLS_CURVE_SIG_SIZE, CBLSSignature>
Expand Down Expand Up @@ -308,10 +314,6 @@ class CBLSSignature : public CBLSWrapper<bls::InsecureSignature, BLS_CURVE_SIG_S
bool VerifySecureAggregated(const std::vector<CBLSPublicKey>& pks, const uint256& hash) const;

bool Recover(const std::vector<CBLSSignature>& sigs, const std::vector<CBLSId>& ids);

protected:
bool InternalSetBuf(const void* buf);
bool InternalGetBuf(void* buf) const;
};

#ifndef BUILD_BITCOIN_INTERNAL
Expand Down