Virgil Security Crypto library  2.6.3
VirgilSymmetricCipher.h
1 
37 #ifndef VIRGIL_CRYPTO_SYMMETRIC_SIPHER_H
38 #define VIRGIL_CRYPTO_SYMMETRIC_SIPHER_H
39 
40 #include <memory>
41 #include <string>
42 
43 #include "../VirgilByteArray.h"
44 #include "asn1/VirgilAsn1Compatible.h"
45 
46 namespace virgil { namespace crypto { namespace foundation {
47 
53 public:
57 
61  enum class Padding {
62  PKCS7 = 0,
63  OneAndZeros,
64  ZerosAndLen,
65  Zeros,
66  None
67  };
68 
72  enum class Algorithm {
73  AES_128_CBC,
74  AES_128_GCM,
75  AES_256_CBC,
76  AES_256_GCM
77  };
79 
80 public:
81 
88 
92  explicit VirgilSymmetricCipher(Algorithm algorithm);
93 
98  explicit VirgilSymmetricCipher(const std::string& name);
99 
104  explicit VirgilSymmetricCipher(const char* name);
106 
109 
114  bool isInited() const;
115 
119  std::string name() const;
120 
125  size_t blockSize() const;
126 
130  size_t ivSize() const;
131 
136  size_t keySize() const;
137 
142  size_t keyLength() const;
143 
148  size_t authTagLength() const;
149 
153  bool isEncryptionMode() const;
154 
158  bool isDecryptionMode() const;
159 
163  bool isAuthMode() const;
164 
168  bool isSupportPadding() const;
169 
173  VirgilByteArray iv() const;
175 
179 
187 
195 
204 
208  void setIV(const virgil::crypto::VirgilByteArray& iv);
209 
216  void setAuthData(const virgil::crypto::VirgilByteArray& authData);
217 
221  void reset();
222 
228  void clear();
230 
233 
243  const virgil::crypto::VirgilByteArray& input,
246 
249 
260 
271 
274  size_t asn1Write(
277  size_t childWrittenBytes = 0) const override;
278 
281 public:
284 
285  VirgilSymmetricCipher& operator=(VirgilSymmetricCipher&& rhs) noexcept;
286 
287  virtual ~VirgilSymmetricCipher() noexcept;
289 
290 private:
294  void checkState() const;
295 
296 private:
297  class Impl;
298 
299  std::unique_ptr<Impl> impl_;
300 };
301 
302 }}}
303 
304 namespace std {
311 }
312 
313 #endif /* VIRGIL_CRYPTO_SYMMETRIC_SIPHER_H */
bool isDecryptionMode() const
Returns true if cipher is in the decryption mode.
Padding mode: zero padding (not reversible!)
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
Algorithm
Definition: VirgilSymmetricCipher.h:72
bool isSupportPadding() const
Returns true if cipher support padding.
size_t asn1Write(virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
Write object state to the writer.
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.
void asn1Read(virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader) override
Read object state from the reader.
Definition: VirgilHash.h:265
This class provides methods for writing ASN.1 data structure.
Definition: VirgilAsn1Writer.h:54
void setPadding(VirgilSymmetricCipher::Padding padding)
Defines padding mode.
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
size_t ivSize() const
Returns the size of the cipher&#39;s IV in octets.
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:50
bool isEncryptionMode() const
Returns true if cipher is in the encryption mode.
virgil::crypto::VirgilByteArray finish()
Cipher finalization method.
VirgilByteArray iv() const
Return cipher IV, or NONCE_COUNTER for CTR-mode ciphers.
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).
Padding
Padding modes for the symmetric cipher.
Definition: VirgilSymmetricCipher.h:61
string to_string(virgil::crypto::foundation::VirgilSymmetricCipher::Algorithm alg)
Returns string representation of the Hash algorithm.
void reset()
Finish preparation before encryption / decryption.
Padding mode: never pad (full blocks only)
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:52
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.
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.