Skip to content

Commit

Permalink
Fix "C2872: 'byte': ambiguous symbol" with Windows Kit (Issue 442, 447)
Browse files Browse the repository at this point in the history
AppVeyor detected the break but we did not receive the email about it. It looks like we have an AppVeyor configuration problem
  • Loading branch information
noloader committed Jul 23, 2017
1 parent 5103f6d commit 00e1337
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rdrand.cpp
Expand Up @@ -97,6 +97,8 @@
# endif
#endif

typedef unsigned char byte;

#if MASM_RDRAND_ASM_AVAILABLE
extern "C" void CRYPTOPP_FASTCALL MASM_RDRAND_GenerateBlock(byte*, size_t);
#endif
Expand Down
10 changes: 10 additions & 0 deletions test.cpp
Expand Up @@ -145,6 +145,7 @@ int CRYPTOPP_API main(int argc, char *argv[])

try
{
using CryptoPP::byte;
RegisterFactories(Test::All);

// Some editors have problems with the '\0' character when redirecting output.
Expand Down Expand Up @@ -455,6 +456,7 @@ SecByteBlock HexDecodeString(const char *hex)

void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed)
{
using CryptoPP::byte;
RandomPool randPool;
randPool.IncorporateEntropy((byte *)seed, strlen(seed));

Expand All @@ -471,6 +473,7 @@ void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char

std::string RSAEncryptString(const char *pubFilename, const char *seed, const char *message)
{
using CryptoPP::byte;
FileSource pubFile(pubFilename, true, new HexDecoder);
RSAES_OAEP_SHA_Encryptor pub(pubFile);

Expand Down Expand Up @@ -551,6 +554,7 @@ void DigestFile(const char *filename)

void HmacFile(const char *hexKey, const char *file)
{
using CryptoPP::byte;
member_ptr<MessageAuthenticationCode> mac;
if (strcmp(hexKey, "selftest") == 0)
{
Expand All @@ -576,6 +580,7 @@ void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile,

std::string EncryptString(const char *instr, const char *passPhrase)
{
using CryptoPP::byte;
std::string outstr;

DefaultEncryptorWithMAC encryptor(passPhrase, new HexEncoder(new StringSink(outstr)));
Expand All @@ -587,6 +592,7 @@ std::string EncryptString(const char *instr, const char *passPhrase)

std::string DecryptString(const char *instr, const char *passPhrase)
{
using CryptoPP::byte;
std::string outstr;

HexDecoder decryptor(new DefaultDecryptorWithMAC(passPhrase, new StringSink(outstr)));
Expand All @@ -608,6 +614,7 @@ void DecryptFile(const char *in, const char *out, const char *passPhrase)

void SecretShareFile(int threshold, int nShares, const char *filename, const char *seed)
{
using CryptoPP::byte;
CRYPTOPP_ASSERT(nShares >= 1 && nShares<=1000);
if (nShares < 1 || nShares > 1000)
throw InvalidArgument("SecretShareFile: " + IntToString(nShares) + " is not in range [1, 1000]");
Expand Down Expand Up @@ -640,6 +647,7 @@ void SecretShareFile(int threshold, int nShares, const char *filename, const cha

void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFilenames)
{
using CryptoPP::byte;
CRYPTOPP_ASSERT(threshold >= 1 && threshold <=1000);
if (threshold < 1 || threshold > 1000)
throw InvalidArgument("SecretRecoverFile: " + IntToString(threshold) + " is not in range [1, 1000]");
Expand Down Expand Up @@ -667,6 +675,7 @@ void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFi

void InformationDisperseFile(int threshold, int nShares, const char *filename)
{
using CryptoPP::byte;
CRYPTOPP_ASSERT(threshold >= 1 && threshold <=1000);
if (threshold < 1 || threshold > 1000)
throw InvalidArgument("InformationDisperseFile: " + IntToString(nShares) + " is not in range [1, 1000]");
Expand Down Expand Up @@ -851,6 +860,7 @@ void ForwardTcpPort(const char *sourcePortName, const char *destinationHost, con

bool Validate(int alg, bool thorough, const char *seedInput)
{
using CryptoPP::byte;
bool result;

// Some editors have problems with the '\0' character when redirecting output.
Expand Down

1 comment on commit 00e1337

@noloader
Copy link
Collaborator Author

@noloader noloader commented on 00e1337 Jul 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test.cpp has a using namespace CryptoPP. The practical problems for us are, (1) Microsoft should not be adding symbols like byte to the global namespace; and (2) main must not be in a namespace.

This was triaged to avoid problems for Windows users. Later we checked-in a changed that effectively moved all functions in test.cpp into the CryptoPP::Test namespace. We needed more time to test the change to ensure it did not break on various platforms.

Also see issue 447, Fix "C2872: 'byte': ambiguous symbol" with Windows Kit (Issue 442, 447).

Please sign in to comment.