mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 10:07:15 +02:00
LibCrypto: Add the UnsignedBigInteger::Word alias
This makes it clearer which variables are operating on words instead of directly operating on raw values.
This commit is contained in:
Notes:
sideshowbarker
2024-07-18 18:13:48 +09:00
Author: https://github.com/Dexesttp Commit: https://github.com/SerenityOS/serenity/commit/f4e6f58cc64 Pull-request: https://github.com/SerenityOS/serenity/pull/7067 Reviewed-by: https://github.com/alimpfard
@@ -19,9 +19,12 @@ constexpr size_t STARTING_WORD_SIZE = 512;
|
||||
|
||||
class UnsignedBigInteger {
|
||||
public:
|
||||
UnsignedBigInteger(u32 x) { m_words.append(x); }
|
||||
using Word = u32;
|
||||
static constexpr size_t BITS_IN_WORD = 32;
|
||||
|
||||
explicit UnsignedBigInteger(Vector<u32, STARTING_WORD_SIZE>&& words)
|
||||
UnsignedBigInteger(Word x) { m_words.append(x); }
|
||||
|
||||
explicit UnsignedBigInteger(Vector<Word, STARTING_WORD_SIZE>&& words)
|
||||
: m_words(move(words))
|
||||
{
|
||||
}
|
||||
@@ -43,10 +46,10 @@ public:
|
||||
static UnsignedBigInteger from_base10(const String& str);
|
||||
String to_base10() const;
|
||||
|
||||
const Vector<u32, STARTING_WORD_SIZE>& words() const { return m_words; }
|
||||
const Vector<Word, STARTING_WORD_SIZE>& words() const { return m_words; }
|
||||
|
||||
void set_to_0();
|
||||
void set_to(u32 other);
|
||||
void set_to(Word other);
|
||||
void set_to(const UnsignedBigInteger& other);
|
||||
|
||||
void invalidate()
|
||||
@@ -81,11 +84,9 @@ public:
|
||||
|
||||
private:
|
||||
friend class UnsignedBigIntegerAlgorithms;
|
||||
|
||||
static constexpr size_t BITS_IN_WORD = 32;
|
||||
// Little endian
|
||||
// m_word[0] + m_word[1] * 256 + m_word[2] * 65536 + ...
|
||||
Vector<u32, STARTING_WORD_SIZE> m_words;
|
||||
// m_word[0] + m_word[1] * Word::MAX + m_word[2] * Word::MAX * Word::MAX + ...
|
||||
Vector<Word, STARTING_WORD_SIZE> m_words;
|
||||
|
||||
// Used to indicate a negative result, or a result of an invalid operation
|
||||
bool m_is_invalid { false };
|
||||
|
||||
Reference in New Issue
Block a user