diff options
author | Jeffrey Walton <noloader@gmail.com> | 2017-09-04 12:01:44 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2017-09-04 12:01:44 -0400 |
commit | fe0a5ee8e83ae08b97b495b8e13d551d23216d24 (patch) | |
tree | a25e85993fa3797ab692f10b460bf15d0057bc70 /rijndael.cpp | |
parent | 75aef9bded7a65a4d227bde883a094249cf1ffc8 (diff) | |
download | cryptopp-git-fe0a5ee8e83ae08b97b495b8e13d551d23216d24.tar.gz |
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.
Diffstat (limited to 'rijndael.cpp')
-rw-r--r-- | rijndael.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
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);
|