学习内容:
一、根据其中把.pl文件变成.so文件流程如下:
1、CC=“gcc” /usr/bin/perl ./openssl/crypto/bn/asm/mips.pl 64 crypto/bn/bn-mips.S 把pl文件变为.S文件
2、gcc -I. -Icrypto/include -Iinclude -Icrypto -I… -I…/crypto/include -I…/include -I…/crypto -fPIC -pthread -mabi=64 -Wa,–noexecstack -Wall -DL_ENDIAN -Wa,–noexecstack -g -O2 -fdebug-prefix-map=/home/loongson/openssl/openssl-1.1.1d=. -fstack-protector-strong -Wformat -Werror=format-security -DOPENSSL_USE_NODELETE -DOPENSSL_PIC -DOPENSSL_BN_ASM_MONT -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DAES_ASM -DPOLY1305_ASM -DOPENSSLDIR=""/usr/lib/ssl"" -DENGINESDIR=""/usr/lib/mips64el-linux-gnuabi64/engines-1.1"" -DNDEBUG -Wdate-time -D_FORTIFY_SOURCE=2 -c -o crypto/bn/bn-mips.o crypto/bn/bn-mips.S
上面两个就会生成bn-mips.o文件了,我们本地测试可以直接根据这个.o文件自己手动生成.so文件,然后写测试程序进行手动测试。我采用如下的方法:
gcc -shared -fPIC bn-mips.o -o libbn-mips.so
lgcc test.c -o test -L. -lbn-mips
~/test$ ./test
输出:0
二、使用默认C语言的crypto的库:
cat test.c
#include <stdio.h>
#define BN_ULONG unsigned int
extern BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
extern BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
int main()
{
BN_ULONG bp = 12;
BN_ULONG d = 20;
int num = 10;
BN_ULONG tp[10] = {1,2,3,4,5,6,7,8,9,10};
BN_ULONG ap[10] = {1,2,3,4,5,6,7,8,9,10};
d = bn_mul_add_words(tp, ap, num, bp);
//d = bn_mul_words(tp,ap,num,bp);
printf("%d\r\n",d);
}
终端shell:
gcc test.c -o test -L. -lcrypto -lpthread -ldl
ls libcrypto.a
我从那个openssl中拷贝过来的静态库。
libcrypto.a
./test
0 //为什么结果是0呢?还是本来就应该是0