Truly independent web browser
AK: Remove timing_safe_compare
Shannon Booth7803e793bbe8
diff --git a/AK/Memory.h b/AK/Memory.hindex f212f25b3b0..0d39e770acc 100644--- a/AK/Memory.h+++ b/AK/Memory.h@@ -21,30 +21,8 @@ inline void secure_zero(void* ptr, size_t size): "memory");}-// Naive implementation of a constant time buffer comparison function.-// The goal being to not use any conditional branching so calls are-// guarded against potential timing attacks.-//-// See OpenBSD's timingsafe_memcmp for more advanced implementations.-inline bool timing_safe_compare(void const* b1, void const* b2, size_t len)-{- auto* c1 = static_cast<char const*>(b1);- auto* c2 = static_cast<char const*>(b2);-- u8 res = 0;- for (size_t i = 0; i < len; i++) {- res |= c1[i] ^ c2[i];- }-- // FIXME: !res can potentially inject branches depending- // on which toolchain is being used for compilation. Ideally- // we would use a more advanced algorithm.- return !res;-}-}#if USING_AK_GLOBALLYusing AK::secure_zero;-using AK::timing_safe_compare;#endifdiff --git a/Tests/AK/TestMemory.cpp b/Tests/AK/TestMemory.cppindex 9ee9d4e69e4..c1c52b309c3 100644--- a/Tests/AK/TestMemory.cpp+++ b/Tests/AK/TestMemory.cpp@@ -6,7 +6,6 @@#include <LibTest/TestCase.h>-#include <AK/ByteString.h>#include <AK/MemMem.h>#include <AK/Memory.h>@@ -75,12 +74,3 @@ TEST_CASE(kmp_two_chunks)EXPECT_EQ(result_2.value_or(9), 4u);EXPECT(!result_3.has_value());}--TEST_CASE(timing_safe_compare)-{- ByteString data_set = "abcdefghijklmnopqrstuvwxyz123456789";- EXPECT_EQ(true, AK::timing_safe_compare(data_set.characters(), data_set.characters(), data_set.length()));-- ByteString reversed = data_set.reverse();- EXPECT_EQ(false, AK::timing_safe_compare(data_set.characters(), reversed.characters(), reversed.length()));-}