Skip to content

Commit

Permalink
Make OpenSSL calls compatible with OpenSSL 1.0 and 1.1
Browse files Browse the repository at this point in the history
(AJN: I copied this patch as supplied [here](#16), without further
modification.  The base I chose is the current tracked commit head in
TCPFlow.)
  • Loading branch information
dkogan authored and ajnelson committed Oct 31, 2016
1 parent 13a8cc2 commit 8198685
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/hash_t.h
Expand Up @@ -189,7 +189,7 @@ inline std::string digest_name<sha512_t>() {

template<const EVP_MD *md(),size_t SIZE>
class hash_generator__ { /* generates the hash */
EVP_MD_CTX mdctx; /* the context for computing the value */
EVP_MD_CTX* mdctx; /* the context for computing the value */
bool initialized; /* has the context been initialized? */
bool finalized;
/* Static function to determine if something is zero */
Expand All @@ -202,21 +202,21 @@ class hash_generator__ { /* generates the hash */
public:
int64_t hashed_bytes;
/* This function takes advantage of the fact that different hash functions produce residues with different sizes */
hash_generator__():mdctx(),initialized(false),finalized(false),hashed_bytes(0){ }
hash_generator__():mdctx(NULL),initialized(false),finalized(false),hashed_bytes(0){ }
~hash_generator__(){
release();
}
void release(){ /* free allocated memory */
if(initialized){
EVP_MD_CTX_cleanup(&mdctx);
EVP_MD_CTX_destroy(mdctx);
initialized = false;
hashed_bytes = 0;
}
}
void init(){
if(initialized==false){
EVP_MD_CTX_init(&mdctx);
EVP_DigestInit_ex(&mdctx, md(), NULL);
mdctx = EVP_MD_CTX_create();
EVP_DigestInit_ex(mdctx, md(), NULL);
initialized = true;
finalized = false;
hashed_bytes = 0;
Expand All @@ -228,7 +228,7 @@ class hash_generator__ { /* generates the hash */
std::cerr << "hashgen_t::update called after finalized\n";
exit(1);
}
EVP_DigestUpdate(&mdctx,buf,bufsize);
EVP_DigestUpdate(mdctx,buf,bufsize);
hashed_bytes += bufsize;
}
hash__<md,SIZE> final() {
Expand All @@ -242,7 +242,7 @@ class hash_generator__ { /* generates the hash */
}
hash__<md,SIZE> val;
unsigned int len = sizeof(val.digest);
EVP_DigestFinal(&mdctx,val.digest,&len);
EVP_DigestFinal(mdctx,val.digest,&len);
finalized = true;
return val;
}
Expand Down

0 comments on commit 8198685

Please sign in to comment.