Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cCipherGCM.h
Go to the documentation of this file.
1 //
5 //
6 #ifndef _INC_cCipherGCM_H
7 #define _INC_cCipherGCM_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cCipherBase.h"
13 #include "cCipherTypeDef.h"
14 
15 namespace GrayLib
16 {
18  {
22 
23  public:
24  static const size_t k_BlockAlign = 16; // 128
25  static const UINT64 k_last4[k_BlockAlign];
26 
27  public:
28  UINT64 m_HL[k_BlockAlign];
29  UINT64 m_HH[k_BlockAlign];
30 
31  UINT64 m_len;
32  UINT64 m_add_len;
33  BYTE m_base_ectr[k_BlockAlign];
34  BYTE m_y[k_BlockAlign];
35  BYTE m_buf[k_BlockAlign];
36 
37  private:
38  HRESULT BuildGCMTable();
39  void MultiplyGCM(const BYTE x[k_BlockAlign], BYTE pOutput[k_BlockAlign]);
40  void SetZeroGCM();
41 
42  public:
43  cCipherGCM(bool bEncodeMode, CipherAlgorithm_TYPE eCipherAlgorithm)
44  : cCipherBlockBase(bEncodeMode, eCipherAlgorithm)
45  , m_len(0)
46  , m_add_len(0)
47  {
48  }
49  virtual ~cCipherGCM()
50  {
51  SetZeroGCM();
52  }
53 
54  virtual HRESULT SetCipherKey(const void* pKeyData, size_t nKeySize) override;
55 
56  virtual HRESULT AuthEncrypt(BYTE* pOutput, const BYTE* pInput, size_t nSize,
57  const BYTE* pIV, size_t nSizeIV,
58  const BYTE* pAdd, size_t nSizeAdd,
59  BYTE* pTag, size_t nSizeTag) override;
60 
61  virtual HRESULT AuthDecrypt(BYTE* pOutput, const BYTE* pInput, size_t nSize,
62  const BYTE* pIV, size_t nSizeIV,
63  const BYTE* pAdd, size_t nSizeAdd,
64  const BYTE* pTag, size_t nSizeTag) override;
65 
72  //
73  HRESULT StartGCM(const BYTE* pIV, size_t nSizeIV, const BYTE* pAdd, size_t nSizeAdd);
74 
79  // If buffers overlap, the output buffer must trail at least 8 bytes
80  // behind the input buffer.
85 
86  HRESULT UpdateGCM(BYTE* pOutput, const BYTE* pInput, size_t nSize);
87 
93  HRESULT FinishGCM(BYTE* pTag, size_t nSizeTag);
94 
96  };
97 
99  {
102  public:
104  {
105  }
106  virtual cCipherBase* AllocCipherAlg(bool bEncodeMode) const
107  {
108  return new cCipherGCM(bEncodeMode, CipherAlgorithm_AES);
109  }
110  };
111 
113  {
116  public:
118  {
119  }
120  virtual cCipherBase* AllocCipherAlg(bool bEncodeMode) const
121  {
122  return new cCipherGCM(bEncodeMode, CipherAlgorithm_Camellia);
123  }
124  };
125 }
126 
127 #endif // _INC_
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cCipherTypeDef.h:67
Definition: cCipherGCM.h:99
cCipherAlgGCM_AES()
Definition: cCipherGCM.h:103
virtual cCipherBase * AllocCipherAlg(bool bEncodeMode) const
Definition: cCipherGCM.h:106
Definition: cCipherGCM.h:113
virtual cCipherBase * AllocCipherAlg(bool bEncodeMode) const
Definition: cCipherGCM.h:120
cCipherAlgGCM_Camellia()
Definition: cCipherGCM.h:117
Definition: cCipherBase.h:125
Definition: cCipherBase.h:234
Definition: cCipherGCM.h:18
cCipherGCM(bool bEncodeMode, CipherAlgorithm_TYPE eCipherAlgorithm)
Definition: cCipherGCM.h:43
UNITTEST_FRIEND(cCipherGCM)
UINT64 m_len
Total data length.
Definition: cCipherGCM.h:31
UINT64 m_add_len
Total pAdd length.
Definition: cCipherGCM.h:32
virtual ~cCipherGCM()
Definition: cCipherGCM.h:49
Definition: cMesh.h:22
CipherAlgorithm_TYPE
Definition: cCipherBase.h:22
@ CipherAlgorithm_AES
Definition: cCipherBase.h:29
@ CipherAlgorithm_GCM_AES
Definition: cCipherBase.h:34
@ CipherAlgorithm_Camellia
Definition: cCipherBase.h:30
@ CipherAlgorithm_GCM_Camellia
Definition: cCipherBase.h:35