I am trying to hash some strings at compile time (they do not need to be retrieved) using the Crypto++ library and a constexpr
function. This is the code I have so far:
constexpr const char* operator "" _SHA3_HASH(const char *input, unsigned int length){
CryptoPP::SHA3_512 hash;
byte digest [CryptoPP::SHA3_512::DIGESTSIZE];
hash.CalculateDigest(digest, (byte*)input, length);
return (const char*) digest;
}
To be used: std::string passwordHash="password1234"_SHA3_HASH
I don't think that there's a way I can get this to work since the CryptoPP::SHA3_512
class probably isn't literal-friendly. Is there a better (or working) alternative I can use?
Notes:
- I would prefer to use Crypto++ library, if possible
- SHA3 would be nice, but any secure hash will do
- If I can't compile-time hash, what are my alternatives?
- I've looked around at possible duplicates, but none appear to reveal any method for complex code in
constexpr
functions. - I'm using the built in compiler in Qt creator, which is MinGW 32 bit.