Skip to content

Commit

Permalink
XrdCryptosslMsgDigest: fix initialization issues for the digest
Browse files Browse the repository at this point in the history
Previous patch was uncomplete.
  • Loading branch information
gganis committed Oct 6, 2016
1 parent 948fc73 commit 7d9f033
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/XrdCrypto/XrdCryptosslMsgDigest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@
#include "XrdCrypto/XrdCryptosslMsgDigest.hh"

//_____________________________________________________________________________
XrdCryptosslMsgDigest::XrdCryptosslMsgDigest(const char *dgst) :
XrdCryptoMsgDigest()
XrdCryptosslMsgDigest::XrdCryptosslMsgDigest(const char *dgst)
: XrdCryptoMsgDigest(), valid(0), mdctx(0)
{
// Constructor.
// Init the message digest calculation

valid = 0;
SetType(0);
Init(dgst);
}
Expand All @@ -55,7 +54,8 @@ XrdCryptosslMsgDigest::~XrdCryptosslMsgDigest()

if (valid) {
unsigned char mdval[EVP_MAX_MD_SIZE];
EVP_DigestFinal(&mdctx, mdval, 0);
EVP_DigestFinal_ex(mdctx, mdval, 0);
EVP_MD_CTX_destroy(mdctx);
}
}

Expand Down Expand Up @@ -88,8 +88,10 @@ int XrdCryptosslMsgDigest::Init(const char *dgst)
}

// Init digest machine
if (!EVP_DigestInit_ex(&mdctx, md, NULL)) {
mdctx = EVP_MD_CTX_create();
if (!EVP_DigestInit_ex(mdctx, md, NULL)) {
PRINT("ERROR: cannot initialize digest");
EVP_MD_CTX_destroy(mdctx);
return -1;
}

Expand All @@ -106,8 +108,9 @@ int XrdCryptosslMsgDigest::Reset(const char *dgst)
// Re-Init the message digest calculation
if (valid) {
unsigned char mdval[EVP_MAX_MD_SIZE];
EVP_DigestFinal(&mdctx, mdval, 0);
EVP_DigestFinal_ex(mdctx, mdval, 0);
SetBuffer(0,0);
EVP_MD_CTX_destroy(mdctx);
}
valid = 0;
Init(dgst);
Expand All @@ -124,7 +127,7 @@ int XrdCryptosslMsgDigest::Update(const char *b, int l)
// Returns -1 if unsuccessful (digest not initialized), 0 otherwise.

if (Type()) {
EVP_DigestUpdate(&mdctx, (char *)b, l);
EVP_DigestUpdate(mdctx, (char *)b, l);
return 0;
}
return -1;
Expand All @@ -144,7 +147,7 @@ int XrdCryptosslMsgDigest::Final()

if (Type()) {
// Finalize what we have
if (EVP_DigestFinal_ex(&mdctx, mdval, &mdlen) == 1) {
if (EVP_DigestFinal_ex(mdctx, mdval, &mdlen) == 1) {
// Save result
SetBuffer(mdlen,(const char *)mdval);
// Notify, if requested
Expand Down
2 changes: 1 addition & 1 deletion src/XrdCrypto/XrdCryptosslMsgDigest.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class XrdCryptosslMsgDigest : public XrdCryptoMsgDigest
{
private:
bool valid;
EVP_MD_CTX mdctx;
EVP_MD_CTX *mdctx;

int Init(const char *dgst);

Expand Down

0 comments on commit 7d9f033

Please sign in to comment.