sP2P c++ STL *nix API  1.2
NAT traversal and peer-to-peer networking API providing all utilities needed to build peer-to-peer application straigth out of box
 All Classes Functions Variables Typedefs Enumerations Enumerator
sp2plib::AESNetworkStream Class Reference

Provides methods to prepare data to be sent crypted over networks channels and to decrypt received data. ATTENTION - This class algorithms are not standardized!!! This class is designed especially for use with SP2P API as easy to use utility. It uses specific methods to guaranty cryped data transmission without delays. Padding is not optional, this class handles padding in a way so excess data transmission is avoided as much as it can be. Use of this class for stream communication (TCP). For UDP datagrams crypting simply use AES class More...

#include <AESNetworkStream.h>

Public Member Functions

 AESNetworkStream (AES::KeySize AESKeySize, unsigned char *AESKeyBytes, AES::Mode AESChiperMode=AES::AESM_CBC, unsigned char *CBCInitialVector=0)
 Initializes AESNetworkStream object
 
unsigned char * CBCInitialVector ()
 Gets the AES CBC initial vector used for first crypted chunks when AES in CBC mode
 
int WriteForCrypt (unsigned char *buff, int offset, int length)
 Writes unencrypted data to crypt buffer to be extracted crypted using ReadCrypted method
 
int ReadCrypted (unsigned char *buff, int offset, int desired_length)
 Reads reads data from crypt buffer, crypts it and stores it in buffer
 
int WriteForDeCrypt (unsigned char *buff, int offset, int length)
 Writes encrypted data to de-crypt buffer to be extracted decrypted using ReadDeCrypted method
 
int ReadDeCrypted (unsigned char *buff, int offset, int desired_length)
 Reads reads data from de-crypt buffer, decrypts it and stores it in buffer
 
int AvailableCrypted ()
 Gets total available size of crypted data to take
 
int AvailableDeCrypted ()
 Gets total available size of decrypted data to take
 
void ClearCrypted ()
 Clears all available crypted data that could be read form stream
 
void ClearDeCrypted ()
 Clears all available decrypted data that could be read form stream
 
void ClearAuxBuffers ()
 Clears all free buffer slots which result is heap memory deallocation, this operation can not cause data loss
 
void Clear ()
 Clears both crypt, de-crypt buffer and free slot buffer, all presend data will be thrown away. You can use AESNetworkStream normaly after that. AESNetworkStream will ocupate heap memory so it can hold all crypted / decrypted data. Total occupied data will be equal to maximal length of crypted and decurypted data in some moment hold in inner data structures AESNetworkStream does not free this memory until you delete whole AESNetworkStream object or call Clear. So you can call Clear after intense use when you know you will not use it for some time (If you use AESNetworkStream so data is hold for some period of time and if memory consumption is important factor)
 
 ~AESNetworkStream ()
 Destructor
 

Detailed Description

Provides methods to prepare data to be sent crypted over networks channels and to decrypt received data. ATTENTION - This class algorithms are not standardized!!! This class is designed especially for use with SP2P API as easy to use utility. It uses specific methods to guaranty cryped data transmission without delays. Padding is not optional, this class handles padding in a way so excess data transmission is avoided as much as it can be. Use of this class for stream communication (TCP). For UDP datagrams crypting simply use AES class

Constructor & Destructor Documentation

sp2plib::AESNetworkStream::AESNetworkStream ( AES::KeySize  AESKeySize,
unsigned char *  AESKeyBytes,
AES::Mode  AESChiperMode = AES::AESM_CBC,
unsigned char *  CBCInitialVector = 0 
)

Initializes AESNetworkStream object

Parameters
AESKeySizeSize of AES key
AESKeyBytesAES key bytes
AESChiperModeSpecifies AES chiper mode. Note that padding is hanled by AESNetworkStream is special way, you dont need to worry about large data in CBC mode. CBC mode is recomended!
CBCInitialVectorIf CBC mode is used this argumenet specifies initial CBC vector used for first chunk XOR pair. If not or null provided and AES in CBC mode random sequence will be generated
sp2plib::AESNetworkStream::~AESNetworkStream ( )

Destructor

Member Function Documentation

int sp2plib::AESNetworkStream::AvailableCrypted ( )

Gets total available size of crypted data to take

int sp2plib::AESNetworkStream::AvailableDeCrypted ( )

Gets total available size of decrypted data to take

unsigned char* sp2plib::AESNetworkStream::CBCInitialVector ( )

Gets the AES CBC initial vector used for first crypted chunks when AES in CBC mode

void sp2plib::AESNetworkStream::Clear ( )

Clears both crypt, de-crypt buffer and free slot buffer, all presend data will be thrown away. You can use AESNetworkStream normaly after that. AESNetworkStream will ocupate heap memory so it can hold all crypted / decrypted data. Total occupied data will be equal to maximal length of crypted and decurypted data in some moment hold in inner data structures AESNetworkStream does not free this memory until you delete whole AESNetworkStream object or call Clear. So you can call Clear after intense use when you know you will not use it for some time (If you use AESNetworkStream so data is hold for some period of time and if memory consumption is important factor)

void sp2plib::AESNetworkStream::ClearAuxBuffers ( )

Clears all free buffer slots which result is heap memory deallocation, this operation can not cause data loss

void sp2plib::AESNetworkStream::ClearCrypted ( )

Clears all available crypted data that could be read form stream

void sp2plib::AESNetworkStream::ClearDeCrypted ( )

Clears all available decrypted data that could be read form stream

int sp2plib::AESNetworkStream::ReadCrypted ( unsigned char *  buff,
int  offset,
int  desired_length 
)

Reads reads data from crypt buffer, crypts it and stores it in buffer

Parameters
buffBuffer to store crypted data to. Make sure buffer is at least 257 bytes
offsetStarting index in buff to start storing data from
desired_lengthDeisred size of crypted data to take
Returns
Number of crypted data bytes stored in buffer
int sp2plib::AESNetworkStream::ReadDeCrypted ( unsigned char *  buff,
int  offset,
int  desired_length 
)

Reads reads data from de-crypt buffer, decrypts it and stores it in buffer

Parameters
buffBuffer to store decrypted data to
offsetStarting index in buff to start storing data from
desired_lengthDeisred size of decrypted data to take
Returns
Number of decrypted data bytes stored in buffer
int sp2plib::AESNetworkStream::WriteForCrypt ( unsigned char *  buff,
int  offset,
int  length 
)

Writes unencrypted data to crypt buffer to be extracted crypted using ReadCrypted method

Parameters
buffBuffer containing data bytes
offsetStarting index in buff to start reading from
lengthTotal size of data to be read
Returns
Number of bytes written to crypt buffer
int sp2plib::AESNetworkStream::WriteForDeCrypt ( unsigned char *  buff,
int  offset,
int  length 
)

Writes encrypted data to de-crypt buffer to be extracted decrypted using ReadDeCrypted method

Parameters
buffBuffer containing crypted data bytes.
offsetStarting index in buff to start reading from.
lengthTotal size of crypted data to be read.
Returns
Number of bytes written to de-crypt buffer

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