Make starting block configurable

pull/794/head
Jeffrey Walton 2019-02-05 15:49:12 -05:00
parent 55883bdacf
commit 5acacbcaa5
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 10 additions and 3 deletions

View File

@ -508,6 +508,12 @@ void XChaCha20_Policy::CipherSetKey(const NameValuePairs &params, const byte *ke
if (rounds != 20)
throw InvalidRounds(XChaCha20::StaticAlgorithmName(), rounds);
word64 block;
if (params.GetValue("InitialBlock", block))
m_state[24] = static_cast<word32>(block);
else
m_state[24] = 1;
// Stash key away for use in CipherResynchronize
GetBlock<word32, LittleEndian> get(key);
get(m_state[KEY+0])(m_state[KEY+1])(m_state[KEY+2])(m_state[KEY+3])
@ -539,7 +545,8 @@ void XChaCha20_Policy::CipherResynchronize(byte *keystreamBuffer, const byte *iv
m_state[2] = 0x79622d32; m_state[3] = 0x6b206574;
// Setup new IV
m_state[12] = 1; m_state[13] = 0;
m_state[12] = m_state[24];
m_state[13] = 0;
m_state[14] = GetWord<word32>(false, LITTLE_ENDIAN_ORDER, iv+16);
m_state[15] = GetWord<word32>(false, LITTLE_ENDIAN_ORDER, iv+20);
}

View File

@ -184,9 +184,9 @@ protected:
std::string AlgorithmName() const;
std::string AlgorithmProvider() const;
FixedSizeAlignedSecBlock<word32, 16+8> m_state;
FixedSizeAlignedSecBlock<word32, 16+8+1> m_state;
CRYPTOPP_CONSTANT(ROUNDS = XChaCha20_Info::ROUNDS)
CRYPTOPP_CONSTANT(KEY = 16) // Index into m_state
CRYPTOPP_CONSTANT(KEY = 16) // Index into m_state
};
/// \brief XChaCha stream cipher