2003-02-24 01:06:41 +00:00
# ifndef CRYPTOPP_MODES_H
# define CRYPTOPP_MODES_H
2002-10-04 17:31:41 +00:00
2003-02-24 01:06:41 +00:00
/*! \file
2002-10-04 17:31:41 +00:00
*/
# include "cryptlib.h"
# include "secblock.h"
# include "misc.h"
# include "strciphr.h"
# include "argnames.h"
2003-02-03 23:59:45 +00:00
# include "algparam.h"
2002-10-04 17:31:41 +00:00
NAMESPACE_BEGIN ( CryptoPP )
2009-03-02 02:39:17 +00:00
//! Cipher modes documentation. See NIST SP 800-38A for definitions of these modes. See AuthenticatedSymmetricCipherDocumentation for authenticated encryption modes.
2002-10-04 17:31:41 +00:00
2003-02-24 01:06:41 +00:00
/*! Each class derived from this one defines two types, Encryption and Decryption,
both of which implement the SymmetricCipher interface .
For each mode there are two classes , one of which is a template class ,
and the other one has a name that ends in " _ExternalCipher " .
The " external cipher " mode objects hold a reference to the underlying block cipher ,
instead of holding an instance of it . The reference must be passed in to the constructor .
For the " cipher holder " classes , the CIPHER template parameter should be a class
derived from BlockCipherDocumentation , for example DES or AES .
2002-10-04 17:31:41 +00:00
*/
2003-02-24 01:06:41 +00:00
struct CipherModeDocumentation : public SymmetricCipherDocumentation
2002-10-04 17:31:41 +00:00
{
} ;
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher
2002-10-04 17:31:41 +00:00
{
public :
2005-07-12 04:23:32 +00:00
size_t MinKeyLength ( ) const { return m_cipher - > MinKeyLength ( ) ; }
size_t MaxKeyLength ( ) const { return m_cipher - > MaxKeyLength ( ) ; }
size_t DefaultKeyLength ( ) const { return m_cipher - > DefaultKeyLength ( ) ; }
size_t GetValidKeyLength ( size_t n ) const { return m_cipher - > GetValidKeyLength ( n ) ; }
bool IsValidKeyLength ( size_t n ) const { return m_cipher - > IsValidKeyLength ( n ) ; }
2002-10-04 17:31:41 +00:00
2009-03-02 02:39:17 +00:00
unsigned int OptimalDataAlignment ( ) const { return m_cipher - > OptimalDataAlignment ( ) ; }
2002-10-04 17:31:41 +00:00
2003-02-24 01:06:41 +00:00
unsigned int IVSize ( ) const { return BlockSize ( ) ; }
virtual IV_Requirement IVRequirement ( ) const = 0 ;
2002-10-04 17:31:41 +00:00
2007-12-05 13:50:44 +00:00
void SetCipher ( BlockCipher & cipher )
{
this - > ThrowIfResynchronizable ( ) ;
this - > m_cipher = & cipher ;
this - > ResizeBuffers ( ) ;
}
void SetCipherWithIV ( BlockCipher & cipher , const byte * iv , int feedbackSize = 0 )
{
this - > ThrowIfInvalidIV ( iv ) ;
this - > m_cipher = & cipher ;
this - > ResizeBuffers ( ) ;
this - > SetFeedbackSize ( feedbackSize ) ;
if ( this - > IsResynchronizable ( ) )
this - > Resynchronize ( iv ) ;
}
2002-10-04 17:31:41 +00:00
protected :
2009-03-02 02:39:17 +00:00
CipherModeBase ( ) : m_cipher ( NULL ) { }
2005-07-12 04:23:32 +00:00
inline unsigned int BlockSize ( ) const { assert ( m_register . size ( ) > 0 ) ; return ( unsigned int ) m_register . size ( ) ; }
2003-02-24 01:06:41 +00:00
virtual void SetFeedbackSize ( unsigned int feedbackSize )
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
if ( ! ( feedbackSize = = 0 | | feedbackSize = = BlockSize ( ) ) )
throw InvalidArgument ( " CipherModeBase: feedback size cannot be specified for this cipher mode " ) ;
2002-10-04 17:31:41 +00:00
}
2003-02-24 01:06:41 +00:00
virtual void ResizeBuffers ( )
2002-10-04 17:31:41 +00:00
{
m_register . New ( m_cipher - > BlockSize ( ) ) ;
}
2003-02-24 01:06:41 +00:00
BlockCipher * m_cipher ;
2009-03-02 02:39:17 +00:00
AlignedSecByteBlock m_register ;
2002-10-04 17:31:41 +00:00
} ;
2003-02-24 01:06:41 +00:00
template < class POLICY_INTERFACE >
2003-05-16 00:53:53 +00:00
class CRYPTOPP_NO_VTABLE ModePolicyCommonTemplate : public CipherModeBase , public POLICY_INTERFACE
2002-10-04 17:31:41 +00:00
{
2009-03-02 02:39:17 +00:00
unsigned int GetAlignment ( ) const { return m_cipher - > OptimalDataAlignment ( ) ; }
2005-07-12 04:23:32 +00:00
void CipherSetKey ( const NameValuePairs & params , const byte * key , size_t length ) ;
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
template < class POLICY_INTERFACE >
2005-07-12 04:23:32 +00:00
void ModePolicyCommonTemplate < POLICY_INTERFACE > : : CipherSetKey ( const NameValuePairs & params , const byte * key , size_t length )
2003-07-04 00:17:37 +00:00
{
m_cipher - > SetKey ( key , length , params ) ;
ResizeBuffers ( ) ;
int feedbackSize = params . GetIntValueWithDefault ( Name : : FeedbackSize ( ) , 0 ) ;
SetFeedbackSize ( feedbackSize ) ;
}
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTemplate < CFB_CipherAbstractPolicy >
2002-10-04 17:31:41 +00:00
{
public :
IV_Requirement IVRequirement ( ) const { return RANDOM_IV ; }
2005-01-20 04:19:35 +00:00
static const char * CRYPTOPP_API StaticAlgorithmName ( ) { return " CFB " ; }
2002-10-04 17:31:41 +00:00
protected :
2003-02-24 01:06:41 +00:00
unsigned int GetBytesPerIteration ( ) const { return m_feedbackSize ; }
2002-10-04 17:31:41 +00:00
byte * GetRegisterBegin ( ) { return m_register + BlockSize ( ) - m_feedbackSize ; }
2009-03-12 11:24:12 +00:00
bool CanIterate ( ) const { return m_feedbackSize = = BlockSize ( ) ; }
void Iterate ( byte * output , const byte * input , CipherDir dir , size_t iterationCount ) ;
void TransformRegister ( ) ;
void CipherResynchronize ( const byte * iv , size_t length ) ;
void SetFeedbackSize ( unsigned int feedbackSize ) ;
void ResizeBuffers ( ) ;
2002-10-04 17:31:41 +00:00
SecByteBlock m_temp ;
unsigned int m_feedbackSize ;
} ;
2003-03-26 21:50:44 +00:00
inline void CopyOrZero ( void * dest , const void * src , size_t s )
{
if ( src )
2006-03-13 13:26:41 +00:00
memcpy_s ( dest , s , src , s ) ;
2003-03-26 21:50:44 +00:00
else
memset ( dest , 0 , s ) ;
}
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTemplate < AdditiveCipherAbstractPolicy >
2002-10-04 17:31:41 +00:00
{
2003-07-04 00:17:37 +00:00
public :
2008-02-02 08:40:27 +00:00
bool CipherIsRandomAccess ( ) const { return false ; }
2007-04-16 00:34:13 +00:00
IV_Requirement IVRequirement ( ) const { return UNIQUE_IV ; }
2005-01-20 04:19:35 +00:00
static const char * CRYPTOPP_API StaticAlgorithmName ( ) { return " OFB " ; }
2003-07-04 00:17:37 +00:00
private :
2003-02-24 01:06:41 +00:00
unsigned int GetBytesPerIteration ( ) const { return BlockSize ( ) ; }
2009-03-02 02:39:17 +00:00
unsigned int GetIterationsToBuffer ( ) const { return m_cipher - > OptimalNumberOfParallelBlocks ( ) ; }
void WriteKeystream ( byte * keystreamBuffer , size_t iterationCount ) ;
void CipherResynchronize ( byte * keystreamBuffer , const byte * iv , size_t length ) ;
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTemplate < AdditiveCipherAbstractPolicy >
2002-10-04 17:31:41 +00:00
{
2003-07-04 00:17:37 +00:00
public :
2008-02-02 08:40:27 +00:00
bool CipherIsRandomAccess ( ) const { return true ; }
2009-03-02 02:39:17 +00:00
IV_Requirement IVRequirement ( ) const { return RANDOM_IV ; }
2006-07-17 14:50:43 +00:00
static const char * CRYPTOPP_API StaticAlgorithmName ( ) { return " CTR " ; }
2003-07-04 00:17:37 +00:00
2009-03-02 02:39:17 +00:00
protected :
virtual void IncrementCounterBy256 ( ) ;
unsigned int GetAlignment ( ) const { return m_cipher - > OptimalDataAlignment ( ) ; }
2003-02-24 01:06:41 +00:00
unsigned int GetBytesPerIteration ( ) const { return BlockSize ( ) ; }
2002-10-04 17:31:41 +00:00
unsigned int GetIterationsToBuffer ( ) const { return m_cipher - > OptimalNumberOfParallelBlocks ( ) ; }
2005-07-12 04:23:32 +00:00
void WriteKeystream ( byte * buffer , size_t iterationCount )
2002-10-04 17:31:41 +00:00
{ OperateKeystream ( WRITE_KEYSTREAM , buffer , NULL , iterationCount ) ; }
bool CanOperateKeystream ( ) const { return true ; }
2005-07-12 04:23:32 +00:00
void OperateKeystream ( KeystreamOperation operation , byte * output , const byte * input , size_t iterationCount ) ;
2009-03-02 02:39:17 +00:00
void CipherResynchronize ( byte * keystreamBuffer , const byte * iv , size_t length ) ;
2003-07-25 00:15:52 +00:00
void SeekToIteration ( lword iterationCount ) ;
2002-10-04 17:31:41 +00:00
2009-03-02 02:39:17 +00:00
AlignedSecByteBlock m_counterArray ;
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase
2002-10-04 17:31:41 +00:00
{
public :
2006-12-10 02:12:23 +00:00
void UncheckedSetKey ( const byte * key , unsigned int length , const NameValuePairs & params ) ;
2003-02-24 01:06:41 +00:00
unsigned int MandatoryBlockSize ( ) const { return BlockSize ( ) ; }
bool IsRandomAccess ( ) const { return false ; }
2002-10-04 17:31:41 +00:00
bool IsSelfInverting ( ) const { return false ; }
bool IsForwardTransformation ( ) const { return m_cipher - > IsForwardTransformation ( ) ; }
2009-03-02 02:39:17 +00:00
void Resynchronize ( const byte * iv , int length = - 1 ) { memcpy_s ( m_register , m_register . size ( ) , iv , ThrowIfInvalidIVLength ( length ) ) ; }
2002-10-04 17:31:41 +00:00
protected :
bool RequireAlignedInput ( ) const { return true ; }
void ResizeBuffers ( )
{
CipherModeBase : : ResizeBuffers ( ) ;
m_buffer . New ( BlockSize ( ) ) ;
}
SecByteBlock m_buffer ;
} ;
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase
2002-10-04 17:31:41 +00:00
{
public :
2007-04-16 00:34:13 +00:00
void SetKey ( const byte * key , size_t length , const NameValuePairs & params = g_nullNameValuePairs )
{ m_cipher - > SetKey ( key , length , params ) ; BlockOrientedCipherModeBase : : ResizeBuffers ( ) ; }
2002-10-04 17:31:41 +00:00
IV_Requirement IVRequirement ( ) const { return NOT_RESYNCHRONIZABLE ; }
2003-02-24 01:06:41 +00:00
unsigned int OptimalBlockSize ( ) const { return BlockSize ( ) * m_cipher - > OptimalNumberOfParallelBlocks ( ) ; }
2009-03-02 02:39:17 +00:00
void ProcessData ( byte * outString , const byte * inString , size_t length ) ;
2005-01-20 04:19:35 +00:00
static const char * CRYPTOPP_API StaticAlgorithmName ( ) { return " ECB " ; }
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherModeBase
2002-10-04 17:31:41 +00:00
{
public :
IV_Requirement IVRequirement ( ) const { return UNPREDICTABLE_RANDOM_IV ; }
bool RequireAlignedInput ( ) const { return false ; }
2003-02-24 01:06:41 +00:00
unsigned int MinLastBlockSize ( ) const { return 0 ; }
2005-01-20 04:19:35 +00:00
static const char * CRYPTOPP_API StaticAlgorithmName ( ) { return " CBC " ; }
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Encryption : public CBC_ModeBase
2002-10-04 17:31:41 +00:00
{
public :
2009-03-02 02:39:17 +00:00
void ProcessData ( byte * outString , const byte * inString , size_t length ) ;
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption
2002-10-04 17:31:41 +00:00
{
public :
void SetStolenIV ( byte * iv ) { m_stolenIV = iv ; }
2003-02-24 01:06:41 +00:00
unsigned int MinLastBlockSize ( ) const { return BlockSize ( ) + 1 ; }
2005-07-12 04:23:32 +00:00
void ProcessLastBlock ( byte * outString , const byte * inString , size_t length ) ;
2005-01-20 04:19:35 +00:00
static const char * CRYPTOPP_API StaticAlgorithmName ( ) { return " CBC/CTS " ; }
2002-10-04 17:31:41 +00:00
protected :
2006-12-10 02:12:23 +00:00
void UncheckedSetKey ( const byte * key , unsigned int length , const NameValuePairs & params )
2002-10-04 17:31:41 +00:00
{
2006-12-10 02:12:23 +00:00
CBC_Encryption : : UncheckedSetKey ( key , length , params ) ;
2003-02-24 01:06:41 +00:00
m_stolenIV = params . GetValueWithDefault ( Name : : StolenIV ( ) , ( byte * ) NULL ) ;
2002-10-04 17:31:41 +00:00
}
byte * m_stolenIV ;
} ;
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase
2002-10-04 17:31:41 +00:00
{
public :
2009-03-02 02:39:17 +00:00
void ProcessData ( byte * outString , const byte * inString , size_t length ) ;
2002-10-04 17:31:41 +00:00
protected :
void ResizeBuffers ( )
{
BlockOrientedCipherModeBase : : ResizeBuffers ( ) ;
m_temp . New ( BlockSize ( ) ) ;
}
2009-03-02 02:39:17 +00:00
AlignedSecByteBlock m_temp ;
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Decryption : public CBC_Decryption
2002-10-04 17:31:41 +00:00
{
2002-10-15 04:05:12 +00:00
public :
2003-02-24 01:06:41 +00:00
unsigned int MinLastBlockSize ( ) const { return BlockSize ( ) + 1 ; }
2005-07-12 04:23:32 +00:00
void ProcessLastBlock ( byte * outString , const byte * inString , size_t length ) ;
2002-10-04 17:31:41 +00:00
} ;
2004-07-22 00:51:57 +00:00
//! _
2003-02-24 01:06:41 +00:00
template < class CIPHER , class BASE >
2004-07-22 00:51:57 +00:00
class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder < CIPHER > , public AlgorithmImpl < BASE , CipherModeFinalTemplate_CipherHolder < CIPHER , BASE > >
2002-10-04 17:31:41 +00:00
{
public :
CipherModeFinalTemplate_CipherHolder ( )
{
2004-06-19 08:28:09 +00:00
this - > m_cipher = & this - > m_object ;
this - > ResizeBuffers ( ) ;
2002-10-04 17:31:41 +00:00
}
2005-07-12 04:23:32 +00:00
CipherModeFinalTemplate_CipherHolder ( const byte * key , size_t length )
2002-10-04 17:31:41 +00:00
{
2004-06-19 08:28:09 +00:00
this - > m_cipher = & this - > m_object ;
this - > SetKey ( key , length ) ;
2002-10-04 17:31:41 +00:00
}
2005-07-12 04:23:32 +00:00
CipherModeFinalTemplate_CipherHolder ( const byte * key , size_t length , const byte * iv )
2004-03-09 12:40:25 +00:00
{
2004-06-19 08:28:09 +00:00
this - > m_cipher = & this - > m_object ;
2009-03-12 11:24:12 +00:00
this - > SetKey ( key , length , MakeParameters ( Name : : IV ( ) , ConstByteArrayParameter ( iv , this - > m_cipher - > BlockSize ( ) ) ) ) ;
2004-03-09 12:40:25 +00:00
}
2005-07-12 04:23:32 +00:00
CipherModeFinalTemplate_CipherHolder ( const byte * key , size_t length , const byte * iv , int feedbackSize )
2002-10-04 17:31:41 +00:00
{
2004-06-19 08:28:09 +00:00
this - > m_cipher = & this - > m_object ;
2009-03-12 11:24:12 +00:00
this - > SetKey ( key , length , MakeParameters ( Name : : IV ( ) , ConstByteArrayParameter ( iv , this - > m_cipher - > BlockSize ( ) ) ) ( Name : : FeedbackSize ( ) , feedbackSize ) ) ;
2002-10-04 17:31:41 +00:00
}
2004-07-22 00:51:57 +00:00
2005-01-20 04:19:35 +00:00
static std : : string CRYPTOPP_API StaticAlgorithmName ( )
2004-07-22 00:51:57 +00:00
{ return CIPHER : : StaticAlgorithmName ( ) + " / " + BASE : : StaticAlgorithmName ( ) ; }
2002-10-04 17:31:41 +00:00
} ;
2004-07-22 00:51:57 +00:00
//! _
2003-02-24 01:06:41 +00:00
template < class BASE >
2002-10-04 17:31:41 +00:00
class CipherModeFinalTemplate_ExternalCipher : public BASE
{
public :
2003-07-18 04:35:30 +00:00
CipherModeFinalTemplate_ExternalCipher ( ) { }
CipherModeFinalTemplate_ExternalCipher ( BlockCipher & cipher )
2008-11-21 03:05:32 +00:00
{ this - > SetCipher ( cipher ) ; }
2003-07-18 04:35:30 +00:00
CipherModeFinalTemplate_ExternalCipher ( BlockCipher & cipher , const byte * iv , int feedbackSize = 0 )
2008-11-21 03:05:32 +00:00
{ this - > SetCipherWithIV ( cipher , iv , feedbackSize ) ; }
2003-07-18 04:35:30 +00:00
2007-12-05 13:50:44 +00:00
std : : string AlgorithmName ( ) const
2009-03-02 02:39:17 +00:00
{ return ( this - > m_cipher ? this - > m_cipher - > AlgorithmName ( ) + " / " : std : : string ( " " ) ) + BASE : : StaticAlgorithmName ( ) ; }
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > ;
CRYPTOPP_DLL_TEMPLATE_CLASS CFB_EncryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > ;
CRYPTOPP_DLL_TEMPLATE_CLASS CFB_DecryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > ;
2003-02-24 01:06:41 +00:00
//! CFB mode
template < class CIPHER >
struct CFB_Mode : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Encryption , ConcretePolicyHolder < Empty , CFB_EncryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > > > Encryption ;
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Encryption , ConcretePolicyHolder < Empty , CFB_DecryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > > > Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-02-24 01:06:41 +00:00
//! CFB mode, external cipher
struct CFB_Mode_ExternalCipher : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_ExternalCipher < ConcretePolicyHolder < Empty , CFB_EncryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > > > Encryption ;
typedef CipherModeFinalTemplate_ExternalCipher < ConcretePolicyHolder < Empty , CFB_DecryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > > > Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2004-04-29 16:00:39 +00:00
//! CFB mode FIPS variant, requiring full block plaintext according to FIPS 800-38A
template < class CIPHER >
struct CFB_FIPS_Mode : public CipherModeDocumentation
{
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Encryption , ConcretePolicyHolder < Empty , CFB_RequireFullDataBlocks < CFB_EncryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > > > > Encryption ;
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Encryption , ConcretePolicyHolder < Empty , CFB_RequireFullDataBlocks < CFB_DecryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > > > > Decryption ;
} ;
//! CFB mode FIPS variant, requiring full block plaintext according to FIPS 800-38A, external cipher
struct CFB_FIPS_Mode_ExternalCipher : public CipherModeDocumentation
{
typedef CipherModeFinalTemplate_ExternalCipher < ConcretePolicyHolder < Empty , CFB_RequireFullDataBlocks < CFB_EncryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > > > > Encryption ;
typedef CipherModeFinalTemplate_ExternalCipher < ConcretePolicyHolder < Empty , CFB_RequireFullDataBlocks < CFB_DecryptionTemplate < AbstractPolicyHolder < CFB_CipherAbstractPolicy , CFB_ModePolicy > > > > > Decryption ;
} ;
2003-07-04 00:17:37 +00:00
CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate < AbstractPolicyHolder < AdditiveCipherAbstractPolicy , OFB_ModePolicy > > ;
2003-02-24 01:06:41 +00:00
//! OFB mode
template < class CIPHER >
struct OFB_Mode : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Encryption , ConcretePolicyHolder < Empty , AdditiveCipherTemplate < AbstractPolicyHolder < AdditiveCipherAbstractPolicy , OFB_ModePolicy > > > > Encryption ;
typedef Encryption Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-02-24 01:06:41 +00:00
//! OFB mode, external cipher
struct OFB_Mode_ExternalCipher : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_ExternalCipher < ConcretePolicyHolder < Empty , AdditiveCipherTemplate < AbstractPolicyHolder < AdditiveCipherAbstractPolicy , OFB_ModePolicy > > > > Encryption ;
typedef Encryption Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate < AbstractPolicyHolder < AdditiveCipherAbstractPolicy , CTR_ModePolicy > > ;
2010-07-24 05:55:22 +00:00
CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher < ConcretePolicyHolder < Empty , AdditiveCipherTemplate < AbstractPolicyHolder < AdditiveCipherAbstractPolicy , CTR_ModePolicy > > > > ;
2003-07-04 00:17:37 +00:00
2003-02-24 01:06:41 +00:00
//! CTR mode
template < class CIPHER >
struct CTR_Mode : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Encryption , ConcretePolicyHolder < Empty , AdditiveCipherTemplate < AbstractPolicyHolder < AdditiveCipherAbstractPolicy , CTR_ModePolicy > > > > Encryption ;
typedef Encryption Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-02-24 01:06:41 +00:00
//! CTR mode, external cipher
struct CTR_Mode_ExternalCipher : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_ExternalCipher < ConcretePolicyHolder < Empty , AdditiveCipherTemplate < AbstractPolicyHolder < AdditiveCipherAbstractPolicy , CTR_ModePolicy > > > > Encryption ;
typedef Encryption Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-02-24 01:06:41 +00:00
//! ECB mode
template < class CIPHER >
struct ECB_Mode : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Encryption , ECB_OneWay > Encryption ;
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Decryption , ECB_OneWay > Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher < ECB_OneWay > ;
2003-02-24 01:06:41 +00:00
//! ECB mode, external cipher
struct ECB_Mode_ExternalCipher : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_ExternalCipher < ECB_OneWay > Encryption ;
typedef Encryption Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-02-24 01:06:41 +00:00
//! CBC mode
template < class CIPHER >
struct CBC_Mode : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Encryption , CBC_Encryption > Encryption ;
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Decryption , CBC_Decryption > Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher < CBC_Encryption > ;
CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher < CBC_Decryption > ;
2003-02-24 01:06:41 +00:00
//! CBC mode, external cipher
struct CBC_Mode_ExternalCipher : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_ExternalCipher < CBC_Encryption > Encryption ;
typedef CipherModeFinalTemplate_ExternalCipher < CBC_Decryption > Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-02-24 01:06:41 +00:00
//! CBC mode with ciphertext stealing
template < class CIPHER >
struct CBC_CTS_Mode : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Encryption , CBC_CTS_Encryption > Encryption ;
typedef CipherModeFinalTemplate_CipherHolder < CPP_TYPENAME CIPHER : : Decryption , CBC_CTS_Decryption > Decryption ;
2002-10-04 17:31:41 +00:00
} ;
2003-07-04 00:17:37 +00:00
CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher < CBC_CTS_Encryption > ;
CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher < CBC_CTS_Decryption > ;
2003-02-24 01:06:41 +00:00
//! CBC mode with ciphertext stealing, external cipher
struct CBC_CTS_Mode_ExternalCipher : public CipherModeDocumentation
2002-10-04 17:31:41 +00:00
{
2003-02-24 01:06:41 +00:00
typedef CipherModeFinalTemplate_ExternalCipher < CBC_CTS_Encryption > Encryption ;
typedef CipherModeFinalTemplate_ExternalCipher < CBC_CTS_Decryption > Decryption ;
2002-10-04 17:31:41 +00:00
} ;
# ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
2003-02-24 01:06:41 +00:00
typedef CFB_Mode_ExternalCipher : : Encryption CFBEncryption ;
typedef CFB_Mode_ExternalCipher : : Decryption CFBDecryption ;
typedef OFB_Mode_ExternalCipher : : Encryption OFB ;
typedef CTR_Mode_ExternalCipher : : Encryption CounterMode ;
2002-10-04 17:31:41 +00:00
# endif
NAMESPACE_END
# endif