Fabcoin Core  0.16.2
P2P Digital Currency
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 
8 
9 #include "seckey.h"
10 #include "secblock.h"
11 #include "misc.h"
12 
14 
15 template <class T>
18 struct MDC_Info : public FixedBlockSize<T::DIGESTSIZE>, public FixedKeyLength<T::BLOCKSIZE>
19 {
20  static std::string StaticAlgorithmName() {return std::string("MDC/")+T::StaticAlgorithmName();}
21 };
22 
23 
28 template <class T>
29 class MDC : public MDC_Info<T>
30 {
33  class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<MDC_Info<T> >
34  {
35  typedef typename T::HashWordType HashWordType;
36 
37  public:
38  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params)
39  {
40  this->AssertValidKeyLength(length);
41  memcpy_s(m_key, m_key.size(), userKey, this->KEYLENGTH);
42  T::CorrectEndianess(Key(), Key(), this->KEYLENGTH);
43  }
44 
45  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
46  {
47  T::CorrectEndianess(Buffer(), (HashWordType *)inBlock, this->BLOCKSIZE);
48  T::Transform(Buffer(), Key());
49  if (xorBlock)
50  {
51  T::CorrectEndianess(Buffer(), Buffer(), this->BLOCKSIZE);
52  xorbuf(outBlock, xorBlock, m_buffer, this->BLOCKSIZE);
53  }
54  else
55  T::CorrectEndianess((HashWordType *)outBlock, Buffer(), this->BLOCKSIZE);
56  }
57 
58  bool IsPermutation() const {return false;}
59 
60  unsigned int OptimalDataAlignment() const {return sizeof(HashWordType);}
61 
62  private:
63  HashWordType *Key() {return (HashWordType *)m_key.data();}
64  const HashWordType *Key() const {return (const HashWordType *)m_key.data();}
65  HashWordType *Buffer() const {return (HashWordType *)m_buffer.data();}
66 
67  // VC60 workaround: bug triggered if using FixedSizeAllocatorWithCleanup
70  };
71 
72 public:
75 };
76 
78 
79 #endif
MDC_Info cipher information.
Definition: mdc.h:18
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
Encrypt or decrypt a block.
Definition: mdc.h:45
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:127
uint8_t byte
Definition: Common.h:57
Utility functions for the Crypto++ library.
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: mdc.h:60
FixedSizeSecBlock< byte, MDC_Info< T >::KEYLENGTH, AllocatorWithCleanup< byte > > m_key
Definition: mdc.h:68
#define T(i, x)
MDC cipher.
Definition: mdc.h:29
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
Definition: misc.h:366
HashWordType * Key()
Definition: mdc.h:63
HashWordType * Buffer() const
Definition: mdc.h:65
static std::string StaticAlgorithmName()
Definition: mdc.h:20
Classes and functions for secure memory allocations.
BlockCipherFinal< ENCRYPTION, Enc > Encryption
use BlockCipher interface
Definition: mdc.h:74
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
const HashWordType * Key() const
Definition: mdc.h:64
Classes and functions for implementing secret key algorithms.
T::HashWordType HashWordType
Definition: mdc.h:35
Fixed size stack-based SecBlock.
Definition: secblock.h:753
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Definition: misc.cpp:28
FixedSizeSecBlock< byte, MDC_Info< T >::BLOCKSIZE, AllocatorWithCleanup< byte > > m_buffer
Definition: mdc.h:69
#define CRYPTOPP_NO_VTABLE
Definition: config.h:369
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params)
Sets the key for this object without performing parameter validation.
Definition: mdc.h:38
#define NAMESPACE_END
Definition: config.h:201
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:311
MDC cipher encryption operation.
Definition: mdc.h:33
bool IsPermutation() const
returns true if this is a permutation (i.e. there is an inverse transformation)
Definition: mdc.h:58
Interface for retrieving values given their names.
Definition: cryptlib.h:279