Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toupper or isspace is not a member of std. #10

Closed
RazviOverflow opened this issue Sep 7, 2021 · 8 comments
Closed

toupper or isspace is not a member of std. #10

RazviOverflow opened this issue Sep 7, 2021 · 8 comments

Comments

@RazviOverflow
Copy link

RazviOverflow commented Sep 7, 2021

I'm trying to use Crypto++ with cryptopp-pem in Windows Visual Studio 2017 (moving the project from a Unix-based environment to Windows) and I'm facing several problems.

After manually adding the sources and headers in their respective cryptlib folders, I had to add #include "pch.h" at the beginning of pem_commong.cpp, pem_read.cpp and pem.write.cpp in order to not get the errors related to the precompiled header (pch.h).

Now, when I try to build cryptlib I get several errors related to C++, regardless of the configuration (it happens either in Debug or Release builds).

When trying to build or compile pem_read.cpp the following errors appear:

1>------ Build started: Project: cryptlib, Configuration: Release x64 ------
1>pem_read.cpp
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(324): error C2039: 'toupper': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(605): error C2039: 'isspace': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(611): error C2039: 'isspace': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(623): error C2039: 'isspace': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(626): error C2039: 'toupper': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(633): error C2039: 'isspace': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(639): error C2039: 'isspace': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(642): error C2039: 'toupper': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(653): error C2039: 'isspace': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(656): error C2039: 'toupper': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(699): error C2039: 'isspace': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>Done building project "cryptlib.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

When trying to build or compile pem_write.cpp the following errors appear:

1>------ Build started: Project: cryptlib, Configuration: Release x64 ------
1>pem_write.cpp
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_write.cpp(321): error C2039: 'toupper': is not a member of 'std'
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\gf2n.h(392): note: see declaration of 'std'
1>Done building project "cryptlib.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

On the other hand, pem_common.cpp compiles or builds without problems.

@RazviOverflow
Copy link
Author

RazviOverflow commented Sep 7, 2021

I managed to "solve" the errors by removing the std part of every std::toupper() or std::isspace() call. That is, the calls are now ::toupper() and ::isspace().

However, now I am getting the following warnings (they are warnings, nevertheless):

1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(1168): warning C4100: 'cert': unreferenced formal parameter
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\algorithm(1443): warning C4242: '=': conversion from 'int' to 'char', possible loss of data
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(319): note: see reference to function template instantiation '_OutIt std::transform<std::_String_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::_String_iterator<std::_String_val<std::_Simple_types<_Ty>>>,int(__cdecl *)(int)>(const _InIt,const _InIt,_OutIt,_Fn)' being compiled
1>        with
1>        [
1>            _OutIt=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
1>            _Ty=char,
1>            _InIt=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
1>            _Fn=int (__cdecl *)(int)
1>        ]
1>pem_write.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\algorithm(1443): warning C4242: '=': conversion from 'int' to 'char', possible loss of data
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_write.cpp(321): note: see reference to function template instantiation '_OutIt std::transform<std::_String_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::_String_iterator<std::_String_val<std::_Simple_types<_Ty>>>,int(__cdecl *)(int)>(const _InIt,const _InIt,_OutIt,_Fn)' being compiled
1>        with
1>        [
1>            _OutIt=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
1>            _Ty=char,
1>            _InIt=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
1>            _Fn=int (__cdecl *)(int)
1>        ]

It might be working but this is just a patch in my local version of Cryptopp-PEM. A fix must be addressed.

@noloader noloader changed the title toupper or isspace is not a member of std. Cryptopp in Microsoft Visual Studio 2017 toupper or isspace is not a member of std. Sep 7, 2021
@noloader
Copy link
Owner

noloader commented Sep 7, 2021

Thanks @RazviOverflow.

Sorry about the troubles. I don't think I have ever compiled this on Visual Studio. Let me give it a whirl.

I'd like to try to keep std::toupper and std::isspace. I suspect the problem has to do with C++ and overloads of std::toupper and std::isspace.

The problem with gf2n.h is kind of interesting. That header is Crypto++ proper. That should be well tested and should not have a problem.

noloader added a commit that referenced this issue Sep 7, 2021
@noloader
Copy link
Owner

noloader commented Sep 7, 2021

Thanks again @RazviOverflow.

Give Commit ac4c98d779bfa8e4 a try. It compiles cleanly under Visual Studio using /W4.

We needed to avoid std::stransform and add ToLower(secure_string) and ToUpper(secure_string). We needed the new functions so we could make a cast to quiet the warnings caused by tolower and toupper using an int rather than a char.

@RazviOverflow
Copy link
Author

Hello again @noloader, you are most welcome! Glad to help.

I manually changed everything in order to make it compile. Tomorrow I will try your ac4c98d779bfa8e4 and afterwards post here my feedback.

Until then, could you tell me how did you import/compile it in MVS? Did you import latest Crypto++ version and add headers and sources into their respective folders or there is something else to it?

@noloader
Copy link
Owner

noloader commented Sep 7, 2021

@RazviOverflow,

could you tell me how did you import/compile it in MVS?

I test the source files from the command line using cryptest.nmake:

> cd cryptopp
> copy ..\crpytopp-pem\*.h .
> copy ..\crpytopp-pem\*.cpp .
> git diff
diff --git a/cryptest.nmake b/cryptest.nmake
index b4b47973..2b42b936 100644
--- a/cryptest.nmake
+++ b/cryptest.nmake
@@ -84,7 +84,8 @@ LIB_SRCS = \
     sse_simd.cpp strciphr.cpp tea.cpp tftables.cpp threefish.cpp tiger.cpp \
     tigertab.cpp ttmac.cpp tweetnacl.cpp twofish.cpp vmac.cpp wake.cpp \
     whrlpool.cpp xed25519.cpp xtr.cpp xtrcrypt.cpp xts.cpp zdeflate.cpp \
-    zinflate.cpp zlib.cpp
+    zinflate.cpp zlib.cpp \
+    pem_common.cpp pem_read.cpp pem_write.cpp

 LIB_OBJS = \
     cryptlib.obj cpu.obj integer.obj 3way.obj adler32.obj algebra.obj \
@@ -115,7 +116,8 @@ LIB_OBJS = \
     sse_simd.obj strciphr.obj tea.obj tftables.obj threefish.obj tiger.obj \
     tigertab.obj ttmac.obj tweetnacl.obj twofish.obj vmac.obj wake.obj \
     whrlpool.obj xed25519.obj xtr.obj xtrcrypt.obj xts.obj zdeflate.obj \
-    zinflate.obj zlib.obj
+    zinflate.obj zlib.obj \
+    pem_common.obj pem_read.obj pem_write.obj

 ASM_OBJS = \
     rdrand-x86.obj rdrand-x64.obj rdseed-x86.obj rdseed-x64.obj x64masm.obj x64dll.obj

Once cryptest.nmake completes, you have the cryptlib.lib and cryptest.exe in the root of cryptopp folder. It is easier than messing around with the the Visual Studio solution and project files.

noloader added a commit that referenced this issue Sep 7, 2021
@noloader
Copy link
Owner

noloader commented Sep 7, 2021

@RazviOverflow,

You will also need Commit 3833d017c6fb. I missed the compile error last time around. I think Nmake failed to build a file that was updated. Or I forgot to copy the updated file into the cryptopp directory.

@RazviOverflow
Copy link
Author

RazviOverflow commented Sep 8, 2021

I explicitly need to use MVS for this project. I will describe step-by-step how I managed to get it working, just for the record @noloader.

  1. Download Crypto++ version 8.5.0 https://github.com/weidai11/cryptopp/releases/tag/CRYPTOPP_8_5_0 and unzip the contents.
  2. Download the latest version 3833d01 and paste the files straight into Crypto++'s folder (where all the .cpp and .h files are).
  3. Open cryptlib.vcxproj in MVS (2017 in my case). You should see 4 projects: cryptdll, cryptest, cryptlib and dlltest.
  4. Open the cryptlib's dropdown menu.
  5. Right click Header Files -> Add -> Existing Item and select pem.h and pem_common.h.
  6. Right click Source Files -> Add -> Existing Item and select pem_common.cpp, pem_read.cpp and .pem_write.cpp
  7. Right click cryptlib and click Build (after selecting the configuration you want Debug/Release and x86/x64).
    Compilation was unsuccessful, reporting the following errors:
1>pem_common.cpp
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_common.cpp(269): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source?
1>pem_read.cpp
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_read.cpp(1259): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source?
1>pem_write.cpp
1>c:\users\user\desktop\cryptopp-master\cryptopp-master\pem_write.cpp(634): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source?
  1. In order to solve it, I manually added #include "pch.h" at the beginning of pem_commong.cpp, pem_read.cpp and pem.write.cpp.

Then I built the project again and it finished with no errors and just 3 LNK4221 warnings that I guess are related to MVS and not the library itself.

1>Generating Code...
1>simple.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
1>polynomi.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
1>algebra.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
1>cryptlib.vcxproj -> C:\Users\User\Desktop\cryptopp-master\cryptopp-master\x64\Output\Release\cryptlib.lib
1>Done building project "cryptlib.vcxproj".
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Hope it helps.
Thank you once again @noloader

noloader added a commit that referenced this issue Sep 9, 2021
@noloader
Copy link
Owner

noloader commented Sep 9, 2021

@RazviOverflow,

I added the precompiled header include at Commit 2b20f9292e3c. That probably should have been there a long time ago.

The linker warnings are par for the course. We have not been able to squash them. They are present because the *.cpp file is included in the *.h file in certain configurations.

There's also a x509cert.cpp you can include if you want to parse certificates. Also see https://cryptopp.com/wiki/X509Certificate on the wiki.

@noloader noloader closed this as completed Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants