国密起步5:GmSSL3交叉编译arm64

初级代码游戏的专栏介绍与文章目录-CSDN博客

我的github:codetoys,所有代码都将会位于ctfc库中。已经放入库中我会指出在库中的位置。

这些代码大部分以Linux为目标但部分代码是纯C++的,可以在任何平台上使用。


        之前已经建立好了交叉编译环境,并且已经完成本地编译GmSSL。这里仅仅是交叉编译GmSSL。

一、源码

        官网下载最近版,应该是3.X,上传到交叉编译环境(Ubuntu 18)。

二、启动交叉编译环境

        我的命令是这个:

source environment-setup-aarch64-unisoc-linux

三、cmake

        因为之前已经本地编译过GmSSL,所以cmake已经可用。无需cmake的交叉编译版本,直接cmake即可:

mkdir build
cd build
cmake ..

        输出如下:

user@vm-ubuntu:~/arm64/GmSSL/build$ cmake ..
-- The C compiler identification is GNU 7.2.1
-- Check for working C compiler: /opt/unisoc-initgc/udx710-module+unisoc-initgc-1.0+20201024+userdebug+native/sysroots/x86_64-unisocsdk-linux/usr/bin/aarch64-unisoc-linux/aarch64-unisoc-linux-gcc
-- Check for working C compiler: /opt/unisoc-initgc/udx710-module+unisoc-initgc-1.0+20201024+userdebug+native/sysroots/x86_64-unisocsdk-linux/usr/bin/aarch64-unisoc-linux/aarch64-unisoc-linux-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- ENABLE_ASM_UNDERSCORE_PREFIX is ON
-- ENABLE_SM4_ECB is ON
-- ENABLE_SM4_OFB is ON
-- ENABLE_SM4_CFB is ON
-- ENABLE_SM4_CCM is ON
-- ENABLE_SM4_XTS is ON
-- ENABLE_SM3_XMSS is ON
-- ENABLE_SHA1 is ON
-- ENABLE_SHA2 is ON
-- ENABLE_AES is ON
-- ENABLE_CHACHA20 is ON
-- ENABLE_SM4_CBC_MAC is ON
-- Looking for getentropy
-- Looking for getentropy - found
-- have getentropy
-- ENABLE_SDF is ON
-- Detected Linux, configuring /etc/ld.so.conf.d/gmssl.conf
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/arm64/GmSSL/build

        注意C编译器已经是交叉编译版本。

四、make

        执行make会顺利完成:

[ 98%] Building C object CMakeFiles/sm2_keytest.dir/tests/sm2_keytest.c.o
[ 98%] Linking C executable bin/sm2_keytest
[ 98%] Built target sm2_keytest
Scanning dependencies of target x509_crltest
[ 99%] Building C object CMakeFiles/x509_crltest.dir/tests/x509_crltest.c.o
[ 99%] Linking C executable bin/x509_crltest
[ 99%] Built target x509_crltest
Scanning dependencies of target tls13test
[ 99%] Building C object CMakeFiles/tls13test.dir/tests/tls13test.c.o
[100%] Linking C executable bin/tls13test
[100%] Built target tls13test

五、不要install,检查输出

        不需要执行install,需要的东西都在bin下面:

user@vm-ubuntu:~/arm64/GmSSL/build/bin$ ls -l
total 5752
-rwxrwxr-x 1 user user   36000 Aug 28 08:48 aestest
-rwxrwxr-x 1 user user   64376 Aug 28 08:48 asn1test
-rwxrwxr-x 1 user user   27488 Aug 28 08:48 base64test
-rwxrwxr-x 1 user user   20248 Aug 28 08:48 block_ciphertest
-rwxrwxr-x 1 user user   21592 Aug 28 08:48 chacha20test
-rwxrwxr-x 1 user user   68048 Aug 28 08:48 cmstest
-rwxrwxr-x 1 user user   22896 Aug 28 08:48 digesttest
-rwxrwxr-x 1 user user   32840 Aug 28 08:48 ectest
-rwxrwxr-x 1 user user   29304 Aug 28 08:48 gf128test
-rwxrwxr-x 1 user user   27576 Aug 28 08:48 ghashtest
-rwxrwxr-x 1 user user  884984 Aug 28 08:48 gmssl
-rwxrwxr-x 1 user user   20216 Aug 28 08:48 hextest
-rwxrwxr-x 1 user user   36112 Aug 28 08:48 hkdftest
-rwxrwxr-x 1 user user   29416 Aug 28 08:48 hmactest
lrwxrwxrwx 1 user user      13 Aug 28 08:48 libgmssl.so -> libgmssl.so.3
lrwxrwxrwx 1 user user      15 Aug 28 08:48 libgmssl.so.3 -> libgmssl.so.3.1
-rwxrwxr-x 1 user user 3242152 Aug 28 08:48 libgmssl.so.3.1
-rwxrwxr-x 1 user user   31704 Aug 28 08:48 pemtest
-rwxrwxr-x 1 user user   28304 Aug 28 08:48 pkcs8test
-rwxrwxr-x 1 user user   22656 Aug 28 08:48 sha1test
-rwxrwxr-x 1 user user   27096 Aug 28 08:48 sha224test
-rwxrwxr-x 1 user user   27096 Aug 28 08:48 sha256test
-rwxrwxr-x 1 user user   26880 Aug 28 08:48 sha384test
-rwxrwxr-x 1 user user   26904 Aug 28 08:48 sha512test
-rwxrwxr-x 1 user user   32752 Aug 28 08:48 sm2_enctest
-rwxrwxr-x 1 user user   31736 Aug 28 08:48 sm2_keytest
-rwxrwxr-x 1 user user   39144 Aug 28 08:48 sm2_signtest
-rwxrwxr-x 1 user user   59664 Aug 28 08:48 sm2_z256test
-rwxrwxr-x 1 user user   31496 Aug 28 08:48 sm3test
-rwxrwxr-x 1 user user   23640 Aug 28 08:48 sm4_cbc_mactest
-rwxrwxr-x 1 user user   38448 Aug 28 08:48 sm4_cbctest
-rwxrwxr-x 1 user user   30888 Aug 28 08:48 sm4_ccmtest
-rwxrwxr-x 1 user user   33312 Aug 28 08:48 sm4_cfbtest
-rwxrwxr-x 1 user user   40280 Aug 28 08:48 sm4_ctrtest
-rwxrwxr-x 1 user user   30408 Aug 28 08:48 sm4_ecbtest
-rwxrwxr-x 1 user user   35848 Aug 28 08:48 sm4_gcmtest
-rwxrwxr-x 1 user user   32192 Aug 28 08:48 sm4_ofbtest
-rwxrwxr-x 1 user user   36576 Aug 28 08:48 sm4_sm3_hmactest
-rwxrwxr-x 1 user user   28352 Aug 28 08:48 sm4test
-rwxrwxr-x 1 user user   29880 Aug 28 08:48 sm4_xtstest
-rwxrwxr-x 1 user user   88160 Aug 28 08:48 sm9test
-rwxrwxr-x 1 user user   28672 Aug 28 08:48 tls13test
-rwxrwxr-x 1 user user   44888 Aug 28 08:48 tlstest
-rwxrwxr-x 1 user user   31744 Aug 28 08:48 x509_algtest
-rwxrwxr-x 1 user user   48432 Aug 28 08:48 x509_crltest
-rwxrwxr-x 1 user user   70288 Aug 28 08:48 x509_exttest
-rwxrwxr-x 1 user user   41032 Aug 28 08:48 x509_oidtest
-rwxrwxr-x 1 user user   34640 Aug 28 08:48 x509_reqtest
-rwxrwxr-x 1 user user   28536 Aug 28 08:48 x509_strtest
-rwxrwxr-x 1 user user   48800 Aug 28 08:48 x509test
-rwxrwxr-x 1 user user   38520 Aug 28 08:48 zuctest

        可以试一下make test,不出意外,全部都是失败(因为格式不对根本无法运行)。

        执行file *看看文件格式:

user@vm-ubuntu:~/arm64/GmSSL/build/bin$ file *
aestest:          ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=fc96f4a8d6a284c1687f7d1806819f357ac93ca6, with debug_info, not stripped
asn1test:         ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=4bedc805b44a1124a70aa5e13bb8b3b6c295b643, with debug_info, not stripped
base64test:       ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=5c45f3d32e8c4b52d521f6ee091af042fd457fdf, with debug_info, not stripped
block_ciphertest: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=7a4852bc99b528a82a3eeb12b19b34e88cd121d0, with debug_info, not stripped
chacha20test:     ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=2d2994ee9497c7b2ab3208c7329861946cded845, with debug_info, not stripped
cmstest:          ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=75c77ade163dc0a4ec66b0e0b0771e66caa18eb0, with debug_info, not stripped
digesttest:       ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=46f9df696214b9cfd41e73027e7031d8aa56c224, with debug_info, not stripped
ectest:           ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=b223db93d1e6e8244e5ad05c8ab2b009a2c6a0eb, with debug_info, not stripped
gf128test:        ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=d059d62e624e2cc84dad1b47dccb1dcf5417683d, with debug_info, not stripped
ghashtest:        ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=fe079002472a4d4b2cb263708c77fe04620aa5a9, with debug_info, not stripped
gmssl:            ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=8ca8ef42860cb011088f39c3cfada2c957b785da, with debug_info, not stripped
hextest:          ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=571cbe3dd7353c7837c30dd90300d5b2d67f418a, with debug_info, not stripped
hkdftest:         ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=618fdf94e341921df437059a1babdd9f58d32c23, with debug_info, not stripped
hmactest:         ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=f16abfbab4fd99db3b5dacf514fd85d1b44086d4, with debug_info, not stripped
libgmssl.so:      symbolic link to libgmssl.so.3
libgmssl.so.3:    symbolic link to libgmssl.so.3.1
libgmssl.so.3.1:  ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=60e001e423da7002ea1de01c8df5c87315eae5f6, with debug_info, not stripped
pemtest:          ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=60e510012b03adc49449e7f5466fc545aa995b2c, with debug_info, not stripped
pkcs8test:        ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=ca6fcbfeb223678dec67ce06de7906fd52aca286, with debug_info, not stripped
sha1test:         ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=cef1160c01b54f196fc311016921af4bef62a545, with debug_info, not stripped
sha224test:       ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=5a369baac9ac5193ec8b0cc8843eca113d44d3c0, with debug_info, not stripped
sha256test:       ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=f1136d4989677f6717bab82e502d1f47b94be0df, with debug_info, not stripped
sha384test:       ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=e7ef0af8438708f94b87c592170e312c3d241e35, with debug_info, not stripped
sha512test:       ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=f68116f0fab592ddb8615830189f71709a20267b, with debug_info, not stripped
sm2_enctest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=47204681d48a02b37943defbeec70202e3355fb2, with debug_info, not stripped
sm2_keytest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=edf2fca1056da0ac2c1a0907063c5d4542d33cf4, with debug_info, not stripped
sm2_signtest:     ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=478900180a755cee6266fa621428e479e09038c4, with debug_info, not stripped
sm2_z256test:     ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=bb39b7143452049f919aad51b3a75cc748cc63f8, with debug_info, not stripped
sm3test:          ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=82868688521ed73e7dfb3a2635271a3293faa146, with debug_info, not stripped
sm4_cbc_mactest:  ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=b982deddbb02419e91ccee658ac1a712ae9f3735, with debug_info, not stripped
sm4_cbctest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=1d207d6517326dfe70c0780a1590c721f9c25e40, with debug_info, not stripped
sm4_ccmtest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=9e62f7933a0e0bc38029dffd32192120855a410a, with debug_info, not stripped
sm4_cfbtest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=422b0f6479e9db053797da998039acd82b4dcbba, with debug_info, not stripped
sm4_ctrtest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=47258c78e5b6d006ad9f99b915a5ce3630320cdc, with debug_info, not stripped
sm4_ecbtest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=e0e1a64470cc5ec71d8be6d32301bbf17634bc2f, with debug_info, not stripped
sm4_gcmtest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=c9bfb792e62aa8efe8909c446accaeb145ac679f, with debug_info, not stripped
sm4_ofbtest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=4f082949d2222467fe6bf51e2d493362d9030ee8, with debug_info, not stripped
sm4_sm3_hmactest: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=ba6498dcf32bf4f504be757459fe07f841c955d5, with debug_info, not stripped
sm4test:          ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=d5f74db24752de276fe16c1d1508e07db2bb0144, with debug_info, not stripped
sm4_xtstest:      ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=6ec5091b09997748c12586dcacfc511b5b9e5b06, with debug_info, not stripped
sm9test:          ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=3a00608a2ebca841fe605e465c57eee37acb957c, with debug_info, not stripped
tls13test:        ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=9badbc59adb81fa4973bf34b5021c19c0970bd08, with debug_info, not stripped
tlstest:          ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=1967e4d7733c9f48256d068d87227acc1983021d, with debug_info, not stripped
x509_algtest:     ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=9964dc2e89bce1e0d021a31b0fee4f1452a62241, with debug_info, not stripped
x509_crltest:     ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=b135facea3168265a56a151582aaadb1044e4b90, with debug_info, not stripped
x509_exttest:     ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=aeae1b9c7970f8a8245f0839a43d9b15162dba08, with debug_info, not stripped
x509_oidtest:     ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=fe75932592d8bed6bba9c02d76e6448f56d9b430, with debug_info, not stripped
x509_reqtest:     ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=1506319bcb9b66f41d452afe984fbc59385df110, with debug_info, not stripped
x509_strtest:     ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=5b6c8fb5c3f3b377a43cba2be6c8d56d0685bc4b, with debug_info, not stripped
x509test:         ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=cf78223b886a1be0680161613f29e7deecdd95a0, with debug_info, not stripped
zuctest:          ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=c8647088245ddfcccfb15ab3b4a1319a04aad076, with debug_info, not stripped

        全部都是ARM aarch64,说明交叉编译正确。

六、设备测试

        输出文件虽然多,但是其实我们只需要gmssl和so文件,我先用ftp下载到本地,三个so变成了相同的文件(两个链接被替换为了链接目标):

国密起步5:GmSSL3交叉编译arm64_第1张图片

        上传到设备测试,发现其实只要有libgmssl.so.3一个就可以了:

root# ./gmssl
./gmssl: error while loading shared libraries: libgmssl.so.3: cannot open shared object file: No such file or directory
root# ./gmssl
Usage: ./gmssl command [options]
command -help

Commands:
  help              Print this help message
  version           Print version
  rand              Generate random bytes
  sm2keygen         Generate SM2 keypair
  sm2sign           Generate SM2 signature
  sm2verify         Verify SM2 signature
。。。。。。

(这里是文档结束)

你可能感兴趣的:(国密,工业,国密,GmSSL,Arm,交叉编译,aarch64)