Virgil Security Crypto library
2.0.7
|
Provides symmetric ciphers algorithms. More...
#include <VirgilSymmetricCipher.h>
Public Types | |
Additional types | |
enum | Padding { Padding::PKCS7 = 0, Padding::OneAndZeros, Padding::ZerosAndLen, Padding::Zeros, Padding::None } |
Padding modes for the symmetric cipher. More... | |
enum | Algorithm { Algorithm::AES_256_CBC, Algorithm::AES_256_GCM } |
Public Member Functions | |
VirgilSymmetricCipher () | |
Create object with undefined algorithm. More... | |
VirgilSymmetricCipher (Algorithm algorithm) | |
Create object with specific algorithm type. | |
VirgilSymmetricCipher (const std::string &name) | |
Create object with given algorithm name. More... | |
VirgilSymmetricCipher (const char *name) | |
Create object with given algorithm name. More... | |
Info | |
std::string | name () const |
Returns the name of the given cipher, as a string. | |
size_t | blockSize () const |
Returns the block size of the current cipher. More... | |
size_t | ivSize () const |
Returns the size of the cipher's IV in octets. | |
size_t | keySize () const |
Returns the key length of the cipher. More... | |
size_t | keyLength () const |
Returns the key length of the cipher. More... | |
size_t | authTagLength () const |
Returns the authentication tag length of the cipher. More... | |
bool | isEncryptionMode () const |
Returns true if cipher is in the encryption mode. | |
bool | isDecryptionMode () const |
Returns true if cipher is in the decryption mode. | |
bool | isAuthMode () const |
Returns true if cipher is configured to support authenticated encryption and decryption. | |
bool | isSupportPadding () const |
Returns true if cipher support padding. | |
VirgilByteArray | iv () const |
Return cipher IV, or NONCE_COUNTER for CTR-mode ciphers. | |
Configuration | |
void | setEncryptionKey (const virgil::crypto::VirgilByteArray &key) |
Configures encryption key. More... | |
void | setDecryptionKey (const virgil::crypto::VirgilByteArray &key) |
Configures decryption key. More... | |
void | setPadding (VirgilSymmetricCipher::Padding padding) |
Defines padding mode. More... | |
void | setIV (const virgil::crypto::VirgilByteArray &iv) |
Configures the initialization vector. | |
void | setAuthData (const virgil::crypto::VirgilByteArray &authData) |
Add additional data (for AEAD ciphers). More... | |
void | reset () |
Finish preparation before encryption / decryption. | |
void | clear () |
Clear all configuration settings. More... | |
Generic Encryption / Decryption | |
virgil::crypto::VirgilByteArray | crypt (const virgil::crypto::VirgilByteArray &input, const virgil::crypto::VirgilByteArray &iv) |
Generic all-in-one encryption / decryption. More... | |
Sequence Encryption / Decryption | |
virgil::crypto::VirgilByteArray | update (const virgil::crypto::VirgilByteArray &input) |
Generic cipher update function. More... | |
virgil::crypto::VirgilByteArray | finish () |
Cipher finalization method. More... | |
VirgilAsn1Compatible implementation | |
size_t | asn1Write (virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override |
Write object state to the writer. More... | |
void | asn1Read (virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader) override |
Read object state from the reader. More... | |
Public Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible | |
virgil::crypto::VirgilByteArray | toAsn1 () const |
Save object state to the ASN.1 structure. | |
void | fromAsn1 (const virgil::crypto::VirgilByteArray &asn1) |
Restore object state from the ASN.1 structure. | |
virtual | ~VirgilAsn1Compatible () noexcept |
Polymorphic destructor. | |
Additional Inherited Members | |
Protected Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible | |
virtual void | checkRequiredField (const VirgilByteArray ¶m) const |
If given parameter is empty exception will be thrown. More... | |
Provides symmetric ciphers algorithms.
virgil::crypto::foundation::VirgilSymmetricCipher::VirgilSymmetricCipher | ( | ) |
Create object with undefined algorithm.
|
explicit |
Create object with given algorithm name.
|
explicit |
Create object with given algorithm name.
|
overridevirtual |
Read object state from the reader.
asn1Reader | reader payloaded with ASN.1 to be read. |
Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.
|
overridevirtual |
Write object state to the writer.
asn1Writer | writer that should be payloaded by subclasses. |
childWrittenBytes | count of bytes that was written by subclasses. |
Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.
size_t virgil::crypto::foundation::VirgilSymmetricCipher::authTagLength | ( | ) | const |
Returns the authentication tag length of the cipher.
size_t virgil::crypto::foundation::VirgilSymmetricCipher::blockSize | ( | ) | const |
Returns the block size of the current cipher.
void virgil::crypto::foundation::VirgilSymmetricCipher::clear | ( | ) |
Clear all configuration settings.
virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilSymmetricCipher::crypt | ( | const virgil::crypto::VirgilByteArray & | input, |
const virgil::crypto::VirgilByteArray & | iv | ||
) |
Generic all-in-one encryption / decryption.
Encrypts or decrypts given data.
input | - data to be encrypted / decrypted. |
iv | - initialization vector. |
virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilSymmetricCipher::finish | ( | ) |
Cipher finalization method.
If data still needs to be flushed from an incomplete block, data contained within it will be padded with the size of the last block, and will be returned.
size_t virgil::crypto::foundation::VirgilSymmetricCipher::keyLength | ( | ) | const |
Returns the key length of the cipher.
size_t virgil::crypto::foundation::VirgilSymmetricCipher::keySize | ( | ) | const |
Returns the key length of the cipher.
void virgil::crypto::foundation::VirgilSymmetricCipher::setAuthData | ( | const virgil::crypto::VirgilByteArray & | authData | ) |
Add additional data (for AEAD ciphers).
void virgil::crypto::foundation::VirgilSymmetricCipher::setDecryptionKey | ( | const virgil::crypto::VirgilByteArray & | key | ) |
Configures decryption key.
Configures cipher to be used in decryption mode with given key.
void virgil::crypto::foundation::VirgilSymmetricCipher::setEncryptionKey | ( | const virgil::crypto::VirgilByteArray & | key | ) |
Configures encryption key.
Configures cipher to be used in encryption mode with given key.
void virgil::crypto::foundation::VirgilSymmetricCipher::setPadding | ( | VirgilSymmetricCipher::Padding | padding | ) |
Defines padding mode.
Default value is PKCS7.
virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilSymmetricCipher::update | ( | const virgil::crypto::VirgilByteArray & | input | ) |
Generic cipher update function.
Encrypts or decrypts given data. Writes as many block size'd blocks of data as possible to output. Any data that cannot be written immediately will either be added to the next block, or flushed when finish is called.