Skip to content

Commit

Permalink
Merge pull request #5471 from AenBleidd/vko_fix_android
Browse files Browse the repository at this point in the history
Fix android build
  • Loading branch information
AenBleidd authored Dec 22, 2023
2 parents 654669a + d14a0ab commit f86319a
Show file tree
Hide file tree
Showing 27 changed files with 1,682 additions and 0 deletions.
704 changes: 704 additions & 0 deletions 3rdParty/vcpkg_ports/ports/openssl/asm-comments.patch

Large diffs are not rendered by default.

188 changes: 188 additions & 0 deletions 3rdParty/vcpkg_ports/ports/openssl/declspec-align.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
diff --git a/crypto/ec/ecp_sm2p256.c b/crypto/ec/ecp_sm2p256.c
index 6ec4245..d47689a 100644
--- a/crypto/ec/ecp_sm2p256.c
+++ b/crypto/ec/ecp_sm2p256.c
@@ -40,28 +40,28 @@ typedef struct {

#if !defined(OPENSSL_NO_SM2_PRECOMP)
/* Coordinates of G, for which we have precomputed tables */
-static const BN_ULONG def_xG[P256_LIMBS] ALIGN32 = {
+ALIGN32 static const BN_ULONG def_xG[P256_LIMBS] = {
0x715a4589334c74c7, 0x8fe30bbff2660be1,
0x5f9904466a39c994, 0x32c4ae2c1f198119
};

-static const BN_ULONG def_yG[P256_LIMBS] ALIGN32 = {
+ALIGN32 static const BN_ULONG def_yG[P256_LIMBS] = {
0x02df32e52139f0a0, 0xd0a9877cc62a4740,
0x59bdcee36b692153, 0xbc3736a2f4f6779c,
};
#endif

/* p and order for SM2 according to GB/T 32918.5-2017 */
-static const BN_ULONG def_p[P256_LIMBS] ALIGN32 = {
+ALIGN32 static const BN_ULONG def_p[P256_LIMBS] = {
0xffffffffffffffff, 0xffffffff00000000,
0xffffffffffffffff, 0xfffffffeffffffff
};
-static const BN_ULONG def_ord[P256_LIMBS] ALIGN32 = {
+ALIGN32 static const BN_ULONG def_ord[P256_LIMBS] = {
0x53bbf40939d54123, 0x7203df6b21c6052b,
0xffffffffffffffff, 0xfffffffeffffffff
};

-static const BN_ULONG ONE[P256_LIMBS] ALIGN32 = {1, 0, 0, 0};
+ALIGN32 static const BN_ULONG ONE[P256_LIMBS] = {1, 0, 0, 0};

/* Functions implemented in assembly */
/*
@@ -139,10 +139,10 @@ static ossl_inline int is_greater(const BN_ULONG *a, const BN_ULONG *b)
/* Binary algorithm for inversion in Fp */
#define BN_MOD_INV(out, in, mod_div, mod_sub, mod) \
do { \
- BN_ULONG u[4] ALIGN32; \
- BN_ULONG v[4] ALIGN32; \
- BN_ULONG x1[4] ALIGN32 = {1, 0, 0, 0}; \
- BN_ULONG x2[4] ALIGN32 = {0}; \
+ ALIGN32 BN_ULONG u[4] ; \
+ ALIGN32 BN_ULONG v[4] ; \
+ ALIGN32 BN_ULONG x1[4] = {1, 0, 0, 0}; \
+ ALIGN32 BN_ULONG x2[4] = {0}; \
\
if (is_zeros(in)) \
return; \
@@ -188,9 +188,9 @@ static ossl_inline void ecp_sm2p256_mod_ord_inverse(BN_ULONG* out,
static void ecp_sm2p256_point_double(P256_POINT *R, const P256_POINT *P)
{
unsigned int i;
- BN_ULONG tmp0[P256_LIMBS] ALIGN32;
- BN_ULONG tmp1[P256_LIMBS] ALIGN32;
- BN_ULONG tmp2[P256_LIMBS] ALIGN32;
+ ALIGN32 BN_ULONG tmp0[P256_LIMBS] ;
+ ALIGN32 BN_ULONG tmp1[P256_LIMBS] ;
+ ALIGN32 BN_ULONG tmp2[P256_LIMBS] ;

/* zero-check P->Z */
if (is_zeros(P->Z)) {
@@ -225,10 +225,10 @@ static void ecp_sm2p256_point_add_affine(P256_POINT *R, const P256_POINT *P,
const P256_POINT_AFFINE *Q)
{
unsigned int i;
- BN_ULONG tmp0[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG tmp1[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG tmp2[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG tmp3[P256_LIMBS] ALIGN32 = {0};
+ ALIGN32 BN_ULONG tmp0[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG tmp1[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG tmp2[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG tmp3[P256_LIMBS] = {0};

/* zero-check P->Z */
if (is_zeros(P->Z)) {
@@ -288,9 +288,9 @@ static void ecp_sm2p256_point_add(P256_POINT *R, const P256_POINT *P,
const P256_POINT *Q)
{
unsigned int i;
- BN_ULONG tmp0[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG tmp1[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG tmp2[P256_LIMBS] ALIGN32 = {0};
+ ALIGN32 BN_ULONG tmp0[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG tmp1[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG tmp2[P256_LIMBS] = {0};

/* zero-check P | Q ->Z */
if (is_zeros(P->Z)) {
@@ -382,7 +382,7 @@ static void ecp_sm2p256_point_P_mul_by_scalar(P256_POINT *R, const BN_ULONG *k,
{
int i, init = 0;
unsigned int index, mask = 0x0f;
- P256_POINT precomputed[16] ALIGN64;
+ ALIGN64 P256_POINT precomputed[16] ;

memset(R, 0, sizeof(P256_POINT));

@@ -427,8 +427,8 @@ static void ecp_sm2p256_point_P_mul_by_scalar(P256_POINT *R, const BN_ULONG *k,
static void ecp_sm2p256_point_get_affine(P256_POINT_AFFINE *R,
const P256_POINT *P)
{
- BN_ULONG z_inv3[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG z_inv2[P256_LIMBS] ALIGN32 = {0};
+ ALIGN32 BN_ULONG z_inv3[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG z_inv2[P256_LIMBS] = {0};

if (is_one(P->Z)) {
memcpy(R->X, P->X, 32);
@@ -461,13 +461,13 @@ static int ecp_sm2p256_get_affine(const EC_GROUP *group,
const EC_POINT *point,
BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
{
- BN_ULONG z_inv2[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG z_inv3[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG x_aff[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG y_aff[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG point_x[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG point_y[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG point_z[P256_LIMBS] ALIGN32 = {0};
+ ALIGN32 BN_ULONG z_inv2[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG z_inv3[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG x_aff[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG y_aff[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG point_x[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG point_y[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG point_z[P256_LIMBS] = {0};

if (EC_POINT_is_at_infinity(group, point)) {
ECerr(ERR_LIB_EC, EC_R_POINT_AT_INFINITY);
@@ -510,7 +510,7 @@ static int ecp_sm2p256_windowed_mul(const EC_GROUP *group,
unsigned int i;
int ret = 0;
const BIGNUM **scalars = NULL;
- BN_ULONG k[P256_LIMBS] ALIGN32 = {0};
+ ALIGN32 BN_ULONG k[P256_LIMBS] = {0};
P256_POINT kP;
ALIGN32 union {
P256_POINT p;
@@ -572,7 +572,7 @@ static int ecp_sm2p256_points_mul(const EC_GROUP *group,
{
int ret = 0, p_is_infinity = 0;
const EC_POINT *generator = NULL;
- BN_ULONG k[P256_LIMBS] ALIGN32 = {0};
+ ALIGN32 BN_ULONG k[P256_LIMBS] = {0};
ALIGN32 union {
P256_POINT p;
P256_POINT_AFFINE a;
@@ -646,9 +646,9 @@ err:
static int ecp_sm2p256_field_mul(const EC_GROUP *group, BIGNUM *r,
const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
- BN_ULONG a_fe[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG b_fe[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG r_fe[P256_LIMBS] ALIGN32 = {0};
+ ALIGN32 BN_ULONG a_fe[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG b_fe[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG r_fe[P256_LIMBS] = {0};

if (a == NULL || b == NULL || r == NULL)
return 0;
@@ -670,8 +670,8 @@ static int ecp_sm2p256_field_mul(const EC_GROUP *group, BIGNUM *r,
static int ecp_sm2p256_field_sqr(const EC_GROUP *group, BIGNUM *r,
const BIGNUM *a, BN_CTX *ctx)
{
- BN_ULONG a_fe[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG r_fe[P256_LIMBS] ALIGN32 = {0};
+ ALIGN32 BN_ULONG a_fe[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG r_fe[P256_LIMBS] = {0};

if (a == NULL || r == NULL)
return 0;
@@ -693,8 +693,8 @@ static int ecp_sm2p256_inv_mod_ord(const EC_GROUP *group, BIGNUM *r,
const BIGNUM *x, BN_CTX *ctx)
{
int ret = 0;
- BN_ULONG t[P256_LIMBS] ALIGN32 = {0};
- BN_ULONG out[P256_LIMBS] ALIGN32 = {0};
+ ALIGN32 BN_ULONG t[P256_LIMBS] = {0};
+ ALIGN32 BN_ULONG out[P256_LIMBS] = {0};

if (bn_wexpand(r, P256_LIMBS) == NULL) {
ECerr(ERR_LIB_EC, ERR_R_BN_LIB);
32 changes: 32 additions & 0 deletions 3rdParty/vcpkg_ports/ports/openssl/install-pc-files.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function(install_pc_file name pc_data)
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
configure_file("${CMAKE_CURRENT_LIST_DIR}/openssl.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/${name}.pc" @ONLY)
endif()
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
configure_file("${CMAKE_CURRENT_LIST_DIR}/openssl.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/${name}.pc" @ONLY)
endif()
endfunction()

install_pc_file(openssl [[
Name: OpenSSL
Description: Secure Sockets Layer and cryptography libraries and tools
Requires: libssl libcrypto
]])

install_pc_file(libssl [[
Name: OpenSSL-libssl
Description: Secure Sockets Layer and cryptography libraries
Libs: -L"${libdir}" -llibssl
Requires: libcrypto
Cflags: -I"${includedir}"
]])

install_pc_file(libcrypto [[
Name: OpenSSL-libcrypto
Description: OpenSSL cryptography library
Libs: -L"${libdir}" -llibcrypto
Libs.private: -lcrypt32 -lws2_32 -ladvapi32 -luser32
Cflags: -I"${includedir}"
]])

vcpkg_fixup_pkgconfig()
6 changes: 6 additions & 0 deletions 3rdParty/vcpkg_ports/ports/openssl/openssl.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
prefix=${pcfiledir}/../..
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Version: @VERSION@
@pc_data@
85 changes: 85 additions & 0 deletions 3rdParty/vcpkg_ports/ports/openssl/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
if(EXISTS "${CURRENT_INSTALLED_DIR}/share/libressl/copyright"
OR EXISTS "${CURRENT_INSTALLED_DIR}/share/boringssl/copyright")
message(FATAL_ERROR "Can't build openssl if libressl/boringssl is installed. Please remove libressl/boringssl, and try install openssl again if you need it.")
endif()

if(VCPKG_TARGET_IS_EMSCRIPTEN)
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
endif()

if (NOT "${VERSION}" MATCHES [[^([0-9]+)\.([0-9]+)\.([0-9]+)$]])
message(FATAL_ERROR "Version regex did not match.")
endif()
set(OPENSSL_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(OPENSSL_VERSION_MINOR "${CMAKE_MATCH_2}")
set(OPENSSL_VERSION_FIX "${CMAKE_MATCH_3}")
configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake.in" "${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake" @ONLY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO openssl/openssl
REF "openssl-${VERSION}"
SHA512 aaf4f13b7b8020be37837f8084ab7aa3db64e6eb1ecabf04473ed5bd09bcabb8790f0dc1f7604febbbf974702b1fbe41795a7b575e7f88b07cbe094493926a6b
PATCHES
asm-comments.patch
declspec-align.patch
qt-msvc.patch
script-prefix.patch
windows/install-layout.patch
windows/install-pdbs.patch
unix/android-cc.patch
unix/move-openssldir.patch
unix/no-empty-dirs.patch
unix/no-static-libs-for-shared.patch
unix/disable-quicserver.patch
)

vcpkg_list(SET CONFIGURE_OPTIONS
enable-static-engine
enable-capieng
no-tests
no-docs
)

set(INSTALL_FIPS "")
if("fips" IN_LIST FEATURES)
vcpkg_list(APPEND INSTALL_FIPS install_fips)
vcpkg_list(APPEND CONFIGURE_OPTIONS enable-fips)
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
vcpkg_list(APPEND CONFIGURE_OPTIONS shared)
else()
vcpkg_list(APPEND CONFIGURE_OPTIONS no-shared no-module)
endif()

if(NOT "tools" IN_LIST FEATURES)
vcpkg_list(APPEND CONFIGURE_OPTIONS no-apps)
endif()

if("weak-ssl-ciphers" IN_LIST FEATURES)
vcpkg_list(APPEND CONFIGURE_OPTIONS enable-weak-ssl-ciphers)
endif()

if("ssl3" IN_LIST FEATURES)
vcpkg_list(APPEND CONFIGURE_OPTIONS enable-ssl3)
vcpkg_list(APPEND CONFIGURE_OPTIONS enable-ssl3-method)
endif()

if(DEFINED OPENSSL_USE_NOPINSHARED)
vcpkg_list(APPEND CONFIGURE_OPTIONS no-pinshared)
endif()

if(OPENSSL_NO_AUTOLOAD_CONFIG)
vcpkg_list(APPEND CONFIGURE_OPTIONS no-autoload-config)
endif()

if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
include("${CMAKE_CURRENT_LIST_DIR}/windows/portfile.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/install-pc-files.cmake")
else()
include("${CMAKE_CURRENT_LIST_DIR}/unix/portfile.cmake")
endif()

file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.txt")
21 changes: 21 additions & 0 deletions 3rdParty/vcpkg_ports/ports/openssl/qt-msvc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/include/openssl/e_ostime.h b/include/openssl/e_ostime.h
index 8a7cc9880fa79..0e17487504992 100644
--- a/include/openssl/e_ostime.h
+++ b/include/openssl/e_ostime.h
@@ -22,7 +22,15 @@
*/

# if defined(OPENSSL_SYS_WINDOWS)
-# include <winsock2.h>
+# if !defined(_WINSOCKAPI_)
+ /*
+ * winsock2.h defines _WINSOCK2API_ and both winsock2.h and winsock.h define
+ * _WINSOCKAPI_. Both of these provide struct timeval. Don't include
+ * winsock2.h if either header has been included to avoid breakage with
+ * applications that prefer to use <winsock.h> over <winsock2.h>.
+ */
+# include <winsock2.h>
+# endif
# else
# include <sys/time.h>
# endif
22 changes: 22 additions & 0 deletions 3rdParty/vcpkg_ports/ports/openssl/script-prefix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/tools/c_rehash.in b/tools/c_rehash.in
index 343cdc1..e48038e 100644
--- a/tools/c_rehash.in
+++ b/tools/c_rehash.in
@@ -12,7 +12,7 @@
# and add symbolic links to their hash values.

my $dir = {- quotify1($config{openssldir}) -};
-my $prefix = {- quotify1($config{prefix}) -};
+use FindBin;

my $errorcount = 0;
my $openssl = $ENV{OPENSSL} || "openssl";
@@ -61,7 +61,7 @@ if (defined(&Cwd::getcwd)) {

# DOS/Win32 or Unix delimiter? Prefix our installdir, then search.
my $path_delim = ($pwd =~ /^[a-z]\:/i) ? ';' : ':';
-$ENV{PATH} = "$prefix/bin" . ($ENV{PATH} ? $path_delim . $ENV{PATH} : "");
+$ENV{PATH} = "$FindBin::Bin" . ($ENV{PATH} ? $path_delim . $ENV{PATH} : "");

if (! -x $openssl) {
my $found = 0;
20 changes: 20 additions & 0 deletions 3rdParty/vcpkg_ports/ports/openssl/unix/android-cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/Configurations/15-android.conf b/Configurations/15-android.conf
index 41ad922..d15e34c 100644
--- a/Configurations/15-android.conf
+++ b/Configurations/15-android.conf
@@ -102,6 +102,7 @@
my $cflags;
my $cppflags;

+if (0) {
# see if there is NDK clang on $PATH, "universal" or "standalone"
if (which("clang") =~ m|^$ndk/.*/prebuilt/([^/]+)/|) {
my $host=$1;
@@ -158,6 +159,7 @@
$sysroot =~ s|^$ndk/||;
$sysroot = " --sysroot=\$($ndk_var)/$sysroot";
}
+}
$android_ndk = {
cflags => $cflags . $sysroot,
cppflags => $cppflags,
Loading

0 comments on commit f86319a

Please sign in to comment.