summaryrefslogtreecommitdiff
path: root/modes.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2009-03-12 11:24:12 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2009-03-12 11:24:12 +0000
commita36c71ecb6840ff799546ccaf665e55f6a6ed5dc (patch)
tree68edc0bccf003f5615716b3ae2d6b97067af39c4 /modes.cpp
parentce1fbfcba325116155a605b8519bc0b4e272348f (diff)
downloadcryptopp-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.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/modes.cpp b/modes.cpp
index cd7450f..81bf4de 100644
--- a/modes.cpp
+++ b/modes.cpp
@@ -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