Skip to content
Snippets Groups Projects

use new ssl/tls openssh toolkit

1 file
+ 8
9
Compare changes
  • Side-by-side
  • Inline
+ 8
9
#include "Hasher.h"
#include <openssl/sha.h>
#include <openssl/evp.h>
#include <sstream>
#include <iomanip>
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);
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;
}
SIGN::Hasher::Hasher()
@@ -37,7 +36,7 @@ void SIGN::Hasher::reset()
size_t SIGN::Hasher::size(void)
{
return SHA256_DIGEST_LENGTH; ;
return EVP_MD_size(EVP_sha256());
}
std::string SIGN::Hasher::print(std::vector<unsigned char> bytes, bool uppercase)
Loading