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

LibCrypto: Small fixes in BigInteger & test-crypto

This commit is contained in:
DexesTTP 2020-05-03 10:56:00 +02:00 committed by Andreas Kling
parent 8ad48cca29
commit d008a38f93
3 changed files with 121 additions and 122 deletions

View file

@ -41,13 +41,12 @@ public:
UnsignedBigInteger(u32 x) { m_words.append(x); }
explicit UnsignedBigInteger(AK::Vector<u32, STARTING_WORD_SIZE>&& words)
: m_words(words)
: m_words(move(words))
{
}
UnsignedBigInteger() { }
UnsignedBigInteger() {}
static UnsignedBigInteger from_base10(const String& str);
static UnsignedBigInteger create_invalid();
static UnsignedBigInteger import_data(const AK::StringView& data) { return import_data((const u8*)data.characters_without_null_termination(), data.length()); }
@ -60,31 +59,31 @@ public:
return export_data(buffer);
}
static UnsignedBigInteger from_base10(const String& str);
String to_base10() const;
const AK::Vector<u32, STARTING_WORD_SIZE>& words() const { return m_words; }
void invalidate() { m_is_invalid = true; }
bool is_invalid() const { return m_is_invalid; }
size_t length() const { return m_words.size(); }
// The "trimmed length" is the number of words after trimming leading zeroed words
size_t trimmed_length() const;
UnsignedBigInteger plus(const UnsignedBigInteger& other) const;
UnsignedBigInteger minus(const UnsignedBigInteger& other) const;
UnsignedBigInteger multiplied_by(const UnsignedBigInteger& other) const;
UnsignedBigInteger shift_left(size_t num_bits) const;
UnsignedBigInteger multiplied_by(const UnsignedBigInteger& other) const;
UnsignedDivisionResult divided_by(const UnsignedBigInteger& divisor) const;
void set_bit_inplace(size_t bit_index);
size_t length() const { return m_words.size(); }
// The "trimmed length" is the number of words after trimming leading zeroed words
size_t trimmed_length() const;
bool operator==(const UnsignedBigInteger& other) const;
bool operator!=(const UnsignedBigInteger& other) const;
bool operator<(const UnsignedBigInteger& other) const;
void invalidate() { m_is_invalid = true; }
bool is_invalid() const { return m_is_invalid; }
String to_base10() const;
private:
ALWAYS_INLINE UnsignedBigInteger shift_left_by_n_words(const size_t number_of_words) const;
ALWAYS_INLINE u32 shift_left_get_one_word(const size_t num_bits, const size_t result_word_index) const;