Crypto++  5.6.3
Free C++ class library of cryptographic schemes
mdc.h
Go to the documentation of this file.
1  // mdc.h - written and placed in the public domain by Wei Dai
2 
3 #ifndef CRYPTOPP_MDC_H
4 #define CRYPTOPP_MDC_H
5 
6 /** \file
7 */
8 
9 #include "seckey.h"
10 #include "secblock.h"
11 #include "misc.h"
12 
13 NAMESPACE_BEGIN(CryptoPP)
14 
15 //! _
16 template <class T>
17 struct MDC_Info : public FixedBlockSize<T::DIGESTSIZE>, public FixedKeyLength<T::BLOCKSIZE>
18 {
19  static std::string StaticAlgorithmName() {return std::string("MDC/")+T::StaticAlgorithmName();}
20 };
21 
22 //! <a href="http://www.weidai.com/scan-mirror/cs.html#MDC">MDC</a>
23 /*! a construction by Peter Gutmann to turn an iterated hash function into a PRF */
24 template <class T>
25 class MDC : public MDC_Info<T>
26 {
27  class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<MDC_Info<T> >
28  {
29  typedef typename T::HashWordType HashWordType;
30 
31  public:
32  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params)
33  {
34  this->AssertValidKeyLength(length);
35  memcpy_s(m_key, m_key.size(), userKey, this->KEYLENGTH);
36  T::CorrectEndianess(Key(), Key(), this->KEYLENGTH);
37  }
38 
39  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
40  {
41  T::CorrectEndianess(Buffer(), (HashWordType *)inBlock, this->BLOCKSIZE);
42  T::Transform(Buffer(), Key());
43  if (xorBlock)
44  {
45  T::CorrectEndianess(Buffer(), Buffer(), this->BLOCKSIZE);
46  xorbuf(outBlock, xorBlock, m_buffer, this->BLOCKSIZE);
47  }
48  else
49  T::CorrectEndianess((HashWordType *)outBlock, Buffer(), this->BLOCKSIZE);
50  }
51 
52  bool IsPermutation() const {return false;}
53 
54  unsigned int OptimalDataAlignment() const {return sizeof(HashWordType);}
55 
56  private:
57  HashWordType *Key() {return (HashWordType *)m_key.data();}
58  const HashWordType *Key() const {return (const HashWordType *)m_key.data();}
59  HashWordType *Buffer() const {return (HashWordType *)m_buffer.data();}
60 
61  // VC60 workaround: bug triggered if using FixedSizeAllocatorWithCleanup
64  };
65 
66 public:
67  //! use BlockCipher interface
69 };
70 
71 NAMESPACE_END
72 
73 #endif
_
Definition: mdc.h:17
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:117
Utility functions for the Crypto++ library.
static const int KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:122
MDC
Definition: mdc.h:25
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
Definition: misc.h:356
Classes and functions for secure memory allocations.
BlockCipherFinal< ENCRYPTION, Enc > Encryption
use BlockCipher interface
Definition: mdc.h:68
Inherited by algorithms with fixed block size.
Definition: seckey.h:34
Classes and functions for implementing secret key algorithms.
Fixed size stack-based SecBlock.
Definition: secblock.h:750
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Definition: misc.cpp:28
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:303
Crypto++ library namespace.
static const int BLOCKSIZE
The block size of the algorithm provided as a constant.
Definition: seckey.h:38
const char * Key()
ConstByteArrayParameter.
Definition: argnames.h:20
Interface for retrieving values given their names.
Definition: cryptlib.h:277