PKIFCryptoPPExternalDigest.cpp
Go to the documentation of this file.00001
00010 #include "PKIFCryptoPPExternalDigest.h"
00011
00012 using namespace CryptoPP;
00013
00021 PKIFCryptoPPExternalDigest::~PKIFCryptoPPExternalDigest()
00022 {
00023 if(m_digestBuf) {
00024 delete[] m_digestBuf;
00025 m_digestBuf = 0;
00026 }
00027 }
00028
00037 void PKIFCryptoPPExternalDigest::SetDigest(const unsigned char * buf, unsigned int length)
00038 {
00039 if(m_digestBuf) {
00040 delete[] m_digestBuf;
00041 m_digestSize = length;
00042 m_digestBuf = new unsigned char[m_digestSize];
00043 } else {
00044 m_digestSize = length;
00045 m_digestBuf = new unsigned char[m_digestSize];
00046 }
00047 memcpy(m_digestBuf,buf,m_digestSize);
00048 }
00049
00055 unsigned int PKIFCryptoPPExternalDigest::DigestSize() const {
00056 return m_digestSize;
00057 }
00058
00064 void PKIFCryptoPPExternalDigest::TruncatedFinal(
00066 byte * digest,
00068 size_t digestSize)
00069 {
00070
00071
00072
00073 if(digestSize > 0) {
00074 memcpy(digest,m_digestBuf,digestSize > m_digestSize ? m_digestSize : digestSize);
00075 }
00076 }
00077
00084 bool PKIFCryptoPPExternalDigest::TruncatedVerify(
00086 const byte * digest,
00088 size_t digestLength)
00089 {
00090 if(digestLength != m_digestSize) return false;
00091 return (0 == memcmp(m_digestBuf,digest, digestLength));
00092 }
00093
00094
00103 PKIFCryptoPPExternalDigestAccumulator * NewEDAccumulator(
00105 unsigned char * digest,
00107 size_t len)
00108 {
00109
00110
00111
00112
00113
00114
00115
00116 PKIFCryptoPPExternalDigestAccumulator * acc = new PKIFCryptoPPExternalDigestAccumulator();
00117 HashTransformation & h = acc->AccessHash();
00118 PKIFCryptoPPExternalDigest * ed = dynamic_cast<PKIFCryptoPPExternalDigest *>(&h);
00119 ed->SetDigest(digest,(unsigned int)len);
00120 return acc;
00121 }