Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: deglobalization of bls_legacy_scheme 3/N #6508

Merged
merged 17 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
refactor: removed unused functions from bls_ies
  • Loading branch information
knst committed Dec 27, 2024
commit 91f10b16ef1f87ee33ae07dd6508c88abe51aba0
36 changes: 0 additions & 36 deletions src/bls/bls_ies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,6 @@ uint256 CBLSIESEncryptedBlob::GetIV(size_t idx) const
return iv;
}

bool CBLSIESEncryptedBlob::Encrypt(size_t idx, const CBLSPublicKey& peerPubKey, const void* plainTextData, size_t dataSize)
{
CBLSSecretKey ephemeralSecretKey;
ephemeralSecretKey.MakeNewKey();
ephemeralPubKey = ephemeralSecretKey.GetPublicKey();

CBLSPublicKey pk;
if (!pk.DHKeyExchange(ephemeralSecretKey, peerPubKey)) {
return false;
}

std::vector<unsigned char> symKey = pk.ToByteVector();
symKey.resize(32);

uint256 iv = GetIV(idx);
return EncryptBlob(plainTextData, dataSize, data, symKey.data(), iv.begin());
}

bool CBLSIESEncryptedBlob::Decrypt(size_t idx, const CBLSSecretKey& secretKey, CDataStream& decryptedDataRet) const
{
CBLSPublicKey pk;
Expand All @@ -75,24 +57,6 @@ bool CBLSIESEncryptedBlob::IsValid() const
return ephemeralPubKey.IsValid() && !data.empty() && !ivSeed.IsNull();
}


bool CBLSIESMultiRecipientBlobs::Encrypt(const std::vector<CBLSPublicKey>& recipients, const BlobVector& _blobs)
{
if (recipients.size() != _blobs.size()) {
return false;
}

InitEncrypt(_blobs.size());

for (size_t i = 0; i < _blobs.size(); i++) {
if (!Encrypt(i, recipients[i], _blobs[i])) {
return false;
}
}

return true;
}

void CBLSIESMultiRecipientBlobs::InitEncrypt(size_t count)
{
ephemeralSecretKey.MakeNewKey();
Expand Down
36 changes: 0 additions & 36 deletions src/bls/bls_ies.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class CBLSIESEncryptedBlob
READWRITE(obj.ephemeralPubKey, obj.ivSeed, obj.data);
}

bool Encrypt(size_t idx, const CBLSPublicKey& peerPubKey, const void* data, size_t dataSize);
bool Decrypt(size_t idx, const CBLSSecretKey& secretKey, CDataStream& decryptedDataRet) const;
bool IsValid() const;
};
Expand All @@ -40,17 +39,6 @@ class CBLSIESEncryptedObject : public CBLSIESEncryptedBlob
data = dataIn;
}

bool Encrypt(size_t idx, const CBLSPublicKey& peerPubKey, const Object& obj, int nVersion)
{
try {
CDataStream ds(SER_NETWORK, nVersion);
ds << obj;
return CBLSIESEncryptedBlob::Encrypt(idx, peerPubKey, ds.data(), ds.size());
} catch (const std::exception&) {
return false;
}
}

bool Decrypt(size_t idx, const CBLSSecretKey& secretKey, Object& objRet, int nVersion) const
{
CDataStream ds(SER_NETWORK, nVersion);
Expand Down Expand Up @@ -80,8 +68,6 @@ class CBLSIESMultiRecipientBlobs
CBLSSecretKey ephemeralSecretKey;
std::vector<uint256> ivVector;

bool Encrypt(const std::vector<CBLSPublicKey>& recipients, const BlobVector& _blobs);

void InitEncrypt(size_t count);
bool Encrypt(size_t idx, const CBLSPublicKey& recipient, const Blob& blob);
bool Decrypt(size_t idx, const CBLSSecretKey& sk, Blob& blobRet) const;
Expand All @@ -96,28 +82,6 @@ template <typename Object>
class CBLSIESMultiRecipientObjects : public CBLSIESMultiRecipientBlobs
{
public:
using ObjectVector = std::vector<Object>;

bool Encrypt(const std::vector<CBLSPublicKey>& recipients, const ObjectVector& _objects, int nVersion)
{
BlobVector blobs;
blobs.resize(_objects.size());

try {
CDataStream ds(SER_NETWORK, nVersion);
for (size_t i = 0; i < _objects.size(); i++) {
ds.clear();

ds << _objects[i];
blobs[i].assign(UCharCast(ds.data()), UCharCast(ds.data() + ds.size()));
}
} catch (const std::exception&) {
return false;
}

return CBLSIESMultiRecipientBlobs::Encrypt(recipients, blobs);
}

bool Encrypt(size_t idx, const CBLSPublicKey& recipient, const Object& obj, int nVersion)
{
CDataStream ds(SER_NETWORK, nVersion);
Expand Down