diff --git a/stepmania/src/crypto51/modes.cpp b/stepmania/src/crypto51/modes.cpp index 70c23234f2..b0c9fb96a4 100644 --- a/stepmania/src/crypto51/modes.cpp +++ b/stepmania/src/crypto51/modes.cpp @@ -13,9 +13,6 @@ void Modes_TestInstantiations() { CFB_Mode::Encryption m0; CFB_Mode::Decryption m1; - OFB_Mode::Encryption m2; - CTR_Mode::Encryption m3; - ECB_Mode::Encryption m4; CBC_Mode::Encryption m5; } @@ -27,8 +24,6 @@ template class AdditiveCipherTemplate<>; template class CFB_CipherTemplate >; template class CFB_EncryptionTemplate >; template class CFB_DecryptionTemplate >; -template class AdditiveCipherTemplate >; -template class AdditiveCipherTemplate >; 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) { 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; } -inline void CTR_ModePolicy::ProcessMultipleBlocks(byte *output, const byte *input, unsigned int n) -{ - unsigned int s = BlockSize(), j = 0; - for (unsigned int i=1; iProcessAndXorMultipleBlocks(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) { 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 diff --git a/stepmania/src/crypto51/modes.h b/stepmania/src/crypto51/modes.h index 46e8dd26d0..347e422c6e 100644 --- a/stepmania/src/crypto51/modes.h +++ b/stepmania/src/crypto51/modes.h @@ -113,41 +113,6 @@ protected: unsigned int m_feedbackSize; }; -class OFB_ModePolicy : public ModePolicyCommonTemplate -{ - 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 -{ - 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 { public: @@ -171,15 +136,6 @@ protected: 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 { public: @@ -225,13 +181,6 @@ protected: 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 CipherModeFinalTemplate_CipherHolder : public ObjectHolder, public BASE @@ -254,20 +203,6 @@ public: } }; -//! . -template -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 template struct CFB_Mode : public CipherModeDocumentation @@ -276,58 +211,6 @@ struct CFB_Mode : public CipherModeDocumentation typedef CipherModeFinalTemplate_CipherHolder > > > Decryption; }; -//! CFB mode, external cipher -struct CFB_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher > > > Encryption; - typedef CipherModeFinalTemplate_ExternalCipher > > > Decryption; -}; - -//! OFB mode -template -struct OFB_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder > > > Encryption; - typedef Encryption Decryption; -}; - -//! OFB mode, external cipher -struct OFB_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher > > > Encryption; - typedef Encryption Decryption; -}; - -//! CTR mode -template -struct CTR_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder > > > Encryption; - typedef Encryption Decryption; -}; - -//! CTR mode, external cipher -struct CTR_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher > > > Encryption; - typedef Encryption Decryption; -}; - -//! ECB mode -template -struct ECB_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder Encryption; - typedef CipherModeFinalTemplate_CipherHolder Decryption; -}; - -//! ECB mode, external cipher -struct ECB_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher Encryption; - typedef Encryption Decryption; -}; - //! CBC mode template struct CBC_Mode : public CipherModeDocumentation @@ -336,35 +219,6 @@ struct CBC_Mode : public CipherModeDocumentation typedef CipherModeFinalTemplate_CipherHolder Decryption; }; -//! CBC mode, external cipher -struct CBC_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher Encryption; - typedef CipherModeFinalTemplate_ExternalCipher Decryption; -}; - -//! CBC mode with ciphertext stealing -template -struct CBC_CTS_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder Encryption; - typedef CipherModeFinalTemplate_CipherHolder Decryption; -}; - -//! CBC mode with ciphertext stealing, external cipher -struct CBC_CTS_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher Encryption; - typedef CipherModeFinalTemplate_ExternalCipher 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 #endif