From fe0a5ee8e83ae08b97b495b8e13d551d23216d24 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 4 Sep 2017 12:01:44 -0400 Subject: Warn of under-aligned buffers when using AES in debug mode This commit supports the upcoming AltiVec and Power8 processor. This commit affects a number of classes due to the ubiquitous use of AES. The commit adds debug asserts to warn of under-aligned and misaligned buffers in debug builds. --- rijndael.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'rijndael.cpp') diff --git a/rijndael.cpp b/rijndael.cpp index 5a354cfa..81576cdb 100644 --- a/rijndael.cpp +++ b/rijndael.cpp @@ -351,6 +351,11 @@ void Rijndael::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLen, c void Rijndael::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const { + CRYPTOPP_ASSERT(IsAlignedOn( m_key, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn( inBlock, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn(xorBlock, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn(outBlock, OptimalDataAlignment())); + #if CRYPTOPP_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) || CRYPTOPP_AESNI_AVAILABLE # if (CRYPTOPP_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_RIJNDAEL_ASM) if (HasSSE2()) @@ -441,6 +446,11 @@ void Rijndael::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock void Rijndael::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const { + CRYPTOPP_ASSERT(IsAlignedOn( m_key, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn( inBlock, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn(xorBlock, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn(outBlock, OptimalDataAlignment())); + #if CRYPTOPP_AESNI_AVAILABLE if (HasAESNI()) { @@ -1088,6 +1098,11 @@ Rijndael::Enc::Enc() { } #if CRYPTOPP_ENABLE_ADVANCED_PROCESS_BLOCKS size_t Rijndael::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const { + CRYPTOPP_ASSERT(IsAlignedOn( m_key, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn( inBlocks, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn(xorBlocks, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn(outBlocks, OptimalDataAlignment())); + #if CRYPTOPP_AESNI_AVAILABLE if (HasAESNI()) return Rijndael_Enc_AdvancedProcessBlocks_AESNI(m_key, m_rounds, inBlocks, xorBlocks, outBlocks, length, flags); @@ -1151,6 +1166,11 @@ size_t Rijndael::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xo size_t Rijndael::Dec::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const { + CRYPTOPP_ASSERT(IsAlignedOn( m_key, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn( inBlocks, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn(xorBlocks, OptimalDataAlignment())); + CRYPTOPP_ASSERT(IsAlignedOn(outBlocks, OptimalDataAlignment())); + #if CRYPTOPP_AESNI_AVAILABLE if (HasAESNI()) return Rijndael_Dec_AdvancedProcessBlocks_AESNI(m_key, m_rounds, inBlocks, xorBlocks, outBlocks, length, flags); -- cgit v1.2.1