diff options
-rw-r--r-- | Tests/LibCrypto/TestBigInteger.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp | 7 |
2 files changed, 3 insertions, 8 deletions
diff --git a/Tests/LibCrypto/TestBigInteger.cpp b/Tests/LibCrypto/TestBigInteger.cpp index 1ff373a987..7af6eb4a1d 100644 --- a/Tests/LibCrypto/TestBigInteger.cpp +++ b/Tests/LibCrypto/TestBigInteger.cpp @@ -526,8 +526,8 @@ TEST_CASE(test_signed_bigint_bitwise_xor) auto num1 = "-3"_sbigint; auto num2 = "1"_sbigint; EXPECT_EQ(num1.bitwise_xor(num1), "0"_sbigint); - EXPECT_EQ(num1.bitwise_xor(num2), "-2"_sbigint); - EXPECT_EQ(num2.bitwise_xor(num1), "-2"_sbigint); + EXPECT_EQ(num1.bitwise_xor(num2), "-4"_sbigint); + EXPECT_EQ(num2.bitwise_xor(num1), "-4"_sbigint); EXPECT_EQ(num2.bitwise_xor(num2), "0"_sbigint); } diff --git a/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp b/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp index 3d52592a6e..084f55e8c1 100644 --- a/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp +++ b/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp @@ -238,12 +238,7 @@ FLATTEN SignedBigInteger SignedBigInteger::bitwise_and(const SignedBigInteger& o FLATTEN SignedBigInteger SignedBigInteger::bitwise_xor(const SignedBigInteger& other) const { - auto result = bitwise_xor(other.unsigned_value()); - - // The sign bit will have to be XOR'd manually. - result.m_sign = is_negative() ^ other.is_negative(); - - return result; + return bitwise_or(other).minus(bitwise_and(other)); } bool SignedBigInteger::operator==(const UnsignedBigInteger& other) const |