Skip to content

Commit

Permalink
Enable same buffer for in and out on ARM A-32 (GH #683)
Browse files Browse the repository at this point in the history
  • Loading branch information
noloader committed Oct 14, 2018
1 parent 1acbedd commit 49d852e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions strciphr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,18 @@ void CFB_CipherTemplate<BASE>::ProcessData(byte *outString, const byte *inString
//
// Also see https://github.com/weidai11/cryptopp/issues/683.
//
#if !defined(__arm__)
unsigned int alignment = policy.GetAlignment();
if (policy.CanIterate() && length >= bytesPerIteration && IsAlignedOn(outString, alignment))
// UPDATE: It appears the issue is related to alignment checks. When we made
// the alignment check result volatile GCC and Clang stopped
// short-circuiting the transform, which is what we wanted. I suspect
// there's a little more to the issue, but we can enable the block again.

const unsigned int alignment = policy.GetAlignment();
volatile bool isAligned = IsAlignedOn(outString, alignment);
if (policy.CanIterate() && length >= bytesPerIteration && isAligned)
{
isAligned &= IsAlignedOn(inString, alignment);
const CipherDir cipherDir = GetCipherDir(*this);
if (IsAlignedOn(inString, alignment))
if (isAligned)
policy.Iterate(outString, inString, cipherDir, length / bytesPerIteration);
else
{
Expand All @@ -226,11 +232,6 @@ void CFB_CipherTemplate<BASE>::ProcessData(byte *outString, const byte *inString
// to use ptrdiff_t when subtracting pointers. We believe the relevant code paths
// are clean.
//
// There are two remaining open questions. The first is aliasing rules. Char-types
// are not bound by aliasing rules so we are OK. The second is array const-ness.
// The arrays are created in datatest.cpp and they are non-const. Since the original
// objects are non-const we are OK casting const-ness away as buffers are twiddled.
//
// One workaround is a distinct and aligned temporary buffer. It [mostly] works
// as expected but requires an extra allocation (casts not shown):
//
Expand All @@ -241,11 +242,11 @@ void CFB_CipherTemplate<BASE>::ProcessData(byte *outString, const byte *inString
memcpy(outString, inString, length);
policy.Iterate(outString, outString, cipherDir, length / bytesPerIteration);
}
inString = PtrAdd(inString, length - length % bytesPerIteration);
outString = PtrAdd(outString, length - length % bytesPerIteration);
length %= bytesPerIteration;
const size_t remainder = length % bytesPerIteration;
inString = PtrAdd(inString, length - remainder);
outString = PtrAdd(outString, length - remainder);
length = remainder;
}
#endif

while (length >= bytesPerIteration)
{
Expand Down

0 comments on commit 49d852e

Please sign in to comment.