00001
00002
00003 #ifndef CRYPTOPP_MDC_H
00004 #define CRYPTOPP_MDC_H
00005
00006
00007
00008
00009 #include "seckey.h"
00010 #include "secblock.h"
00011 #include "misc.h"
00012
00013 NAMESPACE_BEGIN(CryptoPP)
00014
00015
00016 template <class T>
00017 struct MDC_Info : public FixedBlockSize<T::DIGESTSIZE>, public FixedKeyLength<T::BLOCKSIZE>
00018 {
00019 static std::string StaticAlgorithmName() {return std::string("MDC/")+T::StaticAlgorithmName();}
00020 };
00021
00022
00023
00024 template <class T>
00025 class MDC : public MDC_Info<T>
00026 {
00027 class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<MDC_Info<T> >
00028 {
00029 typedef typename T::HashWordType HashWordType;
00030
00031 public:
00032 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
00033 {
00034 this->AssertValidKeyLength(length);
00035 memcpy_s(m_key, m_key.size(), userKey, this->KEYLENGTH);
00036 T::CorrectEndianess(Key(), Key(), this->KEYLENGTH);
00037 }
00038
00039 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
00040 {
00041 T::CorrectEndianess(Buffer(), (HashWordType *)inBlock, this->BLOCKSIZE);
00042 T::Transform(Buffer(), Key());
00043 if (xorBlock)
00044 {
00045 T::CorrectEndianess(Buffer(), Buffer(), this->BLOCKSIZE);
00046 xorbuf(outBlock, xorBlock, m_buffer, this->BLOCKSIZE);
00047 }
00048 else
00049 T::CorrectEndianess((HashWordType *)outBlock, Buffer(), this->BLOCKSIZE);
00050 }
00051
00052 bool IsPermutation() const {return false;}
00053
00054 unsigned int OptimalDataAlignment() const {return sizeof(HashWordType);}
00055
00056 private:
00057 HashWordType *Key() {return (HashWordType *)m_key.data();}
00058 const HashWordType *Key() const {return (const HashWordType *)m_key.data();}
00059 HashWordType *Buffer() const {return (HashWordType *)m_buffer.data();}
00060
00061
00062 FixedSizeSecBlock<byte, MDC_Info<T>::KEYLENGTH, AllocatorWithCleanup<byte> > m_key;
00063 mutable FixedSizeSecBlock<byte, MDC_Info<T>::BLOCKSIZE, AllocatorWithCleanup<byte> > m_buffer;
00064 };
00065
00066 public:
00067
00068 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
00069 };
00070
00071 NAMESPACE_END
00072
00073 #endif