File indexing completed on 2025-01-18 09:55:04
0001
0002
0003
0004
0005
0006 #ifndef CRYPTOPP_MDC_H
0007 #define CRYPTOPP_MDC_H
0008
0009 #include "seckey.h"
0010 #include "secblock.h"
0011 #include "misc.h"
0012
0013
0014 #define HashWordPtr(x) ((HashWordType*)(void*)(x))
0015 #define ConstHashWordPtr(x) ((const HashWordType*)(const void*)(x))
0016
0017 NAMESPACE_BEGIN(CryptoPP)
0018
0019
0020
0021 template <class B>
0022 struct MDC_Info : public FixedBlockSize<B::DIGESTSIZE>, public FixedKeyLength<B::BLOCKSIZE>
0023 {
0024 static std::string StaticAlgorithmName() {return std::string("MDC/")+B::StaticAlgorithmName();}
0025 };
0026
0027
0028
0029
0030
0031 template <class H>
0032 class MDC : public MDC_Info<H>
0033 {
0034
0035 class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<MDC_Info<H> >
0036 {
0037 typedef typename H::HashWordType HashWordType;
0038
0039 public:
0040 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
0041 {
0042 CRYPTOPP_UNUSED(params);
0043 this->AssertValidKeyLength(length);
0044 ConditionalByteReverse(BIG_ENDIAN_ORDER, Key(), ConstHashWordPtr(userKey), this->KEYLENGTH);
0045 }
0046
0047 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
0048 {
0049 ConditionalByteReverse(BIG_ENDIAN_ORDER, Buffer(), ConstHashWordPtr(inBlock), this->BLOCKSIZE);
0050 H::Transform(Buffer(), Key());
0051
0052 if (xorBlock)
0053 {
0054 ConditionalByteReverse(BIG_ENDIAN_ORDER, Buffer(), Buffer(), this->BLOCKSIZE);
0055 xorbuf(outBlock, xorBlock, m_buffer, this->BLOCKSIZE);
0056 }
0057 else
0058 {
0059 ConditionalByteReverse(BIG_ENDIAN_ORDER, HashWordPtr(outBlock), Buffer(), this->BLOCKSIZE);
0060 }
0061 }
0062
0063 bool IsPermutation() const {return false;}
0064
0065 unsigned int OptimalDataAlignment() const {return sizeof(HashWordType);}
0066
0067 private:
0068 HashWordType *Key() {return HashWordPtr(m_key.data());}
0069 const HashWordType *Key() const {return ConstHashWordPtr(m_key.data());}
0070 HashWordType *Buffer() const {return HashWordPtr(m_buffer.data());}
0071
0072
0073 FixedSizeSecBlock<byte, MDC_Info<H>::KEYLENGTH, AllocatorWithCleanup<byte> > m_key;
0074 mutable FixedSizeSecBlock<byte, MDC_Info<H>::BLOCKSIZE, AllocatorWithCleanup<byte> > m_buffer;
0075 };
0076
0077 public:
0078
0079 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0080 };
0081
0082 NAMESPACE_END
0083
0084 #endif