summaryrefslogtreecommitdiff
path: root/modes.cpp
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2009-03-12 11:24:12 +0000
committerweidai <weidai11@users.noreply.github.com>2009-03-12 11:24:12 +0000
commit2779fc60506e2042ab1569ffad4061f1187d186c (patch)
tree68edc0bccf003f5615716b3ae2d6b97067af39c4 /modes.cpp
parent64af4560dc8ba66ef0e2ac3b05dec6f445ec96fe (diff)
downloadcryptopp-git-2779fc60506e2042ab1569ffad4061f1187d186c.tar.gz
- add EAX mode, XSalsa20
- speed up GCM key setup - wipe stack in AES assembly code - speed up CFB mode
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 cd7450f5..81bf4de3 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