Discussion:
Calling NIST validated FIPS Crypto++ v5.3 from .NET C#
Farukh Sharipov
2017-04-28 21:36:45 UTC
Permalink
Hi

I am new to this group and pardon me if this is repeated questions.


Is there are way to call NIST validated FIPS Crypto++ v5.3 from .NET C#?

If yes what would be steps to accomplish this?

Reason for this, we have legacy application which uses Crypto++ and we need
to decrypt some information which it encrypts in our C# application.

Thank you for your time.
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeffrey Walton
2017-04-28 21:52:34 UTC
Permalink
Post by Farukh Sharipov
Hi
I am new to this group and pardon me if this is repeated questions.
Is there are way to call NIST validated FIPS Crypto++ v5.3 from .NET C#?
If yes what would be steps to accomplish this?
I believe you can call C++ from C# using interop; see
http://stackoverflow.com/q/2211867/608639.

Typically, you use a wrapper DLL that exports a bunch of C functions. Your
wrapper DLL links to the static version of Crypto++. This allows you to
control symbol visibility (only your symbols are exported rather than all
Crypto++ symbols).

In your case, because you are using the FIPS DLL, your wrapper DLL only
provides the C symbols to be called by C#. The C++ symbols will still be
visible, but you won't use them because you are using your C symbols.

Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Farukh Sharipov
2017-04-28 22:13:16 UTC
Permalink
Thank you Jeffry for reply.

I am trying to write managed VC++ wrapper for FIPS DLL but getting
following error:


Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: virtual void __thiscall
CryptoPP::DES::Base::ProcessAndXorBlock(unsigned char const *,unsigned char
const *,unsigned char *)const " (?
***@Base@***@CryptoPP@@***@Z) cryptoppwrapper C:\
Users\821973\documents\visual studio 2015\Projects\cryptoppwrapper\
cryptoppwrapper\TDES.obj 1




From browsing discussions here, I found that this is because FIPS DLL
doesn't export DES modules which are not supported by FIPS.

But I don't know how to resolve this, would you be able to help me with
that? I uploaded my sample project to assist with troubleshooting if
possible. You can get it from
here: https://1drv.ms/u/s!Aj3FJgprcdyr_GxmEk8JddUujIDd


Appreciate your help.
Post by Jeffrey Walton
Post by Farukh Sharipov
Hi
I am new to this group and pardon me if this is repeated questions.
Is there are way to call NIST validated FIPS Crypto++ v5.3 from .NET C#?
If yes what would be steps to accomplish this?
I believe you can call C++ from C# using interop; see
http://stackoverflow.com/q/2211867/608639.
Typically, you use a wrapper DLL that exports a bunch of C functions. Your
wrapper DLL links to the static version of Crypto++. This allows you to
control symbol visibility (only your symbols are exported rather than all
Crypto++ symbols).
In your case, because you are using the FIPS DLL, your wrapper DLL only
provides the C symbols to be called by C#. The C++ symbols will still be
visible, but you won't use them because you are using your C symbols.
Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeffrey Walton
2017-04-28 22:29:51 UTC
Permalink
Post by Farukh Sharipov
Thank you Jeffry for reply.
I am trying to write managed VC++ wrapper for FIPS DLL but getting
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: virtual void __thiscall
CryptoPP::DES::Base::ProcessAndXorBlock(unsigned char const *,unsigned char
const *,unsigned char *)const " (?
Users\821973\documents\visual studio 2015\Projects\cryptoppwrapper\
cryptoppwrapper\TDES.obj 1
From browsing discussions here, I found that this is because FIPS DLL
doesn't export DES modules which are not supported by FIPS.
But I don't know how to resolve this, would you be able to help me with
that? I uploaded my sample project to assist with troubleshooting if
https://1drv.ms/u/s!Aj3FJgprcdyr_GxmEk8JddUujIDd
Right. Your wrapper DLL links against the non-FIPS version of the library
to get the missing symbols.

Also see:

* https://www.cryptopp.com/wiki/FIPS_DLL
* https://www.cryptopp.com/wiki/Visual_Studio

Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Farukh Sharipov
2017-05-01 16:36:50 UTC
Permalink
Thank you Jeff for reply.

I was not able to get managed VC++ working, but I was able to get unmanaged
C++ working and write extern "C" wrapper.

This is working fine for 32-bit "cryptopp.dll", but when I try to run
64-bit version I get exception showing:

Exception thrown at 0x0000000000000000 in CryptoppCPP.exe: 0xC0000005:
Access violation executing location 0x0000000000000000.

If there is a handler for this exception, the program may be safely
continued.


Would you be able to give me some insight what could be the issue?

I uploaded sample code
here: https://1drv.ms/u/s!Aj3FJgprcdyr_G9gUZdYXr35MOtu



Thank you very much for your support.

_Farukh Sharipov
Post by Jeffrey Walton
Post by Farukh Sharipov
Thank you Jeffry for reply.
I am trying to write managed VC++ wrapper for FIPS DLL but getting
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: virtual void
__thiscall CryptoPP::DES::Base::ProcessAndXorBlock(unsigned char const
*,unsigned char const *,unsigned char *)const " (?
Users\821973\documents\visual studio 2015\Projects\cryptoppwrapper\
cryptoppwrapper\TDES.obj 1
From browsing discussions here, I found that this is because FIPS DLL
doesn't export DES modules which are not supported by FIPS.
But I don't know how to resolve this, would you be able to help me with
that? I uploaded my sample project to assist with troubleshooting if
https://1drv.ms/u/s!Aj3FJgprcdyr_GxmEk8JddUujIDd
Right. Your wrapper DLL links against the non-FIPS version of the library
to get the missing symbols.
* https://www.cryptopp.com/wiki/FIPS_DLL
* https://www.cryptopp.com/wiki/Visual_Studio
Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Farukh Sharipov
2017-05-02 22:31:12 UTC
Permalink
I thought to add a little more information about what environment I am
using.



I am using VS 2015; Win7.

My Linker command like looks as following:

/OUT:"C:\Users\821973\documents\visual studio
2015\Projects\CryptoExample7\x64\Debug\CryptoExample7.exe" /MANIFEST /NXCOMPAT
/PDB:"C:\Users\821973\documents\visual studio
2015\Projects\CryptoExample7\x64\Debug\CryptoExample7.pdb" /DYNAMICBASE "C:\Users\821973\documents\visual
studio 2015\Projects\CryptoExample7\libs\x64\cryptopp.lib" "kernel32.lib"
"user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib"
"shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib"
"odbccp32.lib" /DEBUG /MACHINE:X64 /INCREMENTAL /PGD:"C:\Users\821973\documents\visual
studio 2015\Projects\CryptoExample7\x64\Debug\CryptoExample7.pgd" /SUBSYSTEM
:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:
"x64\Debug\CryptoExample7.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO
/LIBPATH:"C:\Users\821973\Documents\Visual Studio
2015\Projects\CryptoExample7\libs\x64" /TLBID:1


and C++ command line looks as following:

/GS /W3 /Zc:wchar_t /ZI /Gm /Od /Fd"x64\Debug\vc140.pdb" /Zc:inline /fp:precise
/D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX
- /Zc:forScope /RTC1 /Gd /MTd /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\"
/Fp"x64\Debug\CryptoExample7.pch"


I would appreciate if somebody can help me with 64-bit run time issue.

Best Regards
_Farukh Sharipov
Post by Farukh Sharipov
Thank you Jeff for reply.
I was not able to get managed VC++ working, but I was able to get
unmanaged C++ working and write extern "C" wrapper.
This is working fine for 32-bit "cryptopp.dll", but when I try to run
Access violation executing location 0x0000000000000000.
If there is a handler for this exception, the program may be safely
continued.
Would you be able to give me some insight what could be the issue?
https://1drv.ms/u/s!Aj3FJgprcdyr_G9gUZdYXr35MOtu
Thank you very much for your support.
_Farukh Sharipov
Post by Jeffrey Walton
Post by Farukh Sharipov
Thank you Jeffry for reply.
I am trying to write managed VC++ wrapper for FIPS DLL but getting
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: virtual void
__thiscall CryptoPP::DES::Base::ProcessAndXorBlock(unsigned char const
*,unsigned char const *,unsigned char *)const " (?
Users\821973\documents\visual studio 2015\Projects\cryptoppwrapper\
cryptoppwrapper\TDES.obj 1
From browsing discussions here, I found that this is because FIPS DLL
doesn't export DES modules which are not supported by FIPS.
But I don't know how to resolve this, would you be able to help me with
that? I uploaded my sample project to assist with troubleshooting if
https://1drv.ms/u/s!Aj3FJgprcdyr_GxmEk8JddUujIDd
Right. Your wrapper DLL links against the non-FIPS version of the library
to get the missing symbols.
* https://www.cryptopp.com/wiki/FIPS_DLL
* https://www.cryptopp.com/wiki/Visual_Studio
Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeffrey Walton
2017-05-03 00:04:32 UTC
Permalink
Post by Farukh Sharipov
I thought to add a little more information about what environment I am
using.
I am using VS 2015; Win7.
Does the test program work as expected?

You can build and run it from the command line; see
https://www.cryptopp.com/wiki/MSBuild_(Command_Line)#Building_Cryptest.

I'm also not sure about some of the compiler and linker flags you are
using. You will have to figure out if there are incompatibilities.

Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeffrey Walton
2017-05-03 01:53:02 UTC
Permalink
Post by Farukh Sharipov
I thought to add a little more information about what environment I am
using.
I am using VS 2015; Win7.
/OUT:"C:\Users\821973\documents\visual studio
2015\Projects\CryptoExample7\x64\Debug\CryptoExample7.exe" /MANIFEST /NXCOMPAT
/PDB:"C:\Users\821973\documents\visual studio
2015\Projects\CryptoExample7\x64\Debug\CryptoExample7.pdb" /DYNAMICBASE "C:\Users\821973\documents\visual
studio 2015\Projects\CryptoExample7\libs\x64\cryptopp.lib" "kernel32.lib"
"user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib"
"shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib"
"odbccp32.lib" /DEBUG /MACHINE:X64 /INCREMENTAL /PGD:"C:\Users\821973\documents\visual
studio 2015\Projects\CryptoExample7\x64\Debug\CryptoExample7.pgd" /
SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /
ManifestFile:"x64\Debug\CryptoExample7.exe.intermediate.manifest" /
ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Users\821973\Documents\Visual
Studio 2015\Projects\CryptoExample7\libs\x64" /TLBID:1
/GS /W3 /Zc:wchar_t /ZI /Gm /Od /Fd"x64\Debug\vc140.pdb" /Zc:inline /fp:precise
/D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /
WX- /Zc:forScope /RTC1 /Gd /MTd /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\
Debug\" /Fp"x64\Debug\CryptoExample7.pch"
I would appreciate if somebody can help me with 64-bit run time issue.
You should probably visit https://www.cryptopp.com/wiki/Bug_Report. It
helps when more relevant information is provided, like the source file and
line that's causing the problem.

Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Farukh Sharipov
2017-05-04 21:25:20 UTC
Permalink
Hi Jeff

Thank you for the support.

I was able to resolve the issue, it seems like for 64-bit it was not able
to correctly load *SetNewAndDeleteFromCryptoPP *so I had to add following
code to my *.cpp file before calling anything else.


#ifdef CRYPTOPP_IMPORTS

static PNew s_pNew = NULL;
static PDelete s_pDelete = NULL;

extern "C" __declspec(dllexport) void __cdecl
SetNewAndDeleteFromCryptoPP(PNew pNew, PDelete pDelete, PSetNewHandler
pSetNewHandler)
{
s_pNew = pNew;
s_pDelete = pDelete;
}

void * __cdecl operator new (size_t size)
{
return s_pNew(size);
}

void __cdecl operator delete (void * p)
{
s_pDelete(p);
}

#endif

Strangely it works fine for 32-bit without this lines. I don't fully
understand why, but adding line above works for 32-bit and 64-bit.

Thank you for your support.
Post by Jeffrey Walton
Post by Farukh Sharipov
I thought to add a little more information about what environment I am
using.
I am using VS 2015; Win7.
/OUT:"C:\Users\821973\documents\visual studio
2015\Projects\CryptoExample7\x64\Debug\CryptoExample7.exe" /MANIFEST /NXCOMPAT
/PDB:"C:\Users\821973\documents\visual studio
2015\Projects\CryptoExample7\x64\Debug\CryptoExample7.pdb" /DYNAMICBASE "C:\Users\821973\documents\visual
studio 2015\Projects\CryptoExample7\libs\x64\cryptopp.lib" "kernel32.lib"
"user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib"
"shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib"
"odbccp32.lib" /DEBUG /MACHINE:X64 /INCREMENTAL /PGD:"C:\Users\821973\documents\visual
studio 2015\Projects\CryptoExample7\x64\Debug\CryptoExample7.pgd" /
SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /
ManifestFile:"x64\Debug\CryptoExample7.exe.intermediate.manifest" /
ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Users\821973\Documents\Visual
Studio 2015\Projects\CryptoExample7\libs\x64" /TLBID:1
/GS /W3 /Zc:wchar_t /ZI /Gm /Od /Fd"x64\Debug\vc140.pdb" /Zc:inline /fp:precise
/D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt
/WX- /Zc:forScope /RTC1 /Gd /MTd /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\
Debug\" /Fp"x64\Debug\CryptoExample7.pch"
I would appreciate if somebody can help me with 64-bit run time issue.
You should probably visit https://www.cryptopp.com/wiki/Bug_Report. It
helps when more relevant information is provided, like the source file and
line that's causing the problem.
Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeffrey Walton
2018-08-27 13:40:10 UTC
Permalink
Post by Farukh Sharipov
Hi
I am new to this group and pardon me if this is repeated questions.
Is there are way to call NIST validated FIPS Crypto++ v5.3 from .NET C#?
This is a little late, but...We added a wiki page on creating wrapper DLLs.
Also see https://www.cryptopp.com/wiki/Wrapper_DLL .

You are still out of luck for the FIPS validated cryptography.

Jeff
--
You received this message because you are subscribed to "Crypto++ Users". More information about Crypto++ and this group is available at http://www.cryptopp.com and http://groups.google.com/forum/#!forum/cryptopp-users.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...