Peter DeWeese
Peter DeWeese

Reputation: 18333

Unknown cpu type when compiling OpenSSL FIPS Capable libraries for arm64 or arm7s

I can successfully (at least without warnings and with resulting .a files) compile for arm7, x86_64, and i386.

When I compile for arm64, I get Unknown cpu type 100000c, no adjustments made. When I compile for arm7s, I get Unknown cpu type 100000c, no adjustments made. The script for those two architectures, which is modified from and uses environment scripts from https://github.com/noloader/openssl-1.0.1i-ios is below including arm7, which works and arm7s and arm64, followed by a log tail for arm64. The scripts build non-fips libraries successfully before modification. incore_macho and fips canisters are pre-generated and referenced from this script. I created the fips canisters similarly by modifying instructions from the OpenSSL FIPS 2.0 User Guide iOS appendix, which is incredibly dated and does not work on its own. How can one compile a FIPS capable library for these two platforms?

Edit:

I see that libssl.a and libcrypto.a have actually been created and have the correct architectures, but incore_macho returns an identical Unknown cpu type error.

Update:

Using a copy of incore_macho that is updated for armv7 from @jww at https://github.com/noloader/incore_macho, it now compiles without error for arm7s, so I'm now under the assumption that core_macho may need to be updated for arm64. Can this be done?

sed -i "" 's|\"iphoneos-cross\"\,\"llvm-gcc\:-O3|\"iphoneos-cross\"\,\"clang\:-Os|g' Configure
sed -i "" 's/CC= cc/CC= clang/g' Makefile.org
sed -i "" 's/CFLAG= -O/CFLAG= -Os/g' Makefile.org
sed -i "" 's/MAKEDEPPROG=makedepend/MAKEDEPPROG=$(CC) -M/g' Makefile.org

export LANG=$OLD_LANG
export CC=clang
export IOS_INSTALLDIR="/usr/local/ssl/ios"
unset OPENSSLDIR

################################################################
# Third, build ARMv7
echo "****************************************"
THIS_ARCH=armv7
unset CROSS_ARCH

. ./setenv-ios-$THIS_ARCH.sh
export HOSTCC=/usr/bin/cc
export HOSTCFLAGS="-arch i386"
export FIPS_SIG="/tmp/incore_macho"

./config fips -no-ssl2 -no-ssl3 -no-asm -no-shared -no-hw -no-engine --with-fipsdir="/tmp/openssl fips-2.0.1-iOS-${THIS_ARCH}" --openssldir=$IOS_INSTALLDIR
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=7.1 !" "Makefile"
make clean 2>&1>/dev/null && make all
mkdir $THIS_ARCH
\cp ./libcrypto.a $THIS_ARCH/libcrypto.a
\cp ./libssl.a $THIS_ARCH/libssl.a

################################################################
# Fourth, build ARMv7s
echo "****************************************"
THIS_ARCH=armv7s
unset CROSS_ARCH

. ./setenv-ios-$THIS_ARCH.sh
export HOSTCC=/usr/bin/cc
export HOSTCFLAGS="-arch i386"
export FIPS_SIG="/tmp/incore_macho"

./config fips -no-ssl2 -no-ssl3 -no-asm -no-shared -no-hw -no-engine --with-fipsdir="/tmp/openssl-fips-2.0.1-iOS-${THIS_ARCH}" --openssldir=$IOS_INSTALLDIR
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=7.1 !" "Makefile"
make clean 2>&1>/dev/null && make all
mkdir $THIS_ARCH
\cp ./libcrypto.a $THIS_ARCH/libcrypto.a
\cp ./libssl.a $THIS_ARCH/libssl.a

################################################################
# Fifth, build ARM64
#echo "****************************************"
THIS_ARCH=arm64
unset CROSS_ARCH

. ./setenv-ios-$THIS_ARCH.sh
export HOSTCC=/usr/bin/cc
export HOSTCFLAGS="-arch i386"
export FIPS_SIG="/tmp/incore_macho"

./config fips -no-ssl2 -no-ssl3 -no-asm -no-shared -no-hw -no-engine --with-fipsdir="/tmp/openssl-fips-2.0.1-iOS-${THIS_ARCH}" --openssldir=$IOS_INSTALLDIR
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=7.1 !" "Makefile"
make clean 2>&1>/dev/null && make all
mkdir $THIS_ARCH
\cp ./libcrypto.a $THIS_ARCH/libcrypto.a
\cp ./libssl.a $THIS_ARCH/libssl.a

tail of output for arm64:

shlib_target=; if [ -n "" ]; then \
        shlib_target="darwin-shared"; \
    elif [ -n "libcrypto" ]; then \
      FIPSLD_CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"; CC=/tmp/openssl-fips-2.0.1-iOS-arm64/bin/fipsld; export CC FIPSLD_CC; \
    fi; \
    LIBRARIES="-L.. -lssl  -L.. -lcrypto" ; \
    make -f ../Makefile.shared -e \
        APPNAME=openssl OBJECTS="openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o ec.o ecparam.o x509.o genrsa.o gendsa.o genpkey.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o pkey.o pkeyparam.o pkeyutl.o spkac.o smime.o cms.o rand.o engine.o ocsp.o prime.o ts.o srp.o" \
        LIBDEPS="-Wl,-search_paths_first $LIBRARIES " \
        link_app.${shlib_target}
( :; LIBDEPS="${LIBDEPS:--Wl,-search_paths_first -L.. -lssl  -L.. -lcrypto }"; LDCMD="${LDCMD:-/tmp/openssl-fips-2.0.1-iOS-arm64/bin/fipsld}"; LDFLAGS="${LDFLAGS:--isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk -miphoneos-version-min=7.1  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -Os -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk -fomit-frame-pointer -fno-common -I/tmp/openssl-fips-2.0.1-iOS-arm64/include}"; LIBPATH=`for x in $LIBDEPS; do echo $x; done | sed -e 's/^ *-L//;t' -e d | uniq`; LIBPATH=`echo $LIBPATH | sed -e 's/ /:/g'`; LD_LIBRARY_PATH=$LIBPATH:$LD_LIBRARY_PATH ${LDCMD} ${LDFLAGS} -o ${APPNAME:=openssl} openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o ec.o ecparam.o x509.o genrsa.o gendsa.o genpkey.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o pkey.o pkeyparam.o pkeyutl.o spkac.o smime.o cms.o rand.o engine.o ocsp.o prime.o ts.o srp.o ${LIBDEPS} )
Unknown cpu type 100000c, no adjustments made

Upvotes: 3

Views: 1024

Answers (2)

techie
techie

Reputation: 31

It will work if you add this to cpu_adjustment[]

CPU_TYPE_ARM64,   CPU_SUBTYPE_ARM64_ALL,  12, 12 ,

For reference:

#define CPU_ARCH_ABI64  0x01000000      /* 64 bit ABI */

#define CPU_TYPE_ARM64          (CPU_TYPE_ARM | CPU_ARCH_ABI64)

/*
 *  ARM64 subtypes
 */
#define CPU_SUBTYPE_ARM64_ALL           ((cpu_subtype_t) 0)

Finding the adjustment was fun. ;-)

Upvotes: 3

Blaze
Blaze

Reputation: 1580

I've modified the CPU type before, so it's doable. You may also need to modify the CPU adjustment as well. You need to add an entry to cpu_adjustment[] in incore_macho.c and cputype

I think for arm64 it is CPU_SUBTYPE_ARM64_V8 I do not know the adjustment. Please let us know if you get this to work

Upvotes: 0

Related Questions