Virgil Security Crypto library  1.8.2
Public Member Functions | List of all members
virgil::crypto::foundation::VirgilSymmetricCipher Class Reference

Provides symmetric ciphers algorithms. More...

#include <VirgilSymmetricCipher.h>

Inheritance diagram for virgil::crypto::foundation::VirgilSymmetricCipher:
virgil::crypto::foundation::asn1::VirgilAsn1Compatible

Public Types

Additional types
enum  VirgilSymmetricCipherPadding { VirgilSymmetricCipherPadding_PKCS7, VirgilSymmetricCipherPadding_OneAndZeros, VirgilSymmetricCipherPadding_ZerosAndLen, VirgilSymmetricCipherPadding_Zeros }
 

Public Member Functions

 VirgilSymmetricCipher ()
 Create object with undefined algorithm. More...
 
virtual ~VirgilSymmetricCipher () throw ()
 Polymorphic destructor.
 
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.
 
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 (VirgilSymmetricCipherPadding 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...
 
Copy constructor / assignment operator
Warning
Copy constructor and assignment operator create copy of the object as it was created by on of the creation methods. All changes in the internal state, that was made after creation, are not copied!
 VirgilSymmetricCipher (const VirgilSymmetricCipher &other)
 
VirgilSymmetricCipheroperator= (const VirgilSymmetricCipher &rhs)
 
VirgilAsn1Compatible implementation
virtual size_t asn1Write (virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const
 Write object state to the writer. More...
 
virtual void asn1Read (virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader)
 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 () throw ()
 Polymorphic destructor.
 

Static Public Member Functions

Creation methods
static VirgilSymmetricCipher aes256 ()
 Creates object that handles AES-256 encryption / decription algorithms.
 

Additional Inherited Members

- Protected Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible
virtual void checkAsn1ParamNotEmpty (const virgil::crypto::VirgilByteArray &param, const char *paramName=0) const
 If given parameter is empty exception will be thrown. More...
 

Detailed Description

Provides symmetric ciphers algorithms.

Constructor & Destructor Documentation

virgil::crypto::foundation::VirgilSymmetricCipher::VirgilSymmetricCipher ( )

Create object with undefined algorithm.

Warning
SHOULD be used in conjunction with VirgilAsn1Compatible interface, i.e. VirgilSymmetricCipher cipher = VirgilSymmetricCipher().fromAsn1(asn1);

Member Function Documentation

virtual void virgil::crypto::foundation::VirgilSymmetricCipher::asn1Read ( virgil::crypto::foundation::asn1::VirgilAsn1Reader asn1Reader)
virtual

Read object state from the reader.

Parameters
asn1Readerreader payloaded with ASN.1 to be read.

Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.

virtual size_t virgil::crypto::foundation::VirgilSymmetricCipher::asn1Write ( virgil::crypto::foundation::asn1::VirgilAsn1Writer asn1Writer,
size_t  childWrittenBytes = 0 
) const
virtual

Write object state to the writer.

Parameters
asn1Writerwriter that should be payloaded by subclasses.
childWrittenBytescount of bytes that was written by subclasses.
Returns
Writen bytes count.

Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.

size_t virgil::crypto::foundation::VirgilSymmetricCipher::authTagLength ( ) const

Returns the authentication tag length of the cipher.

Returns
tag length, in octets.
size_t virgil::crypto::foundation::VirgilSymmetricCipher::blockSize ( ) const

Returns the block size of the current cipher.

Returns
block size, in octets.
void virgil::crypto::foundation::VirgilSymmetricCipher::clear ( )

Clear all configuration settings.

Note
This method SHOULD be used if class instance was used for encryption and then will be used for decryption, and vice versa.
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.

Parameters
input- data to be encrypted / decrypted.
iv- initialization vector.
Returns
Encrypted or decrypted bytes (rely on the current mode).
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.

Returns
Encrypted or decrypted bytes (rely on the current mode).
size_t virgil::crypto::foundation::VirgilSymmetricCipher::keyLength ( ) const

Returns the key length of the cipher.

Returns
key length, in octets.
size_t virgil::crypto::foundation::VirgilSymmetricCipher::keySize ( ) const

Returns the key length of the cipher.

Returns
key length, in bits.
void virgil::crypto::foundation::VirgilSymmetricCipher::setAuthData ( const virgil::crypto::VirgilByteArray &  authData)

Add additional data (for AEAD ciphers).

Note
Currently only supported with GCM.
Must be called before reset().
See also
isAuthMode()
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.

Warning
Only one key CAN be set.
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.

Warning
Only one key CAN be set.
void virgil::crypto::foundation::VirgilSymmetricCipher::setPadding ( VirgilSymmetricCipherPadding  padding)

Defines padding mode.

Default value is PKCS7.

Note
This parameter is used only for cipher modes that use padding.
See also
isSupportPadding()
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.

Returns
Encrypted or decrypted bytes (rely on the current mode).

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