5 #ifndef CRYPTOPP_IMPORTS
14 PolicyInterface &policy = this->AccessPolicy();
15 policy.CipherSetKey(params, key, length);
17 unsigned int bufferByteSize = policy.CanOperateKeystream() ? GetBufferByteSize(policy) :
RoundUpToMultipleOf(1024U, GetBufferByteSize(policy));
18 m_buffer.New(bufferByteSize);
20 if (this->IsResynchronizable())
23 const byte *iv = this->GetIVAndThrowIfInvalid(params, ivLength);
24 policy.CipherResynchronize(m_buffer, iv, ivLength);
33 size_t len =
STDMIN(m_leftOver, length);
34 memcpy(outString, KeystreamBufferEnd()-m_leftOver, len);
47 if (length >= bytesPerIteration)
49 size_t iterations = length / bytesPerIteration;
51 outString += iterations * bytesPerIteration;
52 length -= iterations * bytesPerIteration;
58 size_t bufferIterations = bufferByteSize / bytesPerIteration;
60 policy.
WriteKeystream(KeystreamBufferEnd()-bufferByteSize, bufferIterations);
61 memcpy(outString, KeystreamBufferEnd()-bufferByteSize, length);
62 m_leftOver = bufferByteSize - length;
71 size_t len =
STDMIN(m_leftOver, length);
72 xorbuf(outString, inString, KeystreamBufferEnd()-m_leftOver, len);
88 size_t iterations = length / bytesPerIteration;
94 inString += iterations * bytesPerIteration;
95 outString += iterations * bytesPerIteration;
96 length -= iterations * bytesPerIteration;
102 size_t bufferByteSize = m_buffer.size();
103 size_t bufferIterations = bufferByteSize / bytesPerIteration;
105 while (length >= bufferByteSize)
108 xorbuf(outString, inString, KeystreamBufferBegin(), bufferByteSize);
109 length -= bufferByteSize;
110 inString += bufferByteSize;
111 outString += bufferByteSize;
117 bufferIterations = bufferByteSize / bytesPerIteration;
119 policy.
WriteKeystream(KeystreamBufferEnd()-bufferByteSize, bufferIterations);
120 xorbuf(outString, inString, KeystreamBufferEnd()-bufferByteSize, length);
121 m_leftOver = bufferByteSize - length;
130 m_buffer.New(GetBufferByteSize(policy));
134 template <
class BASE>
141 position %= bytesPerIteration;
146 m_leftOver = bytesPerIteration - (
unsigned int)position;
152 template <
class BASE>
155 PolicyInterface &policy = this->AccessPolicy();
156 policy.CipherSetKey(params, key, length);
158 if (this->IsResynchronizable())
161 const byte *iv = this->GetIVAndThrowIfInvalid(params, ivLength);
162 policy.CipherResynchronize(iv, ivLength);
165 m_leftOver = policy.GetBytesPerIteration();
168 template <
class BASE>
176 template <
class BASE>
188 size_t len =
STDMIN(m_leftOver, length);
189 CombineMessageAndShiftRegister(outString, reg + bytesPerIteration - m_leftOver, inString, len);
207 memcpy(outString, inString, length);
210 inString += length - length % bytesPerIteration;
211 outString += length - length % bytesPerIteration;
212 length %= bytesPerIteration;
215 while (length >= bytesPerIteration)
218 CombineMessageAndShiftRegister(outString, reg, inString, bytesPerIteration);
219 length -= bytesPerIteration;
220 inString += bytesPerIteration;
221 outString += bytesPerIteration;
227 CombineMessageAndShiftRegister(outString, reg, inString, length);
228 m_leftOver = bytesPerIteration - length;
232 template <
class BASE>
235 xorbuf(reg, message, length);
236 memcpy(output, reg, length);
239 template <
class BASE>
242 for (
unsigned int i=0; i<length; i++)
245 output[i] = reg[i] ^ b;