1 | // modes.h - written and placed in the public domain by Wei Dai |
---|
2 | |
---|
3 | //! \file modes.h |
---|
4 | //! \brief Class file for modes of operation. |
---|
5 | |
---|
6 | #ifndef CRYPTOPP_MODES_H |
---|
7 | #define CRYPTOPP_MODES_H |
---|
8 | |
---|
9 | #include "cryptlib.h" |
---|
10 | #include "secblock.h" |
---|
11 | #include "misc.h" |
---|
12 | #include "strciphr.h" |
---|
13 | #include "argnames.h" |
---|
14 | #include "algparam.h" |
---|
15 | |
---|
16 | NAMESPACE_BEGIN(CryptoPP) |
---|
17 | |
---|
18 | //! \class CipherModeDocumentation |
---|
19 | //! \brief Block cipher mode of operation information |
---|
20 | //! \details Each class derived from this one defines two types, Encryption and Decryption, |
---|
21 | //! both of which implement the SymmetricCipher interface. |
---|
22 | //! For each mode there are two classes, one of which is a template class, |
---|
23 | //! and the other one has a name that ends in "_ExternalCipher". |
---|
24 | //! The "external cipher" mode objects hold a reference to the underlying block cipher, |
---|
25 | //! instead of holding an instance of it. The reference must be passed in to the constructor. |
---|
26 | //! For the "cipher holder" classes, the CIPHER template parameter should be a class |
---|
27 | //! derived from BlockCipherDocumentation, for example DES or AES. |
---|
28 | //! \details See NIST SP 800-38A for definitions of these modes. See |
---|
29 | //! AuthenticatedSymmetricCipherDocumentation for authenticated encryption modes. |
---|
30 | struct CipherModeDocumentation : public SymmetricCipherDocumentation |
---|
31 | { |
---|
32 | }; |
---|
33 | |
---|
34 | //! \class CipherModeBase |
---|
35 | //! \brief Block cipher mode of operation information |
---|
36 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher |
---|
37 | { |
---|
38 | public: |
---|
39 | size_t MinKeyLength() const {return m_cipher->MinKeyLength();} |
---|
40 | size_t MaxKeyLength() const {return m_cipher->MaxKeyLength();} |
---|
41 | size_t DefaultKeyLength() const {return m_cipher->DefaultKeyLength();} |
---|
42 | size_t GetValidKeyLength(size_t n) const {return m_cipher->GetValidKeyLength(n);} |
---|
43 | bool IsValidKeyLength(size_t n) const {return m_cipher->IsValidKeyLength(n);} |
---|
44 | |
---|
45 | unsigned int OptimalDataAlignment() const {return m_cipher->OptimalDataAlignment();} |
---|
46 | |
---|
47 | unsigned int IVSize() const {return BlockSize();} |
---|
48 | virtual IV_Requirement IVRequirement() const =0; |
---|
49 | |
---|
50 | void SetCipher(BlockCipher &cipher) |
---|
51 | { |
---|
52 | this->ThrowIfResynchronizable(); |
---|
53 | this->m_cipher = &cipher; |
---|
54 | this->ResizeBuffers(); |
---|
55 | } |
---|
56 | |
---|
57 | void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize = 0) |
---|
58 | { |
---|
59 | this->ThrowIfInvalidIV(iv); |
---|
60 | this->m_cipher = &cipher; |
---|
61 | this->ResizeBuffers(); |
---|
62 | this->SetFeedbackSize(feedbackSize); |
---|
63 | if (this->IsResynchronizable()) |
---|
64 | this->Resynchronize(iv); |
---|
65 | } |
---|
66 | |
---|
67 | protected: |
---|
68 | CipherModeBase() : m_cipher(NULL) {} |
---|
69 | inline unsigned int BlockSize() const {CRYPTOPP_ASSERT(m_register.size() > 0); return (unsigned int)m_register.size();} |
---|
70 | virtual void SetFeedbackSize(unsigned int feedbackSize) |
---|
71 | { |
---|
72 | if (!(feedbackSize == 0 || feedbackSize == BlockSize())) |
---|
73 | throw InvalidArgument("CipherModeBase: feedback size cannot be specified for this cipher mode"); |
---|
74 | } |
---|
75 | |
---|
76 | // Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 |
---|
77 | #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 |
---|
78 | virtual void ResizeBuffers(); |
---|
79 | #else |
---|
80 | virtual void ResizeBuffers() |
---|
81 | { |
---|
82 | m_register.New(m_cipher->BlockSize()); |
---|
83 | } |
---|
84 | #endif |
---|
85 | |
---|
86 | BlockCipher *m_cipher; |
---|
87 | AlignedSecByteBlock m_register; |
---|
88 | }; |
---|
89 | |
---|
90 | //! \class ModePolicyCommonTemplate |
---|
91 | //! \brief Block cipher mode of operation common operations |
---|
92 | //! \tparam POLICY_INTERFACE common operations |
---|
93 | template <class POLICY_INTERFACE> |
---|
94 | class CRYPTOPP_NO_VTABLE ModePolicyCommonTemplate : public CipherModeBase, public POLICY_INTERFACE |
---|
95 | { |
---|
96 | unsigned int GetAlignment() const {return m_cipher->OptimalDataAlignment();} |
---|
97 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); |
---|
98 | }; |
---|
99 | |
---|
100 | template <class POLICY_INTERFACE> |
---|
101 | void ModePolicyCommonTemplate<POLICY_INTERFACE>::CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) |
---|
102 | { |
---|
103 | m_cipher->SetKey(key, length, params); |
---|
104 | ResizeBuffers(); |
---|
105 | int feedbackSize = params.GetIntValueWithDefault(Name::FeedbackSize(), 0); |
---|
106 | SetFeedbackSize(feedbackSize); |
---|
107 | } |
---|
108 | |
---|
109 | //! \class CFB_ModePolicy |
---|
110 | //! \brief CFB block cipher mode of operation |
---|
111 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTemplate<CFB_CipherAbstractPolicy> |
---|
112 | { |
---|
113 | public: |
---|
114 | IV_Requirement IVRequirement() const {return RANDOM_IV;} |
---|
115 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "CFB";} |
---|
116 | |
---|
117 | protected: |
---|
118 | unsigned int GetBytesPerIteration() const {return m_feedbackSize;} |
---|
119 | byte * GetRegisterBegin() {return m_register + BlockSize() - m_feedbackSize;} |
---|
120 | bool CanIterate() const {return m_feedbackSize == BlockSize();} |
---|
121 | void Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount); |
---|
122 | void TransformRegister(); |
---|
123 | void CipherResynchronize(const byte *iv, size_t length); |
---|
124 | void SetFeedbackSize(unsigned int feedbackSize); |
---|
125 | void ResizeBuffers(); |
---|
126 | |
---|
127 | SecByteBlock m_temp; |
---|
128 | unsigned int m_feedbackSize; |
---|
129 | }; |
---|
130 | |
---|
131 | inline void CopyOrZero(void *dest, const void *src, size_t s) |
---|
132 | { |
---|
133 | if (src) |
---|
134 | memcpy_s(dest, s, src, s); |
---|
135 | else |
---|
136 | memset(dest, 0, s); |
---|
137 | } |
---|
138 | |
---|
139 | //! \class OFB_ModePolicy |
---|
140 | //! \brief OFB block cipher mode of operation |
---|
141 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy> |
---|
142 | { |
---|
143 | public: |
---|
144 | bool CipherIsRandomAccess() const {return false;} |
---|
145 | IV_Requirement IVRequirement() const {return UNIQUE_IV;} |
---|
146 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "OFB";} |
---|
147 | |
---|
148 | private: |
---|
149 | unsigned int GetBytesPerIteration() const {return BlockSize();} |
---|
150 | unsigned int GetIterationsToBuffer() const {return m_cipher->OptimalNumberOfParallelBlocks();} |
---|
151 | void WriteKeystream(byte *keystreamBuffer, size_t iterationCount); |
---|
152 | void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length); |
---|
153 | }; |
---|
154 | |
---|
155 | //! \class CTR_ModePolicy |
---|
156 | //! \brief CTR block cipher mode of operation |
---|
157 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy> |
---|
158 | { |
---|
159 | public: |
---|
160 | bool CipherIsRandomAccess() const {return true;} |
---|
161 | IV_Requirement IVRequirement() const {return RANDOM_IV;} |
---|
162 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "CTR";} |
---|
163 | |
---|
164 | protected: |
---|
165 | virtual void IncrementCounterBy256(); |
---|
166 | |
---|
167 | unsigned int GetAlignment() const {return m_cipher->OptimalDataAlignment();} |
---|
168 | unsigned int GetBytesPerIteration() const {return BlockSize();} |
---|
169 | unsigned int GetIterationsToBuffer() const {return m_cipher->OptimalNumberOfParallelBlocks();} |
---|
170 | void WriteKeystream(byte *buffer, size_t iterationCount) |
---|
171 | {OperateKeystream(WRITE_KEYSTREAM, buffer, NULL, iterationCount);} |
---|
172 | bool CanOperateKeystream() const {return true;} |
---|
173 | void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); |
---|
174 | void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length); |
---|
175 | void SeekToIteration(lword iterationCount); |
---|
176 | |
---|
177 | AlignedSecByteBlock m_counterArray; |
---|
178 | }; |
---|
179 | |
---|
180 | //! \class BlockOrientedCipherModeBase |
---|
181 | //! \brief Block cipher mode of operation default implementation |
---|
182 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase |
---|
183 | { |
---|
184 | public: |
---|
185 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); |
---|
186 | unsigned int MandatoryBlockSize() const {return BlockSize();} |
---|
187 | bool IsRandomAccess() const {return false;} |
---|
188 | bool IsSelfInverting() const {return false;} |
---|
189 | bool IsForwardTransformation() const {return m_cipher->IsForwardTransformation();} |
---|
190 | void Resynchronize(const byte *iv, int length=-1) {memcpy_s(m_register, m_register.size(), iv, ThrowIfInvalidIVLength(length));} |
---|
191 | |
---|
192 | protected: |
---|
193 | bool RequireAlignedInput() const {return true;} |
---|
194 | |
---|
195 | // Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 |
---|
196 | #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 |
---|
197 | void ResizeBuffers(); |
---|
198 | #else |
---|
199 | void ResizeBuffers() |
---|
200 | { |
---|
201 | CipherModeBase::ResizeBuffers(); |
---|
202 | m_buffer.New(BlockSize()); |
---|
203 | } |
---|
204 | #endif |
---|
205 | |
---|
206 | SecByteBlock m_buffer; |
---|
207 | }; |
---|
208 | |
---|
209 | //! \class ECB_OneWay |
---|
210 | //! \brief ECB block cipher mode of operation default implementation |
---|
211 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase |
---|
212 | { |
---|
213 | public: |
---|
214 | void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs) |
---|
215 | {m_cipher->SetKey(key, length, params); BlockOrientedCipherModeBase::ResizeBuffers();} |
---|
216 | IV_Requirement IVRequirement() const {return NOT_RESYNCHRONIZABLE;} |
---|
217 | unsigned int OptimalBlockSize() const {return BlockSize() * m_cipher->OptimalNumberOfParallelBlocks();} |
---|
218 | void ProcessData(byte *outString, const byte *inString, size_t length); |
---|
219 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECB";} |
---|
220 | }; |
---|
221 | |
---|
222 | //! \class CBC_ModeBase |
---|
223 | //! \brief CBC block cipher mode of operation default implementation |
---|
224 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherModeBase |
---|
225 | { |
---|
226 | public: |
---|
227 | IV_Requirement IVRequirement() const {return UNPREDICTABLE_RANDOM_IV;} |
---|
228 | bool RequireAlignedInput() const {return false;} |
---|
229 | unsigned int MinLastBlockSize() const {return 0;} |
---|
230 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC";} |
---|
231 | }; |
---|
232 | |
---|
233 | //! \class CBC_Encryption |
---|
234 | //! \brief CBC block cipher mode of operation encryption operation |
---|
235 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Encryption : public CBC_ModeBase |
---|
236 | { |
---|
237 | public: |
---|
238 | void ProcessData(byte *outString, const byte *inString, size_t length); |
---|
239 | }; |
---|
240 | |
---|
241 | //! \class CBC_CTS_Encryption |
---|
242 | //! \brief CBC-CTS block cipher mode of operation encryption operation |
---|
243 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption |
---|
244 | { |
---|
245 | public: |
---|
246 | void SetStolenIV(byte *iv) {m_stolenIV = iv;} |
---|
247 | unsigned int MinLastBlockSize() const {return BlockSize()+1;} |
---|
248 | void ProcessLastBlock(byte *outString, const byte *inString, size_t length); |
---|
249 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";} |
---|
250 | |
---|
251 | protected: |
---|
252 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) |
---|
253 | { |
---|
254 | CBC_Encryption::UncheckedSetKey(key, length, params); |
---|
255 | m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), (byte *)NULL); |
---|
256 | } |
---|
257 | |
---|
258 | byte *m_stolenIV; |
---|
259 | }; |
---|
260 | |
---|
261 | //! \class CBC_Decryption |
---|
262 | //! \brief CBC block cipher mode of operation decryption operation |
---|
263 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase |
---|
264 | { |
---|
265 | public: |
---|
266 | void ProcessData(byte *outString, const byte *inString, size_t length); |
---|
267 | |
---|
268 | protected: |
---|
269 | |
---|
270 | // Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 |
---|
271 | #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 |
---|
272 | void ResizeBuffers(); |
---|
273 | #else |
---|
274 | void ResizeBuffers() |
---|
275 | { |
---|
276 | BlockOrientedCipherModeBase::ResizeBuffers(); |
---|
277 | m_temp.New(BlockSize()); |
---|
278 | } |
---|
279 | #endif |
---|
280 | |
---|
281 | AlignedSecByteBlock m_temp; |
---|
282 | }; |
---|
283 | |
---|
284 | //! \class CBC_CTS_Decryption |
---|
285 | //! \brief CBC-CTS block cipher mode of operation decryption operation |
---|
286 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Decryption : public CBC_Decryption |
---|
287 | { |
---|
288 | public: |
---|
289 | unsigned int MinLastBlockSize() const {return BlockSize()+1;} |
---|
290 | void ProcessLastBlock(byte *outString, const byte *inString, size_t length); |
---|
291 | }; |
---|
292 | |
---|
293 | //! \class CipherModeFinalTemplate_CipherHolder |
---|
294 | //! \brief Block cipher mode of operation aggregate |
---|
295 | template <class CIPHER, class BASE> |
---|
296 | class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder<CIPHER>, public AlgorithmImpl<BASE, CipherModeFinalTemplate_CipherHolder<CIPHER, BASE> > |
---|
297 | { |
---|
298 | public: |
---|
299 | CipherModeFinalTemplate_CipherHolder() |
---|
300 | { |
---|
301 | this->m_cipher = &this->m_object; |
---|
302 | this->ResizeBuffers(); |
---|
303 | } |
---|
304 | CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length) |
---|
305 | { |
---|
306 | this->m_cipher = &this->m_object; |
---|
307 | this->SetKey(key, length); |
---|
308 | } |
---|
309 | CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv) |
---|
310 | { |
---|
311 | this->m_cipher = &this->m_object; |
---|
312 | this->SetKey(key, length, MakeParameters(Name::IV(), ConstByteArrayParameter(iv, this->m_cipher->BlockSize()))); |
---|
313 | } |
---|
314 | CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv, int feedbackSize) |
---|
315 | { |
---|
316 | this->m_cipher = &this->m_object; |
---|
317 | this->SetKey(key, length, MakeParameters(Name::IV(), ConstByteArrayParameter(iv, this->m_cipher->BlockSize()))(Name::FeedbackSize(), feedbackSize)); |
---|
318 | } |
---|
319 | |
---|
320 | static std::string CRYPTOPP_API StaticAlgorithmName() |
---|
321 | {return CIPHER::StaticAlgorithmName() + "/" + BASE::StaticAlgorithmName();} |
---|
322 | }; |
---|
323 | |
---|
324 | //! \class CipherModeFinalTemplate_ExternalCipher |
---|
325 | //! \tparam BASE CipherModeFinalTemplate_CipherHolder base class |
---|
326 | //! \details |
---|
327 | template <class BASE> |
---|
328 | class CipherModeFinalTemplate_ExternalCipher : public BASE |
---|
329 | { |
---|
330 | public: |
---|
331 | CipherModeFinalTemplate_ExternalCipher() {} |
---|
332 | CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher) |
---|
333 | {this->SetCipher(cipher);} |
---|
334 | CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize = 0) |
---|
335 | {this->SetCipherWithIV(cipher, iv, feedbackSize);} |
---|
336 | |
---|
337 | std::string AlgorithmName() const |
---|
338 | {return (this->m_cipher ? this->m_cipher->AlgorithmName() + "/" : std::string("")) + BASE::StaticAlgorithmName();} |
---|
339 | }; |
---|
340 | |
---|
341 | CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >; |
---|
342 | CRYPTOPP_DLL_TEMPLATE_CLASS CFB_EncryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >; |
---|
343 | CRYPTOPP_DLL_TEMPLATE_CLASS CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >; |
---|
344 | |
---|
345 | //! \class CFB_Mode |
---|
346 | //! \brief CFB block cipher mode of operation. |
---|
347 | template <class CIPHER> |
---|
348 | struct CFB_Mode : public CipherModeDocumentation |
---|
349 | { |
---|
350 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, CFB_EncryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > Encryption; |
---|
351 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > Decryption; |
---|
352 | }; |
---|
353 | |
---|
354 | //! \class CFB_Mode_ExternalCipher |
---|
355 | //! \brief CFB mode, external cipher. |
---|
356 | struct CFB_Mode_ExternalCipher : public CipherModeDocumentation |
---|
357 | { |
---|
358 | typedef CipherModeFinalTemplate_ExternalCipher<ConcretePolicyHolder<Empty, CFB_EncryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > Encryption; |
---|
359 | typedef CipherModeFinalTemplate_ExternalCipher<ConcretePolicyHolder<Empty, CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > Decryption; |
---|
360 | }; |
---|
361 | |
---|
362 | //! \class CFB_FIPS_Mode |
---|
363 | //! \brief CFB block cipher mode of operation providing FIPS validated cryptography. |
---|
364 | //! \details Requires full block plaintext according to FIPS 800-38A |
---|
365 | template <class CIPHER> |
---|
366 | struct CFB_FIPS_Mode : public CipherModeDocumentation |
---|
367 | { |
---|
368 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, CFB_RequireFullDataBlocks<CFB_EncryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > > Encryption; |
---|
369 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, CFB_RequireFullDataBlocks<CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > > Decryption; |
---|
370 | }; |
---|
371 | |
---|
372 | //! \class CFB_FIPS_Mode_ExternalCipher |
---|
373 | //! \brief CFB mode, external cipher, providing FIPS validated cryptography. |
---|
374 | //! \details Requires full block plaintext according to FIPS 800-38A |
---|
375 | struct CFB_FIPS_Mode_ExternalCipher : public CipherModeDocumentation |
---|
376 | { |
---|
377 | typedef CipherModeFinalTemplate_ExternalCipher<ConcretePolicyHolder<Empty, CFB_RequireFullDataBlocks<CFB_EncryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > > Encryption; |
---|
378 | typedef CipherModeFinalTemplate_ExternalCipher<ConcretePolicyHolder<Empty, CFB_RequireFullDataBlocks<CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > > Decryption; |
---|
379 | }; |
---|
380 | |
---|
381 | CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, OFB_ModePolicy> >; |
---|
382 | |
---|
383 | //! \class OFB_Mode |
---|
384 | //! \brief OFB block cipher mode of operation. |
---|
385 | template <class CIPHER> |
---|
386 | struct OFB_Mode : public CipherModeDocumentation |
---|
387 | { |
---|
388 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, OFB_ModePolicy> > > > Encryption; |
---|
389 | typedef Encryption Decryption; |
---|
390 | }; |
---|
391 | |
---|
392 | //! \class OFB_Mode_ExternalCipher |
---|
393 | //! \brief OFB mode, external cipher. |
---|
394 | struct OFB_Mode_ExternalCipher : public CipherModeDocumentation |
---|
395 | { |
---|
396 | typedef CipherModeFinalTemplate_ExternalCipher<ConcretePolicyHolder<Empty, AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, OFB_ModePolicy> > > > Encryption; |
---|
397 | typedef Encryption Decryption; |
---|
398 | }; |
---|
399 | |
---|
400 | CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, CTR_ModePolicy> >; |
---|
401 | CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher<ConcretePolicyHolder<Empty, AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, CTR_ModePolicy> > > >; |
---|
402 | |
---|
403 | //! \class CTR_Mode |
---|
404 | //! \brief CTR block cipher mode of operation. |
---|
405 | template <class CIPHER> |
---|
406 | struct CTR_Mode : public CipherModeDocumentation |
---|
407 | { |
---|
408 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, CTR_ModePolicy> > > > Encryption; |
---|
409 | typedef Encryption Decryption; |
---|
410 | }; |
---|
411 | |
---|
412 | //! \class CTR_Mode_ExternalCipher |
---|
413 | //! \brief CTR mode, external cipher. |
---|
414 | struct CTR_Mode_ExternalCipher : public CipherModeDocumentation |
---|
415 | { |
---|
416 | typedef CipherModeFinalTemplate_ExternalCipher<ConcretePolicyHolder<Empty, AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, CTR_ModePolicy> > > > Encryption; |
---|
417 | typedef Encryption Decryption; |
---|
418 | }; |
---|
419 | |
---|
420 | //! \class ECB_Mode |
---|
421 | //! \brief ECB block cipher mode of operation. |
---|
422 | template <class CIPHER> |
---|
423 | struct ECB_Mode : public CipherModeDocumentation |
---|
424 | { |
---|
425 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ECB_OneWay> Encryption; |
---|
426 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Decryption, ECB_OneWay> Decryption; |
---|
427 | }; |
---|
428 | |
---|
429 | CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher<ECB_OneWay>; |
---|
430 | |
---|
431 | //! \class ECB_Mode_ExternalCipher |
---|
432 | //! \brief ECB mode, external cipher. |
---|
433 | struct ECB_Mode_ExternalCipher : public CipherModeDocumentation |
---|
434 | { |
---|
435 | typedef CipherModeFinalTemplate_ExternalCipher<ECB_OneWay> Encryption; |
---|
436 | typedef Encryption Decryption; |
---|
437 | }; |
---|
438 | |
---|
439 | //! CBC mode |
---|
440 | template <class CIPHER> |
---|
441 | struct CBC_Mode : public CipherModeDocumentation |
---|
442 | { |
---|
443 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, CBC_Encryption> Encryption; |
---|
444 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Decryption, CBC_Decryption> Decryption; |
---|
445 | }; |
---|
446 | |
---|
447 | CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher<CBC_Encryption>; |
---|
448 | CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher<CBC_Decryption>; |
---|
449 | |
---|
450 | //! CBC mode, external cipher |
---|
451 | struct CBC_Mode_ExternalCipher : public CipherModeDocumentation |
---|
452 | { |
---|
453 | typedef CipherModeFinalTemplate_ExternalCipher<CBC_Encryption> Encryption; |
---|
454 | typedef CipherModeFinalTemplate_ExternalCipher<CBC_Decryption> Decryption; |
---|
455 | }; |
---|
456 | |
---|
457 | //! CBC mode with ciphertext stealing |
---|
458 | template <class CIPHER> |
---|
459 | struct CBC_CTS_Mode : public CipherModeDocumentation |
---|
460 | { |
---|
461 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, CBC_CTS_Encryption> Encryption; |
---|
462 | typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Decryption, CBC_CTS_Decryption> Decryption; |
---|
463 | }; |
---|
464 | |
---|
465 | CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher<CBC_CTS_Encryption>; |
---|
466 | CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher<CBC_CTS_Decryption>; |
---|
467 | |
---|
468 | //! \class CBC_CTS_Mode_ExternalCipher |
---|
469 | //! \brief CBC mode with ciphertext stealing, external cipher |
---|
470 | struct CBC_CTS_Mode_ExternalCipher : public CipherModeDocumentation |
---|
471 | { |
---|
472 | typedef CipherModeFinalTemplate_ExternalCipher<CBC_CTS_Encryption> Encryption; |
---|
473 | typedef CipherModeFinalTemplate_ExternalCipher<CBC_CTS_Decryption> Decryption; |
---|
474 | }; |
---|
475 | |
---|
476 | #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY |
---|
477 | typedef CFB_Mode_ExternalCipher::Encryption CFBEncryption; |
---|
478 | typedef CFB_Mode_ExternalCipher::Decryption CFBDecryption; |
---|
479 | typedef OFB_Mode_ExternalCipher::Encryption OFB; |
---|
480 | typedef CTR_Mode_ExternalCipher::Encryption CounterMode; |
---|
481 | #endif |
---|
482 | |
---|
483 | NAMESPACE_END |
---|
484 | |
---|
485 | #endif |
---|