Virgil Security Crypto library  2.0.7
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 <virgil/crypto/VirgilByteArray.h>
44 #include <virgil/crypto/foundation/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_256_CBC,
75  };
77 
78 public:
79 
86 
90  explicit VirgilSymmetricCipher(Algorithm algorithm);
91 
96  explicit VirgilSymmetricCipher(const std::string& name);
97 
102  explicit VirgilSymmetricCipher(const char* name);
104 
107 
111  std::string name() const;
112 
117  size_t blockSize() const;
118 
122  size_t ivSize() const;
123 
128  size_t keySize() const;
129 
134  size_t keyLength() const;
135 
140  size_t authTagLength() const;
141 
145  bool isEncryptionMode() const;
146 
150  bool isDecryptionMode() const;
151 
155  bool isAuthMode() const;
156 
160  bool isSupportPadding() const;
161 
165  VirgilByteArray iv() const;
167 
171 
179 
187 
196 
201 
208  void setAuthData(const virgil::crypto::VirgilByteArray& authData);
209 
213  void reset();
214 
220  void clear();
222 
225 
235  const virgil::crypto::VirgilByteArray& input,
238 
241 
252 
263 
266  size_t asn1Write(
269  size_t childWrittenBytes = 0) const override;
270 
273 public:
276 
277  VirgilSymmetricCipher& operator=(VirgilSymmetricCipher&& rhs) noexcept;
278 
279  virtual ~VirgilSymmetricCipher() noexcept;
281 
282 private:
286  void checkState() const;
287 
288 private:
289  class Impl;
290 
291  std::unique_ptr<Impl> impl_;
292 };
293 
294 }}}
295 
296 namespace std {
303 }
304 
305 #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.
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:252
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's IV in octets.
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:53
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)
size_t asn1Write(virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
Write object state to the writer.
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.