LibC: Expose AK::timing_safe_compare via timingsafe_memcmp(..)

Ports / other userland often needs such an implementation to function.
Lets expose `AK::timing_safe_compare` under the same name used used in
OpenBSD / FreeBSD / Solaris and other projects.
This commit is contained in:
Brian Gianforcaro 2022-03-12 22:09:54 -08:00 committed by Brian Gianforcaro
parent 0a5321b3f9
commit 01bd3c5563
Notes: sideshowbarker 2024-07-17 17:27:47 +09:00
2 changed files with 8 additions and 0 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Brian Gianforcaro <bgianf@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -121,6 +122,11 @@ int memcmp(const void* v1, const void* v2, size_t n)
return 0;
}
int timingsafe_memcmp(const void* b1, const void* b2, size_t len)
{
return AK::timing_safe_compare(b1, b2, len) ? 1 : 0;
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/memcpy.html
void* memcpy(void* dest_ptr, const void* src_ptr, size_t n)
{

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Brian Gianforcaro <bgianf@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -23,6 +24,7 @@ int strcmp(const char*, const char*);
int strncmp(const char*, const char*, size_t);
int memcmp(const void*, const void*, size_t);
int timingsafe_memcmp(const void*, const void*, size_t);
void* memcpy(void*, const void*, size_t);
void* memmove(void*, const void*, size_t);
void* memchr(const void*, int c, size_t);