cryptopp使用Qt mingw编译,以及海思平台交叉编译

简介: cryptopp使用Qt mingw编译,以及海思平台交叉编译

编译工程生成,使用qmake生成qt工程文件(海思平台时,要用海思平台的qmake),将

TEMPLATE = app修改为:TEMPLATE = lib


添加如下:

win32:LIBS += -lws2_32  #windows下用的QMAKE_CXXFLAGS += -msse4 -maes -mpclmul -msha


在windows下,用mingw


windows下编译好之后,头文件放入到mingw的include里,如下路径:

D:\Qt\Qt5.12.6\5.12.6\mingw73_32\include


libcryptopp.a要放在如下目录里:

D:\Qt\Qt5.12.6\Tools\mingw730_32\lib


海思的库文件和头文件编译好之后,可以放入到编译器的安装目录下(我用的是静态库):

/opt/hisi-linux/x86-arm/arm-hisiv500-linux/target/usr

这个目录下的include和lib下面


windows下编译没有遇到问题,直接可以编译通过,下面都是海思编译器交叉编译的问题:


1.编译错误1

arm-hisiv500-linux-g++ -c -pipe -msse4 -maes -mpclmul -msha -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../../cryptopp800 -I. -I../../cryptopp800 -I/opt/qt5.12-arm/include -I/opt/qt5.12-arm/include/QtGui -I/opt/qt5.12-arm/include/QtCore -I. -I/opt/qt5.12-arm/mkspecs/linux-hisiv500-g++ -o 3way.o ../3way.cpp
arm-hisiv500-linux-g++: error: unrecognized command line option ‘-msse4’
arm-hisiv500-linux-g++: error: unrecognized command line option ‘-maes’
arm-hisiv500-linux-g++: error: unrecognized command line option ‘-mpclmul’
arm-hisiv500-linux-g++: error: unrecognized command line option ‘-msha’
Makefile:1303: recipe for target '3way.o' failed
make: *** [3way.o] Error 1


原因:

海思编译器可能不支持-msse4 -maes -mpclmul -msha编译选项;

去掉这几项即可编译


2.编译错误2

/opt/hisi-linux/x86-arm/arm-hisiv500-linux/lib/gcc/arm-hisiv500-linux-uclibcgnueabi/4.9.4/include/arm_neon.h:31:2: error: #error You must enable NEON instructions (e.g. -mfloat-abi=softfp -mfpu=neon) to use arm_neon.h
 #error You must enable NEON instructions (e.g. -mfloat-abi=softfp -mfpu=neon) to use arm_neon.h
  ^
../aria_simd.cpp:66:34: error: ‘uint32x4_t’ does not name a type
 inline void ARIA_GSRK_NEON(const uint32x4_t X, const uint32x4_t Y, byte RK[16])
                                  ^
../aria_simd.cpp:66:54: error: ‘uint32x4_t’ does not name a type
 inline void ARIA_GSRK_NEON(const uint32x4_t X, const uint32x4_t Y, byte RK[16])
                                                      ^
../aria_simd.cpp: In function ‘void CryptoPP::ARIA_UncheckedSetKey_Schedule_NEON(CryptoPP::byte*, CryptoPP::word32*, unsigned int)’:
../aria_simd.cpp:81:8: error: ‘uint32x4_t’ does not name a type
  const uint32x4_t w0 = vld1q_u32(ws+ 0);
        ^
../aria_simd.cpp:82:8: error: ‘uint32x4_t’ does not name a type
  const uint32x4_t w1 = vld1q_u32(ws+ 8);
        ^
../aria_simd.cpp:83:8: error: ‘uint32x4_t’ does not name a type
  const uint32x4_t w2 = vld1q_u32(ws+12);
        ^
../aria_simd.cpp:84:8: error: ‘uint32x4_t’ does not name a type
  const uint32x4_t w3 = vld1q_u32(ws+16);
        ^
../aria_simd.cpp:86:21: error: ‘w0’ was not declared in this scope
  ARIA_GSRK_NEON<19>(w0, w1, rk +   0);
                     ^
../aria_simd.cpp:86:25: error: ‘w1’ was not declared in this scope
  ARIA_GSRK_NEON<19>(w0, w1, rk +   0);
                         ^
../aria_simd.cpp:87:25: error: ‘w2’ was not declared in this scope
  ARIA_GSRK_NEON<19>(w1, w2, rk +  16);
                         ^
../aria_simd.cpp:88:25: error: ‘w3’ was not declared in this scope
  ARIA_GSRK_NEON<19>(w2, w3, rk +  32);
                         ^
../aria_simd.cpp: At global scope:
../aria_simd.cpp:79:59: warning: unused parameter ‘ws’ [-Wunused-parameter]
 void ARIA_UncheckedSetKey_Schedule_NEON(byte* rk, word32* ws, unsigned int keylen)
                                                           ^
../aria_simd.cpp: In function ‘void CryptoPP::ARIA_ProcessAndXorBlock_NEON(const byte*, CryptoPP::byte*, const byte*, CryptoPP::word32*)’:
../aria_simd.cpp:137:22: error: ‘vld1q_u8’ was not declared in this scope
     vld1q_u8(xorBlock),
                      ^
../aria_simd.cpp:140:31: error: ‘vrev32q_u8’ was not declared in this scope
      vrev32q_u8(vld1q_u8((rk))))));
                               ^
../aria_simd.cpp:140:32: error: ‘veorq_u8’ was not declared in this scope
      vrev32q_u8(vld1q_u8((rk))))));
                                ^
../aria_simd.cpp:140:33: error: ‘veorq_u8’ was not declared in this scope
      vrev32q_u8(vld1q_u8((rk))))));
                                 ^
../aria_simd.cpp:140:33: error: redeclaration of ‘<typeprefixerror>veorq_u8’
../aria_simd.cpp:140:32: note: previous declaration ‘<typeprefixerror>veorq_u8’
      vrev32q_u8(vld1q_u8((rk))))));
                                ^
../aria_simd.cpp:140:34: error: ‘vst1q_u8’ was not declared in this scope
      vrev32q_u8(vld1q_u8((rk))))));
                                  ^
../aria_simd.cpp:146:22: error: ‘vld1q_u8’ was not declared in this scope
     vld1q_u8(outBlock),
                      ^
../aria_simd.cpp:147:28: error: ‘vrev32q_u8’ was not declared in this scope
     vrev32q_u8(vld1q_u8(rk))));
                            ^
../aria_simd.cpp:147:29: error: ‘veorq_u8’ was not declared in this scope
     vrev32q_u8(vld1q_u8(rk))));
                             ^
../aria_simd.cpp:147:30: error: ‘vst1q_u8’ was not declared in this scope
     vrev32q_u8(vld1q_u8(rk))));
                              ^
Makefile:1378: recipe for target 'aria_simd.o' failed
make: *** [aria_simd.o] Error 1

原因:

Makefile中的加上-mfloat-abi=softfp -mfpu=neon编译选项:

CXXFLAGS      = -pipe  -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC $(DEFINES) -mfloat-abi=softfp -mfpu=neon


3.问题3,这个是编译测试代码时的问题:

arm-hisiv500-linux-g++ -Wl,-O1 -Wl,-rpath,/opt/qt5.12-arm/lib -o ../bin/CerealApp temp/obj/harddriver.o temp/obj/main.o temp/obj/registerhandle.o temp/obj/moc_registerhandle.o   -lcryptopp /opt/qt5.12-arm/lib/libQt5Charts.so /opt/qt5.12-arm/lib/libQt5Widgets.so /opt/qt5.12-arm/lib/libQt5Gui.so /opt/qt5.12-arm/lib/libQt5Network.so /opt/qt5.12-arm/lib/libQt5Sql.so /opt/qt5.12-arm/lib/libQt5SerialPort.so /opt/qt5.12-arm/lib/libQt5Core.so -lpthread   
/opt/hisi-linux/x86-arm/arm-hisiv500-linux/bin/../target/usr/lib/libcryptopp.a(rijndael.o):在函数‘CryptoPP::CRYPTOGAMS_set_encrypt_key(unsigned char const*, int, unsigned int*)’中:
rijndael.cpp:(.text+0x300):对‘AES_set_encrypt_key’未定义的引用
/opt/hisi-linux/x86-arm/arm-hisiv500-linux/bin/../target/usr/lib/libcryptopp.a(rijndael.o):在函数‘CryptoPP::CRYPTOGAMS_set_decrypt_key(unsigned char const*, int, unsigned int*)’中:
rijndael.cpp:(.text+0x304):对‘AES_set_decrypt_key’未定义的引用
/opt/hisi-linux/x86-arm/arm-hisiv500-linux/bin/../target/usr/lib/libcryptopp.a(rijndael.o):在函数‘CryptoPP::CRYPTOGAMS_encrypt(unsigned char const*, unsigned char const*, unsigned char*, unsigned int const*)’中:
rijndael.cpp:(.text+0x31c):对‘AES_encrypt’未定义的引用
/opt/hisi-linux/x86-arm/arm-hisiv500-linux/bin/../target/usr/lib/libcryptopp.a(rijndael.o):在函数‘CryptoPP::CRYPTOGAMS_decrypt(unsigned char const*, unsigned char const*, unsigned char*, unsigned int const*)’中:
rijndael.cpp:(.text+0xadc):对‘AES_decrypt’未定义的引用
collect2: error: ld returned 1 exit status
Makefile:206: recipe for target '../bin/CerealApp' failed
make: *** [../bin/CerealApp] Error 1

问题原因是:

aes_armv4.S文件没有编译,在使用qmake生成工程文件时,该文件没有被加进去,

只需要在工程文件里的添加到source,然后重新执行qmake生成Makefile,再次编译没有问题了。

 

使用方法,核心代码:

   //------------------------
    // 生成RSA密钥对
    //------------------------
    void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed){
        RandomPool randPool;
        randPool.IncorporateEntropy((unsigned char *)seed, strlen(seed));
 
        RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
        HexEncoder privFile(new FileSink(privFilename));
        priv.AccessMaterial().Save(privFile);
        privFile.MessageEnd();
 
        RSAES_OAEP_SHA_Encryptor pub(priv);
        HexEncoder pubFile(new FileSink(pubFilename));
        pub.AccessMaterial().Save(pubFile);
        pubFile.MessageEnd();
    }
 
    //------------------------
    // RSA加密
    //------------------------
    string RSAEncryptString(const char *pubFilename, const char *seed, const char *message){
 
        FileSource pubFile(pubFilename, true, new HexDecoder);
        RSAES_OAEP_SHA_Encryptor pub(pubFile);
 
        RandomPool randPool;
        randPool.IncorporateEntropy((unsigned char *)seed, strlen(seed));
 
        std::string result;
        StringSource(message, true, new PK_EncryptorFilter(randPool, pub, new HexEncoder(new StringSink(result))));
        return result;
    }
 
    //------------------------
    // RSA解密
    //------------------------
    string RSADecryptString(const char *privFilename, const char *ciphertext){
        FileSource privFile(privFilename, true, new HexDecoder);
        RSAES_OAEP_SHA_Decryptor priv(privFile);
 
        std::string result;
        try{
            StringSource(ciphertext, true,
                         new HexDecoder(new PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result))));
        }
        catch(const Exception &e)
        {
            std::cout << "\nException caught: " << e.what() << std::endl;
            return "";
        }
        catch(const std::exception &e)
        {
            std::cout << "\nstd::exception caught: " << e.what() << std::endl;
            return "";
        }
//        std::cout << "result: " << result<< std::endl;
 
        return result;
    }
目录
相关文章
|
4月前
|
编译器 Linux C语言
QT编译安装QtMqtt子模块,WIN平台
QT编译安装QtMqtt子模块,WIN平台
|
2月前
|
Oracle 关系型数据库 Linux
讲解linux下的Qt如何编译oracle的驱动库libqsqloci.so
通过这一连串的步骤,可以专业且有效地在Linux下为Qt编译Oracle驱动库 `libqsqloci.so`,使得Qt应用能够通过OCI与Oracle数据库进行交互。这些步骤适用于具备一定Linux和Qt经验的开发者,并且能够为需要使用Qt开发数据库应用的专业人士提供指导。
60 1
讲解linux下的Qt如何编译oracle的驱动库libqsqloci.so
|
4月前
|
自然语言处理 编译器 程序员
【Qt底层之 元对象的编译】Qt 元对象系统及其编译流程解析
【Qt底层之 元对象的编译】Qt 元对象系统及其编译流程解析
163 4
|
4月前
|
存储
Qt编译出现cc1plus.exe: out of memory allocating 65536 bytes问题
Qt编译出现cc1plus.exe: out of memory allocating 65536 bytes问题
204 0
|
4月前
|
Linux 编译器 C语言
QT编译安装QtMqtt子模块,Linux平台
QT编译安装QtMqtt子模块,Linux平台
|
4月前
|
编译器
正点原子IMX6ULL-安装交叉编译器、编译tslib触摸屏库、编译arm环境qt源代码
正点原子IMX6ULL-安装交叉编译器、编译tslib触摸屏库、编译arm环境qt源代码
127 0
|
2月前
|
数据安全/隐私保护 C++ 计算机视觉
Qt(C++)开发一款图片防盗用水印制作小工具
文本水印是一种常用的防盗用手段,可以将文本信息嵌入到图片、视频等文件中,用于识别和证明文件的版权归属。在数字化和网络化的时代,大量的原创作品容易被不法分子盗用或侵犯版权,因此加入文本水印成为了保护原创作品和维护知识产权的必要手段。 通常情况下,文本水印可以包含版权声明、制作者姓名、日期、网址等信息,以帮助识别文件的来源和版权归属。同时,为了增强防盗用效果,文本水印通常会采用字体、颜色、角度等多种组合方式,使得水印难以被删除或篡改,有效地降低了盗用意愿和风险。 开发人员可以使用图像处理技术和编程语言实现文本水印的功能,例如使用Qt的QPainter类进行文本绘制操作,将文本信息嵌入到图片中,
116 1
Qt(C++)开发一款图片防盗用水印制作小工具
|
16天前
|
监控 C++ 容器
【qt】MDI多文档界面开发
【qt】MDI多文档界面开发
30 0
|
3天前
|
C++
C++ Qt开发:QUdpSocket网络通信组件
QUdpSocket是Qt网络编程中一个非常有用的组件,它提供了在UDP协议下进行数据发送和接收的能力。通过简单的方法和信号,可以轻松实现基于UDP的网络通信。不过,需要注意的是,UDP协议本身不保证数据的可靠传输,因此在使用QUdpSocket时,可能需要在应用层实现一些机制来保证数据的完整性和顺序,或者选择在适用的场景下使用UDP协议。
12 2
|
13天前
Qt开发网络嗅探器02
Qt开发网络嗅探器02