Virgil Security Crypto library  1.8.2
VirgilSymmetricCipher.h
1 
37 #ifndef VIRGIL_CRYPTO_SYMMETRIC_SIPHER_H
38 #define VIRGIL_CRYPTO_SYMMETRIC_SIPHER_H
39 
40 #include <string>
41 
42 #include <virgil/crypto/VirgilByteArray.h>
43 #include <virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h>
44 
45 namespace virgil { namespace crypto { namespace foundation {
46 
50 class VirgilSymmetricCipherImpl;
53 
58 public:
62  typedef enum {
64  VirgilSymmetricCipherPadding_PKCS7,
65  VirgilSymmetricCipherPadding_OneAndZeros,
66  VirgilSymmetricCipherPadding_ZerosAndLen,
67  VirgilSymmetricCipherPadding_Zeros
68  } VirgilSymmetricCipherPadding;
70 
71 public:
75 
81 
87 
91  virtual ~VirgilSymmetricCipher() throw();
93 
96 
100  std::string name() const;
101 
106  size_t blockSize() const;
107 
111  size_t ivSize() const;
112 
117  size_t keySize() const;
118 
123  size_t keyLength() const;
124 
129  size_t authTagLength() const;
130 
134  bool isEncryptionMode() const;
135 
139  bool isDecryptionMode() const;
140 
144  bool isAuthMode() const;
145 
149  bool isSupportPadding() const;
151 
155 
162  void setEncryptionKey(const virgil::crypto::VirgilByteArray& key);
163 
170  void setDecryptionKey(const virgil::crypto::VirgilByteArray& key);
171 
179  void setPadding(VirgilSymmetricCipherPadding padding);
180 
184  void setIV(const virgil::crypto::VirgilByteArray& iv);
185 
192  void setAuthData(const virgil::crypto::VirgilByteArray& authData);
193 
197  void reset();
198 
204  void clear();
206 
209 
218  virgil::crypto::VirgilByteArray crypt(
219  const virgil::crypto::VirgilByteArray& input,
220  const virgil::crypto::VirgilByteArray& iv);
222 
225 
235  virgil::crypto::VirgilByteArray update(const virgil::crypto::VirgilByteArray& input);
236 
245  virgil::crypto::VirgilByteArray finish();
247 
255 
256  VirgilSymmetricCipher& operator=(const VirgilSymmetricCipher& rhs);
258 
261  virtual size_t asn1Write(
264  size_t childWrittenBytes = 0) const;
265 
268 private:
273  explicit VirgilSymmetricCipher(int type);
274 
278  void checkState() const;
279 
280 private:
281  VirgilSymmetricCipherImpl* impl_;
282 };
283 
284 }}}
285 
286 #endif /* VIRGIL_CRYPTO_SYMMETRIC_SIPHER_H */
void setPadding(VirgilSymmetricCipherPadding padding)
Defines padding mode.
bool isDecryptionMode() const
Returns true if cipher is in the decryption mode.
void setIV(const virgil::crypto::VirgilByteArray &iv)
Configures the initialization vector.
This class provides methods for reading ASN.1 data structure.
Definition: VirgilAsn1Reader.h:53
bool isSupportPadding() const
Returns true if cipher support padding.
bool isAuthMode() const
Returns true if cipher is configured to support authenticated encryption and decryption.
This class provides interface that allow to save and restore object state in the ASN.1 structure.
Definition: VirgilAsn1Compatible.h:59
size_t keyLength() const
Returns the key length of the cipher.
virtual void asn1Read(virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader)
Read object state from the reader.
This class provides methods for writing ASN.1 data structure.
Definition: VirgilAsn1Writer.h:54
Definition: VirgilAsn1Compatible.h:46
size_t ivSize() const
Returns the size of the cipher's IV in octets.
bool isEncryptionMode() const
Returns true if cipher is in the encryption mode.
virgil::crypto::VirgilByteArray finish()
Cipher finalization method.
static VirgilSymmetricCipher aes256()
Creates object that handles AES-256 encryption / decription algorithms.
virtual size_t asn1Write(virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const
Write object state to the writer.
VirgilSymmetricCipher()
Create object with undefined algorithm.
void setDecryptionKey(const virgil::crypto::VirgilByteArray &key)
Configures decryption key.
size_t authTagLength() const
Returns the authentication tag length of the cipher.
void setAuthData(const virgil::crypto::VirgilByteArray &authData)
Add additional data (for AEAD ciphers).
void reset()
Finish preparation before encryption / decryption.
void setEncryptionKey(const virgil::crypto::VirgilByteArray &key)
Configures encryption key.
virgil::crypto::VirgilByteArray update(const virgil::crypto::VirgilByteArray &input)
Generic cipher update function.
Provides symmetric ciphers algorithms.
Definition: VirgilSymmetricCipher.h:57
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.
virtual ~VirgilSymmetricCipher()
Polymorphic destructor.
void clear()
Clear all configuration settings.
size_t keySize() const
Returns the key length of the cipher.
virgil::crypto::VirgilByteArray crypt(const virgil::crypto::VirgilByteArray &input, const virgil::crypto::VirgilByteArray &iv)
Generic all-in-one encryption / decryption.