Skip to content

SHA256_Init, SHA256_Update and SHA256_Final are depricated in OpenSSL 3.0

The functions SHA256_Init, SHA256_Update and SHA256_Final used by the SIGN Project in Hasher.cpp

#include <openssl/sha.h>

std::vector<unsigned char> SIGN::Hasher::sha256(const unsigned char* data, size_t length)
{
	SHA256_CTX context;
	SHA256_Init(&context);
	SHA256_Update(&context, data, length);
	std::vector<unsigned char> buffer(SHA256_DIGEST_LENGTH);
	SHA256_Final(buffer.data(), &context);
	return buffer;

}

size_t SIGN::Hasher::size(void)
{
	return SHA256_DIGEST_LENGTH; ;
}

are deprecated in OpenSSL 3.0 and should be replaced with the new Cryptography and SSL/TLS Toolkit

#include <openssl/evp.h>

std::vector<unsigned char> SIGN::Hasher::sha256(const unsigned char* data, size_t length)
{
	EVP_MD_CTX* context = EVP_MD_CTX_new();
	EVP_DigestInit_ex(context, EVP_sha256(), NULL);
	EVP_DigestUpdate(context, data, length);
	std::vector<unsigned char> buffer(EVP_MD_size(EVP_sha256()));
	EVP_DigestFinal_ex(context, buffer.data(), NULL);
	EVP_MD_CTX_free(context);
	return buffer;
}

size_t SIGN::Hasher::size(void)
{
	return EVP_MD_size(EVP_sha256());
}
Edited by Tim Heß