remove unused stuff
This commit is contained in:
@@ -13,9 +13,6 @@ void Modes_TestInstantiations()
|
|||||||
{
|
{
|
||||||
CFB_Mode<DES>::Encryption m0;
|
CFB_Mode<DES>::Encryption m0;
|
||||||
CFB_Mode<DES>::Decryption m1;
|
CFB_Mode<DES>::Decryption m1;
|
||||||
OFB_Mode<DES>::Encryption m2;
|
|
||||||
CTR_Mode<DES>::Encryption m3;
|
|
||||||
ECB_Mode<DES>::Encryption m4;
|
|
||||||
CBC_Mode<DES>::Encryption m5;
|
CBC_Mode<DES>::Encryption m5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,8 +24,6 @@ template class AdditiveCipherTemplate<>;
|
|||||||
template class CFB_CipherTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >;
|
template class CFB_CipherTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >;
|
||||||
template class CFB_EncryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >;
|
template class CFB_EncryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >;
|
||||||
template class CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >;
|
template class CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >;
|
||||||
template class AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, OFB_ModePolicy> >;
|
|
||||||
template class AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, CTR_ModePolicy> >;
|
|
||||||
|
|
||||||
void CipherModeBase::SetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
|
void CipherModeBase::SetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
@@ -60,18 +55,6 @@ void CipherModeBase::SetIV(const byte *iv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTR_ModePolicy::SeekToIteration(dword iterationCount)
|
|
||||||
{
|
|
||||||
int carry=0;
|
|
||||||
for (int i=BlockSize()-1; i>=0; i--)
|
|
||||||
{
|
|
||||||
unsigned int sum = m_register[i] + byte(iterationCount) + carry;
|
|
||||||
m_counterArray[i] = (byte) sum;
|
|
||||||
carry = sum >> 8;
|
|
||||||
iterationCount >>= 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void IncrementCounterByOne(byte *inout, unsigned int s)
|
static inline void IncrementCounterByOne(byte *inout, unsigned int s)
|
||||||
{
|
{
|
||||||
for (int i=s-1, carry=1; i>=0 && carry; i--)
|
for (int i=s-1, carry=1; i>=0 && carry; i--)
|
||||||
@@ -84,53 +67,6 @@ static inline void IncrementCounterByOne(byte *output, const byte *input, unsign
|
|||||||
carry = !(output[i] = input[i]+carry) && carry;
|
carry = !(output[i] = input[i]+carry) && carry;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CTR_ModePolicy::ProcessMultipleBlocks(byte *output, const byte *input, unsigned int n)
|
|
||||||
{
|
|
||||||
unsigned int s = BlockSize(), j = 0;
|
|
||||||
for (unsigned int i=1; i<n; i++, j+=s)
|
|
||||||
IncrementCounterByOne(m_counterArray + j + s, m_counterArray + j, s);
|
|
||||||
m_cipher->ProcessAndXorMultipleBlocks(m_counterArray, input, output, n);
|
|
||||||
IncrementCounterByOne(m_counterArray, m_counterArray + s*(n-1), s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CTR_ModePolicy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, unsigned int iterationCount)
|
|
||||||
{
|
|
||||||
unsigned int maxBlocks = m_cipher->OptimalNumberOfParallelBlocks();
|
|
||||||
if (maxBlocks == 1)
|
|
||||||
{
|
|
||||||
unsigned int sizeIncrement = BlockSize();
|
|
||||||
while (iterationCount)
|
|
||||||
{
|
|
||||||
m_cipher->ProcessAndXorBlock(m_counterArray, input, output);
|
|
||||||
IncrementCounterByOne(m_counterArray, sizeIncrement);
|
|
||||||
output += sizeIncrement;
|
|
||||||
input += sizeIncrement;
|
|
||||||
iterationCount -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unsigned int sizeIncrement = maxBlocks * BlockSize();
|
|
||||||
while (iterationCount >= maxBlocks)
|
|
||||||
{
|
|
||||||
ProcessMultipleBlocks(output, input, maxBlocks);
|
|
||||||
output += sizeIncrement;
|
|
||||||
input += sizeIncrement;
|
|
||||||
iterationCount -= maxBlocks;
|
|
||||||
}
|
|
||||||
if (iterationCount > 0)
|
|
||||||
ProcessMultipleBlocks(output, input, iterationCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CTR_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv)
|
|
||||||
{
|
|
||||||
unsigned int s = BlockSize();
|
|
||||||
memcpy(m_register, iv, s);
|
|
||||||
m_counterArray.New(s * m_cipher->OptimalNumberOfParallelBlocks());
|
|
||||||
memcpy(m_counterArray, iv, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BlockOrientedCipherModeBase::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length)
|
void BlockOrientedCipherModeBase::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length)
|
||||||
{
|
{
|
||||||
m_cipher->SetKey(key, length, params);
|
m_cipher->SetKey(key, length, params);
|
||||||
@@ -229,38 +165,4 @@ void CBC_Decryption::ProcessBlocks(byte *outString, const byte *inString, unsign
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBC_CTS_Decryption::ProcessLastBlock(byte *outString, const byte *inString, unsigned int length)
|
|
||||||
{
|
|
||||||
const byte *pn, *pn1;
|
|
||||||
bool stealIV = length <= BlockSize();
|
|
||||||
|
|
||||||
if (stealIV)
|
|
||||||
{
|
|
||||||
pn = inString;
|
|
||||||
pn1 = m_register;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pn = inString + BlockSize();
|
|
||||||
pn1 = inString;
|
|
||||||
length -= BlockSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// decrypt last partial plaintext block
|
|
||||||
memcpy(m_temp, pn1, BlockSize());
|
|
||||||
m_cipher->ProcessBlock(m_temp);
|
|
||||||
xorbuf(m_temp, pn, length);
|
|
||||||
|
|
||||||
if (stealIV)
|
|
||||||
memcpy(outString, m_temp, length);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memcpy(outString+BlockSize(), m_temp, length);
|
|
||||||
// decrypt next to last plaintext block
|
|
||||||
memcpy(m_temp, pn, length);
|
|
||||||
m_cipher->ProcessBlock(m_temp);
|
|
||||||
xorbuf(outString, m_temp, m_register, BlockSize());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NAMESPACE_END
|
NAMESPACE_END
|
||||||
|
|||||||
@@ -113,41 +113,6 @@ protected:
|
|||||||
unsigned int m_feedbackSize;
|
unsigned int m_feedbackSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OFB_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
|
|
||||||
{
|
|
||||||
unsigned int GetBytesPerIteration() const {return BlockSize();}
|
|
||||||
unsigned int GetIterationsToBuffer() const {return 1;}
|
|
||||||
void WriteKeystream(byte *keystreamBuffer, unsigned int iterationCount)
|
|
||||||
{
|
|
||||||
assert(iterationCount == 1);
|
|
||||||
m_cipher->ProcessBlock(keystreamBuffer);
|
|
||||||
}
|
|
||||||
void CipherResynchronize(byte *keystreamBuffer, const byte *iv)
|
|
||||||
{
|
|
||||||
memcpy(keystreamBuffer, iv, BlockSize());
|
|
||||||
}
|
|
||||||
bool IsRandomAccess() const {return false;}
|
|
||||||
IV_Requirement IVRequirement() const {return STRUCTURED_IV;}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CTR_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
|
|
||||||
{
|
|
||||||
unsigned int GetBytesPerIteration() const {return BlockSize();}
|
|
||||||
unsigned int GetIterationsToBuffer() const {return m_cipher->OptimalNumberOfParallelBlocks();}
|
|
||||||
void WriteKeystream(byte *buffer, unsigned int iterationCount)
|
|
||||||
{OperateKeystream(WRITE_KEYSTREAM, buffer, NULL, iterationCount);}
|
|
||||||
bool CanOperateKeystream() const {return true;}
|
|
||||||
void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, unsigned int iterationCount);
|
|
||||||
void CipherResynchronize(byte *keystreamBuffer, const byte *iv);
|
|
||||||
bool IsRandomAccess() const {return true;}
|
|
||||||
void SeekToIteration(dword iterationCount);
|
|
||||||
IV_Requirement IVRequirement() const {return STRUCTURED_IV;}
|
|
||||||
|
|
||||||
inline void ProcessMultipleBlocks(byte *output, const byte *input, unsigned int n);
|
|
||||||
|
|
||||||
SecByteBlock m_counterArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BlockOrientedCipherModeBase : public CipherModeBase
|
class BlockOrientedCipherModeBase : public CipherModeBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -171,15 +136,6 @@ protected:
|
|||||||
SecByteBlock m_buffer;
|
SecByteBlock m_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ECB_OneWay : public BlockOrientedCipherModeBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IV_Requirement IVRequirement() const {return NOT_RESYNCHRONIZABLE;}
|
|
||||||
unsigned int OptimalBlockSize() const {return BlockSize() * m_cipher->OptimalNumberOfParallelBlocks();}
|
|
||||||
void ProcessBlocks(byte *outString, const byte *inString, unsigned int numberOfBlocks)
|
|
||||||
{m_cipher->ProcessAndXorMultipleBlocks(inString, NULL, outString, numberOfBlocks);}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CBC_ModeBase : public BlockOrientedCipherModeBase
|
class CBC_ModeBase : public BlockOrientedCipherModeBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -225,13 +181,6 @@ protected:
|
|||||||
SecByteBlock m_temp;
|
SecByteBlock m_temp;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBC_CTS_Decryption : public CBC_Decryption
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
unsigned int MinLastBlockSize() const {return BlockSize()+1;}
|
|
||||||
void ProcessLastBlock(byte *outString, const byte *inString, unsigned int length);
|
|
||||||
};
|
|
||||||
|
|
||||||
//! .
|
//! .
|
||||||
template <class CIPHER, class BASE>
|
template <class CIPHER, class BASE>
|
||||||
class CipherModeFinalTemplate_CipherHolder : public ObjectHolder<CIPHER>, public BASE
|
class CipherModeFinalTemplate_CipherHolder : public ObjectHolder<CIPHER>, public BASE
|
||||||
@@ -254,20 +203,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//! .
|
|
||||||
template <class BASE>
|
|
||||||
class CipherModeFinalTemplate_ExternalCipher : public BASE
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv = NULL, int feedbackSize = 0)
|
|
||||||
{
|
|
||||||
m_cipher = &cipher;
|
|
||||||
ResizeBuffers();
|
|
||||||
SetFeedbackSize(feedbackSize);
|
|
||||||
SetIV(iv);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//! CFB mode
|
//! CFB mode
|
||||||
template <class CIPHER>
|
template <class CIPHER>
|
||||||
struct CFB_Mode : public CipherModeDocumentation
|
struct CFB_Mode : public CipherModeDocumentation
|
||||||
@@ -276,58 +211,6 @@ struct CFB_Mode : public CipherModeDocumentation
|
|||||||
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > Decryption;
|
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> > > > Decryption;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! CFB mode, external cipher
|
|
||||||
struct CFB_Mode_ExternalCipher : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! OFB mode
|
|
||||||
template <class CIPHER>
|
|
||||||
struct OFB_Mode : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, OFB_ModePolicy> > > > Encryption;
|
|
||||||
typedef Encryption Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! OFB mode, external cipher
|
|
||||||
struct OFB_Mode_ExternalCipher : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
typedef CipherModeFinalTemplate_ExternalCipher<ConcretePolicyHolder<Empty, AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, OFB_ModePolicy> > > > Encryption;
|
|
||||||
typedef Encryption Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! CTR mode
|
|
||||||
template <class CIPHER>
|
|
||||||
struct CTR_Mode : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ConcretePolicyHolder<Empty, AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, CTR_ModePolicy> > > > Encryption;
|
|
||||||
typedef Encryption Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! CTR mode, external cipher
|
|
||||||
struct CTR_Mode_ExternalCipher : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
typedef CipherModeFinalTemplate_ExternalCipher<ConcretePolicyHolder<Empty, AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, CTR_ModePolicy> > > > Encryption;
|
|
||||||
typedef Encryption Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! ECB mode
|
|
||||||
template <class CIPHER>
|
|
||||||
struct ECB_Mode : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, ECB_OneWay> Encryption;
|
|
||||||
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Decryption, ECB_OneWay> Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! ECB mode, external cipher
|
|
||||||
struct ECB_Mode_ExternalCipher : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
typedef CipherModeFinalTemplate_ExternalCipher<ECB_OneWay> Encryption;
|
|
||||||
typedef Encryption Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! CBC mode
|
//! CBC mode
|
||||||
template <class CIPHER>
|
template <class CIPHER>
|
||||||
struct CBC_Mode : public CipherModeDocumentation
|
struct CBC_Mode : public CipherModeDocumentation
|
||||||
@@ -336,35 +219,6 @@ struct CBC_Mode : public CipherModeDocumentation
|
|||||||
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Decryption, CBC_Decryption> Decryption;
|
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Decryption, CBC_Decryption> Decryption;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! CBC mode, external cipher
|
|
||||||
struct CBC_Mode_ExternalCipher : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
typedef CipherModeFinalTemplate_ExternalCipher<CBC_Encryption> Encryption;
|
|
||||||
typedef CipherModeFinalTemplate_ExternalCipher<CBC_Decryption> Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! CBC mode with ciphertext stealing
|
|
||||||
template <class CIPHER>
|
|
||||||
struct CBC_CTS_Mode : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Encryption, CBC_CTS_Encryption> Encryption;
|
|
||||||
typedef CipherModeFinalTemplate_CipherHolder<CPP_TYPENAME CIPHER::Decryption, CBC_CTS_Decryption> Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! CBC mode with ciphertext stealing, external cipher
|
|
||||||
struct CBC_CTS_Mode_ExternalCipher : public CipherModeDocumentation
|
|
||||||
{
|
|
||||||
typedef CipherModeFinalTemplate_ExternalCipher<CBC_CTS_Encryption> Encryption;
|
|
||||||
typedef CipherModeFinalTemplate_ExternalCipher<CBC_CTS_Decryption> Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
|
|
||||||
typedef CFB_Mode_ExternalCipher::Encryption CFBEncryption;
|
|
||||||
typedef CFB_Mode_ExternalCipher::Decryption CFBDecryption;
|
|
||||||
typedef OFB_Mode_ExternalCipher::Encryption OFB;
|
|
||||||
typedef CTR_Mode_ExternalCipher::Encryption CounterMode;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NAMESPACE_END
|
NAMESPACE_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user