Skip to content

Commit 5c2acc8

Browse files
committed
crypto: add IsEmptySet method to MuHash3072 class
1 parent 3d99f25 commit 5c2acc8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/crypto/muhash.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,15 @@ MuHash3072& MuHash3072::operator/=(const MuHash3072& div) noexcept
573573
return *this;
574574
}
575575

576+
bool MuHash3072::IsEmptySet() noexcept
577+
{
578+
unsigned char num_bytes[Num3072::BYTE_SIZE];
579+
unsigned char den_bytes[Num3072::BYTE_SIZE];
580+
m_numerator.ToBytes(num_bytes);
581+
m_denominator.ToBytes(den_bytes);
582+
return std::equal(std::begin(num_bytes), std::end(num_bytes), std::begin(den_bytes));
583+
}
584+
576585
MuHash3072& MuHash3072::Insert(Span<const unsigned char> in) noexcept {
577586
m_numerator.Multiply(ToNum3072(in));
578587
return *this;

src/crypto/muhash.h

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class MuHash3072
123123
/* Divide (resulting in a hash for the difference of the sets) */
124124
MuHash3072& operator/=(const MuHash3072& div) noexcept;
125125

126+
/* Check if the set is empty. */
127+
bool IsEmptySet() noexcept;
128+
126129
/* Finalize into a 32-byte hash. Does not change this object's value. */
127130
void Finalize(uint256& out) noexcept;
128131

0 commit comments

Comments
 (0)