summaryrefslogtreecommitdiff
path: root/strciphr.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-09-04 11:03:10 -0400
committerJeffrey Walton <noloader@gmail.com>2017-09-04 11:03:10 -0400
commit32cc92e048ecdad5b5c1d901a14c5d4f2ab66444 (patch)
tree7c8c9868e4a4b1f3a718c425d8f6b925dad343a7 /strciphr.h
parent6b1a56cf72b07dd7ad95611b914605ffab924736 (diff)
downloadcryptopp-git-32cc92e048ecdad5b5c1d901a14c5d4f2ab66444.tar.gz
Fixup under-aligned buffers for stream ciphers on AltiVec and Power8
This commit supports the upcoming AltiVec and Power8 processor support for stream ciphers. This commit affects GlobalRNG() most because its an AES-based generator. The commit favors AlignedSecByteBlock over SecByteBlock in places where messages are handled on the AltiVec and Power8 processor data paths. The data paths include all block cipher modes of operation, and some filters like FilterWithBufferedInput. Intel and ARM processors are tolerant of under-aligned buffers when using crypto instructions. AltiVec and Power8 are less tolerant, and they simply ignore the three low-order bits to ensure an address is aligned. The AltiVec and Power8 have caused a fair number of wild writes on the stack and in the heap. Testing on a 64-bit Intel Skylake show a marked improvement in performance. We suspect GCC is generating better code since it knows the alignment of the pointers, and does not have to emit fixup code for under-aligned and mis-aligned data. Testing on an mid-2000s 32-bit VIA C7-D with SSE2+SSSE3 showed no improvement, and no performance was lost.
Diffstat (limited to 'strciphr.h')
-rw-r--r--strciphr.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/strciphr.h b/strciphr.h
index 10082907..bc105a27 100644
--- a/strciphr.h
+++ b/strciphr.h
@@ -187,13 +187,12 @@ struct CRYPTOPP_NO_VTABLE AdditiveCipherConcretePolicy : public BASE
typedef WT WordType;
CRYPTOPP_CONSTANT(BYTES_PER_ITERATION = sizeof(WordType) * W)
-#if !(CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X64)
//! \brief Provides data alignment requirements
//! \returns data alignment requirements, in bytes
//! \details Internally, the default implementation returns 1. If the stream cipher is implemented
- //! using an SSE2 ASM or intrinsics, then the value returned is usually 16.
+ //! using an SSE2 ASM or intrinsics, then the value returned is usually 16. If the cipher is
+ //! AES on AltiVec or Power 8 then 16 is returned.
unsigned int GetAlignment() const {return GetAlignmentOf<WordType>();}
-#endif
//! \brief Provides number of bytes operated upon during an iteration
//! \returns bytes operated upon during an iteration, in bytes
@@ -340,7 +339,7 @@ protected:
inline byte * KeystreamBufferBegin() {return this->m_buffer.data();}
inline byte * KeystreamBufferEnd() {return (this->m_buffer.data() + this->m_buffer.size());}
- SecByteBlock m_buffer;
+ AlignedSecByteBlock m_buffer;
size_t m_leftOver;
};