1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:57:35 +00:00

LibCrypto: Add hash methods to {Signed, Unsigned}BigInteger

These just use hash the underlying bytes that make up the integer words
This commit is contained in:
Idan Horowitz 2021-06-08 23:43:44 +03:00 committed by Linus Groh
parent 71c54198fa
commit b17a282b4b
4 changed files with 25 additions and 0 deletions

View file

@ -56,6 +56,7 @@ public:
{
m_is_invalid = true;
m_cached_trimmed_length = {};
m_cached_hash = 0;
}
bool is_odd() const { return m_words.size() && (m_words[0] & 1); }
@ -78,6 +79,8 @@ public:
UnsignedBigInteger multiplied_by(const UnsignedBigInteger& other) const;
UnsignedDivisionResult divided_by(const UnsignedBigInteger& divisor) const;
u32 hash() const;
void set_bit_inplace(size_t bit_index);
bool operator==(const UnsignedBigInteger& other) const;
@ -90,6 +93,8 @@ private:
// m_word[0] + m_word[1] * Word::MAX + m_word[2] * Word::MAX * Word::MAX + ...
Vector<Word, STARTING_WORD_SIZE> m_words;
mutable u32 m_cached_hash { 0 };
// Used to indicate a negative result, or a result of an invalid operation
bool m_is_invalid { false };