diff options
author | Jeffrey Walton <noloader@gmail.com> | 2018-10-25 08:24:13 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2018-10-25 08:24:13 -0400 |
commit | 352083b1d06f73ea571ff4804d4169630e3eab88 (patch) | |
tree | 557829a92452bffb0f34eb2a26705df708952c7c /hc256.cpp | |
parent | ba5ca6b8cded2abdf7f082980e6452ffdf322650 (diff) | |
download | cryptopp-git-352083b1d06f73ea571ff4804d4169630e3eab88.tar.gz |
Cleanup HC128 and HC256 OperateKeystream
Diffstat (limited to 'hc256.cpp')
-rw-r--r-- | hc256.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -94,19 +94,27 @@ void HC256Policy::CipherSetKey(const NameValuePairs ¶ms, const byte *userKey void HC256Policy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
{
- size_t msglen = GetBytesPerIteration() * iterationCount;
- byte* out = output;
- for (size_t i = 0; i < (msglen >> 2); i++, out += 4)
- PutWord(false, LITTLE_ENDIAN_ORDER, out, Generate());
-
- // If AdditiveCipherTemplate does not have an accumulated keystream
- // then it will ask OperateKeystream to generate one. Optionally it
- // will ask for an XOR of the input with the keystream while
- // writing the result to the output buffer. In all cases the
- // keystream is written to the output buffer. The optional part is
- // adding the input buffer and keystream.
- if ((operation & INPUT_NULL) != INPUT_NULL)
- xorbuf(output, input, msglen);
+ while (iterationCount--)
+ {
+ PutWord(false, LITTLE_ENDIAN_ORDER, output + 0, Generate());
+ PutWord(false, LITTLE_ENDIAN_ORDER, output + 4, Generate());
+ PutWord(false, LITTLE_ENDIAN_ORDER, output + 8, Generate());
+ PutWord(false, LITTLE_ENDIAN_ORDER, output + 12, Generate());
+
+ // If AdditiveCipherTemplate does not have an accumulated keystream
+ // then it will ask OperateKeystream to generate one. Optionally it
+ // will ask for an XOR of the input with the keystream while
+ // writing the result to the output buffer. In all cases the
+ // keystream is written to the output buffer. The optional part is
+ // adding the input buffer and keystream.
+ if ((operation & INPUT_NULL) != INPUT_NULL)
+ {
+ xorbuf(output, input, BYTES_PER_ITERATION);
+ input += BYTES_PER_ITERATION;
+ }
+
+ output += BYTES_PER_ITERATION;
+ }
}
void HC256Policy::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
|