Hashing, encrypting, basically everything failing to build, except AES::DEFAULT_KEYLENGTH print to the console

583 views
Skip to first unread message

zavodny...@gmail.com

unread,
May 1, 2018, 8:19:46 AM5/1/18
to Crypto++ Users

Firstly asked at: https://github.com/weidai11/cryptopp/issues/651


As the title says, everything failing to build. I have this code (below), and I'm not able to build it (logs below the code). I use CMake to create the Visual Studio solution file. I also tried version 6.1.0 and 6.0.0, same problem occurs.


Steps to build CryptoPP: download CryptoPP source code (from website) -> open cryptest.sln -> Retarget solution (to use my version of Windows SDK - 10.0.16299.0) -> Ok -> Batch Build -> tick cryptlib - Release|Win32 -> Build


cryptopp-test.cpp:

https://gist.github.com/zavodnyrichard/f51ec376cda91c9732ac822bab26189b#file-cryptopp-test-cpp


CMakeLists.txt:

https://gist.github.com/zavodnyrichard/f51ec376cda91c9732ac822bab26189b#file-cmakelists-txt


$cmake ..

https://gist.github.com/zavodnyrichard/f51ec376cda91c9732ac822bab26189b#file-cmake


$msbuild cryptopp-test.sln

https://gist.github.com/zavodnyrichard/f51ec376cda91c9732ac822bab26189b#file-msbuild-cryptopp-test-sln


However if I'll try to build this code (below) using the same steps (and CMakeList.txt) as above, everything is fine.

https://gist.github.com/zavodnyrichard/f51ec376cda91c9732ac822bab26189b#file-cryptopp-test-cpp-works-well

zavodny...@gmail.com

unread,
May 1, 2018, 1:11:32 PM5/1/18
to Crypto++ Users

...I'm really confused. Did I build the CryptoPP wrong (if so, then why I'm able to print the key lenghts?)?

zavodny...@gmail.com

unread,
May 1, 2018, 2:47:33 PM5/1/18
to Crypto++ Users
I can confirm the same happening for versions 7.0.0, 6.1.0, 6.0.0, 5.6.5.


On Tuesday, May 1, 2018 at 2:19:46 PM UTC+2, zavodny...@gmail.com wrote:

Jeffrey Walton

unread,
May 1, 2018, 7:41:20 PM5/1/18
to zavodny...@gmail.com, Crypto++ Users
I have very little CMake skills so I am probably one of the last
people who should advise about it... There's a minimally maintained
CMake for Crypto++ located at
https://github.com/noloader/cryptopp-cmake . You might consider taking
a look at it.

There's also a wiki page available for the Cmake files at
https://www.cryptopp.com/wiki/CMake . You might find some helpful
information there, too.

The GNUmakefile will provide most/all the flags you should need for
each source file. For example, notice the *-simd.cpp files require
additional architectural flags:

$ make -j 4
...
g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -c cryptlib.cpp
g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -c cpu.cpp
g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -c integer.cpp
...
g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -mssse3 -c aria-simd.cpp
...
g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -msse4.1 -c blake2-simd.cpp
...

Finally, you can list the library source files and the test source files with:

$ make sources
Library sources: cryptlib.cpp cpu.cpp integer.cpp 3way.cpp adler32.cpp
algebra.cpp algparam.cpp ...

Library headers: 3way.h adler32.h adv-simd.h aes.h algebra.h
algparam.h androidpay.h arc4.h ...

Test sources: adhoc.cpp test.cpp bench1.cpp bench2.cpp validat0.cpp
validat1.cpp validat2.cpp ...

Test headers: bench.h factory.h validate.h

Jeff

zavodny...@gmail.com

unread,
May 2, 2018, 1:32:42 AM5/2/18
to Crypto++ Users
Actually I don't think problem is in CMake but somewhere between the linking process (when running msbuild cryptopp-test.sln) or building the library. Can you confirm that building the library this way: download CryptoPP source code (from website) -> open cryptest.sln -> Retarget solution (to use my version of Windows SDK - 10.0.16299.0) -> Ok -> Batch Build -> tick cryptlib - Release/Debug|Win32 -> Build; is correct?

Jeffrey Walton

unread,
May 2, 2018, 11:03:15 PM5/2/18
to Crypto++ Users

According to :

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\bin\HostX86\x86\link.exe /ERR
ORREPORT:QUEUE /OUT:"E:\projects\cpp-utils\cryptopp-test\build\Debug\cryptopp-test.exe" /INCREMENTAL /NOLOGO kernel32
.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFES
T /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"E:/projects/cpp-utils/cryptopp-test/
build/Debug/cryptopp-test.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"E:/projects/cpp-utils/cryp
topp-test/build/Debug/cryptopp-test.lib" /MACHINE:X86 /SAFESEH /machine:X86 "cryptopp-test.dir\Debug\cryptopp-test.o
bj"

It looks like you are trying to link against a DLL based on the /IMPLIB. That usually ends badly when using the Crypto++ DLL because it is a FIPS DLL and missing a lot of classes. Also see https://www.cryptopp.com/wiki/FIPS_DLL .

Usually you want to link against the static archive.

Jeff
Link:
 

zavodny...@gmail.com

unread,
May 3, 2018, 11:13:18 AM5/3/18
to Crypto++ Users
Yeah I definitely want use static library. I'm not sure why it trying to use dynamic library, when I have only static (.lib) compiled. :/

zavodny...@gmail.com

unread,
May 6, 2018, 8:12:26 AM5/6/18
to Crypto++ Users
I builded my project using /MTd flag after reading this topic on Stackoverflow as CryptoPP is builded, but still...


On Tuesday, May 1, 2018 at 2:19:46 PM UTC+2, zavodny...@gmail.com wrote:

zavodny...@gmail.com

unread,
May 7, 2018, 12:04:18 AM5/7/18
to Crypto++ Users
FINALLY! I managed to fix the problem. It seems that CMake wanted absolute path to the builded library. Also it is important to set /MT and /MTd flags for Release and Debug mode respectively.

Here is my fixed CMakeLists.txt:
cmake_minimum_required(VERSION 3.10.0)

project
(cryptopp-test)
add_executable
(cryptopp-test cryptopp-test.cpp)

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")

#search for CryptoPP and include it
set(CRYPTOPP_ROOT_DIR "C:\\libs\\cryptopp700\\cryptopp\\Win32\\Output\\Debug\\cryptlib.lib")
set(CRYPTOPP_LIBRARY "C:\\libs\\cryptopp700\\cryptopp\\Win32\\Output\\Debug\\cryptlib.lib")
set(CRYPTOPP_INCLUDE_DIR "C:\\libs\\cryptopp700")

find_package
(CryptoPP REQUIRED)

if(CRYPTOPP_FOUND)
    target_link_libraries
(cryptopp-test ${CRYPTOPP_LIBRARIES})
    include_directories
(${CRYPTOPP_INCLUDE_DIRS})
endif
()
#--

On Tuesday, May 1, 2018 at 2:19:46 PM UTC+2, zavodny...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages