-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guard increment of inBlock in CTR_ModePolicy::OperateKeystream
- Loading branch information
Showing
1 changed file
with
12 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#ifndef CRYPTOPP_IMPORTS | ||
|
||
#include "modes.h" | ||
#include "strciphr.h" | ||
#include "misc.h" | ||
|
||
#if defined(CRYPTOPP_DEBUG) | ||
|
@@ -137,25 +138,29 @@ void CTR_ModePolicy::IncrementCounterBy256() | |
IncrementCounterByOne(m_counterArray, BlockSize()-1); | ||
} | ||
|
||
void CTR_ModePolicy::OperateKeystream(KeystreamOperation /*operation*/, byte *output, const byte *input, size_t iterationCount) | ||
void CTR_ModePolicy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) | ||
{ | ||
CRYPTOPP_ASSERT(output); | ||
// CRYPTOPP_ASSERT(input); // input is sometimes NULL | ||
CRYPTOPP_ASSERT(m_cipher->IsForwardTransformation()); | ||
CRYPTOPP_ASSERT(m_counterArray.size() == BlockSize()); | ||
CRYPTOPP_UNUSED(operation); | ||
|
||
const unsigned int s = BlockSize(); | ||
const unsigned int inputIncrement = input ? s : 0; | ||
const size_t s = BlockSize(); | ||
|
||
while (iterationCount) | ||
{ | ||
const byte lsb = m_counterArray[s-1]; | ||
const size_t blocks = UnsignedMin(iterationCount, 256U-lsb); | ||
const size_t blocks = UnsignedMin(iterationCount, 256u-lsb); | ||
const size_t outIncrement = output ? blocks*s : 0; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
irwir
Contributor
|
||
const size_t inIncrement = input ? blocks*s : 0; | ||
|
||
m_cipher->AdvancedProcessBlocks(m_counterArray, input, output, blocks*s, BlockTransformation::BT_InBlockIsCounter|BlockTransformation::BT_AllowParallel); | ||
if ((m_counterArray[s-1] = byte(lsb + blocks)) == 0) | ||
if ((m_counterArray[s-1] = static_cast<byte>(lsb + blocks)) == 0) | ||
IncrementCounterBy256(); | ||
|
||
output = PtrAdd(output, blocks*s); | ||
input = PtrAdd(input, blocks*inputIncrement); | ||
output = PtrAdd(output, outIncrement); | ||
input = PtrAdd(input, inIncrement); | ||
iterationCount -= blocks; | ||
} | ||
} | ||
|
Might be better to remove lines 155-156 and replace lines 162-163 with: