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