diff options
author | Jeffrey Walton <noloader@gmail.com> | 2018-07-05 07:11:44 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2018-07-05 07:11:44 -0400 |
commit | 23c8bfde7e4212703e3d5925a47cbb38ed0c3fd4 (patch) | |
tree | bea57d3fd5cd76f7f298dc959e8ecea93ea3e8cc /hc256.cpp | |
parent | 989bf6dc5e333791d5e64916be0cd49d026a71c2 (diff) | |
download | cryptopp-git-23c8bfde7e4212703e3d5925a47cbb38ed0c3fd4.tar.gz |
Rework OperateKeystream (GH #680)
This improves performance on a Core i5 6400 from 5.4 cpb to 2.9 cpb
Diffstat (limited to 'hc256.cpp')
-rw-r--r-- | hc256.cpp | 51 |
1 files changed, 25 insertions, 26 deletions
@@ -18,43 +18,43 @@ using CryptoPP::rotrConstant; inline word32 f1(word32 x)
{
- return rotrConstant<7>(x) ^ rotrConstant<18>(x) ^ ((x) >> 3);
+ return rotrConstant<7>(x) ^ rotrConstant<18>(x) ^ (x >> 3);
}
inline word32 f2(word32 x)
{
- return rotrConstant<17>(x) ^ rotrConstant<19>(x) ^ ((x) >> 10);
+ return rotrConstant<17>(x) ^ rotrConstant<19>(x) ^ (x >> 10);
}
ANONYMOUS_NAMESPACE_END
NAMESPACE_BEGIN(CryptoPP)
-word32 HC256Policy::H1(word32 u)
+inline word32 HC256Policy::H1(word32 u)
{
word32 tem;
- unsigned char a, b, c, d;
- a = (unsigned char)((u));
- b = (unsigned char)((u) >> 8);
- c = (unsigned char)((u) >> 16);
- d = (unsigned char)((u) >> 24);
+ byte a, b, c, d;
+ a = (byte)((u));
+ b = (byte)((u) >> 8);
+ c = (byte)((u) >> 16);
+ d = (byte)((u) >> 24);
tem = m_Q[a] + m_Q[256 + b] + m_Q[512 + c] + m_Q[768 + d];
return (tem);
}
-word32 HC256Policy::H2(word32 u)
+inline word32 HC256Policy::H2(word32 u)
{
word32 tem;
- unsigned char a, b, c, d;
- a = (unsigned char)((u));
- b = (unsigned char)((u) >> 8);
- c = (unsigned char)((u) >> 16);
- d = (unsigned char)((u) >> 24);
+ byte a, b, c, d;
+ a = (byte)((u));
+ b = (byte)((u) >> 8);
+ c = (byte)((u) >> 16);
+ d = (byte)((u) >> 24);
tem = m_P[a] + m_P[256 + b] + m_P[512 + c] + m_P[768 + d];
return (tem);
}
-word32 HC256Policy::Generate() /*one step of the cipher*/
+inline word32 HC256Policy::Generate() /*one step of the cipher*/
{
word32 i, i3, i10, i12, i1023;
word32 output;
@@ -94,17 +94,16 @@ 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) >> 2;
- for (unsigned int i = 0; i < msglen; i++, input += 4, output += 4)
- {
- PutWord(false, LITTLE_ENDIAN_ORDER, output, Generate());
-
- // If AdditiveCipherTemplate does not have an acculated keystream
- // then it will ask OperateKeystream to XOR the plaintext with
- // the keystream and write it to the ciphertext buffer.
- if ((operation & INPUT_NULL) != INPUT_NULL)
- xorbuf(output, input, 4);
- }
+ size_t msglen = GetBytesPerIteration() * iterationCount;
+ const byte* in = input; byte* out = output;
+ for (unsigned int i = 0; i < (msglen >> 2); i++, in += 4, out += 4)
+ PutWord(false, LITTLE_ENDIAN_ORDER, out, Generate());
+
+ // If AdditiveCipherTemplate does not have an acculated keystream
+ // then it will ask OperateKeystream to XOR the plaintext with
+ // the keystream and write it to the ciphertext buffer.
+ if ((operation & INPUT_NULL) != INPUT_NULL)
+ xorbuf(output, input, msglen);
}
void HC256Policy::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
|