LibCrypto: Remove the concept of invalid big integers

This concept is rarely used in codebase and very much error-prone
if you forget to check it.

Instead, make it so that operations that would produce invalid integers
return an error instead.
This commit is contained in:
devgianlu 2025-04-25 21:28:00 +02:00 committed by Jelle Raaijmakers
parent 14387e5411
commit 5f1a30197c
Notes: github-actions[bot] 2025-04-28 10:06:55 +00:00
12 changed files with 34 additions and 109 deletions

View file

@ -73,14 +73,13 @@ void UnsignedBigIntegerAlgorithms::add_into_accumulator_without_allocation(Unsig
/**
* Complexity: O(N) where N is the number of words in the larger number
*/
void UnsignedBigIntegerAlgorithms::subtract_without_allocation(
ErrorOr<void> UnsignedBigIntegerAlgorithms::subtract_without_allocation(
UnsignedBigInteger const& left,
UnsignedBigInteger const& right,
UnsignedBigInteger& output)
{
if (left < right) {
output.invalidate();
return;
return Error::from_string_literal("Invalid subtraction: left < right");
}
u8 borrow = 0;
@ -103,6 +102,8 @@ void UnsignedBigIntegerAlgorithms::subtract_without_allocation(
// This assertion should not fail, because we verified that *this>=other at the beginning of the function
VERIFY(borrow == 0);
return {};
}
}