CryptoSys API
6.22.1
|
Generic block cipher functions. More...
Public Types | |
enum class | Alg |
Block cipher algorithm. More... | |
enum class | Mode |
Block cipher mode. More... | |
enum | Opts : unsigned int |
Advanced options. More... | |
enum class | Pad |
Block cipher padding options. More... | |
Public Member Functions | |
bool | Final () |
Clear the Cipher object. More... | |
bool | InitDecrypt (const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode) |
Initialise the Cipher object ready for repeated incremental decryption operations. More... | |
bool | InitEncrypt (const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode) |
Initialise the Cipher object ready for repeated incremental encryption operations. More... | |
crsysapi::bvec_t | Update (const bvec_t &data) |
Transform byte input data with previously initialized key, mode and direction. More... | |
Static Public Member Functions | |
static std::string | AlgName (Alg alg) |
Get the algorithm name as a string. More... | |
static int | BlockBytes (Alg alg) |
Get the block size in bytes for a given cipher algorithm. More... | |
static crsysapi::bvec_t | Decrypt (const bvec_t &data, const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode=Mode::ECB, Pad pad=Pad::Default, Opts opts=Opts::None) |
Decrypt data in a byte array using the specified block cipher algorithm, mode and padding, with advanced options. More... | |
static crsysapi::bvec_t | Decrypt (const bvec_t &data, const bvec_t &key, const bvec_t &iv, const std::string &algModePad, Opts opts=Opts::None) |
Decrypt data in a byte array using the specified block cipher algorithm, mode and padding, with advanced options. More... | |
static crsysapi::bvec_t | DecryptBlock (const bvec_t &data, const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode=Mode::ECB) |
Decrypt a block of data. More... | |
static crsysapi::bvec_t | Encrypt (const bvec_t &data, const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode=Mode::ECB, Pad pad=Pad::Default, Opts opts=Opts::None) |
Encrypt data in a byte array using the specified block cipher algorithm, mode and padding. More... | |
static crsysapi::bvec_t | Encrypt (const bvec_t &data, const bvec_t &key, const bvec_t &iv, const std::string &algModePad, Opts opts=Opts::None) |
Encrypt data in a byte array using the specified block cipher algorithm, mode and padding. More... | |
static crsysapi::bvec_t | EncryptBlock (const bvec_t &data, const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode=Mode::ECB) |
Encrypt a block of data. More... | |
static int | KeyBytes (Alg alg) |
Get the key size in bytes for a given cipher algorithm. More... | |
static crsysapi::bvec_t | KeyUnwrap (const bvec_t &data, const bvec_t &kek, Alg alg) |
Unwrap (decrypt) encrypted key material with a key-encryption key. More... | |
static crsysapi::bvec_t | KeyWrap (const bvec_t &data, const bvec_t &kek, Alg alg) |
Wrap (encrypt) key material with a key-encryption key. More... | |
static std::string | ModeName (Mode mode) |
Get mode name as a string. More... | |
Generic block cipher functions.
|
strong |
|
strong |
enum crsysapi::Cipher::Opts : unsigned int |
|
strong |
Block cipher padding options.
Enumerator | |
---|---|
Default | Use default padding. |
NoPad | No padding is added. |
Pkcs5 | The padding scheme described in PKCS#5/#7. |
OneAndZeroes | Pad with 0x80 followed by as many zero bytes necessary to fill the block. |
AnsiX923 | The padding scheme described in ANSI X9.23. |
W3CPadding | The padding scheme described in W3C https://www.w3.org/TR/xmlenc-core1/#sec-Padding |
|
static |
Get the algorithm name as a string.
alg | Cipher algorithm |
|
static |
Get the block size in bytes for a given cipher algorithm.
alg | Cipher algorithm |
|
static |
Decrypt data in a byte array using the specified block cipher algorithm, mode and padding, with advanced options.
data | Input data to be decrypted |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (see Cipher::BlockBytes()) or an empty vector bvec_t() for ECB mode |
alg | Cipher algorithm |
mode | Cipher mode |
pad | Padding method to use |
opts | Advanced options. Use Cipher::Opts::PrefixIV to expect the IV to be prepended at the start of the input. |
Pkcs5
for ECB and CBC mode and NoPad
for all other modes. It is an error if the specified padding is not found after decryption.
|
static |
Decrypt data in a byte array using the specified block cipher algorithm, mode and padding, with advanced options.
data | Input data to be decrypted |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (see Cipher::BlockBytes()) or an empty vector bvec_t() for ECB mode |
algModePad | String with block cipher algorithm, mode and padding, e.g. "aes128/cbc/pkcs5"
|
opts | Advanced options. Use Cipher::Opts::PrefixIV to expect the IV to be prepended at the start of the input. |
Pkcs5
for ECB and CBC mode and NoPad
for all other modes. It is an error if the specified padding is not found after decryption.
|
static |
Decrypt a block of data.
Must be an exact multiple of block length.
data | Input data to be decrypted |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (see Cipher::BlockBytes()) or an empty vector bvec_t() for ECB mode |
alg | Cipher algorithm (required) |
mode | Cipher mode (default = ECB) |
std::runtime_error | Exception with error code. |
|
static |
Encrypt data in a byte array using the specified block cipher algorithm, mode and padding.
data | Input data to be encrypted |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (see Cipher::BlockBytes()) or an empty vector bvec_t() for ECB mode |
alg | Cipher algorithm |
mode | Cipher mode |
pad | Padding method to use |
opts | Advanced options. Use Cipher::Opts::PrefixIV to prepend the IV to the output. |
Pkcs5
for ECB and CBC mode and NoPad
for all other modes.
|
static |
Encrypt data in a byte array using the specified block cipher algorithm, mode and padding.
data | Input data to be encrypted |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (see Cipher::BlockBytes()) or an empty vector bvec_t() for ECB mode |
algModePad | String with block cipher algorithm, mode and padding, e.g. "aes128/cbc/pkcs5"
|
opts | Advanced options. Use Cipher::Opts::PrefixIV to prepend the IV to the output. |
Pkcs5
for ECB and CBC mode and NoPad
for all other modes.
|
static |
Encrypt a block of data.
Must be an exact multiple of block length.
data | Input data to be encrypted |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (see Cipher::BlockBytes()) or an empty vector bvec_t() for ECB mode |
alg | Cipher algorithm (required) |
mode | Cipher mode (default = ECB) |
std::runtime_error | Exception with error code. |
bool crsysapi::Cipher::Final | ( | ) |
Clear the Cipher object.
Initialise the Cipher object ready for repeated incremental decryption operations.
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (see Cipher::BlockBytes()) or an empty vector bvec_t() for ECB mode |
alg | Cipher algorithm to be used |
mode | Cipher mode |
Initialise the Cipher object ready for repeated incremental encryption operations.
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (see Cipher::BlockBytes()) or an empty vector bvec_t() for ECB mode |
alg | Cipher algorithm to be used |
mode | Cipher mode |
|
static |
Get the key size in bytes for a given cipher algorithm.
alg | Cipher algorithm |
|
static |
Unwrap (decrypt) encrypted key material with a key-encryption key.
data | Input data to be decrypted |
kek | Key encryption key |
alg | Cipher algorithm (required) |
std::runtime_error | Exception with error code. |
|
static |
Wrap (encrypt) key material with a key-encryption key.
data | Input key material to be encrypted |
kek | Key encryption key |
alg | Cipher algorithm (required) |
std::runtime_error | Exception with error code. |
|
static |
Get mode name as a string.
mode | Block cipher mode |
crsysapi::bvec_t crsysapi::Cipher::Update | ( | const bvec_t & | data | ) |
Transform byte input data with previously initialized key, mode and direction.
data | Input data |