mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:47:34 +00:00
Everywhere: Run clang-format
This commit is contained in:
parent
0376c127f6
commit
086969277e
1665 changed files with 8479 additions and 8479 deletions
|
@ -12,12 +12,12 @@
|
|||
|
||||
namespace {
|
||||
|
||||
static u32 to_u32(const u8* b)
|
||||
static u32 to_u32(u8 const* b)
|
||||
{
|
||||
return AK::convert_between_host_and_big_endian(ByteReader::load32(b));
|
||||
}
|
||||
|
||||
static void to_u8s(u8* b, const u32* w)
|
||||
static void to_u8s(u8* b, u32 const* w)
|
||||
{
|
||||
for (auto i = 0; i < 4; ++i) {
|
||||
ByteReader::store(b + i * 4, AK::convert_between_host_and_big_endian(w[i]));
|
||||
|
|
|
@ -24,7 +24,7 @@ struct GHashDigest {
|
|||
constexpr static size_t Size = 16;
|
||||
u8 data[Size];
|
||||
|
||||
const u8* immutable_data() const { return data; }
|
||||
u8 const* immutable_data() const { return data; }
|
||||
size_t data_length() { return Size; }
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,7 @@ public:
|
|||
using TagType = GHashDigest;
|
||||
|
||||
template<size_t N>
|
||||
explicit GHash(const char (&key)[N])
|
||||
explicit GHash(char const (&key)[N])
|
||||
: GHash({ key, N })
|
||||
{
|
||||
}
|
||||
|
|
|
@ -39,23 +39,23 @@ public:
|
|||
reset();
|
||||
}
|
||||
|
||||
TagType process(const u8* message, size_t length)
|
||||
TagType process(u8 const* message, size_t length)
|
||||
{
|
||||
reset();
|
||||
update(message, length);
|
||||
return digest();
|
||||
}
|
||||
|
||||
void update(const u8* message, size_t length)
|
||||
void update(u8 const* message, size_t length)
|
||||
{
|
||||
m_inner_hasher.update(message, length);
|
||||
}
|
||||
|
||||
TagType process(ReadonlyBytes span) { return process(span.data(), span.size()); }
|
||||
TagType process(StringView string) { return process((const u8*)string.characters_without_null_termination(), string.length()); }
|
||||
TagType process(StringView string) { return process((u8 const*)string.characters_without_null_termination(), string.length()); }
|
||||
|
||||
void update(ReadonlyBytes span) { return update(span.data(), span.size()); }
|
||||
void update(StringView string) { return update((const u8*)string.characters_without_null_termination(), string.length()); }
|
||||
void update(StringView string) { return update((u8 const*)string.characters_without_null_termination(), string.length()); }
|
||||
|
||||
TagType digest()
|
||||
{
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
#endif
|
||||
|
||||
private:
|
||||
void derive_key(const u8* key, size_t length)
|
||||
void derive_key(u8 const* key, size_t length)
|
||||
{
|
||||
auto block_size = m_inner_hasher.block_size();
|
||||
// Note: The block size of all the current hash functions is 512 bits.
|
||||
|
|
|
@ -32,7 +32,7 @@ FLATTEN void UnsignedBigIntegerAlgorithms::bitwise_or_without_allocation(
|
|||
return;
|
||||
}
|
||||
|
||||
const UnsignedBigInteger *shorter, *longer;
|
||||
UnsignedBigInteger const *shorter, *longer;
|
||||
if (left.length() < right.length()) {
|
||||
shorter = &left;
|
||||
longer = &right;
|
||||
|
@ -71,7 +71,7 @@ FLATTEN void UnsignedBigIntegerAlgorithms::bitwise_and_without_allocation(
|
|||
return;
|
||||
}
|
||||
|
||||
const UnsignedBigInteger *shorter, *longer;
|
||||
UnsignedBigInteger const *shorter, *longer;
|
||||
if (left.length() < right.length()) {
|
||||
shorter = &left;
|
||||
longer = &right;
|
||||
|
@ -110,7 +110,7 @@ FLATTEN void UnsignedBigIntegerAlgorithms::bitwise_xor_without_allocation(
|
|||
return;
|
||||
}
|
||||
|
||||
const UnsignedBigInteger *shorter, *longer;
|
||||
UnsignedBigInteger const *shorter, *longer;
|
||||
if (left.length() < right.length()) {
|
||||
shorter = &left;
|
||||
longer = &right;
|
||||
|
|
|
@ -17,8 +17,8 @@ void UnsignedBigIntegerAlgorithms::add_without_allocation(
|
|||
UnsignedBigInteger const& right,
|
||||
UnsignedBigInteger& output)
|
||||
{
|
||||
const UnsignedBigInteger* const longer = (left.length() > right.length()) ? &left : &right;
|
||||
const UnsignedBigInteger* const shorter = (longer == &right) ? &left : &right;
|
||||
UnsignedBigInteger const* const longer = (left.length() > right.length()) ? &left : &right;
|
||||
UnsignedBigInteger const* const shorter = (longer == &right) ? &left : &right;
|
||||
|
||||
output.set_to(*longer);
|
||||
add_into_accumulator_without_allocation(output, *shorter);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Crypto {
|
||||
|
||||
SignedBigInteger SignedBigInteger::import_data(const u8* ptr, size_t length)
|
||||
SignedBigInteger SignedBigInteger::import_data(u8 const* ptr, size_t length)
|
||||
{
|
||||
bool sign = *ptr;
|
||||
auto unsigned_data = UnsignedBigInteger::import_data(ptr + 1, length - 1);
|
||||
|
@ -71,7 +71,7 @@ double SignedBigInteger::to_double() const
|
|||
return -unsigned_value;
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::plus(const SignedBigInteger& other) const
|
||||
FLATTEN SignedBigInteger SignedBigInteger::plus(SignedBigInteger const& other) const
|
||||
{
|
||||
// If both are of the same sign, just add the unsigned data and return.
|
||||
if (m_sign == other.m_sign)
|
||||
|
@ -81,7 +81,7 @@ FLATTEN SignedBigInteger SignedBigInteger::plus(const SignedBigInteger& other) c
|
|||
return m_sign ? other.minus(this->m_unsigned_data) : minus(other.m_unsigned_data);
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::minus(const SignedBigInteger& other) const
|
||||
FLATTEN SignedBigInteger SignedBigInteger::minus(SignedBigInteger const& other) const
|
||||
{
|
||||
// If the signs are different, convert the op to an addition.
|
||||
if (m_sign != other.m_sign) {
|
||||
|
@ -120,7 +120,7 @@ FLATTEN SignedBigInteger SignedBigInteger::minus(const SignedBigInteger& other)
|
|||
return SignedBigInteger { 0 };
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::plus(const UnsignedBigInteger& other) const
|
||||
FLATTEN SignedBigInteger SignedBigInteger::plus(UnsignedBigInteger const& other) const
|
||||
{
|
||||
if (m_sign) {
|
||||
if (other < m_unsigned_data)
|
||||
|
@ -132,7 +132,7 @@ FLATTEN SignedBigInteger SignedBigInteger::plus(const UnsignedBigInteger& other)
|
|||
return { m_unsigned_data.plus(other), false };
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::minus(const UnsignedBigInteger& other) const
|
||||
FLATTEN SignedBigInteger SignedBigInteger::minus(UnsignedBigInteger const& other) const
|
||||
{
|
||||
if (m_sign)
|
||||
return { m_unsigned_data.plus(m_unsigned_data), true };
|
||||
|
@ -167,7 +167,7 @@ FLATTEN SignedDivisionResult SignedBigInteger::divided_by(UnsignedBigInteger con
|
|||
};
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::bitwise_or(const SignedBigInteger& other) const
|
||||
FLATTEN SignedBigInteger SignedBigInteger::bitwise_or(SignedBigInteger const& other) const
|
||||
{
|
||||
// See bitwise_and() for derivations.
|
||||
if (!is_negative() && !other.is_negative())
|
||||
|
@ -191,7 +191,7 @@ FLATTEN SignedBigInteger SignedBigInteger::bitwise_or(const SignedBigInteger& ot
|
|||
return { unsigned_value().minus(1).bitwise_and(other.unsigned_value().minus(1)).plus(1), true };
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::bitwise_and(const SignedBigInteger& other) const
|
||||
FLATTEN SignedBigInteger SignedBigInteger::bitwise_and(SignedBigInteger const& other) const
|
||||
{
|
||||
if (!is_negative() && !other.is_negative())
|
||||
return { unsigned_value().bitwise_and(other.unsigned_value()), false };
|
||||
|
@ -229,33 +229,33 @@ FLATTEN SignedBigInteger SignedBigInteger::bitwise_and(const SignedBigInteger& o
|
|||
return { unsigned_value().minus(1).bitwise_or(other.unsigned_value().minus(1)).plus(1), true };
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::bitwise_xor(const SignedBigInteger& other) const
|
||||
FLATTEN SignedBigInteger SignedBigInteger::bitwise_xor(SignedBigInteger const& other) const
|
||||
{
|
||||
return bitwise_or(other).minus(bitwise_and(other));
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator==(const UnsignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator==(UnsignedBigInteger const& other) const
|
||||
{
|
||||
if (m_sign)
|
||||
return false;
|
||||
return m_unsigned_data == other;
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator!=(const UnsignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator!=(UnsignedBigInteger const& other) const
|
||||
{
|
||||
if (m_sign)
|
||||
return true;
|
||||
return m_unsigned_data != other;
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator<(const UnsignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator<(UnsignedBigInteger const& other) const
|
||||
{
|
||||
if (m_sign)
|
||||
return true;
|
||||
return m_unsigned_data < other;
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator>(const UnsignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator>(UnsignedBigInteger const& other) const
|
||||
{
|
||||
return *this != other && !(*this < other);
|
||||
}
|
||||
|
@ -265,13 +265,13 @@ FLATTEN SignedBigInteger SignedBigInteger::shift_left(size_t num_bits) const
|
|||
return SignedBigInteger { m_unsigned_data.shift_left(num_bits), m_sign };
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::multiplied_by(const SignedBigInteger& other) const
|
||||
FLATTEN SignedBigInteger SignedBigInteger::multiplied_by(SignedBigInteger const& other) const
|
||||
{
|
||||
bool result_sign = m_sign ^ other.m_sign;
|
||||
return { m_unsigned_data.multiplied_by(other.m_unsigned_data), result_sign };
|
||||
}
|
||||
|
||||
FLATTEN SignedDivisionResult SignedBigInteger::divided_by(const SignedBigInteger& divisor) const
|
||||
FLATTEN SignedDivisionResult SignedBigInteger::divided_by(SignedBigInteger const& divisor) const
|
||||
{
|
||||
// Aa / Bb -> (A^B)q, Ar
|
||||
bool result_sign = m_sign ^ divisor.m_sign;
|
||||
|
@ -292,7 +292,7 @@ void SignedBigInteger::set_bit_inplace(size_t bit_index)
|
|||
m_unsigned_data.set_bit_inplace(bit_index);
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator==(const SignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator==(SignedBigInteger const& other) const
|
||||
{
|
||||
if (is_invalid() != other.is_invalid())
|
||||
return false;
|
||||
|
@ -303,12 +303,12 @@ bool SignedBigInteger::operator==(const SignedBigInteger& other) const
|
|||
return m_sign == other.m_sign && m_unsigned_data == other.m_unsigned_data;
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator!=(const SignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator!=(SignedBigInteger const& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator<(const SignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator<(SignedBigInteger const& other) const
|
||||
{
|
||||
if (m_sign ^ other.m_sign)
|
||||
return m_sign;
|
||||
|
@ -319,24 +319,24 @@ bool SignedBigInteger::operator<(const SignedBigInteger& other) const
|
|||
return m_unsigned_data < other.m_unsigned_data;
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator<=(const SignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator<=(SignedBigInteger const& other) const
|
||||
{
|
||||
return *this < other || *this == other;
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator>(const SignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator>(SignedBigInteger const& other) const
|
||||
{
|
||||
return *this != other && !(*this < other);
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator>=(const SignedBigInteger& other) const
|
||||
bool SignedBigInteger::operator>=(SignedBigInteger const& other) const
|
||||
{
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ErrorOr<void> AK::Formatter<Crypto::SignedBigInteger>::format(FormatBuilder& fmtbuilder, const Crypto::SignedBigInteger& value)
|
||||
ErrorOr<void> AK::Formatter<Crypto::SignedBigInteger>::format(FormatBuilder& fmtbuilder, Crypto::SignedBigInteger const& value)
|
||||
{
|
||||
if (value.is_negative())
|
||||
TRY(fmtbuilder.put_string("-"));
|
||||
|
|
|
@ -45,8 +45,8 @@ public:
|
|||
return { UnsignedBigInteger::create_invalid(), false };
|
||||
}
|
||||
|
||||
static SignedBigInteger import_data(StringView data) { return import_data((const u8*)data.characters_without_null_termination(), data.length()); }
|
||||
static SignedBigInteger import_data(const u8* ptr, size_t length);
|
||||
static SignedBigInteger import_data(StringView data) { return import_data((u8 const*)data.characters_without_null_termination(), data.length()); }
|
||||
static SignedBigInteger import_data(u8 const* ptr, size_t length);
|
||||
|
||||
static SignedBigInteger create_from(i64 value)
|
||||
{
|
||||
|
@ -69,8 +69,8 @@ public:
|
|||
u64 to_u64() const;
|
||||
double to_double() const;
|
||||
|
||||
const UnsignedBigInteger& unsigned_value() const { return m_unsigned_data; }
|
||||
const Vector<u32, STARTING_WORD_SIZE> words() const { return m_unsigned_data.words(); }
|
||||
UnsignedBigInteger const& unsigned_value() const { return m_unsigned_data; }
|
||||
Vector<u32, STARTING_WORD_SIZE> const words() const { return m_unsigned_data.words(); }
|
||||
bool is_negative() const { return m_sign; }
|
||||
|
||||
void negate()
|
||||
|
@ -90,7 +90,7 @@ public:
|
|||
m_unsigned_data.set_to((u32)other);
|
||||
m_sign = other < 0;
|
||||
}
|
||||
void set_to(const SignedBigInteger& other)
|
||||
void set_to(SignedBigInteger const& other)
|
||||
{
|
||||
m_unsigned_data.set_to(other.m_unsigned_data);
|
||||
m_sign = other.m_sign;
|
||||
|
@ -107,36 +107,36 @@ public:
|
|||
size_t length() const { return m_unsigned_data.length() + 1; }
|
||||
size_t trimmed_length() const { return m_unsigned_data.trimmed_length() + 1; };
|
||||
|
||||
SignedBigInteger plus(const SignedBigInteger& other) const;
|
||||
SignedBigInteger minus(const SignedBigInteger& other) const;
|
||||
SignedBigInteger bitwise_or(const SignedBigInteger& other) const;
|
||||
SignedBigInteger bitwise_and(const SignedBigInteger& other) const;
|
||||
SignedBigInteger bitwise_xor(const SignedBigInteger& other) const;
|
||||
SignedBigInteger plus(SignedBigInteger const& other) const;
|
||||
SignedBigInteger minus(SignedBigInteger const& other) const;
|
||||
SignedBigInteger bitwise_or(SignedBigInteger const& other) const;
|
||||
SignedBigInteger bitwise_and(SignedBigInteger const& other) const;
|
||||
SignedBigInteger bitwise_xor(SignedBigInteger const& other) const;
|
||||
SignedBigInteger bitwise_not() const;
|
||||
SignedBigInteger shift_left(size_t num_bits) const;
|
||||
SignedBigInteger multiplied_by(const SignedBigInteger& other) const;
|
||||
SignedDivisionResult divided_by(const SignedBigInteger& divisor) const;
|
||||
SignedBigInteger multiplied_by(SignedBigInteger const& other) const;
|
||||
SignedDivisionResult divided_by(SignedBigInteger const& divisor) const;
|
||||
|
||||
SignedBigInteger plus(const UnsignedBigInteger& other) const;
|
||||
SignedBigInteger minus(const UnsignedBigInteger& other) const;
|
||||
SignedBigInteger multiplied_by(const UnsignedBigInteger& other) const;
|
||||
SignedDivisionResult divided_by(const UnsignedBigInteger& divisor) const;
|
||||
SignedBigInteger plus(UnsignedBigInteger const& other) const;
|
||||
SignedBigInteger minus(UnsignedBigInteger const& other) const;
|
||||
SignedBigInteger multiplied_by(UnsignedBigInteger const& other) const;
|
||||
SignedDivisionResult divided_by(UnsignedBigInteger const& divisor) const;
|
||||
|
||||
u32 hash() const;
|
||||
|
||||
void set_bit_inplace(size_t bit_index);
|
||||
|
||||
bool operator==(const SignedBigInteger& other) const;
|
||||
bool operator!=(const SignedBigInteger& other) const;
|
||||
bool operator<(const SignedBigInteger& other) const;
|
||||
bool operator<=(const SignedBigInteger& other) const;
|
||||
bool operator>(const SignedBigInteger& other) const;
|
||||
bool operator>=(const SignedBigInteger& other) const;
|
||||
bool operator==(SignedBigInteger const& other) const;
|
||||
bool operator!=(SignedBigInteger const& other) const;
|
||||
bool operator<(SignedBigInteger const& other) const;
|
||||
bool operator<=(SignedBigInteger const& other) const;
|
||||
bool operator>(SignedBigInteger const& other) const;
|
||||
bool operator>=(SignedBigInteger const& other) const;
|
||||
|
||||
bool operator==(const UnsignedBigInteger& other) const;
|
||||
bool operator!=(const UnsignedBigInteger& other) const;
|
||||
bool operator<(const UnsignedBigInteger& other) const;
|
||||
bool operator>(const UnsignedBigInteger& other) const;
|
||||
bool operator==(UnsignedBigInteger const& other) const;
|
||||
bool operator!=(UnsignedBigInteger const& other) const;
|
||||
bool operator<(UnsignedBigInteger const& other) const;
|
||||
bool operator>(UnsignedBigInteger const& other) const;
|
||||
|
||||
private:
|
||||
void ensure_sign_is_valid()
|
||||
|
@ -162,7 +162,7 @@ struct AK::Formatter<Crypto::SignedBigInteger> : AK::Formatter<Crypto::UnsignedB
|
|||
};
|
||||
|
||||
inline Crypto::SignedBigInteger
|
||||
operator""_sbigint(const char* string, size_t length)
|
||||
operator""_sbigint(char const* string, size_t length)
|
||||
{
|
||||
return Crypto::SignedBigInteger::from_base(10, { string, length });
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
namespace Crypto {
|
||||
|
||||
UnsignedBigInteger::UnsignedBigInteger(const u8* ptr, size_t length)
|
||||
UnsignedBigInteger::UnsignedBigInteger(u8 const* ptr, size_t length)
|
||||
{
|
||||
m_words.resize_and_keep_capacity((length + sizeof(u32) - 1) / sizeof(u32));
|
||||
size_t in = length, out = 0;
|
||||
|
@ -136,7 +136,7 @@ void UnsignedBigInteger::set_to(UnsignedBigInteger::Word other)
|
|||
m_cached_hash = 0;
|
||||
}
|
||||
|
||||
void UnsignedBigInteger::set_to(const UnsignedBigInteger& other)
|
||||
void UnsignedBigInteger::set_to(UnsignedBigInteger const& other)
|
||||
{
|
||||
m_is_invalid = other.m_is_invalid;
|
||||
m_words.resize_and_keep_capacity(other.m_words.size());
|
||||
|
@ -195,7 +195,7 @@ size_t UnsignedBigInteger::one_based_index_of_highest_set_bit() const
|
|||
return index;
|
||||
}
|
||||
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::plus(const UnsignedBigInteger& other) const
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::plus(UnsignedBigInteger const& other) const
|
||||
{
|
||||
UnsignedBigInteger result;
|
||||
|
||||
|
@ -204,7 +204,7 @@ FLATTEN UnsignedBigInteger UnsignedBigInteger::plus(const UnsignedBigInteger& ot
|
|||
return result;
|
||||
}
|
||||
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::minus(const UnsignedBigInteger& other) const
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::minus(UnsignedBigInteger const& other) const
|
||||
{
|
||||
UnsignedBigInteger result;
|
||||
|
||||
|
@ -213,7 +213,7 @@ FLATTEN UnsignedBigInteger UnsignedBigInteger::minus(const UnsignedBigInteger& o
|
|||
return result;
|
||||
}
|
||||
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::bitwise_or(const UnsignedBigInteger& other) const
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::bitwise_or(UnsignedBigInteger const& other) const
|
||||
{
|
||||
UnsignedBigInteger result;
|
||||
|
||||
|
@ -222,7 +222,7 @@ FLATTEN UnsignedBigInteger UnsignedBigInteger::bitwise_or(const UnsignedBigInteg
|
|||
return result;
|
||||
}
|
||||
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::bitwise_and(const UnsignedBigInteger& other) const
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::bitwise_and(UnsignedBigInteger const& other) const
|
||||
{
|
||||
UnsignedBigInteger result;
|
||||
|
||||
|
@ -231,7 +231,7 @@ FLATTEN UnsignedBigInteger UnsignedBigInteger::bitwise_and(const UnsignedBigInte
|
|||
return result;
|
||||
}
|
||||
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::bitwise_xor(const UnsignedBigInteger& other) const
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::bitwise_xor(UnsignedBigInteger const& other) const
|
||||
{
|
||||
UnsignedBigInteger result;
|
||||
|
||||
|
@ -260,7 +260,7 @@ FLATTEN UnsignedBigInteger UnsignedBigInteger::shift_left(size_t num_bits) const
|
|||
return output;
|
||||
}
|
||||
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::multiplied_by(const UnsignedBigInteger& other) const
|
||||
FLATTEN UnsignedBigInteger UnsignedBigInteger::multiplied_by(UnsignedBigInteger const& other) const
|
||||
{
|
||||
UnsignedBigInteger result;
|
||||
UnsignedBigInteger temp_shift_result;
|
||||
|
@ -272,7 +272,7 @@ FLATTEN UnsignedBigInteger UnsignedBigInteger::multiplied_by(const UnsignedBigIn
|
|||
return result;
|
||||
}
|
||||
|
||||
FLATTEN UnsignedDivisionResult UnsignedBigInteger::divided_by(const UnsignedBigInteger& divisor) const
|
||||
FLATTEN UnsignedDivisionResult UnsignedBigInteger::divided_by(UnsignedBigInteger const& divisor) const
|
||||
{
|
||||
UnsignedBigInteger quotient;
|
||||
UnsignedBigInteger remainder;
|
||||
|
@ -299,7 +299,7 @@ u32 UnsignedBigInteger::hash() const
|
|||
if (m_cached_hash != 0)
|
||||
return m_cached_hash;
|
||||
|
||||
return m_cached_hash = string_hash((const char*)m_words.data(), sizeof(Word) * m_words.size());
|
||||
return m_cached_hash = string_hash((char const*)m_words.data(), sizeof(Word) * m_words.size());
|
||||
}
|
||||
|
||||
void UnsignedBigInteger::set_bit_inplace(size_t bit_index)
|
||||
|
@ -318,7 +318,7 @@ void UnsignedBigInteger::set_bit_inplace(size_t bit_index)
|
|||
m_cached_hash = 0;
|
||||
}
|
||||
|
||||
bool UnsignedBigInteger::operator==(const UnsignedBigInteger& other) const
|
||||
bool UnsignedBigInteger::operator==(UnsignedBigInteger const& other) const
|
||||
{
|
||||
if (is_invalid() != other.is_invalid())
|
||||
return false;
|
||||
|
@ -331,12 +331,12 @@ bool UnsignedBigInteger::operator==(const UnsignedBigInteger& other) const
|
|||
return !__builtin_memcmp(m_words.data(), other.words().data(), length * (BITS_IN_WORD / 8));
|
||||
}
|
||||
|
||||
bool UnsignedBigInteger::operator!=(const UnsignedBigInteger& other) const
|
||||
bool UnsignedBigInteger::operator!=(UnsignedBigInteger const& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool UnsignedBigInteger::operator<(const UnsignedBigInteger& other) const
|
||||
bool UnsignedBigInteger::operator<(UnsignedBigInteger const& other) const
|
||||
{
|
||||
auto length = trimmed_length();
|
||||
auto other_length = other.trimmed_length();
|
||||
|
@ -360,7 +360,7 @@ bool UnsignedBigInteger::operator<(const UnsignedBigInteger& other) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool UnsignedBigInteger::operator>(const UnsignedBigInteger& other) const
|
||||
bool UnsignedBigInteger::operator>(UnsignedBigInteger const& other) const
|
||||
{
|
||||
return *this != other && !(*this < other);
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ bool UnsignedBigInteger::operator>=(UnsignedBigInteger const& other) const
|
|||
|
||||
}
|
||||
|
||||
ErrorOr<void> AK::Formatter<Crypto::UnsignedBigInteger>::format(FormatBuilder& fmtbuilder, const Crypto::UnsignedBigInteger& value)
|
||||
ErrorOr<void> AK::Formatter<Crypto::UnsignedBigInteger>::format(FormatBuilder& fmtbuilder, Crypto::UnsignedBigInteger const& value)
|
||||
{
|
||||
if (value.is_invalid())
|
||||
return Formatter<StringView>::format(fmtbuilder, "invalid");
|
||||
|
|
|
@ -30,14 +30,14 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
explicit UnsignedBigInteger(const u8* ptr, size_t length);
|
||||
explicit UnsignedBigInteger(u8 const* ptr, size_t length);
|
||||
|
||||
UnsignedBigInteger() = default;
|
||||
|
||||
static UnsignedBigInteger create_invalid();
|
||||
|
||||
static UnsignedBigInteger import_data(StringView data) { return import_data((const u8*)data.characters_without_null_termination(), data.length()); }
|
||||
static UnsignedBigInteger import_data(const u8* ptr, size_t length)
|
||||
static UnsignedBigInteger import_data(StringView data) { return import_data((u8 const*)data.characters_without_null_termination(), data.length()); }
|
||||
static UnsignedBigInteger import_data(u8 const* ptr, size_t length)
|
||||
{
|
||||
return UnsignedBigInteger(ptr, length);
|
||||
}
|
||||
|
@ -60,11 +60,11 @@ public:
|
|||
u64 to_u64() const;
|
||||
double to_double() const;
|
||||
|
||||
const Vector<Word, STARTING_WORD_SIZE>& words() const { return m_words; }
|
||||
Vector<Word, STARTING_WORD_SIZE> const& words() const { return m_words; }
|
||||
|
||||
void set_to_0();
|
||||
void set_to(Word other);
|
||||
void set_to(const UnsignedBigInteger& other);
|
||||
void set_to(UnsignedBigInteger const& other);
|
||||
|
||||
void invalidate()
|
||||
{
|
||||
|
@ -86,24 +86,24 @@ public:
|
|||
|
||||
size_t one_based_index_of_highest_set_bit() const;
|
||||
|
||||
UnsignedBigInteger plus(const UnsignedBigInteger& other) const;
|
||||
UnsignedBigInteger minus(const UnsignedBigInteger& other) const;
|
||||
UnsignedBigInteger bitwise_or(const UnsignedBigInteger& other) const;
|
||||
UnsignedBigInteger bitwise_and(const UnsignedBigInteger& other) const;
|
||||
UnsignedBigInteger bitwise_xor(const UnsignedBigInteger& other) const;
|
||||
UnsignedBigInteger plus(UnsignedBigInteger const& other) const;
|
||||
UnsignedBigInteger minus(UnsignedBigInteger const& other) const;
|
||||
UnsignedBigInteger bitwise_or(UnsignedBigInteger const& other) const;
|
||||
UnsignedBigInteger bitwise_and(UnsignedBigInteger const& other) const;
|
||||
UnsignedBigInteger bitwise_xor(UnsignedBigInteger const& other) const;
|
||||
UnsignedBigInteger bitwise_not_fill_to_one_based_index(size_t) const;
|
||||
UnsignedBigInteger shift_left(size_t num_bits) const;
|
||||
UnsignedBigInteger multiplied_by(const UnsignedBigInteger& other) const;
|
||||
UnsignedDivisionResult divided_by(const UnsignedBigInteger& divisor) const;
|
||||
UnsignedBigInteger multiplied_by(UnsignedBigInteger const& other) const;
|
||||
UnsignedDivisionResult divided_by(UnsignedBigInteger const& divisor) const;
|
||||
|
||||
u32 hash() const;
|
||||
|
||||
void set_bit_inplace(size_t bit_index);
|
||||
|
||||
bool operator==(const UnsignedBigInteger& other) const;
|
||||
bool operator!=(const UnsignedBigInteger& other) const;
|
||||
bool operator<(const UnsignedBigInteger& other) const;
|
||||
bool operator>(const UnsignedBigInteger& other) const;
|
||||
bool operator==(UnsignedBigInteger const& other) const;
|
||||
bool operator!=(UnsignedBigInteger const& other) const;
|
||||
bool operator<(UnsignedBigInteger const& other) const;
|
||||
bool operator>(UnsignedBigInteger const& other) const;
|
||||
bool operator>=(UnsignedBigInteger const& other) const;
|
||||
|
||||
private:
|
||||
|
@ -133,7 +133,7 @@ struct AK::Formatter<Crypto::UnsignedBigInteger> : Formatter<StringView> {
|
|||
};
|
||||
|
||||
inline Crypto::UnsignedBigInteger
|
||||
operator""_bigint(const char* string, size_t length)
|
||||
operator""_bigint(char const* string, size_t length)
|
||||
{
|
||||
return Crypto::UnsignedBigInteger::from_base(10, { string, length });
|
||||
}
|
||||
|
|
|
@ -197,13 +197,13 @@ void AESCipherKey::expand_decrypt_key(ReadonlyBytes user_key, size_t bits)
|
|||
}
|
||||
}
|
||||
|
||||
void AESCipher::encrypt_block(const AESCipherBlock& in, AESCipherBlock& out)
|
||||
void AESCipher::encrypt_block(AESCipherBlock const& in, AESCipherBlock& out)
|
||||
{
|
||||
u32 s0, s1, s2, s3, t0, t1, t2, t3;
|
||||
size_t r { 0 };
|
||||
|
||||
const auto& dec_key = key();
|
||||
const auto* round_keys = dec_key.round_keys();
|
||||
auto const& dec_key = key();
|
||||
auto const* round_keys = dec_key.round_keys();
|
||||
|
||||
s0 = get_key(in.bytes().offset_pointer(0)) ^ round_keys[0];
|
||||
s1 = get_key(in.bytes().offset_pointer(4)) ^ round_keys[1];
|
||||
|
@ -289,13 +289,13 @@ void AESCipher::encrypt_block(const AESCipherBlock& in, AESCipherBlock& out)
|
|||
// clang-format on
|
||||
}
|
||||
|
||||
void AESCipher::decrypt_block(const AESCipherBlock& in, AESCipherBlock& out)
|
||||
void AESCipher::decrypt_block(AESCipherBlock const& in, AESCipherBlock& out)
|
||||
{
|
||||
u32 s0, s1, s2, s3, t0, t1, t2, t3;
|
||||
size_t r { 0 };
|
||||
|
||||
const auto& dec_key = key();
|
||||
const auto* round_keys = dec_key.round_keys();
|
||||
auto const& dec_key = key();
|
||||
auto const* round_keys = dec_key.round_keys();
|
||||
|
||||
s0 = get_key(in.bytes().offset_pointer(0)) ^ round_keys[0];
|
||||
s1 = get_key(in.bytes().offset_pointer(4)) ^ round_keys[1];
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
: CipherBlock(mode)
|
||||
{
|
||||
}
|
||||
AESCipherBlock(const u8* data, size_t length, PaddingMode mode = PaddingMode::CMS)
|
||||
AESCipherBlock(u8 const* data, size_t length, PaddingMode mode = PaddingMode::CMS)
|
||||
: AESCipherBlock(mode)
|
||||
{
|
||||
CipherBlock::overwrite(data, length);
|
||||
|
@ -40,7 +40,7 @@ public:
|
|||
virtual Bytes bytes() override { return Bytes { m_data, sizeof(m_data) }; }
|
||||
|
||||
virtual void overwrite(ReadonlyBytes) override;
|
||||
virtual void overwrite(const u8* data, size_t size) override { overwrite({ data, size }); }
|
||||
virtual void overwrite(u8 const* data, size_t size) override { overwrite({ data, size }); }
|
||||
|
||||
virtual void apply_initialization_vector(ReadonlyBytes ivec) override
|
||||
{
|
||||
|
@ -68,9 +68,9 @@ struct AESCipherKey : public CipherKey {
|
|||
String to_string() const;
|
||||
#endif
|
||||
|
||||
const u32* round_keys() const
|
||||
u32 const* round_keys() const
|
||||
{
|
||||
return (const u32*)m_rd_keys;
|
||||
return (u32 const*)m_rd_keys;
|
||||
}
|
||||
|
||||
AESCipherKey(ReadonlyBytes user_key, size_t key_bits, Intent intent)
|
||||
|
@ -114,11 +114,11 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual const AESCipherKey& key() const override { return m_key; };
|
||||
virtual AESCipherKey const& key() const override { return m_key; };
|
||||
virtual AESCipherKey& key() override { return m_key; };
|
||||
|
||||
virtual void encrypt_block(const BlockType& in, BlockType& out) override;
|
||||
virtual void decrypt_block(const BlockType& in, BlockType& out) override;
|
||||
virtual void encrypt_block(BlockType const& in, BlockType& out) override;
|
||||
virtual void decrypt_block(BlockType const& in, BlockType& out) override;
|
||||
|
||||
#ifndef KERNEL
|
||||
virtual String class_name() const override
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
virtual ReadonlyBytes bytes() const = 0;
|
||||
|
||||
virtual void overwrite(ReadonlyBytes) = 0;
|
||||
virtual void overwrite(const u8* data, size_t size) { overwrite({ data, size }); }
|
||||
virtual void overwrite(u8 const* data, size_t size) { overwrite({ data, size }); }
|
||||
|
||||
virtual void apply_initialization_vector(ReadonlyBytes ivec) = 0;
|
||||
|
||||
|
@ -102,15 +102,15 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual const KeyType& key() const = 0;
|
||||
virtual KeyType const& key() const = 0;
|
||||
virtual KeyType& key() = 0;
|
||||
|
||||
constexpr static size_t block_size() { return BlockType::block_size(); }
|
||||
|
||||
PaddingMode padding_mode() const { return m_padding_mode; }
|
||||
|
||||
virtual void encrypt_block(const BlockType& in, BlockType& out) = 0;
|
||||
virtual void decrypt_block(const BlockType& in, BlockType& out) = 0;
|
||||
virtual void encrypt_block(BlockType const& in, BlockType& out) = 0;
|
||||
virtual void decrypt_block(BlockType const& in, BlockType& out) = 0;
|
||||
|
||||
#ifndef KERNEL
|
||||
virtual String class_name() const = 0;
|
||||
|
|
|
@ -99,7 +99,7 @@ public:
|
|||
// FIXME: Add back the default intent parameter once clang-11 is the default in GitHub Actions.
|
||||
// Once added back, remove the parameter where it's constructed in get_random_bytes in Kernel/Random.h.
|
||||
template<typename KeyType, typename... Args>
|
||||
explicit constexpr CTR(const KeyType& user_key, size_t key_bits, Intent, Args... args)
|
||||
explicit constexpr CTR(KeyType const& user_key, size_t key_bits, Intent, Args... args)
|
||||
: Mode<T>(user_key, key_bits, Intent::Encryption, args...)
|
||||
{
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
this->encrypt_or_stream(&in, out, ivec, ivec_out);
|
||||
}
|
||||
|
||||
void key_stream(Bytes& out, const Bytes& ivec = {}, Bytes* ivec_out = nullptr)
|
||||
void key_stream(Bytes& out, Bytes const& ivec = {}, Bytes* ivec_out = nullptr)
|
||||
{
|
||||
this->encrypt_or_stream(nullptr, out, ivec, ivec_out);
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ private:
|
|||
protected:
|
||||
constexpr static IncrementFunctionType increment {};
|
||||
|
||||
void encrypt_or_stream(const ReadonlyBytes* in, Bytes& out, ReadonlyBytes ivec, Bytes* ivec_out = nullptr)
|
||||
void encrypt_or_stream(ReadonlyBytes const* in, Bytes& out, ReadonlyBytes ivec, Bytes* ivec_out = nullptr)
|
||||
{
|
||||
size_t length;
|
||||
if (in) {
|
||||
|
|
|
@ -19,7 +19,7 @@ struct Digest {
|
|||
constexpr static size_t Size = DigestS / 8;
|
||||
u8 data[Size];
|
||||
|
||||
[[nodiscard]] ALWAYS_INLINE const u8* immutable_data() const { return data; }
|
||||
[[nodiscard]] ALWAYS_INLINE u8 const* immutable_data() const { return data; }
|
||||
[[nodiscard]] ALWAYS_INLINE size_t data_length() const { return Size; }
|
||||
|
||||
[[nodiscard]] ALWAYS_INLINE ReadonlyBytes bytes() const { return { immutable_data(), data_length() }; }
|
||||
|
@ -39,12 +39,12 @@ public:
|
|||
constexpr static size_t block_size() { return BlockSize; }
|
||||
constexpr static size_t digest_size() { return DigestSize; }
|
||||
|
||||
virtual void update(const u8*, size_t) = 0;
|
||||
virtual void update(u8 const*, size_t) = 0;
|
||||
|
||||
void update(Bytes buffer) { update(buffer.data(), buffer.size()); }
|
||||
void update(ReadonlyBytes buffer) { update(buffer.data(), buffer.size()); }
|
||||
void update(const ByteBuffer& buffer) { update(buffer.data(), buffer.size()); }
|
||||
void update(StringView string) { update((const u8*)string.characters_without_null_termination(), string.length()); }
|
||||
void update(ByteBuffer const& buffer) { update(buffer.data(), buffer.size()); }
|
||||
void update(StringView string) { update((u8 const*)string.characters_without_null_termination(), string.length()); }
|
||||
|
||||
virtual DigestType peek() = 0;
|
||||
virtual DigestType digest() = 0;
|
||||
|
|
|
@ -59,25 +59,25 @@ struct MultiHashDigestVariant {
|
|||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] const u8* immutable_data() const
|
||||
[[nodiscard]] u8 const* immutable_data() const
|
||||
{
|
||||
return m_digest.visit(
|
||||
[&](const Empty&) -> const u8* { VERIFY_NOT_REACHED(); },
|
||||
[&](const auto& value) { return value.immutable_data(); });
|
||||
[&](Empty const&) -> u8 const* { VERIFY_NOT_REACHED(); },
|
||||
[&](auto const& value) { return value.immutable_data(); });
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t data_length() const
|
||||
{
|
||||
return m_digest.visit(
|
||||
[&](const Empty&) -> size_t { VERIFY_NOT_REACHED(); },
|
||||
[&](const auto& value) { return value.data_length(); });
|
||||
[&](Empty const&) -> size_t { VERIFY_NOT_REACHED(); },
|
||||
[&](auto const& value) { return value.data_length(); });
|
||||
}
|
||||
|
||||
[[nodiscard]] ReadonlyBytes bytes() const
|
||||
{
|
||||
return m_digest.visit(
|
||||
[&](const Empty&) -> ReadonlyBytes { VERIFY_NOT_REACHED(); },
|
||||
[&](const auto& value) { return value.bytes(); });
|
||||
[&](Empty const&) -> ReadonlyBytes { VERIFY_NOT_REACHED(); },
|
||||
[&](auto const& value) { return value.bytes(); });
|
||||
}
|
||||
|
||||
using DigestVariant = Variant<Empty, MD5::DigestType, SHA1::DigestType, SHA256::DigestType, SHA384::DigestType, SHA512::DigestType>;
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
m_pre_init_buffer = ByteBuffer();
|
||||
}
|
||||
|
||||
Manager(const Manager& other) // NOT a copy constructor!
|
||||
Manager(Manager const& other) // NOT a copy constructor!
|
||||
{
|
||||
m_pre_init_buffer = ByteBuffer(); // will not be used
|
||||
initialize(other.m_kind);
|
||||
|
@ -113,15 +113,15 @@ public:
|
|||
inline size_t digest_size() const
|
||||
{
|
||||
return m_algorithm.visit(
|
||||
[&](const Empty&) -> size_t { return 0; },
|
||||
[&](const auto& hash) { return hash.digest_size(); });
|
||||
[&](Empty const&) -> size_t { return 0; },
|
||||
[&](auto const& hash) { return hash.digest_size(); });
|
||||
}
|
||||
|
||||
inline size_t block_size() const
|
||||
{
|
||||
return m_algorithm.visit(
|
||||
[&](const Empty&) -> size_t { return 0; },
|
||||
[&](const auto& hash) { return hash.block_size(); });
|
||||
[&](Empty const&) -> size_t { return 0; },
|
||||
[&](auto const& hash) { return hash.block_size(); });
|
||||
}
|
||||
|
||||
inline void initialize(HashKind kind)
|
||||
|
@ -154,7 +154,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
virtual void update(const u8* data, size_t length) override
|
||||
virtual void update(u8 const* data, size_t length) override
|
||||
{
|
||||
auto size = m_pre_init_buffer.size();
|
||||
if (size) {
|
||||
|
@ -195,8 +195,8 @@ public:
|
|||
virtual String class_name() const override
|
||||
{
|
||||
return m_algorithm.visit(
|
||||
[&](const Empty&) -> String { return "UninitializedHashManager"; },
|
||||
[&](const auto& hash) { return hash.class_name(); });
|
||||
[&](Empty const&) -> String { return "UninitializedHashManager"; },
|
||||
[&](auto const& hash) { return hash.class_name(); });
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ static constexpr void round_4(u32& a, u32 b, u32 c, u32 d, u32 x, u32 s, u32 ac)
|
|||
namespace Crypto {
|
||||
namespace Hash {
|
||||
|
||||
void MD5::update(const u8* input, size_t length)
|
||||
void MD5::update(u8 const* input, size_t length)
|
||||
{
|
||||
auto index = (u32)(m_count[0] >> 3) & 0x3f;
|
||||
size_t offset { 0 };
|
||||
|
@ -101,7 +101,7 @@ MD5::DigestType MD5::peek()
|
|||
return digest;
|
||||
}
|
||||
|
||||
void MD5::encode(const u32* from, u8* to, size_t length)
|
||||
void MD5::encode(u32 const* from, u8* to, size_t length)
|
||||
{
|
||||
for (size_t i = 0, j = 0; j < length; ++i, j += 4) {
|
||||
to[j] = (u8)(from[i] & 0xff);
|
||||
|
@ -111,13 +111,13 @@ void MD5::encode(const u32* from, u8* to, size_t length)
|
|||
}
|
||||
}
|
||||
|
||||
void MD5::decode(const u8* from, u32* to, size_t length)
|
||||
void MD5::decode(u8 const* from, u32* to, size_t length)
|
||||
{
|
||||
for (size_t i = 0, j = 0; j < length; ++i, j += 4)
|
||||
to[i] = (((u32)from[j]) | (((u32)from[j + 1]) << 8) | (((u32)from[j + 2]) << 16) | (((u32)from[j + 3]) << 24));
|
||||
}
|
||||
|
||||
void MD5::transform(const u8* block)
|
||||
void MD5::transform(u8 const* block)
|
||||
{
|
||||
auto a = m_A;
|
||||
auto b = m_B;
|
||||
|
|
|
@ -52,7 +52,7 @@ class MD5 final : public HashFunction<512, 128> {
|
|||
public:
|
||||
using HashFunction::update;
|
||||
|
||||
virtual void update(const u8*, size_t) override;
|
||||
virtual void update(u8 const*, size_t) override;
|
||||
virtual DigestType digest() override;
|
||||
virtual DigestType peek() override;
|
||||
|
||||
|
@ -63,15 +63,15 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
inline static DigestType hash(const u8* data, size_t length)
|
||||
inline static DigestType hash(u8 const* data, size_t length)
|
||||
{
|
||||
MD5 md5;
|
||||
md5.update(data, length);
|
||||
return md5.digest();
|
||||
}
|
||||
|
||||
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
inline static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
inline virtual void reset() override
|
||||
{
|
||||
m_A = MD5Constants::init_A;
|
||||
|
@ -86,10 +86,10 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
inline void transform(const u8*);
|
||||
inline void transform(u8 const*);
|
||||
|
||||
static void encode(const u32* from, u8* to, size_t length);
|
||||
static void decode(const u8* from, u32* to, size_t length);
|
||||
static void encode(u32 const* from, u8* to, size_t length);
|
||||
static void decode(u8 const* from, u32* to, size_t length);
|
||||
|
||||
u32 m_A { MD5Constants::init_A }, m_B { MD5Constants::init_B }, m_C { MD5Constants::init_C }, m_D { MD5Constants::init_D };
|
||||
u32 m_count[2] { 0, 0 };
|
||||
|
|
|
@ -17,11 +17,11 @@ static constexpr auto ROTATE_LEFT(u32 value, size_t bits)
|
|||
return (value << bits) | (value >> (32 - bits));
|
||||
}
|
||||
|
||||
inline void SHA1::transform(const u8* data)
|
||||
inline void SHA1::transform(u8 const* data)
|
||||
{
|
||||
u32 blocks[80];
|
||||
for (size_t i = 0; i < 16; ++i)
|
||||
blocks[i] = AK::convert_between_host_and_network_endian(((const u32*)data)[i]);
|
||||
blocks[i] = AK::convert_between_host_and_network_endian(((u32 const*)data)[i]);
|
||||
|
||||
// w[i] = (w[i-3] xor w[i-8] xor w[i-14] xor w[i-16]) leftrotate 1
|
||||
for (size_t i = 16; i < Rounds; ++i)
|
||||
|
@ -67,7 +67,7 @@ inline void SHA1::transform(const u8* data)
|
|||
secure_zero(blocks, 16 * sizeof(u32));
|
||||
}
|
||||
|
||||
void SHA1::update(const u8* message, size_t length)
|
||||
void SHA1::update(u8 const* message, size_t length)
|
||||
{
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
if (m_data_length == BlockSize) {
|
||||
|
|
|
@ -37,20 +37,20 @@ public:
|
|||
reset();
|
||||
}
|
||||
|
||||
virtual void update(const u8*, size_t) override;
|
||||
virtual void update(u8 const*, size_t) override;
|
||||
|
||||
virtual DigestType digest() override;
|
||||
virtual DigestType peek() override;
|
||||
|
||||
inline static DigestType hash(const u8* data, size_t length)
|
||||
inline static DigestType hash(u8 const* data, size_t length)
|
||||
{
|
||||
SHA1 sha;
|
||||
sha.update(data, length);
|
||||
return sha.digest();
|
||||
}
|
||||
|
||||
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
inline static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
|
||||
#ifndef KERNEL
|
||||
virtual String class_name() const override
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
inline void transform(const u8*);
|
||||
inline void transform(u8 const*);
|
||||
|
||||
u8 m_data_buffer[BlockSize] {};
|
||||
size_t m_data_length { 0 };
|
||||
|
|
|
@ -25,7 +25,7 @@ constexpr static auto EP1(u64 x) { return ROTRIGHT(x, 14) ^ ROTRIGHT(x, 18) ^ RO
|
|||
constexpr static auto SIGN0(u64 x) { return ROTRIGHT(x, 1) ^ ROTRIGHT(x, 8) ^ (x >> 7); }
|
||||
constexpr static auto SIGN1(u64 x) { return ROTRIGHT(x, 19) ^ ROTRIGHT(x, 61) ^ (x >> 6); }
|
||||
|
||||
inline void SHA256::transform(const u8* data)
|
||||
inline void SHA256::transform(u8 const* data)
|
||||
{
|
||||
u32 m[64];
|
||||
|
||||
|
@ -66,7 +66,7 @@ inline void SHA256::transform(const u8* data)
|
|||
m_state[7] += h;
|
||||
}
|
||||
|
||||
void SHA256::update(const u8* message, size_t length)
|
||||
void SHA256::update(u8 const* message, size_t length)
|
||||
{
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
if (m_data_length == BlockSize) {
|
||||
|
@ -142,7 +142,7 @@ SHA256::DigestType SHA256::peek()
|
|||
return digest;
|
||||
}
|
||||
|
||||
inline void SHA384::transform(const u8* data)
|
||||
inline void SHA384::transform(u8 const* data)
|
||||
{
|
||||
u64 m[80];
|
||||
|
||||
|
@ -184,7 +184,7 @@ inline void SHA384::transform(const u8* data)
|
|||
m_state[7] += h;
|
||||
}
|
||||
|
||||
void SHA384::update(const u8* message, size_t length)
|
||||
void SHA384::update(u8 const* message, size_t length)
|
||||
{
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
if (m_data_length == BlockSize) {
|
||||
|
@ -267,7 +267,7 @@ SHA384::DigestType SHA384::peek()
|
|||
return digest;
|
||||
}
|
||||
|
||||
inline void SHA512::transform(const u8* data)
|
||||
inline void SHA512::transform(u8 const* data)
|
||||
{
|
||||
u64 m[80];
|
||||
|
||||
|
@ -308,7 +308,7 @@ inline void SHA512::transform(const u8* data)
|
|||
m_state[7] += h;
|
||||
}
|
||||
|
||||
void SHA512::update(const u8* message, size_t length)
|
||||
void SHA512::update(u8 const* message, size_t length)
|
||||
{
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
if (m_data_length == BlockSize) {
|
||||
|
|
|
@ -85,20 +85,20 @@ public:
|
|||
reset();
|
||||
}
|
||||
|
||||
virtual void update(const u8*, size_t) override;
|
||||
virtual void update(u8 const*, size_t) override;
|
||||
|
||||
virtual DigestType digest() override;
|
||||
virtual DigestType peek() override;
|
||||
|
||||
inline static DigestType hash(const u8* data, size_t length)
|
||||
inline static DigestType hash(u8 const* data, size_t length)
|
||||
{
|
||||
SHA256 sha;
|
||||
sha.update(data, length);
|
||||
return sha.digest();
|
||||
}
|
||||
|
||||
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
inline static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
|
||||
#ifndef KERNEL
|
||||
virtual String class_name() const override
|
||||
|
@ -116,7 +116,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
inline void transform(const u8*);
|
||||
inline void transform(u8 const*);
|
||||
|
||||
u8 m_data_buffer[BlockSize] {};
|
||||
size_t m_data_length { 0 };
|
||||
|
@ -137,20 +137,20 @@ public:
|
|||
reset();
|
||||
}
|
||||
|
||||
virtual void update(const u8*, size_t) override;
|
||||
virtual void update(u8 const*, size_t) override;
|
||||
|
||||
virtual DigestType digest() override;
|
||||
virtual DigestType peek() override;
|
||||
|
||||
inline static DigestType hash(const u8* data, size_t length)
|
||||
inline static DigestType hash(u8 const* data, size_t length)
|
||||
{
|
||||
SHA384 sha;
|
||||
sha.update(data, length);
|
||||
return sha.digest();
|
||||
}
|
||||
|
||||
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
inline static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
|
||||
#ifndef KERNEL
|
||||
virtual String class_name() const override
|
||||
|
@ -168,7 +168,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
inline void transform(const u8*);
|
||||
inline void transform(u8 const*);
|
||||
|
||||
u8 m_data_buffer[BlockSize] {};
|
||||
size_t m_data_length { 0 };
|
||||
|
@ -189,20 +189,20 @@ public:
|
|||
reset();
|
||||
}
|
||||
|
||||
virtual void update(const u8*, size_t) override;
|
||||
virtual void update(u8 const*, size_t) override;
|
||||
|
||||
virtual DigestType digest() override;
|
||||
virtual DigestType peek() override;
|
||||
|
||||
inline static DigestType hash(const u8* data, size_t length)
|
||||
inline static DigestType hash(u8 const* data, size_t length)
|
||||
{
|
||||
SHA512 sha;
|
||||
sha.update(data, length);
|
||||
return sha.digest();
|
||||
}
|
||||
|
||||
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
inline static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
||||
inline static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||
|
||||
#ifndef KERNEL
|
||||
virtual String class_name() const override
|
||||
|
@ -220,7 +220,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
inline void transform(const u8*);
|
||||
inline void transform(u8 const*);
|
||||
|
||||
u8 m_data_buffer[BlockSize] {};
|
||||
size_t m_data_length { 0 };
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
namespace Crypto {
|
||||
namespace NumberTheory {
|
||||
|
||||
UnsignedBigInteger ModularInverse(const UnsignedBigInteger& a_, const UnsignedBigInteger& b)
|
||||
UnsignedBigInteger ModularInverse(UnsignedBigInteger const& a_, UnsignedBigInteger const& b)
|
||||
{
|
||||
if (b == 1)
|
||||
return { 1 };
|
||||
|
@ -32,7 +32,7 @@ UnsignedBigInteger ModularInverse(const UnsignedBigInteger& a_, const UnsignedBi
|
|||
return result;
|
||||
}
|
||||
|
||||
UnsignedBigInteger ModularPower(const UnsignedBigInteger& b, const UnsignedBigInteger& e, const UnsignedBigInteger& m)
|
||||
UnsignedBigInteger ModularPower(UnsignedBigInteger const& b, UnsignedBigInteger const& e, UnsignedBigInteger const& m)
|
||||
{
|
||||
if (m == 1)
|
||||
return 0;
|
||||
|
@ -68,7 +68,7 @@ UnsignedBigInteger ModularPower(const UnsignedBigInteger& b, const UnsignedBigIn
|
|||
return result;
|
||||
}
|
||||
|
||||
UnsignedBigInteger GCD(const UnsignedBigInteger& a, const UnsignedBigInteger& b)
|
||||
UnsignedBigInteger GCD(UnsignedBigInteger const& a, UnsignedBigInteger const& b)
|
||||
{
|
||||
UnsignedBigInteger temp_a { a };
|
||||
UnsignedBigInteger temp_b { b };
|
||||
|
@ -85,7 +85,7 @@ UnsignedBigInteger GCD(const UnsignedBigInteger& a, const UnsignedBigInteger& b)
|
|||
return output;
|
||||
}
|
||||
|
||||
UnsignedBigInteger LCM(const UnsignedBigInteger& a, const UnsignedBigInteger& b)
|
||||
UnsignedBigInteger LCM(UnsignedBigInteger const& a, UnsignedBigInteger const& b)
|
||||
{
|
||||
UnsignedBigInteger temp_a { a };
|
||||
UnsignedBigInteger temp_b { b };
|
||||
|
@ -113,7 +113,7 @@ UnsignedBigInteger LCM(const UnsignedBigInteger& a, const UnsignedBigInteger& b)
|
|||
return output;
|
||||
}
|
||||
|
||||
static bool MR_primality_test(UnsignedBigInteger n, const Vector<UnsignedBigInteger, 256>& tests)
|
||||
static bool MR_primality_test(UnsignedBigInteger n, Vector<UnsignedBigInteger, 256> const& tests)
|
||||
{
|
||||
// Written using Wikipedia:
|
||||
// https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test#Miller%E2%80%93Rabin_test
|
||||
|
@ -158,7 +158,7 @@ static bool MR_primality_test(UnsignedBigInteger n, const Vector<UnsignedBigInte
|
|||
return true; // "probably prime"
|
||||
}
|
||||
|
||||
UnsignedBigInteger random_number(const UnsignedBigInteger& min, const UnsignedBigInteger& max_excluded)
|
||||
UnsignedBigInteger random_number(UnsignedBigInteger const& min, UnsignedBigInteger const& max_excluded)
|
||||
{
|
||||
VERIFY(min < max_excluded);
|
||||
auto range = max_excluded.minus(min);
|
||||
|
@ -181,7 +181,7 @@ UnsignedBigInteger random_number(const UnsignedBigInteger& min, const UnsignedBi
|
|||
return divmod.remainder.plus(min);
|
||||
}
|
||||
|
||||
bool is_probably_prime(const UnsignedBigInteger& p)
|
||||
bool is_probably_prime(UnsignedBigInteger const& p)
|
||||
{
|
||||
// Is it a small number?
|
||||
if (p < 49) {
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
namespace Crypto {
|
||||
namespace NumberTheory {
|
||||
|
||||
UnsignedBigInteger ModularInverse(const UnsignedBigInteger& a_, const UnsignedBigInteger& b);
|
||||
UnsignedBigInteger ModularPower(const UnsignedBigInteger& b, const UnsignedBigInteger& e, const UnsignedBigInteger& m);
|
||||
UnsignedBigInteger ModularInverse(UnsignedBigInteger const& a_, UnsignedBigInteger const& b);
|
||||
UnsignedBigInteger ModularPower(UnsignedBigInteger const& b, UnsignedBigInteger const& e, UnsignedBigInteger const& m);
|
||||
|
||||
// Note: This function _will_ generate extremely huge numbers, and in doing so,
|
||||
// it will allocate and free a lot of memory!
|
||||
// Please use |ModularPower| if your use-case is modexp.
|
||||
template<typename IntegerType>
|
||||
static IntegerType Power(const IntegerType& b, const IntegerType& e)
|
||||
static IntegerType Power(IntegerType const& b, IntegerType const& e)
|
||||
{
|
||||
IntegerType ep { e };
|
||||
IntegerType base { b };
|
||||
|
@ -39,11 +39,11 @@ static IntegerType Power(const IntegerType& b, const IntegerType& e)
|
|||
return exp;
|
||||
}
|
||||
|
||||
UnsignedBigInteger GCD(const UnsignedBigInteger& a, const UnsignedBigInteger& b);
|
||||
UnsignedBigInteger LCM(const UnsignedBigInteger& a, const UnsignedBigInteger& b);
|
||||
UnsignedBigInteger GCD(UnsignedBigInteger const& a, UnsignedBigInteger const& b);
|
||||
UnsignedBigInteger LCM(UnsignedBigInteger const& a, UnsignedBigInteger const& b);
|
||||
|
||||
UnsignedBigInteger random_number(const UnsignedBigInteger& min, const UnsignedBigInteger& max_excluded);
|
||||
bool is_probably_prime(const UnsignedBigInteger& p);
|
||||
UnsignedBigInteger random_number(UnsignedBigInteger const& min, UnsignedBigInteger const& max_excluded);
|
||||
bool is_probably_prime(UnsignedBigInteger const& p);
|
||||
UnsignedBigInteger random_big_prime(size_t bits);
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
virtual void encode(ReadonlyBytes in, ByteBuffer& out, size_t em_bits) = 0;
|
||||
virtual VerificationConsistency verify(ReadonlyBytes msg, ReadonlyBytes emsg, size_t em_bits) = 0;
|
||||
|
||||
const HashFunction& hasher() const { return m_hasher; }
|
||||
HashFunction const& hasher() const { return m_hasher; }
|
||||
HashFunction& hasher() { return m_hasher; }
|
||||
|
||||
protected:
|
||||
|
|
|
@ -56,7 +56,7 @@ RSA::KeyPairType RSA::parse_rsa_key(ReadonlyBytes der)
|
|||
|
||||
bool has_read_error = false;
|
||||
|
||||
const auto check_if_pkcs8_rsa_key = [&] {
|
||||
auto const check_if_pkcs8_rsa_key = [&] {
|
||||
// see if it's a sequence:
|
||||
auto tag_result = decoder.peek();
|
||||
if (tag_result.is_error()) {
|
||||
|
|
|
@ -31,8 +31,8 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
const Integer& modulus() const { return m_modulus; }
|
||||
const Integer& public_exponent() const { return m_public_exponent; }
|
||||
Integer const& modulus() const { return m_modulus; }
|
||||
Integer const& public_exponent() const { return m_public_exponent; }
|
||||
size_t length() const { return m_length; }
|
||||
void set_length(size_t length) { m_length = length; }
|
||||
|
||||
|
@ -62,9 +62,9 @@ public:
|
|||
|
||||
RSAPrivateKey() = default;
|
||||
|
||||
const Integer& modulus() const { return m_modulus; }
|
||||
const Integer& private_exponent() const { return m_private_exponent; }
|
||||
const Integer& public_exponent() const { return m_public_exponent; }
|
||||
Integer const& modulus() const { return m_modulus; }
|
||||
Integer const& private_exponent() const { return m_private_exponent; }
|
||||
Integer const& public_exponent() const { return m_public_exponent; }
|
||||
size_t length() const { return m_length; }
|
||||
void set_length(size_t length) { m_length = length; }
|
||||
|
||||
|
@ -135,7 +135,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
RSA(const ByteBuffer& publicKeyPEM, const ByteBuffer& privateKeyPEM)
|
||||
RSA(ByteBuffer const& publicKeyPEM, ByteBuffer const& privateKeyPEM)
|
||||
{
|
||||
import_public_key(publicKeyPEM);
|
||||
import_private_key(privateKeyPEM);
|
||||
|
@ -176,8 +176,8 @@ public:
|
|||
void import_public_key(ReadonlyBytes, bool pem = true);
|
||||
void import_private_key(ReadonlyBytes, bool pem = true);
|
||||
|
||||
const PrivateKeyType& private_key() const { return m_private_key; }
|
||||
const PublicKeyType& public_key() const { return m_public_key; }
|
||||
PrivateKeyType const& private_key() const { return m_private_key; }
|
||||
PublicKeyType const& public_key() const { return m_public_key; }
|
||||
};
|
||||
|
||||
template<typename HashFunction>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue