Skip to content
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
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ AM_CONDITIONAL([HOST_ASM_ELF_MIPS64],
[test "x$HOST_ABI" = "xelf" -a "$host_cpu" = "mips64" -a "x$enable_asm" != "xno"])
AM_CONDITIONAL([HOST_ASM_ELF_X86_64],
[test "x$HOST_ABI" = "xelf" -a "$host_cpu" = "x86_64" -a "x$enable_asm" != "xno"])
AM_CONDITIONAL([HOST_ASM_MACOSX_AARCH64],
[test "x$HOST_ABI" = "xmacosx" -a "$host_cpu" = "aarch64" -a "x$enable_asm" != "xno"])
AM_CONDITIONAL([HOST_ASM_MACOSX_X86_64],
[test "x$HOST_ABI" = "xmacosx" -a "$host_cpu" = "x86_64" -a "x$enable_asm" != "xno"])
AM_CONDITIONAL([HOST_ASM_MASM_X86_64],
Expand Down
14 changes: 14 additions & 0 deletions crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ if(HOST_ASM_ELF_X86_64)
set(CRYPTO_SRC ${CRYPTO_SRC} ${ASM_X86_64_ELF_SRC})
endif()

if(HOST_ASM_MACOSX_AARCH64)
set(CRYPTO_SRC ${CRYPTO_SRC} sha/sha1_amd64.c sha/sha256_amd64.c sha/sha512_amd64.c)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong architecture here.


set(
ASM_AARCH64_MACOSX_SRC

sha/sha1_aarch64_ce.S
sha/sha256_aarch64_ce.S
sha/sha512_aarch64_ce.S
)
set(CRYPTO_SRC ${CRYPTO_SRC} ${ASM_AARCH64_MACOSX_SRC})
add_definitions(-DLIBRESSL_USE_SHA_ASSEMBLY)
endif()

if(HOST_ASM_MACOSX_X86_64)
set(CRYPTO_SRC ${CRYPTO_SRC} aes/aes_amd64.c)
set(CRYPTO_SRC ${CRYPTO_SRC} bn/arch/amd64/bn_arch.c)
Expand Down
4 changes: 4 additions & 0 deletions crypto/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,15 @@ EXTRA_libcrypto_la_SOURCES =
include Makefile.am.elf-mips
include Makefile.am.elf-mips64
include Makefile.am.elf-x86_64
include Makefile.am.macosx-aarch64
include Makefile.am.macosx-x86_64
include Makefile.am.masm-x86_64
include Makefile.am.mingw64-x86_64

if !HOST_ASM_ELF_MIPS
if !HOST_ASM_ELF_MIPS64
if !HOST_ASM_ELF_X86_64
if !HOST_ASM_MACOSX_AARCH64
if !HOST_ASM_MACOSX_X86_64
if !HOST_ASM_MASM_X86_64
if !HOST_ASM_MINGW64_X86_64
Expand All @@ -225,6 +227,7 @@ endif
endif
endif
endif
endif

if HOST_AARCH64
if HOST_DARWIN
Expand Down Expand Up @@ -264,6 +267,7 @@ libcrypto_la_SOURCES += compat/crypto_lock_win.c
endif
libcrypto_la_SOURCES += crypto_memory.c
noinst_HEADERS += constant_time.h
noinst_HEADERS += crypto_assembly.h
noinst_HEADERS += crypto_internal.h
noinst_HEADERS += crypto_local.h
noinst_HEADERS += x86_arch.h
Expand Down
16 changes: 16 additions & 0 deletions crypto/Makefile.am.macosx-aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

ASM_AARCH64_MACOSX = sha/sha1_aarch64_ce.S
ASM_AARCH64_MACOSX += sha/sha256_aarch64_ce.S
ASM_AARCH64_MACOSX += sha/sha512_aarch64_ce.S

EXTRA_DIST += $(ASM_AARCH64_MACOSX)

if HOST_ASM_MACOSX_AARCH64
libcrypto_la_SOURCES += sha/sha1_aarch64.c
libcrypto_la_SOURCES += sha/sha256_aarch64.c
libcrypto_la_SOURCES += sha/sha512_aarch64.c

libcrypto_la_CPPFLAGS += -DLIBRESSL_USE_SHA_ASSEMBLY

libcrypto_la_SOURCES += $(ASM_AARCH64_MACOSX)
endif
61 changes: 61 additions & 0 deletions crypto/crypto_assembly.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2026 Joel Sing <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef HEADER_CRYPTO_ASSEMBLY_H
#define HEADER_CRYPTO_ASSEMBLY_H

#if defined(__APPLE__)
#define CRYPTO_ASSEMBLY_SECTION_TEXT __TEXT,__text
#define CRYPTO_ASSEMBLY_SECTION_RODATA __DATA,__const

#define CRYPTO_ASSEMBLY_SYMBOL_NAME(name) _##name
#define CRYPTO_ASSEMBLY_TYPE_FUNCTION(name)
#define CRYPTO_ASSEMBLY_TYPE_OBJECT(name)
#define CRYPTO_ASSEMBLY_OBJECT_SIZE(name)

#define CRYPTO_ASSEMBLY_AARCH64_SYM_HI(name) name##@PAGE
#define CRYPTO_ASSEMBLY_AARCH64_SYM_LO(name) name##@PAGEOFF

#else
#define CRYPTO_ASSEMBLY_SECTION_TEXT .text
#define CRYPTO_ASSEMBLY_SECTION_RODATA .rodata

#define CRYPTO_ASSEMBLY_SYMBOL_NAME(name) name
#define CRYPTO_ASSEMBLY_TYPE_FUNCTION(name) .type name##,@function
#define CRYPTO_ASSEMBLY_TYPE_OBJECT(name) .type name##,@object
#define CRYPTO_ASSEMBLY_OBJECT_SIZE(name) .size name##,.-##name

#define CRYPTO_ASSEMBLY_AARCH64_SYM_HI(name) name
#define CRYPTO_ASSEMBLY_AARCH64_SYM_LO(name) :lo12:##name
#endif

#if defined(__APPLE__) && defined(__aarch64__)
#define CRYPTO_ASSEMBLY_NEWLINE %%
#else
#define CRYPTO_ASSEMBLY_NEWLINE ;
#endif

/* Ensure _CET_ENDBR is always defined on amd64. */
#ifdef __amd64__
#ifdef __CET__
#include <cet.h>
#else
#define _CET_ENDBR
#endif
#endif

#endif
Loading