mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
Compare commits
7 Commits
2387cbfb09
...
0a7e30a1f2
Author | SHA1 | Date | |
---|---|---|---|
|
0a7e30a1f2 | ||
|
47972aab8c | ||
|
dd96032e12 | ||
|
3bbe16c390 | ||
|
43043e623f | ||
|
efd5c566da | ||
|
257fd5ef9e |
@ -123,6 +123,14 @@ public:
|
||||
cachedHash.SetNull();
|
||||
}
|
||||
|
||||
std::array<uint8_t, SerSize> ToBytes(const bool specificLegacyScheme) const
|
||||
{
|
||||
if (!fValid) {
|
||||
return std::array<uint8_t, SerSize>{};
|
||||
}
|
||||
return impl.SerializeToArray(specificLegacyScheme);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> ToByteVector(const bool specificLegacyScheme) const
|
||||
{
|
||||
if (!fValid) {
|
||||
@ -131,9 +139,9 @@ public:
|
||||
return impl.Serialize(specificLegacyScheme);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> ToByteVector() const
|
||||
std::array<uint8_t, SerSize> ToBytes() const
|
||||
{
|
||||
return ToByteVector(bls::bls_legacy_scheme.load());
|
||||
return ToBytes(bls::bls_legacy_scheme.load());
|
||||
}
|
||||
|
||||
const uint256& GetHash() const
|
||||
@ -167,7 +175,7 @@ public:
|
||||
template <typename Stream>
|
||||
inline void Serialize(Stream& s, const bool specificLegacyScheme) const
|
||||
{
|
||||
s.write(AsBytes(Span{ToByteVector(specificLegacyScheme).data(), SerSize}));
|
||||
s.write(AsBytes(Span{ToBytes(specificLegacyScheme)}));
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
@ -206,7 +214,7 @@ public:
|
||||
|
||||
inline bool CheckMalleable(Span<uint8_t> vecBytes, const bool specificLegacyScheme) const
|
||||
{
|
||||
if (memcmp(vecBytes.data(), ToByteVector(specificLegacyScheme).data(), SerSize)) {
|
||||
if (memcmp(vecBytes.data(), ToBytes(specificLegacyScheme).data(), SerSize)) {
|
||||
// TODO not sure if this is actually possible with the BLS libs. I'm assuming here that somewhere deep inside
|
||||
// these libs masking might happen, so that 2 different binary representations could result in the same object
|
||||
// representation
|
||||
@ -222,7 +230,7 @@ public:
|
||||
|
||||
inline std::string ToString(const bool specificLegacyScheme) const
|
||||
{
|
||||
std::vector<uint8_t> buf = ToByteVector(specificLegacyScheme);
|
||||
auto buf = ToBytes(specificLegacyScheme);
|
||||
return HexStr(buf);
|
||||
}
|
||||
|
||||
@ -245,10 +253,12 @@ struct CBLSIdImplicit : public uint256
|
||||
memcpy(instance.begin(), buffer, sizeof(CBLSIdImplicit));
|
||||
return instance;
|
||||
}
|
||||
[[nodiscard]] std::vector<uint8_t> Serialize(const bool fLegacy) const
|
||||
[[nodiscard]] std::vector<uint8_t> SerializeToVec(const bool fLegacy) const
|
||||
{
|
||||
return {begin(), end()};
|
||||
}
|
||||
[[nodiscard]] std::array<uint8_t, WIDTH> Serialize(const bool fLegacy) const { return m_data; }
|
||||
[[nodiscard]] std::array<uint8_t, WIDTH> SerializeToArray(const bool fLegacy) const { return Serialize(fLegacy); }
|
||||
};
|
||||
|
||||
class CBLSId : public CBLSWrapper<CBLSIdImplicit, BLS_CURVE_ID_SIZE, CBLSId>
|
||||
@ -381,7 +391,7 @@ class CBLSLazyWrapper
|
||||
private:
|
||||
mutable std::mutex mutex;
|
||||
|
||||
mutable std::vector<uint8_t> vecBytes;
|
||||
mutable std::array<uint8_t, BLSObject::SerSize> vecBytes{};
|
||||
mutable bool bufValid{false};
|
||||
mutable bool bufLegacyScheme{true};
|
||||
|
||||
@ -392,7 +402,6 @@ private:
|
||||
|
||||
public:
|
||||
CBLSLazyWrapper() :
|
||||
vecBytes(BLSObject::SerSize, 0),
|
||||
bufLegacyScheme(bls::bls_legacy_scheme.load())
|
||||
{}
|
||||
|
||||
@ -410,7 +419,6 @@ public:
|
||||
if (r.bufValid) {
|
||||
vecBytes = r.vecBytes;
|
||||
} else {
|
||||
vecBytes.resize(BLSObject::SerSize);
|
||||
std::fill(vecBytes.begin(), vecBytes.end(), 0);
|
||||
}
|
||||
objInitialized = r.objInitialized;
|
||||
@ -433,10 +441,9 @@ public:
|
||||
{
|
||||
std::unique_lock<std::mutex> l(mutex);
|
||||
if (!objInitialized && !bufValid) {
|
||||
vecBytes.resize(BLSObject::SerSize);
|
||||
std::fill(vecBytes.begin(), vecBytes.end(), 0);
|
||||
} else if (!bufValid || (bufLegacyScheme != specificLegacyScheme)) {
|
||||
vecBytes = obj.ToByteVector(specificLegacyScheme);
|
||||
vecBytes = obj.ToBytes(specificLegacyScheme);
|
||||
bufValid = true;
|
||||
bufLegacyScheme = specificLegacyScheme;
|
||||
hash.SetNull();
|
||||
@ -518,11 +525,10 @@ public:
|
||||
{
|
||||
std::unique_lock<std::mutex> l(mutex);
|
||||
if (!objInitialized && !bufValid) {
|
||||
vecBytes.resize(BLSObject::SerSize);
|
||||
std::fill(vecBytes.begin(), vecBytes.end(), 0);
|
||||
hash.SetNull();
|
||||
} else if (!bufValid) {
|
||||
vecBytes = obj.ToByteVector(bufLegacyScheme);
|
||||
vecBytes = obj.ToBytes(bufLegacyScheme);
|
||||
bufValid = true;
|
||||
hash.SetNull();
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ bool CBLSIESEncryptedBlob::Encrypt(size_t idx, const CBLSPublicKey& peerPubKey,
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> symKey = pk.ToByteVector();
|
||||
symKey.resize(32);
|
||||
auto symKey = pk.ToBytes();
|
||||
|
||||
uint256 iv = GetIV(idx);
|
||||
return EncryptBlob(plainTextData, dataSize, data, symKey.data(), iv.begin());
|
||||
@ -63,10 +62,9 @@ bool CBLSIESEncryptedBlob::Decrypt(size_t idx, const CBLSSecretKey& secretKey, C
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> symKey = pk.ToByteVector();
|
||||
symKey.resize(32);
|
||||
|
||||
uint256 iv = GetIV(idx);
|
||||
auto symKey = pk.ToBytes();
|
||||
|
||||
return DecryptBlob(data.data(), data.size(), decryptedDataRet, symKey.data(), iv.begin());
|
||||
}
|
||||
|
||||
@ -117,8 +115,7 @@ bool CBLSIESMultiRecipientBlobs::Encrypt(size_t idx, const CBLSPublicKey& recipi
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> symKey = pk.ToByteVector();
|
||||
symKey.resize(32);
|
||||
auto symKey = pk.ToBytes();
|
||||
|
||||
return EncryptBlob(blob.data(), blob.size(), blobs[idx], symKey.data(), ivVector[idx].begin());
|
||||
}
|
||||
@ -134,13 +131,11 @@ bool CBLSIESMultiRecipientBlobs::Decrypt(size_t idx, const CBLSSecretKey& sk, Bl
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> symKey = pk.ToByteVector();
|
||||
symKey.resize(32);
|
||||
|
||||
uint256 iv = ivSeed;
|
||||
for (size_t i = 0; i < idx; i++) {
|
||||
iv = ::SerializeHash(iv);
|
||||
}
|
||||
auto symKey = pk.ToBytes();
|
||||
|
||||
return DecryptBlob(blobs[idx].data(), blobs[idx].size(), blobRet, symKey.data(), iv.begin());
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ bool CCoinJoinQueue::Sign(const CActiveMasternodeManager& mn_activeman)
|
||||
if (!sig.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
vchSig = sig.ToByteVector(false);
|
||||
vchSig = sig.ToBytes(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -94,7 +94,7 @@ bool CCoinJoinBroadcastTx::Sign(const CActiveMasternodeManager& mn_activeman)
|
||||
if (!sig.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
vchSig = sig.ToByteVector(false);
|
||||
vchSig = sig.ToBytes(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <coinjoin/common.h>
|
||||
|
||||
#include <bls/bls.h>
|
||||
#include <core_io.h>
|
||||
#include <netaddress.h>
|
||||
#include <primitives/block.h>
|
||||
@ -183,7 +184,7 @@ public:
|
||||
uint256 m_protxHash;
|
||||
int64_t nTime{0};
|
||||
bool fReady{false}; //ready for submit
|
||||
std::vector<unsigned char> vchSig;
|
||||
std::array<unsigned char, BLS_CURVE_SIG_SIZE> vchSig;
|
||||
// memory only
|
||||
bool fTried{false};
|
||||
|
||||
@ -243,7 +244,7 @@ public:
|
||||
CTransactionRef tx;
|
||||
COutPoint masternodeOutpoint;
|
||||
uint256 m_protxHash;
|
||||
std::vector<unsigned char> vchSig;
|
||||
std::array<unsigned char, BLS_CURVE_SIG_SIZE> vchSig;
|
||||
int64_t sigTime{0};
|
||||
CCoinJoinBroadcastTx() :
|
||||
tx(MakeTransactionRef(CMutableTransaction{}))
|
||||
|
@ -1,5 +1,5 @@
|
||||
AC_PREREQ([2.60])
|
||||
AC_INIT([libdashbls],[1.3.4])
|
||||
AC_INIT([libdashbls],[1.3.5])
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AC_CONFIG_MACRO_DIR([build-aux/m4])
|
||||
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
GTElement Pair(const G2Element &b) const;
|
||||
uint32_t GetFingerprint(bool fLegacy = false) const;
|
||||
std::vector<uint8_t> Serialize(bool fLegacy = false) const;
|
||||
std::array<uint8_t, SIZE> SerializeToArray(bool fLegacy = false) const;
|
||||
G1Element Copy();
|
||||
|
||||
friend bool operator==(const G1Element &a, const G1Element &b);
|
||||
@ -102,6 +103,7 @@ public:
|
||||
G2Element Negate() const;
|
||||
GTElement Pair(const G1Element &a) const;
|
||||
std::vector<uint8_t> Serialize(bool fLegacy = false) const;
|
||||
std::array<uint8_t, G2Element::SIZE> SerializeToArray(bool fLegacy = false) const;
|
||||
G2Element Copy();
|
||||
|
||||
friend bool operator==(G2Element const &a, G2Element const &b);
|
||||
@ -127,6 +129,7 @@ public:
|
||||
|
||||
void Serialize(uint8_t *buffer) const;
|
||||
std::vector<uint8_t> Serialize() const;
|
||||
std::array<uint8_t, SIZE> SerializeToArray() const;
|
||||
|
||||
friend bool operator==(GTElement const &a, GTElement const &b);
|
||||
friend bool operator!=(GTElement const &a, GTElement const &b);
|
||||
|
@ -82,6 +82,7 @@ class PrivateKey {
|
||||
// Serialize the key into bytes
|
||||
void Serialize(uint8_t *buffer) const;
|
||||
std::vector<uint8_t> Serialize(bool fLegacy = false) const;
|
||||
std::array<uint8_t, PrivateKey::PRIVATE_KEY_SIZE> SerializeToArray(bool fLegacy = false) const;
|
||||
|
||||
G2Element SignG2(
|
||||
const uint8_t *msg,
|
||||
|
@ -171,11 +171,16 @@ uint32_t G1Element::GetFingerprint(const bool fLegacy) const
|
||||
}
|
||||
|
||||
std::vector<uint8_t> G1Element::Serialize(const bool fLegacy) const {
|
||||
const auto arr = G1Element::SerializeToArray(fLegacy);
|
||||
return std::vector<uint8_t>{arr.begin(), arr.end()};
|
||||
}
|
||||
|
||||
std::array<uint8_t, G1Element::SIZE> G1Element::SerializeToArray(const bool fLegacy) const {
|
||||
uint8_t buffer[G1Element::SIZE + 1];
|
||||
g1_write_bin(buffer, G1Element::SIZE + 1, p, 1);
|
||||
|
||||
std::array<uint8_t, G1Element::SIZE> result{};
|
||||
if (buffer[0] == 0x00) { // infinity
|
||||
std::vector<uint8_t> result(G1Element::SIZE, 0);
|
||||
result[0] = 0xc0;
|
||||
return result;
|
||||
}
|
||||
@ -187,7 +192,9 @@ std::vector<uint8_t> G1Element::Serialize(const bool fLegacy) const {
|
||||
if (!fLegacy) {
|
||||
buffer[1] |= 0x80; // indicate compression
|
||||
}
|
||||
return std::vector<uint8_t>(buffer + 1, buffer + 1 + G1Element::SIZE);
|
||||
|
||||
std::copy_n(buffer + 1, G1Element::SIZE, result.begin());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool operator==(const G1Element & a, const G1Element &b)
|
||||
@ -386,11 +393,18 @@ G2Element G2Element::Negate() const
|
||||
GTElement G2Element::Pair(const G1Element& a) const { return a & (*this); }
|
||||
|
||||
std::vector<uint8_t> G2Element::Serialize(const bool fLegacy) const {
|
||||
const auto arr = G2Element::SerializeToArray(fLegacy);
|
||||
return std::vector<uint8_t>{arr.begin(), arr.end()};
|
||||
}
|
||||
|
||||
std::array<uint8_t, G2Element::SIZE> G2Element::SerializeToArray(const bool fLegacy) const {
|
||||
uint8_t buffer[G2Element::SIZE + 1];
|
||||
g2_write_bin(buffer, G2Element::SIZE + 1, (g2_st*)q, 1);
|
||||
|
||||
std::array<uint8_t, G2Element::SIZE> result{};
|
||||
|
||||
if (buffer[0] == 0x00) { // infinity
|
||||
std::vector<uint8_t> result(G2Element::SIZE, 0);
|
||||
result.fill(0);
|
||||
result[0] = 0xc0;
|
||||
return result;
|
||||
}
|
||||
@ -410,7 +424,6 @@ std::vector<uint8_t> G2Element::Serialize(const bool fLegacy) const {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint8_t> result(G2Element::SIZE, 0);
|
||||
if (fLegacy) {
|
||||
std::memcpy(result.data(), buffer + 1, G2Element::SIZE);
|
||||
} else {
|
||||
@ -551,4 +564,11 @@ std::vector<uint8_t> GTElement::Serialize() const
|
||||
return data;
|
||||
}
|
||||
|
||||
std::array<uint8_t, GTElement::SIZE> GTElement::SerializeToArray() const
|
||||
{
|
||||
std::array<uint8_t, GTElement::SIZE> data{};
|
||||
Serialize(data.data());
|
||||
return data;
|
||||
}
|
||||
|
||||
} // end namespace bls
|
||||
|
@ -284,6 +284,13 @@ std::vector<uint8_t> PrivateKey::Serialize(const bool fLegacy) const
|
||||
return data;
|
||||
}
|
||||
|
||||
std::array<uint8_t, PrivateKey::PRIVATE_KEY_SIZE> PrivateKey::SerializeToArray(bool fLegacy) const
|
||||
{
|
||||
std::array<uint8_t, PRIVATE_KEY_SIZE> data{};
|
||||
Serialize(data.data());
|
||||
return data;
|
||||
}
|
||||
|
||||
G2Element PrivateKey::SignG2(
|
||||
const uint8_t *msg,
|
||||
size_t len,
|
||||
|
@ -31,21 +31,21 @@ using namespace bls;
|
||||
void benchSigs() {
|
||||
string testName = "Signing";
|
||||
const int numIters = 5000;
|
||||
PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed());
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
vector<uint8_t> message1 = sk.GetG1Element().Serialize();
|
||||
|
||||
auto start = startStopwatch();
|
||||
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
AugSchemeMPL().Sign(sk, message1);
|
||||
BasicSchemeMPL().Sign(sk, message1);
|
||||
}
|
||||
endStopwatch(testName, start, numIters);
|
||||
}
|
||||
|
||||
void benchVerification() {
|
||||
string testName = "Verification";
|
||||
const int numIters = 10000;
|
||||
PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed());
|
||||
const int numIters = 1000;
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
|
||||
std::vector<G2Element> sigs;
|
||||
@ -54,7 +54,7 @@ void benchVerification() {
|
||||
uint8_t message[4];
|
||||
Util::IntToFourBytes(message, i);
|
||||
vector<uint8_t> messageBytes(message, message + 4);
|
||||
sigs.push_back(AugSchemeMPL().Sign(sk, messageBytes));
|
||||
sigs.push_back(BasicSchemeMPL().Sign(sk, messageBytes));
|
||||
}
|
||||
|
||||
auto start = startStopwatch();
|
||||
@ -62,34 +62,36 @@ void benchVerification() {
|
||||
uint8_t message[4];
|
||||
Util::IntToFourBytes(message, i);
|
||||
vector<uint8_t> messageBytes(message, message + 4);
|
||||
bool ok = AugSchemeMPL().Verify(pk, messageBytes, sigs[i]);
|
||||
bool ok = BasicSchemeMPL().Verify(pk, messageBytes, sigs[i]);
|
||||
ASSERT(ok);
|
||||
}
|
||||
endStopwatch(testName, start, numIters);
|
||||
}
|
||||
|
||||
void benchBatchVerification() {
|
||||
const int numIters = 100000;
|
||||
const int numIters = 10000;
|
||||
|
||||
vector<vector<uint8_t>> sig_bytes;
|
||||
vector<vector<uint8_t>> pk_bytes;
|
||||
vector<vector<uint8_t>> ms;
|
||||
|
||||
auto start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
uint8_t message[4];
|
||||
Util::IntToFourBytes(message, i);
|
||||
vector<uint8_t> messageBytes(message, message + 4);
|
||||
PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed());
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
sig_bytes.push_back(AugSchemeMPL().Sign(sk, messageBytes).Serialize());
|
||||
sig_bytes.push_back(BasicSchemeMPL().Sign(sk, messageBytes).Serialize());
|
||||
pk_bytes.push_back(pk.Serialize());
|
||||
ms.push_back(messageBytes);
|
||||
}
|
||||
endStopwatch("Batch verification preparation", start, numIters);
|
||||
|
||||
vector<G1Element> pks;
|
||||
pks.reserve(numIters);
|
||||
|
||||
auto start = startStopwatch();
|
||||
start = startStopwatch();
|
||||
for (auto const& pk : pk_bytes) {
|
||||
pks.emplace_back(G1Element::FromBytes(Bytes(pk)));
|
||||
}
|
||||
@ -105,52 +107,71 @@ void benchBatchVerification() {
|
||||
endStopwatch("Signature validation", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
G2Element aggSig = AugSchemeMPL().Aggregate(sigs);
|
||||
G2Element aggSig = BasicSchemeMPL().Aggregate(sigs);
|
||||
endStopwatch("Aggregation", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
bool ok = AugSchemeMPL().AggregateVerify(pks, ms, aggSig);
|
||||
bool ok = BasicSchemeMPL().AggregateVerify(pks, ms, aggSig);
|
||||
ASSERT(ok);
|
||||
endStopwatch("Batch verification", start, numIters);
|
||||
}
|
||||
|
||||
void benchFastAggregateVerification() {
|
||||
const int numIters = 5000;
|
||||
|
||||
vector<G2Element> sigs;
|
||||
vector<G1Element> pks;
|
||||
vector<uint8_t> message = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
vector<G2Element> pops;
|
||||
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
PrivateKey sk = PopSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
sigs.push_back(PopSchemeMPL().Sign(sk, message));
|
||||
pops.push_back(PopSchemeMPL().PopProve(sk));
|
||||
pks.push_back(pk);
|
||||
}
|
||||
void benchSerialize() {
|
||||
const int numIters = 5000000;
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
vector<uint8_t> message = sk.GetG1Element().Serialize();
|
||||
G2Element sig = BasicSchemeMPL().Sign(sk, message);
|
||||
|
||||
auto start = startStopwatch();
|
||||
G2Element aggSig = PopSchemeMPL().Aggregate(sigs);
|
||||
endStopwatch("PopScheme Aggregation", start, numIters);
|
||||
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
sk.Serialize();
|
||||
}
|
||||
endStopwatch("Serialize PrivateKey", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
bool ok = PopSchemeMPL().PopVerify(pks[i], pops[i]);
|
||||
ASSERT(ok);
|
||||
pk.Serialize();
|
||||
}
|
||||
endStopwatch("PopScheme Proofs verification", start, numIters);
|
||||
endStopwatch("Serialize G1Element", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
bool ok = PopSchemeMPL().FastAggregateVerify(pks, message, aggSig);
|
||||
ASSERT(ok);
|
||||
endStopwatch("PopScheme verification", start, numIters);
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
sig.Serialize();
|
||||
}
|
||||
endStopwatch("Serialize G2Element", start, numIters);
|
||||
}
|
||||
|
||||
void benchSerializeToArray() {
|
||||
const int numIters = 5000000;
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
vector<uint8_t> message = sk.GetG1Element().Serialize();
|
||||
G2Element sig = BasicSchemeMPL().Sign(sk, message);
|
||||
|
||||
auto start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
sk.SerializeToArray();
|
||||
}
|
||||
endStopwatch("SerializeToArray PrivateKey", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
pk.SerializeToArray();
|
||||
}
|
||||
endStopwatch("SerializeToArray G1Element", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
sig.SerializeToArray();
|
||||
}
|
||||
endStopwatch("SerializeToArray G2Element", start, numIters);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
benchSigs();
|
||||
benchVerification();
|
||||
benchBatchVerification();
|
||||
benchFastAggregateVerification();
|
||||
benchSerialize();
|
||||
benchSerializeToArray();
|
||||
}
|
||||
|
@ -1016,12 +1016,12 @@ void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages, PeerManag
|
||||
|
||||
if (lieType == 3) {
|
||||
const bool is_bls_legacy = bls::bls_legacy_scheme.load();
|
||||
std::vector<uint8_t> buf = qc.sig.ToByteVector(is_bls_legacy);
|
||||
auto buf = qc.sig.ToBytes(is_bls_legacy);
|
||||
buf[5]++;
|
||||
qc.sig.SetByteVector(buf, is_bls_legacy);
|
||||
} else if (lieType == 4) {
|
||||
const bool is_bls_legacy = bls::bls_legacy_scheme.load();
|
||||
std::vector<uint8_t> buf = qc.quorumSig.ToByteVector(is_bls_legacy);
|
||||
auto buf = qc.quorumSig.ToBytes(is_bls_legacy);
|
||||
buf[5]++;
|
||||
qc.quorumSig.SetByteVector(buf, is_bls_legacy);
|
||||
}
|
||||
|
@ -820,6 +820,9 @@ template<typename Stream, unsigned int N, typename T> inline void Unserialize(St
|
||||
template<typename Stream, typename T, typename A> inline void Serialize(Stream& os, const std::vector<T, A>& v);
|
||||
template<typename Stream, typename T, typename A> inline void Unserialize(Stream& is, std::vector<T, A>& v);
|
||||
|
||||
template <typename Stream, typename T, std::size_t N> void Serialize(Stream& os, const std::array<T, N>& a);
|
||||
template <typename Stream, typename T, std::size_t N> void Unserialize(Stream& is, std::array<T, N>& a);
|
||||
|
||||
/**
|
||||
* pair
|
||||
*/
|
||||
@ -1051,6 +1054,54 @@ void Unserialize(Stream& is, std::vector<T, A>& v)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* array
|
||||
*/
|
||||
template <typename Stream, typename T, std::size_t N>
|
||||
void Serialize(Stream& os, const std::array<T, N>& a)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, unsigned char>) {
|
||||
// Directly write the byte data without writing the size
|
||||
if (!a.empty()) {
|
||||
os.write(MakeByteSpan(a));
|
||||
}
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, bool>) {
|
||||
// Serialize each bool individually
|
||||
for (const bool& elem : a) {
|
||||
::Serialize(os, elem);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Serialize each element using the default Serialize function
|
||||
for (const T& elem : a) {
|
||||
::Serialize(os, elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Stream, typename T, std::size_t N>
|
||||
void Unserialize(Stream& is, std::array<T, N>& a)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, unsigned char>) {
|
||||
// Directly read the byte data without reading the size
|
||||
if (N > 0) {
|
||||
is.read(AsWritableBytes(Span{a}));
|
||||
}
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, bool>) {
|
||||
// Unserialize each bool individually
|
||||
for (bool& elem : a) {
|
||||
::Unserialize(is, elem);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Unserialize each element using the default Unserialize function
|
||||
for (T& elem : a) {
|
||||
::Unserialize(is, elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pair
|
||||
|
Loading…
Reference in New Issue
Block a user