Is this engine bugs? CryptoPP

Hello,

I need sha256 and some other cryptographic algorithms. I know that from version 4.11 to the engine include support Crypt ++. However, I was not at hand engine build from source, and I would like to always have the latest version of Crypt ++. I added to the engine library and headers as the ThirdParty being guided this article:

After preparation (create Third Person from template, create cryptlib.lib,and add lib as ThirdParty),

10ab1019cd7f5c5205a38ca83d5c2e79fd201eeb.jpeg
17df867c1fb3cecb6994adabc85603b50897a7cc.jpeg




//.build.cs

using UnrealBuildTool;
using System.IO;
using System; // Console.WriteLine("");

public class MyProject : ModuleRules
{

    private string ModulePath
    {
        get { return ModuleDirectory; }
    }

    private string ThirdPartyPath
    {
        get { return Path.GetFullPath( Path.Combine( ModulePath, "../../ThirdParty/" ) ); }
    }
	
    public MyProject(TargetInfo Target)
    {
        PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });

        string LibrariesPath = Path.Combine(ThirdPartyPath, "CryptoPP", "Libraries");
	string IncludesPath = Path.Combine(ThirdPartyPath, "CryptoPP", "Includes");

        Console.WriteLine("... LibrariesPath -> " + LibrariesPath);
        Console.WriteLine("... IncludesPath -> " + IncludesPath);

        PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "cryptlib.lib"));
        PublicIncludePaths.Add(IncludesPath);

    }   
}

I import #include “cryptlib.h” in MyProjectCharacter.cpp to check availability and get the following error:


1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(588): warning C4266: 'void FOutputDevice::Serialize(const TCHAR *,ELogVerbosity::Type,const FName &,const double)': no override available for virtual member function from base 'FOutputDevice'; function is hidden
1>  e:\program files\epic games\4.13\engine\source\runtime\core\public\Misc/OutputDevice.h(250): note: see declaration of 'FOutputDevice::Serialize'
1>  E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\Guid.h(7): note: see declaration of 'FOutputDevice'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(642): error C2143: syntax error: missing ';' before '<'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(642): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(642): error C2238: unexpected token(s) preceding ';'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(645): error C2143: syntax error: missing ';' before '<'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(645): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(645): error C2238: unexpected token(s) preceding ';'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\CoreUObject\Public\UObject\CoreNet.h(260): warning C4242: 'initializing': conversion from 'int32' to 'uint16', possible loss of data
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\CoreUObject\Public\Serialization\ArchiveUObject.h(1658): error C2143: syntax error: missing ';' before '<'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\CoreUObject\Public\Serialization\ArchiveUObject.h(1658): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\CoreUObject\Public\Serialization\ArchiveUObject.h(1658): error C2238: unexpected token(s) preceding ';'

This time, I copied all headers of crypt++.

I started to search for the reason, I thought that the library is not available, wrong way or I did something wrong.

Created for test a library with simple mathematical operation (addition and subtraction) as written here:

Walkthrough: Creating and Using a Static Library (C++)

Added to the project in the same way, it worked! no errors, .lib 100% loaded correctly!

Now back to the Crypto ++, I decided to add only the headers needed to compile #include "cryptlib.h"

17df867c1fb3cecb6994adabc85603b50897a7cc.jpeg

Compiled without errors. Next I add headers to #include “sha.h”
Added this headers:

8e879fdf5652ade257bd29b8cd5fe50ebc9f1299.jpeg

Everything is compiled. Now I want to get the hash sha256, for this I add another couple of necessary headers:

6fa748ced39f462e12bed163cddbfdeb53ac4ce2.jpeg

Everything is good, I create function and assign a button, include headers:


#include "sha.h"
#include "filters.h"
#include "hex.h"

void AMyProjectCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
        // crypto test
	PlayerInputComponent->BindAction("T", IE_Pressed, this, &AMyProjectCharacter::CryptoTest);
}

void AMyProjectCharacter::CryptoTest()
{
	CryptoPP::SHA256 hash;
	std::string message = "baron";
	std::string digest;

	CryptoPP::StringSource s(message, true, new CryptoPP::HashFilter(hash, new CryptoPP::HexEncoder(new CryptoPP::StringSink(digest))));

	FString HappyHash(digest.c_str());

	GLog->Log(HappyHash);;
}


========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Now I get to receive a hash clicking T-key in the game, it works!

But now whan I press Clear/ReBuild MyProject and I again can not compile and give an error the same as if I added all the headers Crypt ++ at once:



1>------ Rebuild All started: Project: MyProject, Configuration: Development_Editor x64 ------
1>  Cleaning MyProjectEditor Binaries...
1>  Creating makefile for MyProjectEditor (no existing makefile)
1>  Performing full C++ include scan (no include cache file)
1>  Parsing headers for MyProjectEditor
1>    Running UnrealHeaderTool "C:\Users\Vadim\Documents\Unreal Projects\MyProject\MyProject.uproject" "C:\Users\Vadim\Documents\Unreal Projects\MyProject\Intermediate\Build\Win64\MyProjectEditor\Development\MyProjectEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -installed
1>  Reflection code generated for MyProjectEditor in 3,3700004 seconds
1>  Performing 8 actions (2 in parallel)
1>  [2/8] Resource PCLaunch.rc
1>  PCH.MyProject.h.cpp
1>  [3/8] Resource ModuleVersionResource.rc.inl
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(588): warning C4266: 'void FOutputDevice::Serialize(const TCHAR *,ELogVerbosity::Type,const FName &,const double)': no override available for virtual member function from base 'FOutputDevice'; function is hidden
1>  e:\program files\epic games\4.13\engine\source\runtime\core\public\Misc/OutputDevice.h(250): note: see declaration of 'FOutputDevice::Serialize'
1>  E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\Guid.h(7): note: see declaration of 'FOutputDevice'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(642): error C2143: syntax error: missing ';' before '<'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(642): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(642): error C2238: unexpected token(s) preceding ';'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(645): error C2143: syntax error: missing ';' before '<'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(645): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\Core\Public\Misc\AutomationTest.h(645): error C2238: unexpected token(s) preceding ';'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\CoreUObject\Public\UObject\CoreNet.h(260): warning C4242: 'initializing': conversion from 'int32' to 'uint16', possible loss of data
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\CoreUObject\Public\Serialization\ArchiveUObject.h(1658): error C2143: syntax error: missing ';' before '<'
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\CoreUObject\Public\Serialization\ArchiveUObject.h(1658): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>E:\Program Files\Epic Games\4.13\Engine\Source\Runtime\CoreUObject\Public\Serialization\ArchiveUObject.h(1658): error C2238: unexpected token(s) preceding ';'
1>ERROR : UBT error : Failed to produce item: C:\Users\Vadim\Documents\Unreal Projects\MyProject\Binaries\Win64\UE4Editor-MyProject.dll
1>  Total build time: 20,60 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(46,5): error MSB3073: The command ""E:\Program Files\Epic Games\4.13\Engine\Build\BatchFiles\Rebuild.bat" MyProjectEditor Win64 Development "C:\Users\Vadim\Documents\Unreal Projects\MyProject\MyProject.uproject" -waitmutex" exited with code -1.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


I think that this is probably an engine bug, why do I get compile only than I do it step by step, adding headers one by one?

Engine 4.13

There is also a question on ansvers, without solution, the same mistake with the source built crypt ++ =\

https://answers.unrealengine.com/questions/404387/how-to-include-the-new-cryptopp-lib-in-411.html

If you want I can send project. Sorry for my English :slight_smile:

Given that the engine already builds with CryptoPP, I think your best bet would be to check out the full engine source, then fold in the newer CryptoPP source as a replacement for what’s in there now (basically, merge-new-version,) and then fix whatever API breakage may have happened.
Once you’ve done that, you can send a pull request to Epic, too, for updating to the latest version.

I don’t know what this error means, even close and how to solve it.

Fortunately, this is not the only one cryptographic library. I compile the latest version of OpenSSL to .lib and add as the ThirdParty, it worked immediately and without error.

Here’s how to get the hash for example:


// SHA256
#include <iomanip>
#include <sstream>
#include <string>
#include <openssl/sha.h>

...

FString AMyProjectCharacter::SHA256(const FString UEStr)
{
	std::string str(TCHAR_TO_UTF8(*UEStr));

	unsigned char hash[SHA256_DIGEST_LENGTH];
	SHA256_CTX sha256;
	SHA256_Init(&sha256);
	SHA256_Update(&sha256, str.c_str(), str.size());
	SHA256_Final(hash, &sha256);
	std::stringstream ss;

	for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
	{
		ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash*;
	}

	return ss.str().c_str();
}

void AMyProjectCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
	...

	// crypto test
	PlayerInputComponent->BindAction("T", IE_Pressed, this, &AMyProjectCharacter::CryptoTest);
}

void AMyProjectCharacter::CryptoTest()
{
	GLog->Log(SHA256("baron")); // output 99c2bb3e7c93dd54a206c77388ee09708e39db1a6f544ff6887612495bce3920
}

Just make sure source code are not there within the ‘Source’ folders even though they are not added to Project File (vcproj/sln). UBT behavior is to compile every source code (CPP/H) even though they are not added. This maybe is your case.

Hi Syntopia,

Really appreciate if you could send a step by step process on compiling the OpenSSL and using it in unreal engine. I’m a newbie to Unreal and C++

Hi, Can you provide a good proceedure of compiling OpenSSL and integrating it with unreal?