diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2009-03-12 11:24:12 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2009-03-12 11:24:12 +0000 |
commit | a36c71ecb6840ff799546ccaf665e55f6a6ed5dc (patch) | |
tree | 68edc0bccf003f5615716b3ae2d6b97067af39c4 /modes.cpp | |
parent | ce1fbfcba325116155a605b8519bc0b4e272348f (diff) | |
download | cryptopp-a36c71ecb6840ff799546ccaf665e55f6a6ed5dc.tar.gz |
- add EAX mode, XSalsa20
- speed up GCM key setup
- wipe stack in AES assembly code
- speed up CFB mode
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@444 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'modes.cpp')
-rw-r--r-- | modes.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -24,6 +24,55 @@ void Modes_TestInstantiations() } #endif +void CFB_ModePolicy::Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount) +{ + assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt + assert(m_feedbackSize == BlockSize()); + + unsigned int s = BlockSize(); + if (dir == ENCRYPTION) + { + m_cipher->ProcessAndXorBlock(m_register, input, output); + m_cipher->AdvancedProcessBlocks(output, input+s, output+s, (iterationCount-1)*s, 0); + memcpy(m_register, output+(iterationCount-1)*s, s); + } + else + { + memcpy(m_temp, input+(iterationCount-1)*s, s); // make copy first in case of in-place decryption + m_cipher->AdvancedProcessBlocks(input, input+s, output+s, (iterationCount-1)*s, BlockTransformation::BT_ReverseDirection); + m_cipher->ProcessAndXorBlock(m_register, input, output); + memcpy(m_register, m_temp, s); + } +} + +void CFB_ModePolicy::TransformRegister() +{ + assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt + m_cipher->ProcessBlock(m_register, m_temp); + unsigned int updateSize = BlockSize()-m_feedbackSize; + memmove_s(m_register, m_register.size(), m_register+m_feedbackSize, updateSize); + memcpy_s(m_register+updateSize, m_register.size()-updateSize, m_temp, m_feedbackSize); +} + +void CFB_ModePolicy::CipherResynchronize(const byte *iv, size_t length) +{ + memcpy_s(m_register, m_register.size(), iv, BlockSize()); + TransformRegister(); +} + +void CFB_ModePolicy::SetFeedbackSize(unsigned int feedbackSize) +{ + if (feedbackSize > BlockSize()) + throw InvalidArgument("CFB_Mode: invalid feedback size"); + m_feedbackSize = feedbackSize ? feedbackSize : BlockSize(); +} + +void CFB_ModePolicy::ResizeBuffers() +{ + CipherModeBase::ResizeBuffers(); + m_temp.New(BlockSize()); +} + void OFB_ModePolicy::WriteKeystream(byte *keystreamBuffer, size_t iterationCount) { assert(m_cipher->IsForwardTransformation()); // OFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt |