Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-127897: backport HACL* compatibility changes #127932

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Modules/_hacl/Lib_Memzero0.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <windows.h>
#endif

#if defined(__APPLE__) && defined(__MACH__)
#include <AvailabilityMacros.h>
#endif

#if (defined(__APPLE__) && defined(__MACH__)) || defined(__linux__)
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
Expand Down Expand Up @@ -37,7 +41,7 @@ void Lib_Memzero0_memzero0(void *dst, uint64_t len) {

#ifdef _WIN32
SecureZeroMemory(dst, len_);
#elif defined(__APPLE__) && defined(__MACH__)
#elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
memset_s(dst, len_, 0, len_);
#elif (defined(__linux__) && !defined(LINUX_NO_EXPLICIT_BZERO)) || defined(__FreeBSD__)
explicit_bzero(dst, len_);
Expand Down
18 changes: 18 additions & 0 deletions Modules/_hacl/include/krml/internal/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
# define inline __inline__
#endif

/* There is no support for aligned_alloc() in macOS before Catalina, so
* let's make a macro to use _mm_malloc() and _mm_free() functions
* from mm_malloc.h. */
#if defined(__APPLE__) && defined(__MACH__)
# include <AvailabilityMacros.h>
# if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
(MAC_OS_X_VERSION_MIN_REQUIRED < 101500)
# include <mm_malloc.h>
# define LEGACY_MACOS
# else
# undef LEGACY_MACOS
#endif
#endif

/******************************************************************************/
/* Macros that KaRaMeL will generate. */
/******************************************************************************/
Expand Down Expand Up @@ -133,6 +147,8 @@
defined(_MSC_VER) || \
(defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)))
# define KRML_ALIGNED_MALLOC(X, Y) _aligned_malloc(Y, X)
# elif defined(LEGACY_MACOS)
# define KRML_ALIGNED_MALLOC(X, Y) _mm_malloc(Y, X)
# else
# define KRML_ALIGNED_MALLOC(X, Y) aligned_alloc(X, Y)
# endif
Expand All @@ -150,6 +166,8 @@
defined(_MSC_VER) || \
(defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)))
# define KRML_ALIGNED_FREE(X) _aligned_free(X)
# elif defined(LEGACY_MACOS)
# define KRML_ALIGNED_FREE(X) _mm_free(X)
# else
# define KRML_ALIGNED_FREE(X) free(X)
# endif
Expand Down
Loading