Link Here
|
|
|
1 |
--- plugins/dfxml/src/hash_t.h.orig 2014-09-16 18:34:02 UTC |
2 |
+++ plugins/dfxml/src/hash_t.h |
3 |
@@ -189,7 +189,8 @@ inline std::string digest_name<sha512_t> |
4 |
|
5 |
template<const EVP_MD *md(),size_t SIZE> |
6 |
class hash_generator__ { /* generates the hash */ |
7 |
- EVP_MD_CTX mdctx; /* the context for computing the value */ |
8 |
+ private: |
9 |
+ EVP_MD_CTX* mdctx; /* the context for computing the value */ |
10 |
bool initialized; /* has the context been initialized? */ |
11 |
bool finalized; |
12 |
/* Static function to determine if something is zero */ |
13 |
@@ -199,24 +200,36 @@ class hash_generator__ { /* generates |
14 |
} |
15 |
return true; |
16 |
} |
17 |
+ /* Not allowed to copy; these are prototyped but not defined, so any attempt to use them will fail, but we won't get the -Weffc++ warnings */ |
18 |
+ hash_generator__ & operator=(const hash_generator__ &); |
19 |
+ hash_generator__(const hash_generator__ &); |
20 |
public: |
21 |
int64_t hashed_bytes; |
22 |
/* This function takes advantage of the fact that different hash functions produce residues with different sizes */ |
23 |
- hash_generator__():mdctx(),initialized(false),finalized(false),hashed_bytes(0){ } |
24 |
+ hash_generator__():mdctx(NULL),initialized(false),finalized(false),hashed_bytes(0){ } |
25 |
~hash_generator__(){ |
26 |
release(); |
27 |
} |
28 |
void release(){ /* free allocated memory */ |
29 |
if(initialized){ |
30 |
- EVP_MD_CTX_cleanup(&mdctx); |
31 |
+#ifdef HAVE_EVP_MD_CTX_FREE |
32 |
+ EVP_MD_CTX_free(mdctx); |
33 |
+#else |
34 |
+ EVP_MD_CTX_destroy(mdctx); |
35 |
+#endif |
36 |
initialized = false; |
37 |
hashed_bytes = 0; |
38 |
} |
39 |
} |
40 |
void init(){ |
41 |
if(initialized==false){ |
42 |
- EVP_MD_CTX_init(&mdctx); |
43 |
- EVP_DigestInit_ex(&mdctx, md(), NULL); |
44 |
+#ifdef HAVE_EVP_MD_CTX_NEW |
45 |
+ mdctx = EVP_MD_CTX_new(); |
46 |
+#else |
47 |
+ mdctx = EVP_MD_CTX_create(); |
48 |
+#endif |
49 |
+ if (!mdctx) throw std::bad_alloc(); |
50 |
+ EVP_DigestInit_ex(mdctx, md(), NULL); |
51 |
initialized = true; |
52 |
finalized = false; |
53 |
hashed_bytes = 0; |
54 |
@@ -228,21 +241,21 @@ public: |
55 |
std::cerr << "hashgen_t::update called after finalized\n"; |
56 |
exit(1); |
57 |
} |
58 |
- EVP_DigestUpdate(&mdctx,buf,bufsize); |
59 |
+ EVP_DigestUpdate(mdctx,buf,bufsize); |
60 |
hashed_bytes += bufsize; |
61 |
} |
62 |
hash__<md,SIZE> final() { |
63 |
if(finalized){ |
64 |
std::cerr << "currently friendly_geneator does not cache the final value\n"; |
65 |
assert(0); |
66 |
- /* code below will never be executed after assert(0) */ |
67 |
+ exit(1); // in case compiled with assertions disabled |
68 |
} |
69 |
if(!initialized){ |
70 |
init(); /* do it now! */ |
71 |
} |
72 |
hash__<md,SIZE> val; |
73 |
unsigned int len = sizeof(val.digest); |
74 |
- EVP_DigestFinal(&mdctx,val.digest,&len); |
75 |
+ EVP_DigestFinal(mdctx,val.digest,&len); |
76 |
finalized = true; |
77 |
return val; |
78 |
} |