From bdac2de36ea56953fc58cb5eccfc66a28bcbe0cc Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 10 Jul 2018 17:41:23 -0400 Subject: [PATCH] Increase use of ptrdiff_t when performing pointer math --- modes.cpp | 6 +++--- strciphr.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modes.cpp b/modes.cpp index 39e5dd0d..b88208f9 100644 --- a/modes.cpp +++ b/modes.cpp @@ -65,8 +65,8 @@ void CFB_ModePolicy::TransformRegister() const ptrdiff_t updateSize = BlockSize()-m_feedbackSize; m_cipher->ProcessBlock(m_register, m_temp); - memmove_s(m_register, m_register.size(), m_register+m_feedbackSize, updateSize); - memcpy_s(m_register+updateSize, m_register.size()-updateSize, m_temp, m_feedbackSize); + memmove_s(m_register, m_register.size(), PtrAdd(m_register.begin(),m_feedbackSize), updateSize); + memcpy_s(PtrAdd(m_register.begin(),updateSize), m_register.size()-updateSize, m_temp, m_feedbackSize); } void CFB_ModePolicy::CipherResynchronize(const byte *iv, size_t length) @@ -150,7 +150,7 @@ void CTR_ModePolicy::OperateKeystream(KeystreamOperation /*operation*/, byte *ou byte lsb = m_counterArray[s-1]; size_t blocks = UnsignedMin(iterationCount, 256U-lsb); m_cipher->AdvancedProcessBlocks(m_counterArray, input, output, blocks*s, BlockTransformation::BT_InBlockIsCounter|BlockTransformation::BT_AllowParallel); - if ((m_counterArray[s-1] = static_cast(lsb + (blocks & 0xff))) == 0) + if ((m_counterArray[s-1] = static_cast(lsb + blocks)) == 0) IncrementCounterBy256(); output = PtrAdd(output, blocks*s); diff --git a/strciphr.h b/strciphr.h index 3439ca63..9198b55a 100644 --- a/strciphr.h +++ b/strciphr.h @@ -541,6 +541,9 @@ template class CRYPTOPP_NO_VTABLE CFB_CipherTemplate : public BASE { public: + virtual ~CFB_CipherTemplate() {} + CFB_CipherTemplate() : m_leftOver(0) {} + /// \brief Apply keystream to data /// \param outString a buffer to write the transformed data /// \param inString a buffer to read the data