Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cCipherAES Class Reference

#include <cCipherAES.h>

Inheritance diagram for GrayLib::cCipherAES:
GrayLib::cCipherBase Gray::CObject ICipherBase

Public Member Functions

 cCipherAES (bool bEncodeMode)
 
virtual ~cCipherAES ()
 
virtual size_t get_BlockAlignSize () const override
 
virtual HRESULT SetCipherKey (const void *pKeyData, size_t nKeySize) override
 
virtual HRESULT CipherModeECB (BYTE *pOutput, const BYTE *pInput) override
 
virtual HRESULT CipherModeCBC (BYTE *pOutput, const BYTE *pInput, size_t nSize, BYTE *pIV) override
 
virtual HRESULT CipherModeCFB (BYTE *pOutput, const BYTE *pInput, size_t nSize, BYTE pIV[k_BlockAlign], size_t *pnIVOffset) override
 
virtual HRESULT CipherModeCTR (BYTE *pOutput, const BYTE *pInput, size_t nSize, BYTE pNonceCounter[k_BlockAlign], size_t *pNCOffset, BYTE pStreamBlock[k_BlockAlign]) override
 
virtual HRESULT Cipher (BYTE *pOutput, const BYTE *pInput, size_t nSizeBytes) override
 
 UNITTEST_FRIEND (cCipherAES)
 
- Public Member Functions inherited from GrayLib::cCipherBase
 cCipherBase (bool bEncodeMode=true, CIPHER_BLOCK_TYPE eBlockMode=CIPHER_BLOCK_UNK) noexcept
 
virtual ~cCipherBase ()
 
void put_EncodeMode (bool bEncodeMode) noexcept
 
bool get_EncodeMode () const noexcept
 
void put_BlockMode (CIPHER_BLOCK_TYPE eBlockMode) noexcept
 
virtual HRESULT CipherModeCFB (BYTE *pOutput, const BYTE *pInput, size_t nSize, BYTE *pIV, size_t *pIVOffset)
 
virtual HRESULT CipherModeCTR (BYTE *pOutput, const BYTE *pInput, size_t nSize, BYTE *pNonceCounter, size_t *pNCOffset, BYTE *pStreamBlock)
 
- Public Member Functions inherited from Gray::CObject
virtual ~CObject ()
 
virtual bool isValidCheck () const noexcept
 < memory allocation and structure definitions are valid. More...
 
virtual void AssertValid () const
 < memory allocation and structure definitions are valid. More...
 
virtual void Serialize (cArchive &a)
 

Public Attributes

int m_nRounds
 number of rounds. based on key size. More...
 
UINT32 m_RK [68]
 max round keys. 14*4 + 18 More...
 

Static Public Attributes

static const size_t k_BlockAlign = 16
 
static const cCipherAESTables_T = nullptr
 static tables. constructed on demand. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from GrayLib::cCipherBase
static size_t GRAYCALL CopyFillX (void *pOutput, size_t nOutSize, const void *pInput, size_t nInputSize)
 
- Protected Attributes inherited from GrayLib::cCipherBase
bool m_bEncodeMode
 We are in encode/encrypt mode vs decode/decrypt mode. More...
 
CIPHER_BLOCK_TYPE m_eBlockMode
 Cipher block mode. How are sequences of blocks treated? More...
 

Constructor & Destructor Documentation

◆ cCipherAES()

GrayLib::cCipherAES::cCipherAES ( bool  bEncodeMode)
inline

◆ ~cCipherAES()

virtual GrayLib::cCipherAES::~cCipherAES ( )
inlinevirtual

Member Function Documentation

◆ Cipher()

HRESULT GrayLib::cCipherAES::Cipher ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSizeBytes 
)
overridevirtual

Any CIPHER_BLOCK_TYPE

Returns
<0 = error. Amount of data i could actually process (some may be dropped for alignment) NEVER ADDED.

Reimplemented from GrayLib::cCipherBase.

◆ CipherModeCBC()

HRESULT GrayLib::cCipherAES::CipherModeCBC ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSize,
BYTE *  pIV 
)
overridevirtual

CIPHER_BLOCK_CBC AES-CBC buffer encryption/decryption [k_BlockAlign] CIPHER_BLOCK_CBC Length should be a multiple of the block size (16 bytes)

Note
Upon exit, the content of the IV is updated so that you can call the function same function again on the following block(s) of data and get the same result as if it was encrypted in one call. This allows a "streaming" usage. If on the other hand you need to retain the contents of the IV, you should either save it manually or use the cipher module instead.
  • pOutput = buffer holding the output data
  • pInput = buffer holding the input data
  • nSize = length of the input data
  • pIV = initialization vector (updated after use)
    Returns
    0 if successful, or NTE_BAD_LEN

Reimplemented from GrayLib::cCipherBase.

◆ CipherModeCFB()

HRESULT GrayLib::cCipherAES::CipherModeCFB ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSize,
BYTE  pIV[k_BlockAlign],
size_t *  pnIVOffset 
)
overridevirtual

CIPHER_BLOCK_CFB AES-CFB128 buffer encryption/decryption. CIPHER_BLOCK_CFB

Note
Due to the nature of CFB you should use the same key schedule for both encryption and decryption. So a context initialized with aes_setkey_enc() for bEncodeMode.
Upon exit, the content of the IV is updated so that you can call the function same function again on the following block(s) of data and get the same result as if it was encrypted in one call. This allows a "streaming" usage. If on the other hand you need to retain the contents of the IV, you should either save it manually or use the cipher module instead.
  • pOutput = buffer holding the output data
  • pInput = buffer holding the input data
  • nSize = length of the input data
  • pIV = initialization vector (updated after use)
  • pnIVOffset = offset in IV (updated after use)
Returns
0 if successful

◆ CipherModeCTR()

HRESULT GrayLib::cCipherAES::CipherModeCTR ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSize,
BYTE  pNonceCounter[k_BlockAlign],
size_t *  pNCOffset,
BYTE  pStreamBlock[k_BlockAlign] 
)
overridevirtual

CIPHER_BLOCK_CTR AES-CTR buffer encryption/decryption. CIPHER_BLOCK_CTR

Warning: You have to keep the maximum use of your counter in mind!

Note: Due to the nature of CTR you should use the same key schedule for both encryption and decryption. So a context initialized with aes_setkey_enc() for bEncodeMode

  • pOutput = buffer holding the output data
  • pInput = buffer holding the input data
  • nSize = length of the input data
  • pNonceCounter = The 128-bit nonce and counter.
  • pNCOffset = The offset in the current stream_block (for resuming within current cipher stream). The offset pointer to should be 0 at the start of a stream.
  • stream_block = The saved stream-block for resuming. Is overwritten by the function.
    Returns
    0 if successful

◆ CipherModeECB()

HRESULT GrayLib::cCipherAES::CipherModeECB ( BYTE *  pOutput,
const BYTE *  pInput 
)
overridevirtual

CIPHER_BLOCK_ECB AES-ECB block encryption/decryption. k_BlockAlign CIPHER_BLOCK_ECB

  • pInput = 16-byte input block
  • pOutput = 16-byte output block
    Returns
    0 if successful

Reimplemented from GrayLib::cCipherBase.

◆ get_BlockAlignSize()

virtual size_t GrayLib::cCipherAES::get_BlockAlignSize ( ) const
inlineoverridevirtual

override ICipherBase

Returns
Data block alignment for this type of Cipher.

Reimplemented from GrayLib::cCipherBase.

◆ SetCipherKey()

HRESULT GrayLib::cCipherAES::SetCipherKey ( const void *  pKeyData,
size_t  nKeySize 
)
overridevirtual

set AES key schedule

  • pKeyData = set cipher key. Fix it if unaligned.
  • nKeySize = must be 128/8, 192/8 or 256/8
    Returns
    0 if successful, or NTE_BAD_LEN

Reimplemented from GrayLib::cCipherBase.

◆ UNITTEST_FRIEND()

GrayLib::cCipherAES::UNITTEST_FRIEND ( cCipherAES  )

Member Data Documentation

◆ k_BlockAlign

const size_t GrayLib::cCipherAES::k_BlockAlign = 16
static

◆ m_nRounds

int GrayLib::cCipherAES::m_nRounds

number of rounds. based on key size.

◆ m_RK

UINT32 GrayLib::cCipherAES::m_RK[68]

max round keys. 14*4 + 18

◆ s_T

const cCipherAESTable * GrayLib::cCipherAES::s_T = nullptr
static

static tables. constructed on demand.


The documentation for this class was generated from the following files: