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

#include <cCipherBase.h>

Inheritance diagram for GrayLib::cCipherBase:
Gray::CObject ICipherBase GrayLib::cCipherAES GrayLib::cCipherBlockBase GrayLib::cCipherBlowfish GrayLib::cCipherCamellia GrayLib::cCipherDES GrayLib::cCipherNone GrayLib::cCipherRC4 GrayLib::cCipherRotary

Public Member Functions

 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 size_t get_BlockAlignSize () const override
 
virtual HRESULT SetCipherKey (const void *pKeyData=nullptr, size_t nKeySize=0)
 
virtual HRESULT CipherModeECB (BYTE *pOutput, const BYTE *pInput)
 
virtual HRESULT CipherModeCBC (BYTE *pOutput, const BYTE *pInput, size_t nSize, BYTE *pIV)
 
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)
 
virtual HRESULT Cipher (BYTE *pOutput, const BYTE *pInput, size_t nSize) override
 
- 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)
 

Static Public Member Functions

static size_t GRAYCALL CopyFillX (void *pOutput, size_t nOutSize, const void *pInput, size_t nInputSize)
 

Protected Attributes

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...
 

Detailed Description

Abstract Base class for all block cipher crypt algorithms. State information.

Note
Some algorithms may have min/max key sizes. (get_BlockAlignSize())
State information can not always be shared with encrypt and decrypt sides of the same channel ! Base for: cCipherAES, cCipherBlowfish, cCipherCamellia, cCipherDES, cCipherRC4 Base for wrappers cCipherCCM and cCipherGCM. Defined by cCipherTypeDef

Constructor & Destructor Documentation

◆ cCipherBase()

GrayLib::cCipherBase::cCipherBase ( bool  bEncodeMode = true,
CIPHER_BLOCK_TYPE  eBlockMode = CIPHER_BLOCK_UNK 
)
inlinenoexcept

◆ ~cCipherBase()

virtual GrayLib::cCipherBase::~cCipherBase ( )
inlinevirtual

Member Function Documentation

◆ Cipher()

virtual HRESULT GrayLib::cCipherBase::Cipher ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSize 
)
inlineoverridevirtual

Encrypt using STREAM. CIPHER_BLOCK_UNK default just copy the stream un-ciphered.

Reimplemented in GrayLib::cCipherRotary, GrayLib::cCipherRC4, GrayLib::cCipherDES, GrayLib::cCipherBlowfish, GrayLib::cCipherNone, GrayLib::cCipherAES, and GrayLib::cCipherCamellia.

◆ CipherModeCBC()

virtual HRESULT GrayLib::cCipherBase::CipherModeCBC ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSize,
BYTE *  pIV 
)
inlinevirtual

◆ CipherModeCFB()

virtual HRESULT GrayLib::cCipherBase::CipherModeCFB ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSize,
BYTE *  pIV,
size_t *  pIVOffset 
)
inlinevirtual

CIPHER_BLOCK_CFB for: cCipherAES, cCipherBlowfish, cCipherCamellia

◆ CipherModeCTR()

virtual HRESULT GrayLib::cCipherBase::CipherModeCTR ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSize,
BYTE *  pNonceCounter,
size_t *  pNCOffset,
BYTE *  pStreamBlock 
)
inlinevirtual

CIPHER_BLOCK_CTR

◆ CipherModeECB()

virtual HRESULT GrayLib::cCipherBase::CipherModeECB ( BYTE *  pOutput,
const BYTE *  pInput 
)
inlinevirtual

CIPHER_BLOCK_ECB Fixed size block. 8 or 16 bytes.

Reimplemented in GrayLib::cCipherAES.

◆ CopyFillX()

size_t GRAYCALL GrayLib::cCipherBase::CopyFillX ( void *  pOutput,
size_t  nOutSize,
const void *  pInput,
size_t  nInputSize 
)
static

Used to copy a crypt key. Maybe be bigger than native key size (wrap XOR). else Fill any extra space by just duping/repeating the key.

Returns
Smaller size of nOutSize and nInputSize.

◆ get_BlockAlignSize()

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

override ICipherBase

Returns
Data block alignment for this type of Cipher. default = no min block size (1 byte).

Reimplemented in GrayLib::cCipherDES, GrayLib::cCipherCamellia, GrayLib::cCipherBlowfish, GrayLib::cCipherNone, and GrayLib::cCipherAES.

◆ get_EncodeMode()

bool GrayLib::cCipherBase::get_EncodeMode ( ) const
inlinenoexcept

◆ put_BlockMode()

void GrayLib::cCipherBase::put_BlockMode ( CIPHER_BLOCK_TYPE  eBlockMode)
inlinenoexcept

◆ put_EncodeMode()

void GrayLib::cCipherBase::put_EncodeMode ( bool  bEncodeMode)
inlinenoexcept

Are we crypt/encode or decrypt/decode mode ?

Note
we may need to call SetCipherKey again!

◆ SetCipherKey()

virtual HRESULT GrayLib::cCipherBase::SetCipherKey ( const void *  pKeyData = nullptr,
size_t  nKeySize = 0 
)
inlinevirtual

defaults to doing nothing. Key may or may not be properly sized for the algorithm. Make it best fit.

  • nKeySize = bytes.

Reimplemented in GrayLib::cCipherRotary, GrayLib::cCipherRC4, GrayLib::cCipherBlowfish, GrayLib::cCipherNone, GrayLib::cCipherGCM, GrayLib::cCipherDES, GrayLib::cCipherCCM, GrayLib::cCipherCamellia, and GrayLib::cCipherAES.

Member Data Documentation

◆ m_bEncodeMode

bool GrayLib::cCipherBase::m_bEncodeMode
protected

We are in encode/encrypt mode vs decode/decrypt mode.

◆ m_eBlockMode

CIPHER_BLOCK_TYPE GrayLib::cCipherBase::m_eBlockMode
protected

Cipher block mode. How are sequences of blocks treated?


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