23 #include <interfaces/generator/digest.h> 24 #include <interfaces/generator/exceptions.h> 25 #include <openssl/evp.h> 29 #define FILE_STEP 1024 46 EVP_MD_CTX *ctx = EVP_MD_CTX_create();
47 if (!EVP_DigestInit(ctx, EVP_md5())) {
48 EVP_MD_CTX_destroy(ctx);
49 throw Exception(
"Could not initialize digest context");
52 FILE *f = fopen(config_filename.c_str(),
"r");
53 void *buf = malloc(FILE_STEP);
54 while (!feof(f) && !ferror(f)) {
56 if ((rb = fread(buf, 1, FILE_STEP, f)) > 0) {
57 if (!EVP_DigestUpdate(ctx, buf, rb)) {
59 EVP_MD_CTX_destroy(ctx);
60 throw Exception(
"Failed to update digest");
66 EVP_MD_CTX_destroy(ctx);
67 throw Exception(
"Failure while reading the file");
71 digest_size = EVP_MD_CTX_size(ctx);
72 digest =
new unsigned char[digest_size];
74 if (!EVP_DigestFinal(ctx, digest, NULL)) {
77 EVP_MD_CTX_destroy(ctx);
78 throw Exception(
"Could not finalize digest");
80 EVP_MD_CTX_destroy(ctx);
Fawkes library namespace.
const unsigned char * get_hash()
Get hash.
Base class for exceptions in Fawkes.
size_t get_hash_size()
Get hash size.
~InterfaceDigest()
Destructor.
InterfaceDigest(std::string config_filename)
Constructor.