Fabcoin Core  0.16.2
P2P Digital Currency
ccm.h
Go to the documentation of this file.
1 // ccm.h - written and placed in the public domain by Wei Dai
2 
6 
7 #ifndef CRYPTOPP_CCM_H
8 #define CRYPTOPP_CCM_H
9 
10 #include "authenc.h"
11 #include "modes.h"
12 
14 
20 {
21 public:
23  : m_digestSize(0), m_L(0), m_messageLength(0), m_aadLength(0) {}
24 
25  // AuthenticatedSymmetricCipher
26  std::string AlgorithmName() const
27  {return GetBlockCipher().AlgorithmName() + std::string("/CCM");}
28  size_t MinKeyLength() const
29  {return GetBlockCipher().MinKeyLength();}
30  size_t MaxKeyLength() const
31  {return GetBlockCipher().MaxKeyLength();}
32  size_t DefaultKeyLength() const
33  {return GetBlockCipher().DefaultKeyLength();}
34  size_t GetValidKeyLength(size_t keylength) const
35  {return GetBlockCipher().GetValidKeyLength(keylength);}
36  bool IsValidKeyLength(size_t keylength) const
37  {return GetBlockCipher().IsValidKeyLength(keylength);}
38  unsigned int OptimalDataAlignment() const
39  {return GetBlockCipher().OptimalDataAlignment();}
41  {return UNIQUE_IV;}
42  unsigned int IVSize() const
43  {return 8;}
44  unsigned int MinIVLength() const
45  {return 7;}
46  unsigned int MaxIVLength() const
47  {return 13;}
48  unsigned int DigestSize() const
49  {return m_digestSize;}
51  {return W64LIT(0)-1;}
53  {return m_L<8 ? (W64LIT(1)<<(8*m_L))-1 : W64LIT(0)-1;}
55  {return true;}
56  void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength);
57 
58 protected:
59  // AuthenticatedSymmetricCipherBase
61  {return true;}
62  unsigned int AuthenticationBlockSize() const
63  {return GetBlockCipher().BlockSize();}
64  void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params);
65  void Resync(const byte *iv, size_t len);
66  size_t AuthenticateBlocks(const byte *data, size_t len);
67  void AuthenticateLastHeaderBlock();
68  void AuthenticateLastConfidentialBlock();
69  void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
71 
72  virtual BlockCipher & AccessBlockCipher() =0;
73  virtual int DefaultDigestSize() const =0;
74 
75  const BlockCipher & GetBlockCipher() const {return const_cast<CCM_Base *>(this)->AccessBlockCipher();};
76  byte *CBC_Buffer() {return m_buffer+REQUIRED_BLOCKSIZE;}
77 
78  enum {REQUIRED_BLOCKSIZE = 16};
79  int m_digestSize, m_L;
80  word64 m_messageLength, m_aadLength;
82 };
83 
90 template <class T_BlockCipher, int T_DefaultDigestSize, bool T_IsEncryption>
91 class CCM_Final : public CCM_Base
92 {
93 public:
94  static std::string StaticAlgorithmName()
95  {return T_BlockCipher::StaticAlgorithmName() + std::string("/CCM");}
97  {return T_IsEncryption;}
98 
99 private:
101  int DefaultDigestSize() const {return T_DefaultDigestSize;}
102  typename T_BlockCipher::Encryption m_cipher;
103 };
104 
113 template <class T_BlockCipher, int T_DefaultDigestSize = 16>
115 {
118 };
119 
121 
122 #endif
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: ccm.h:26
unsigned int AuthenticationBlockSize() const
Definition: ccm.h:62
bool AuthenticationIsOnPlaintext() const
Definition: ccm.h:60
unsigned int MinIVLength() const
Provides the minimum size of an IV.
Definition: ccm.h:44
SymmetricCipher & AccessSymmetricCipher()
Definition: ccm.h:70
uint8_t byte
Definition: Common.h:57
Class file for modes of operation.
unsigned int MaxIVLength() const
Provides the maximum size of an IV.
Definition: ccm.h:46
BlockCipher & AccessBlockCipher()
Definition: ccm.h:100
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
CCM block cipher mode of operation.
Definition: ccm.h:114
T_BlockCipher::Encryption m_cipher
Definition: ccm.h:102
Provides Encryption and Decryption typedefs used by derived classes to implement an authenticated enc...
Definition: seckey.h:437
int DefaultDigestSize() const
Definition: ccm.h:101
CCM_Final< T_BlockCipher, T_DefaultDigestSize, true > Encryption
Definition: ccm.h:116
CTR_Mode_ExternalCipher::Encryption m_ctr
Definition: ccm.h:81
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1095
unsigned int IVSize() const
Returns length of the IV accepted by this object.
Definition: ccm.h:42
bool IsValidKeyLength(size_t keylength) const
Returns whether keylength is a valid key length.
Definition: ccm.h:36
size_t DefaultKeyLength() const
Returns default key length.
Definition: ccm.h:32
bool NeedsPrespecifiedDataLengths() const
Determines if data lengths must be specified prior to inputting data.
Definition: ccm.h:54
word64 m_messageLength
Definition: ccm.h:80
#define W64LIT(x)
Definition: config.h:241
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1103
Base implementation for one direction (encryption or decryption) of a stream cipher or block cipher m...
Definition: authenc.h:19
size_t MinKeyLength() const
Returns smallest valid key length.
Definition: ccm.h:28
unsigned long long word64
Definition: config.h:240
size_t MaxKeyLength() const
Returns largest valid key length.
Definition: ccm.h:30
CCM block cipher base implementation.
Definition: ccm.h:19
size_t GetValidKeyLength(size_t keylength) const
Returns a valid key length for the algorithm.
Definition: ccm.h:34
#define CRYPTOPP_NO_VTABLE
Definition: config.h:369
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: ccm.h:40
byte * CBC_Buffer()
Definition: ccm.h:76
lword MaxHeaderLength() const
Provides the maximum length of AAD that can be input.
Definition: ccm.h:50
IV_Requirement
Secure IVs requirements as enumerated values.
Definition: cryptlib.h:598
lword MaxMessageLength() const
Provides the maximum length of encrypted data.
Definition: ccm.h:52
#define NAMESPACE_END
Definition: config.h:201
const BlockCipher & GetBlockCipher() const
Definition: ccm.h:75
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: ccm.h:38
word64 lword
Definition: config.h:245
int m_L
Definition: ccm.h:79
#define CRYPTOPP_DLL
Definition: config.h:704
CCM_Final< T_BlockCipher, T_DefaultDigestSize, false > Decryption
Definition: ccm.h:117
Base classes for working with authenticated encryption modes of encryption.
uint8_t const * data
Definition: sha3.h:19
static std::string StaticAlgorithmName()
Definition: ccm.h:94
CCM_Base()
Definition: ccm.h:22
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: ccm.h:48
CCM block cipher final implementation.
Definition: ccm.h:91
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: ccm.h:96
Interface for retrieving values given their names.
Definition: cryptlib.h:279