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

LibCrypto: Use UnsignedBigInteger::is_odd() instead of manually checking

The previous implementation ignored "empty" bigints that represented
zero, leading to random crashes.
This commit is contained in:
Ali Mohammad Pur 2024-03-13 15:40:22 +01:00 committed by Andrew Kaster
parent d451f84f31
commit dc1180d6b2

View file

@ -27,7 +27,7 @@ void UnsignedBigIntegerAlgorithms::modular_inverse_without_allocation(
UnsignedBigInteger one { 1 };
temp_u.set_to(a);
if (a.words()[0] % 2 == 0) {
if (!a.is_odd()) {
// u += b
add_into_accumulator_without_allocation(temp_u, b);
}
@ -47,8 +47,8 @@ void UnsignedBigIntegerAlgorithms::modular_inverse_without_allocation(
// d += x
add_into_accumulator_without_allocation(temp_d, temp_x);
while (temp_u.words()[0] % 2 == 0) {
if (temp_d.words()[0] % 2 == 1) {
while (!temp_u.is_odd()) {
if (temp_d.is_odd()) {
// d += b
add_into_accumulator_without_allocation(temp_d, b);
}
@ -70,8 +70,8 @@ void UnsignedBigIntegerAlgorithms::modular_inverse_without_allocation(
// x += d
add_into_accumulator_without_allocation(temp_x, temp_d);
while (temp_v.words()[0] % 2 == 0) {
if (temp_x.words()[0] % 2 == 1) {
while (!temp_v.is_odd()) {
if (temp_x.is_odd()) {
// x += b
add_into_accumulator_without_allocation(temp_x, b);
}