CryptoSys PKI
23.0.0
|
Generic block cipher functions. More...
Public Types | |
enum class | AeadAlg |
Authenticated encryption algorithm. More... | |
enum class | Alg |
Block cipher algorithm. More... | |
enum class | Mode |
Block cipher mode. More... | |
enum | Opts : unsigned int |
Advanced options [BitFlags]. More... | |
enum class | Padding |
Block cipher padding options. More... | |
Static Public Member Functions | |
static std::string | AlgName (Alg alg) |
Get the algorithm name. More... | |
static int | BlockBytes (Alg alg) |
Get the block size in bytes for a given cipher algorithm. More... | |
static bvec_t | Decrypt (const bvec_t &data, const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode=Mode::ECB, Padding pad=Padding::Default, Opts opts=Opts::None) |
Decrypt data in a byte array using the specified block cipher algorithm, mode and padding. More... | |
static 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. More... | |
static bvec_t | DecryptAEAD (const bvec_t &input, const bvec_t &key, const bvec_t &iv, AeadAlg aeadAlg, Opts opts=Opts::None, const bvec_t &aad=bvec_t()) |
Decrypt data using authenticated encryption with additional authenticated data (AAD). More... | |
static 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 bvec_t | Encrypt (const bvec_t &data, const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode=Mode::ECB, Padding pad=Padding::Default, Opts opts=Opts::None) |
Encrypt data in a byte array using the specified block cipher algorithm, mode and padding. More... | |
static 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 bvec_t | EncryptAEAD (const bvec_t &input, const bvec_t &key, const bvec_t &iv, AeadAlg aeadAlg, Opts opts=Opts::None, const bvec_t &aad=bvec_t()) |
Encrypt data using authenticated encryption with additional authenticated data (AAD). More... | |
static 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 | FileDecrypt (const std::string &fileOut, const std::string &fileIn, const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode=Mode::ECB, Padding pad=Padding::Default, Opts opts=Opts::None) |
Decrypt a file. More... | |
static int | FileEncrypt (const std::string &fileOut, const std::string &fileIn, const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode=Mode::ECB, Padding pad=Padding::Default, Opts opts=Opts::None) |
Encrypt a file. More... | |
static int | KeyBytes (Alg alg) |
Get the key size in bytes for a given cipher algorithm. More... | |
static bvec_t | KeyUnwrap (const bvec_t &data, const bvec_t &kek, Alg alg) |
Unwrap (decrypt) key material with a key-encryption key. More... | |
static bvec_t | KeyWrap (const bvec_t &data, const bvec_t &kek, Alg alg) |
Wrap (encrypt) key material with a key-encryption key. More... | |
static bvec_t | Pad (const bvec_t &input, Alg alg, Padding pad=Padding::Pkcs5) |
Pad byte array to correct length for ECB and CBC encryption. More... | |
static bvec_t | Unpad (const bvec_t &input, Alg alg, Padding pad=Padding::Pkcs5) |
Remove padding from an encryption block. More... | |
Generic block cipher functions.
|
strong |
Authenticated encryption algorithm.
|
strong |
|
strong |
enum dipki::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.
alg | Cipher algorithm |
"AES-128"
.
|
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.
data | Input data to be decrypted |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (use Cipher::BlockBytes) or an empty vector bvec_t() for ECB mode or if IV is prefixed. |
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 to 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.
data | Input data to be decrypted |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (use Cipher::BlockBytes) or an empty vector bvec_t() for ECB mode or if IV is prefixed. |
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 to the input. |
Pkcs5
for ECB and CBC mode and NoPad
for all other modes. GCM mode is only available with AES.
|
static |
Decrypt data using authenticated encryption with additional authenticated data (AAD).
input | Input data to be decrypted. |
key | Key of exact length for algorithm (16, 24 or 32 bytes). |
iv | Initialization Vector (IV) (aka nonce) exactly 12 bytes long, or an empty vector bvec_t() if IV is prefixed. |
aeadAlg | Authenticated encryption algorithm. |
opts | Advanced options. Use Cipher::Opts::PrefixIV to expect the IV to be prepended at the start of the input. |
aad | (optional) Additional authenticated data - this must be identical to the AAD provided during encryption. |
Cipher::Opts::PrefixIV
option is used. In all cases the IV must be exactly 12 bytes (96 bits) and the tag must be exactly 16 bytes (128 bits).
|
static |
Decrypt a block of data.
data | Input data to be decrypted. Must be an exact multiple of block length for ECB and CBC mode. |
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 (use 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 (use 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. GCM mode is only available with AES.
|
static |
Encrypt data using authenticated encryption with additional authenticated data (AAD).
input | Input data to be encrypted. |
key | Key of exact length for algorithm (16, 24 or 32 bytes). |
iv | Initialization Vector (IV) (aka nonce) exactly 12 bytes long. |
aeadAlg | Authenticated encryption algorithm. |
opts | Advanced options. Use Cipher::Opts::PrefixIV to prepend the 12-byte IV to the output |
aad | (optional) Additional authenticated data. |
|
static |
Encrypt a block of data.
data | Input data to be encrypted. Must be an exact multiple of block length for ECB and CBC mode. |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (use 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 |
Decrypt a file.
fileOut | Name of output file to be created or overwritten |
fileIn | Name of input file |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (use 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 a file.
fileOut | Name of output file to be created or overwritten |
fileIn | Name of input file |
key | Key of exact length for block cipher algorithm |
iv | Initialization Vector (IV) of exactly the block size (use 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 |
Get the key size in bytes for a given cipher algorithm.
alg | Cipher algorithm |
Unwrap (decrypt) key material with a key-encryption key.
data | Wrapped key. |
kek | Key encryption key of exact length for key wrap algorithm. |
alg | Block cipher to use for wrapping. |
Wrap (encrypt) key material with a key-encryption key.
data | Key material to be wrapped. |
kek | Key encryption key of exact length for key wrap algorithm. |
alg | Block cipher to use for wrapping. |
|
static |
Pad byte array to correct length for ECB and CBC encryption.
input | Data to be padded |
alg | Block cipher being used |
pad | Padding method to use (default is PKCS#5/#7) |
|
static |
Remove padding from an encryption block.
input | Padded data |
alg | Block cipher being used |
pad | Padding method to use (default is PKCS#5/#7) |
std::runtime_error | Exception with error code. |