From c6a16ea57396658108f819447de60f8ae296d642 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Thu, 28 Sep 2023 09:05:16 -0400 Subject: [PATCH] Add GenerateKeystream to HC256 This keeps HC-128 and HC-256 consistent --- hc256.cpp | 13 +++++++++---- hc256.h | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/hc256.cpp b/hc256.cpp index b0567615..3a93f21e 100644 --- a/hc256.cpp +++ b/hc256.cpp @@ -88,6 +88,14 @@ inline word32 HC256Policy::Generate() /*one step of the cipher*/ return (output); } +void HC256Policy::GenerateKeystream(word32 keystream[4]) +{ + keystream[0] = Generate(); + keystream[1] = Generate(); + keystream[2] = Generate(); + keystream[3] = Generate(); +} + void HC256Policy::CipherSetKey(const NameValuePairs ¶ms, const byte *userKey, size_t keylen) { CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(keylen); @@ -108,10 +116,7 @@ void HC256Policy::OperateKeystream(KeystreamOperation operation, byte *output, c while (iterationCount--) { FixedSizeSecBlock keystream; - keystream[0] = Generate(); - keystream[1] = Generate(); - keystream[2] = Generate(); - keystream[3] = Generate(); + GenerateKeystream(keystream); CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(HC256_OUTPUT, BYTES_PER_ITERATION); } diff --git a/hc256.h b/hc256.h index ccd1ca05..aa1e88ee 100644 --- a/hc256.h +++ b/hc256.h @@ -39,6 +39,8 @@ protected: word32 H1(word32 u); word32 H2(word32 u); + + void GenerateKeystream(word32* keystream); word32 Generate(); private: