From 6d85fbf3d90614cda6ccb87a12bbaebd9b4e59b7 Mon Sep 17 00:00:00 2001 From: Andrey Matoshko Date: Thu, 24 Jun 2021 13:41:15 +0300 Subject: [PATCH 1/6] Change privateKeyNum checking --- Sources/BitcoinKitPrivate/BitcoinKit.Private.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/BitcoinKitPrivate/BitcoinKit.Private.swift b/Sources/BitcoinKitPrivate/BitcoinKit.Private.swift index 83006ab2..3bd2c0dd 100644 --- a/Sources/BitcoinKitPrivate/BitcoinKit.Private.swift +++ b/Sources/BitcoinKitPrivate/BitcoinKit.Private.swift @@ -224,13 +224,13 @@ public class _HDKey { } BN_mod_add(privateKeyNum, privateKeyNum, factor, curveOrder, ctx) - // Check for invalid derivation. - //if BN_is_zero(privateKeyNum) { - // return nil - //} - if privateKeyNum.pointee.top == 0 { // BN_is_zero +// Check for invalid derivation. + if (BN_is_zero(privateKeyNum) != 0) { return nil } +// if privateKeyNum.pointee.top == 0 { // BN_is_zero +// return nil +// } let numBytes = ((BN_num_bits(privateKeyNum)+7)/8) // BN_num_bytes result = Data(count: Int(numBytes)) result.withUnsafeMutableBytes { (ptr: UnsafeMutableRawBufferPointer) in From 6b7d95bf1389f616d2a5236eacfd6fc995bf90e6 Mon Sep 17 00:00:00 2001 From: Andrey Matoshko Date: Thu, 24 Jun 2021 15:17:00 +0300 Subject: [PATCH 2/6] Update build_crypto.sh --- setup/build_crypto.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/build_crypto.sh b/setup/build_crypto.sh index 8fcc1734..6feaaf85 100644 --- a/setup/build_crypto.sh +++ b/setup/build_crypto.sh @@ -9,7 +9,7 @@ trap "{ cd - ; rm -rf $TDIR; exit 255; }" SIGINT cd $TDIR -curl -O https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz +curl -O https://www.openssl.org/source/old/1.0.2/openssl-$OPENSSL_VERSION.tar.gz tar zxf openssl-$OPENSSL_VERSION.tar.gz cd openssl-$OPENSSL_VERSION From c0c92461dd4b6c21127b205179e542628286d611 Mon Sep 17 00:00:00 2001 From: Andrey Matoshko Date: Thu, 24 Jun 2021 15:38:03 +0300 Subject: [PATCH 3/6] Increase Openssl version --- setup/build_crypto.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/build_crypto.sh b/setup/build_crypto.sh index 6feaaf85..31a97d93 100644 --- a/setup/build_crypto.sh +++ b/setup/build_crypto.sh @@ -9,7 +9,7 @@ trap "{ cd - ; rm -rf $TDIR; exit 255; }" SIGINT cd $TDIR -curl -O https://www.openssl.org/source/old/1.0.2/openssl-$OPENSSL_VERSION.tar.gz +curl -O https://www.openssl.org/source/old/3.0/openssl-$OPENSSL_VERSION.tar.gz tar zxf openssl-$OPENSSL_VERSION.tar.gz cd openssl-$OPENSSL_VERSION From 6206cbcbc2785b1eb9ad7b07bb3fd4fa124f7776 Mon Sep 17 00:00:00 2001 From: Andrey Matoshko Date: Thu, 24 Jun 2021 15:47:22 +0300 Subject: [PATCH 4/6] Decrease version & remove unnessesary archs --- setup/build_crypto.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/setup/build_crypto.sh b/setup/build_crypto.sh index 31a97d93..19e34d3e 100644 --- a/setup/build_crypto.sh +++ b/setup/build_crypto.sh @@ -9,7 +9,7 @@ trap "{ cd - ; rm -rf $TDIR; exit 255; }" SIGINT cd $TDIR -curl -O https://www.openssl.org/source/old/3.0/openssl-$OPENSSL_VERSION.tar.gz +curl -O https://www.openssl.org/source/old/1.0.2/openssl-$OPENSSL_VERSION.tar.gz tar zxf openssl-$OPENSSL_VERSION.tar.gz cd openssl-$OPENSSL_VERSION @@ -17,16 +17,12 @@ cd openssl-$OPENSSL_VERSION sh "$SCRIPT_DIR/build_crypto_impl.sh" iphoneos arm64 sh "$SCRIPT_DIR/build_crypto_impl.sh" iphoneos armv7s sh "$SCRIPT_DIR/build_crypto_impl.sh" iphoneos armv7 -sh "$SCRIPT_DIR/build_crypto_impl.sh" iphonesimulator x86_64 -sh "$SCRIPT_DIR/build_crypto_impl.sh" iphonesimulator i386 mkdir -p "$SCRIPT_DIR/../Libraries/openssl/lib" xcrun lipo -create .build/iphoneos/arm64/libcrypto.a \ .build/iphoneos/armv7s/libcrypto.a \ .build/iphoneos/armv7/libcrypto.a \ - .build/iphonesimulator/x86_64/libcrypto.a \ - .build/iphonesimulator/i386/libcrypto.a \ -o "$SCRIPT_DIR/../Libraries/openssl/lib/libcrypto.a" cp -rf $TDIR/openssl-$OPENSSL_VERSION/include "$SCRIPT_DIR/../Libraries/openssl/" From 6d3c8a58a8b9232035f818d287091ad8d98997c4 Mon Sep 17 00:00:00 2001 From: Andrey Matoshko Date: Thu, 24 Jun 2021 16:17:57 +0300 Subject: [PATCH 5/6] Remove i386 --- BitcoinKit.xcodeproj/project.pbxproj | 7 ++++--- setup/build_secp256k1.sh | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/BitcoinKit.xcodeproj/project.pbxproj b/BitcoinKit.xcodeproj/project.pbxproj index 92968933..41570fc7 100644 --- a/BitcoinKit.xcodeproj/project.pbxproj +++ b/BitcoinKit.xcodeproj/project.pbxproj @@ -1278,7 +1278,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\n pwd\n swiftlint autocorrect\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + shellScript = "if which swiftlint >/dev/null; then\n pwd\n swiftlint autocorrect\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; /* End PBXShellScriptBuildPhase section */ @@ -1615,7 +1615,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -1671,8 +1671,9 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; + ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; diff --git a/setup/build_secp256k1.sh b/setup/build_secp256k1.sh index 631dde0f..9dec35bd 100644 --- a/setup/build_secp256k1.sh +++ b/setup/build_secp256k1.sh @@ -19,7 +19,7 @@ TARGETDIR_SIMULATOR="$CURRENTPATH/.build/iphonesimulator" mkdir -p "$TARGETDIR_SIMULATOR" (cd src && ./autogen.sh) -(cd src && ./configure --host=x86_64-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch i386 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch i386 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" --prefix="$TARGETDIR_IPHONEOS" && make install) +(cd src && ./configure --host=x86_64-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" --prefix="$TARGETDIR_IPHONEOS" && make install) (cd src && ./configure --host=arm-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" --prefix="$TARGETDIR_SIMULATOR" && make install) cd - From 18a6821d3dddc361ba4fa7e7d757d9f7a700d0e1 Mon Sep 17 00:00:00 2001 From: Andrey Matoshko Date: Thu, 24 Jun 2021 20:49:36 +0300 Subject: [PATCH 6/6] Fix build_crypto.sh & Add Archs --- BitcoinKit.xcodeproj/project.pbxproj | 6 +++--- setup/build_crypto.sh | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/BitcoinKit.xcodeproj/project.pbxproj b/BitcoinKit.xcodeproj/project.pbxproj index 41570fc7..ceb75be8 100644 --- a/BitcoinKit.xcodeproj/project.pbxproj +++ b/BitcoinKit.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -1157,8 +1157,8 @@ isa = PBXNativeTarget; buildConfigurationList = 147494DB201F9A29006D1CF8 /* Build configuration list for PBXNativeTarget "BitcoinKit" */; buildPhases = ( - 292B636820E7BF7000F5040A /* SwiftLint */, 1482B628202954CC0098B612 /* Build Libraries */, + 292B636820E7BF7000F5040A /* SwiftLint */, 147494C2201F9A29006D1CF8 /* Sources */, 147494C3201F9A29006D1CF8 /* Frameworks */, 147494C4201F9A29006D1CF8 /* Headers */, @@ -1253,6 +1253,7 @@ /* Begin PBXShellScriptBuildPhase section */ 1482B628202954CC0098B612 /* Build Libraries */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -1264,7 +1265,6 @@ runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "if [ ! -d \"$SRCROOT/Libraries/secp256k1/lib\" ] || [ ! -d \"$SRCROOT/Libraries/openssl/lib\" ]; then\n env -i PATH=$PATH sh \"$SRCROOT/setup/build_libraries.sh\"\nfi\n"; - showEnvVarsInLog = 0; }; 292B636820E7BF7000F5040A /* SwiftLint */ = { isa = PBXShellScriptBuildPhase; diff --git a/setup/build_crypto.sh b/setup/build_crypto.sh index 19e34d3e..7934da01 100644 --- a/setup/build_crypto.sh +++ b/setup/build_crypto.sh @@ -1,7 +1,7 @@ #!/bin/sh set -ex -SCRIPT_DIR="`pwd`/`dirname $0`" +SCRIPT_DIR="`dirname $0`" OPENSSL_VERSION=1.0.2n TDIR=`mktemp -d` @@ -17,12 +17,18 @@ cd openssl-$OPENSSL_VERSION sh "$SCRIPT_DIR/build_crypto_impl.sh" iphoneos arm64 sh "$SCRIPT_DIR/build_crypto_impl.sh" iphoneos armv7s sh "$SCRIPT_DIR/build_crypto_impl.sh" iphoneos armv7 +sh "$SCRIPT_DIR/build_crypto_impl.sh" iphonesimulator i386 +sh "$SCRIPT_DIR/build_crypto_impl.sh" iphonesimulator x86_64 + + mkdir -p "$SCRIPT_DIR/../Libraries/openssl/lib" xcrun lipo -create .build/iphoneos/arm64/libcrypto.a \ .build/iphoneos/armv7s/libcrypto.a \ .build/iphoneos/armv7/libcrypto.a \ + .build/iphonesimulator/x86_64/libcrypto.a \ + .build/iphonesimulator/i386/libcrypto.a \ -o "$SCRIPT_DIR/../Libraries/openssl/lib/libcrypto.a" cp -rf $TDIR/openssl-$OPENSSL_VERSION/include "$SCRIPT_DIR/../Libraries/openssl/"