Skip to content

Commit

Permalink
[libsodium] Fix arm builds (android NDK r26) (microsoft#37932)
Browse files Browse the repository at this point in the history
Upstream patch, adjusted. Cherry-picked from
microsoft#35851.
Fixes microsoft#37423,
  • Loading branch information
dg0yt authored Apr 3, 2024
1 parent 733b918 commit 11ed791
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 2 deletions.
119 changes: 119 additions & 0 deletions ports/libsodium/arm-neon.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
diff --git a/configure.ac b/configure.ac
index df83ef5..be67d34 100644
--- a/configure.ac
+++ b/configure.ac
@@ -398,11 +398,6 @@ AS_IF([test "x$EMSCRIPTEN" = "x"], [
have_armcrypto=no
AC_MSG_CHECKING(for ARM crypto instructions set)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
- #ifdef __clang__
- # pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
- #elif defined(__GNUC__)
- # pragma GCC target("+simd+crypto")
- #endif
#ifndef __ARM_FEATURE_CRYPTO
# define __ARM_FEATURE_CRYPTO 1
#endif
@@ -411,6 +406,12 @@ AS_IF([test "x$EMSCRIPTEN" = "x"], [
#endif

#include <arm_neon.h>
+
+ #ifdef __clang__
+ # pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
+ #elif defined(__GNUC__)
+ # pragma GCC target("+simd+crypto")
+ #endif
]], [[
vaeseq_u8(vmovq_n_u8(0), vmovq_n_u8(0));

diff --git a/src/libsodium/crypto_aead/aegis128l/aegis128l_armcrypto.c b/src/libsodium/crypto_aead/aegis128l/aegis128l_armcrypto.c
index 825de8a..a01f60c 100644
--- a/src/libsodium/crypto_aead/aegis128l/aegis128l_armcrypto.c
+++ b/src/libsodium/crypto_aead/aegis128l/aegis128l_armcrypto.c
@@ -17,12 +17,6 @@

#include "aegis128l_armcrypto.h"

-#ifdef __clang__
-#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
-#elif defined(__GNUC__)
-#pragma GCC target("+simd+crypto")
-#endif
-
#ifndef __ARM_FEATURE_CRYPTO
#define __ARM_FEATURE_CRYPTO 1
#endif
@@ -32,6 +26,12 @@

#include <arm_neon.h>

+#ifdef __clang__
+#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
+#elif defined(__GNUC__)
+#pragma GCC target("+simd+crypto")
+#endif
+
#define AES_BLOCK_LENGTH 16

typedef uint8x16_t aes_block_t;
diff --git a/src/libsodium/crypto_aead/aegis256/aegis256_armcrypto.c b/src/libsodium/crypto_aead/aegis256/aegis256_armcrypto.c
index e1ebd57..058e207 100644
--- a/src/libsodium/crypto_aead/aegis256/aegis256_armcrypto.c
+++ b/src/libsodium/crypto_aead/aegis256/aegis256_armcrypto.c
@@ -17,12 +17,6 @@

#include "aegis256_armcrypto.h"

-#ifdef __clang__
-#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
-#elif defined(__GNUC__)
-#pragma GCC target("+simd+crypto")
-#endif
-
#ifndef __ARM_FEATURE_CRYPTO
#define __ARM_FEATURE_CRYPTO 1
#endif
@@ -32,6 +26,12 @@

#include <arm_neon.h>

+#ifdef __clang__
+#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
+#elif defined(__GNUC__)
+#pragma GCC target("+simd+crypto")
+#endif
+
#define AES_BLOCK_LENGTH 16

typedef uint8x16_t aes_block_t;
diff --git a/src/libsodium/crypto_aead/aes256gcm/armcrypto/aead_aes256gcm_armcrypto.c b/src/libsodium/crypto_aead/aes256gcm/armcrypto/aead_aes256gcm_armcrypto.c
index 0a5a128..aa76f5c 100644
--- a/src/libsodium/crypto_aead/aes256gcm/armcrypto/aead_aes256gcm_armcrypto.c
+++ b/src/libsodium/crypto_aead/aes256gcm/armcrypto/aead_aes256gcm_armcrypto.c
@@ -19,12 +19,6 @@
#define __vectorcall
#endif

-#ifdef __clang__
-#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
-#elif defined(__GNUC__)
-#pragma GCC target("+simd+crypto")
-#endif
-
#ifndef __ARM_FEATURE_CRYPTO
#define __ARM_FEATURE_CRYPTO 1
#endif
@@ -34,6 +28,12 @@

#include <arm_neon.h>

+#ifdef __clang__
+#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
+#elif defined(__GNUC__)
+#pragma GCC target("+simd+crypto")
+#endif
+
#define ABYTES crypto_aead_aes256gcm_ABYTES
#define NPUBBYTES crypto_aead_aes256gcm_NPUBBYTES
#define KEYBYTES crypto_aead_aes256gcm_KEYBYTES
2 changes: 2 additions & 0 deletions ports/libsodium/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ vcpkg_from_github(
REF ${VERSION}
SHA512 6094d7bf191ea3be85f2ddab76b71f1b9c69c786493db5b84d3c5d5a0237003377ddf6a8687a962ea651fe4a9369cf5ee1676ba0bae82690f5f7ef31a698efa9
HEAD_REF master
PATCHES
arm-neon.diff # https://github.com/jedisct1/libsodium/commit/8f453f41f8834e0fe47610f2a3e03e696ddb3450 with fuzz 2
)

if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
Expand Down
2 changes: 1 addition & 1 deletion ports/libsodium/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "libsodium",
"version": "1.0.19",
"port-version": 1,
"port-version": 2,
"description": "A modern and easy-to-use crypto library",
"homepage": "https://libsodium.org/",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4938,7 +4938,7 @@
},
"libsodium": {
"baseline": "1.0.19",
"port-version": 1
"port-version": 2
},
"libsonic": {
"baseline": "0.2.0",
Expand Down
5 changes: 5 additions & 0 deletions versions/l-/libsodium.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "24563a7817fe403090f82593e4be4c3bc8219510",
"version": "1.0.19",
"port-version": 2
},
{
"git-tree": "38de4073e90ae48d9d7bc68db71b850b5645f5ab",
"version": "1.0.19",
Expand Down

0 comments on commit 11ed791

Please sign in to comment.