How to Generate Whirlpool Hash with C++ and OpenSSL

The Whirlpool Galaxy (M51) inspired the name of the algorithm.

How to Generate Whirlpool Hash with C++ and OpenSSL

In the previous article we showed how to generate Hash with MD5, as described there, the concepts will be similar.

Whirlpool (sometimes called WHIRLPOOL ) is a cryptographic hash function based on an AES block cipher.

It generates a hash of length of 128 characters.

Using with C++

For this example, we are going to hash the word Terminal Root . Follow the code below:


#include <iostream>
#include <iomanip>
#include <sstream>
#include <openssl/whrlpool.h>

std::string whirlpool(const std::string &str){
  unsigned char hash[WHIRLPOOL_DIGEST_LENGTH];

  WHIRLPOOL_CTX whirlpool;
  WHIRLPOOL_Update(&whirlpool, str.c_str(), str.size());
  WHIRLPOOL_Final(hash, &whirlpool);

  std::stringstream ss;

  for(int i = 0; i < WHIRLPOOL_DIGEST_LENGTH; i++){
    ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>( hash[i] );
  return ss.str();

int main() {
  std::cout << whirlpool("Terminal Root") << '\n';
  return 0;

To compile, run:

g++ whirlpool.cpp -lcrypto

The possible and expected output will be:


To check if it is correct, use the rhash command with the following arguments:

rhash --whirlpool -m "Terminal Root"

Links Ășteis

cpp cryptography openssl