Crypto++ : Hash generation hangs on windows 10

102 views Asked by At

I have the following simple program :

#include <cryptlib.h>
#include "sha.h"
#include <sha3.h>
#include <filters.h>
#include <hex.h>
#include <beast/core/detail/base64.hpp>

using namespace CryptoPP;
using namespace boost::beast::detail::base64;

int main(int argc, char** argv) {

    if (argc < 2) {
        std::cout << "missing argument 1 : password";
        return 0;
    }
    std::string password = std::string(argv[1]);
    byte digest[SHA3_256::DIGESTSIZE];

    SHA3 digestAlgo = SHA3_256();
    std::cout << "going to calculate the digest\n";
    digestAlgo.Update((const byte*) password.data(), password.size());
    std::cout << "updated...\n";
    digestAlgo.Final(digest);
    std::cout << "calculated the digest\n";

    char* b64encodedHash = (char*)malloc(sizeof(byte)*1000);
    encode(b64encodedHash, digest, sizeof(byte)*1000);

    std::cout << "password hashed : " << b64encodedHash << "\n";

    return 1;
}

When I run it the text : "going to calculate the digest" is output on the command line and the program does not continue. It hangs. Does anyone know why ? I am trying to follow the examples on the Crypto++ wiki, and this is very similar to theirs. After the Final call I want to base64 encode the digest, you can remove that part, it uses a boost header file.

Thanks, Regards

1

There are 1 answers

1
kelalaka On BEST ANSWER

Change the line

SHA3 digestAlgo = SHA3_256();

to

SHA3_256 digestAlgo;