MeNotMe MeNotMe - 3 months ago 10
C++ Question

error: ‘GlobalRNG’ was not declared in this scope



So i'm using Crypto++ to encrypt files in c++

And i'm using this code over here

It doesn't contain the headers files so I added my own :


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <cryptopp/cryptlib.h>
#include <cryptopp/sha.h>
#include <cryptopp/secblock.h>
#include <cryptopp/files.h>
#include <cryptopp/queue.h>
#include <cryptopp/hex.h>
#include <cryptopp/base64.h>
#include <cryptopp/filters.h>
#include <cryptopp/osrng.h>
#include <cryptopp/integer.h>
#include <cryptopp/dh.h>
#include <cryptopp/sha.h>
#include <cryptopp/modes.h>
#include <cryptopp/eax.h>
#include <cryptopp/tea.h>
#include <cryptopp/blowfish.h>
#include <cryptopp/pssr.h>
#include <cryptopp/rsa.h>
#include <cryptopp/nbtheory.h>
#include <cryptopp/eccrypto.h>
#include <cryptopp/oids.h>
#include <cryptopp/modes.h>
#include <cryptopp/gzip.h>
#include <cryptopp/blowfish.h>
#include <cryptopp/rsa.h>
#include <cryptopp/rng.h>
#include <cryptopp/cryptlib.h>
#include <cryptopp/filters.h>
#include <cryptopp/rdrand.h>

using namespace std;
using namespace CryptoPP;


But unfortunately the code doesn't work

Saying that the GlobalRNG is not declared !


error: ‘GlobalRNG’ was not declared in this scope


I googled and kept looking for a solution for 2 days i found that it's a bug and fixed but i'm having the latest version : 5.6.3 !



So i really don't know why this error is showing !



Answer

In the version 5.6.3 GlobalRNG is defined in the file validate.h, as:

// Functions that need a RNG; uses AES inf CFB mode with Seed.
CryptoPP::RandomNumberGenerator & GlobalRNG();

Just add this inclusion:

#include <cryptopp/validate.h>

to solve definition problem.