Virgil Security Crypto library  2.4.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
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,
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 
113  std::string name() const;
114 
119  size_t blockSize() const;
120 
124  size_t ivSize() const;
125 
130  size_t keySize() const;
131 
136  size_t keyLength() const;
137 
142  size_t authTagLength() const;
143 
147  bool isEncryptionMode() const;
148 
152  bool isDecryptionMode() const;
153 
157  bool isAuthMode() const;
158 
162  bool isSupportPadding() const;
163 
167  VirgilByteArray iv() const;
169 
173 
181 
189 
198 
203 
210  void setAuthData(const virgil::crypto::VirgilByteArray& authData);
211 
215  void reset();
216 
222  void clear();
224 
227 
237  const virgil::crypto::VirgilByteArray& input,
240 
243 
254 
265 
268  size_t asn1Write(
271  size_t childWrittenBytes = 0) const override;
272 
275 public:
278 
279  VirgilSymmetricCipher& operator=(VirgilSymmetricCipher&& rhs) noexcept;
280 
281  virtual ~VirgilSymmetricCipher() noexcept;
283 
284 private:
288  void checkState() const;
289 
290 private:
291  class Impl;
292 
293  std::unique_ptr<Impl> impl_;
294 };
295 
296 }}}
297 
298 namespace std {
305 }
306 
307 #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.
This class provides methods for writing ASN.1 data structure.
Definition: VirgilAsn1Writer.h:54
void setPadding(VirgilSymmetricCipher::Padding padding)
Defines padding mode.
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: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.