weidai11 / cryptopp

free C++ class library of cryptographic schemes
https://cryptopp.com
Other
4.83k stars 1.49k forks source link

MinGW cross-compilation does not work #1222

Closed jeandudey closed 1 year ago

jeandudey commented 1 year ago

Crypto++ Issue Report

I'm trying to build Crypto++ with make cryptopp.dll on a Windows host and it fails with the following errors:

x86_64-w64-mingw32-g++ -DNDEBUG -D_WIN32_WINNT=0x0501 -DCRYPTOPP_EXPORTS -g2 -O3 -pipe -c aria_simd.cpp -o aria_simd.export.o
In file included from aria_simd.cpp:14:
/gnu/store/dsy1v48inzkwngvjrkr2sm4i1d3ianbm-gcc-cross-x86_64-w64-mingw32-11.3.0-lib/lib/gcc/x86_64-w64-mingw32/11.3.0/include/tmmintrin.h: In function ?void CryptoPP::ARIA_ProcessAndXorBlock_SSSE3(const byte*, CryptoPP::byte*, const byte*, CryptoPP::word32*)?:
/gnu/store/dsy1v48inzkwngvjrkr2sm4i1d3ianbm-gcc-cross-x86_64-w64-mingw32-11.3.0-lib/lib/gcc/x86_64-w64-mingw32/11.3.0/include/tmmintrin.h:136:1: error: inlining failed in call to ?always_inline? ?__m128i _mm_shuffle_epi8(__m128i, __m128i)?: target specific option mismatch
  136 | _mm_shuffle_epi8 (__m128i __X, __m128i __Y)
      | ^~~~~~~~~~~~~~~~
aria_simd.cpp:176:33: note: called from here
  176 |                 _mm_storeu_si128(M128_CAST(outBlock),
      |                 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
  177 |                         _mm_xor_si128(
      |                         ~~~~~~~~~~~~~~
  178 |                                 _mm_loadu_si128(CONST_M128_CAST(xorBlock)),
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  179 |                                 _mm_xor_si128(
      |                                 ~~~~~~~~~~~~~~
  180 |                                         _mm_loadu_si128(CONST_M128_CAST(outBlock)),
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  181 |                                         _mm_shuffle_epi8(_mm_load_si128(CONST_M128_CAST(rk)), MASK)))
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  182 |                         );

It seems that on:

https://github.com/weidai11/cryptopp/blob/6ecc789df1cea7640f54ddc2aed149c6b188891f/GNUmakefile#L1788

The SSE flags aren't passed to the compiler when compiling the _simd.cpp files.

noloader commented 1 year ago

Thanks @jeandudey ,

cryptopp.dll is the FIPS DLL. It was last used about 15 years ago. It is scheduled for removal. We don't spend time on it.

If you want to give it a go, then add -DCRYPTOPP_DISABLE_ASM=1 to CXXFLAGS to disable the arch specific code paths, or add -march=native to CXXFLAGS to enable the ISAs on your local machine. If you are going to distribute the binary, then use -DCRYPTOPP_DISABLE_ASM=1.

jeandudey commented 1 year ago

cryptopp.dll is the FIPS DLL.

How could the library be built for a windows target? i.e. no FIPS DLL, but the normal build of Crypto++.

By building the static library only?

SeanTolstoyevski commented 1 year ago

@jeandudey hi I don't know how to compile cryptopp for windows on a linux machine but for windows machine i can explain:

Open Git Bash. Switch to the project's directory. Then you can type: make -f GNUMakefile in the Git Bash terminal. This creates a dynamic library. I have no idea how the flags should be for static compilation.

jeandudey commented 1 year ago

Closing this issue, I'm using the static target now for building Crypto++ using MinGW.