A generic data ciphering class.
More...
#include <secure.h>
|
typedef Key * | key_t |
|
enum | mode_t { ENCRYPT = 1
, DECRYPT = 0
} |
|
|
size_t | align (void) const |
|
| Cipher (const key_t key, mode_t mode, uint8_t *address=NULL, size_t size=0) |
|
size_t | flush (void) |
| Push a final cipher block.
|
|
secure::keybytes | iv () |
|
secure::keybytes | key () |
|
size_t | pad (const uint8_t *address, size_t size) |
| This is used to process any data unaligned to the blocksize at the end of a cipher session.
|
|
size_t | pos (void) const |
|
size_t | process (uint8_t *address, size_t size, bool flag=false) |
| Process encrypted data in-place.
|
|
size_t | put (const uint8_t *data, size_t size) |
| Process cipher data.
|
|
size_t | puts (const char *string) |
| This essentially encrypts a single string and pads with NULL bytes as needed.
|
|
void | set (const key_t key, mode_t mode, uint8_t *address, size_t size=0) |
|
void | set (uint8_t *address, size_t size=0) |
|
size_t | size (void) const |
|
|
static bool | has (const char *name) |
| Check if a specific cipher is supported.
|
|
|
virtual void | push (uint8_t *address, size_t size) |
|
void | release (void) |
|
A generic data ciphering class.
This is used to construct cryptographic ciphers to encode and decode data as needed. The cipher type is specified by the key object. This class can be used to send output streaming to memory or in a fixed size buffer. If the latter is used, a push() method is called through a virtual when the buffer is full. Since block ciphers are used, buffers should be aligned to the block size.
- Author
- David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org
- Examples
- cipher.cpp.
Definition at line 289 of file secure.h.
◆ key_t
◆ mode_t
enum ucommon::Cipher::mode_t |
◆ align()
size_t ucommon::Cipher::align |
( |
void | | ) |
const |
|
inline |
◆ flush()
size_t ucommon::Cipher::flush |
( |
void | | ) |
|
Push a final cipher block.
This is used to push the final buffer into the push method for any remaining data.
- Examples
- cipher.cpp.
◆ has()
static bool ucommon::Cipher::has |
( |
const char * | name | ) |
|
|
static |
Check if a specific cipher is supported.
- Parameters
-
- Returns
- true if supported, false if not.
◆ iv()
secure::keybytes ucommon::Cipher::iv |
( |
| ) |
|
|
inline |
◆ key()
secure::keybytes ucommon::Cipher::key |
( |
| ) |
|
|
inline |
◆ pad()
size_t ucommon::Cipher::pad |
( |
const uint8_t * | address, |
|
|
size_t | size ) |
This is used to process any data unaligned to the blocksize at the end of a cipher session.
On an encryption, it will add padding or an entire padding block with the number of bytes to strip. On decryption it will remove padding at the end. The pkcs5 method of padding with removal count is used. This also sets the address buffer to NULL to prevent further puts until reset.
- Parameters
-
address | of data to add before final pad. |
size | of data to add before final pad. |
- Returns
- actual bytes encrypted or decrypted.
◆ pos()
size_t ucommon::Cipher::pos |
( |
void | | ) |
const |
|
inline |
◆ process()
size_t ucommon::Cipher::process |
( |
uint8_t * | address, |
|
|
size_t | size, |
|
|
bool | flag = false ) |
Process encrypted data in-place.
This assumes no need to set the address buffer.
- Parameters
-
address | of data to process. |
size | of data to process. |
flag | if to pad data. |
- Returns
- bytes processed and written back to buffer.
◆ put()
size_t ucommon::Cipher::put |
( |
const uint8_t * | data, |
|
|
size_t | size ) |
Process cipher data.
This requires the size to be a multiple of the cipher block size. If an unaligned sized block of data is used, it will be ignored and the size returned will be 0.
- Parameters
-
data | to process. |
size | of data to process. |
- Returns
- size of processed output, should be same as size or 0 if error.
- Examples
- cipher.cpp.
◆ puts()
size_t ucommon::Cipher::puts |
( |
const char * | string | ) |
|
This essentially encrypts a single string and pads with NULL bytes as needed.
- Parameters
-
- Returns
- total encrypted size.
- Examples
- cipher.cpp.
◆ size()
size_t ucommon::Cipher::size |
( |
void | | ) |
const |
|
inline |
The documentation for this class was generated from the following file:
- /builddir/build/BUILD/ucommon-7.0.0-build/ucommon-7.0.0/inc/ucommon/secure.h