Skip to content

Commit

Permalink
Since moving to split sources (base+simd) we found SecBlocks declared…
Browse files Browse the repository at this point in the history
… in headers may not be 16-byte aligned because the architecture switch is present on the simd file, and not the base file.

16-byte aligned is the default for most systems nowadays, so we side stepped alignment problems on all platforms except 32-bit Solaris. We need the 16-byte alignment for all Intel compatibles since the late 1990s, which is nearly all processors in the class.

The worst case is, if a processor lacks SSE2, then it gets an aligned SecBlock anyways. The last time we saw processors without the features was 486 and early Pentiums, and that was 1996 or so. Even low-end processors like Intel Atoms and VIA have SSE2+SSSE3.

Also see "Enable 16-byte alignment full-time for i386 and x86_64?" (https://groups.google.com/forum/#!topic/cryptopp-users/ubp-gFC1BJI) for a discussion.
  • Loading branch information
noloader committed Aug 28, 2017
2 parents 7c667bc + d4ac135 commit 9731791
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Expand Up @@ -826,7 +826,7 @@ convert:
@-$(CHMOD) 0700 $(EXEC_FILES) *.sh *.cmd TestScripts/*.sh TestScripts/*.pl TestScripts/*.cmd
@-$(CHMOD) 0700 *.cmd *.sh GNUmakefile GNUmakefile-cross TestScripts/*.sh TestScripts/*.pl
-unix2dos --keepdate --quiet $(TEXT_FILES) .*.yml *.asm *.cmd *.cmake TestScripts/*.*
-dos2unix --keepdate --quiet GNUmakefile GNUmakefile-cross *.s *.sh TestScripts/*.sh
-dos2unix --keepdate --quiet GNUmakefile GNUmakefile-cross *.s *.sh *.mapfile TestScripts/*.sh
ifneq ($(IS_DARWIN),0)
@-xattr -c *
endif
Expand Down
16 changes: 12 additions & 4 deletions config.h
Expand Up @@ -470,6 +470,7 @@ NAMESPACE_END
#define CRYPTOPP_X64_ASM_AVAILABLE 1
#endif

// 32-bit SunCC does not enable SSE2 by default.
#if !defined(CRYPTOPP_DISABLE_ASM) && (defined(_MSC_VER) || defined(__SSE2__))
#define CRYPTOPP_SSE2_INTRIN_AVAILABLE 1
#endif
Expand Down Expand Up @@ -498,16 +499,22 @@ NAMESPACE_END
#define CRYPTOPP_SSE42_AVAILABLE 1
#endif

// Requires Sun Studio 12.3 (SunCC 0x5120)
#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_CLMUL) && \
// Couple to CRYPTOPP_DISABLE_AES, but use CRYPTOPP_CLMUL_AVAILABLE so we can selectively
// disable for misbehaving platofrms and compilers, like Solaris or some Clang.
#if defined(CRYPTOPP_DISABLE_AES)
#define CRYPTOPP_DISABLE_CLMUL 1
#endif

// Requires Sun Studio 12.3 (SunCC 0x5120) in theory.
#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_CLMUL) && defined(CRYPTOPP_SSE42_AVAILABLE) && \
(defined(__PCLMUL__) || (_MSC_FULL_VER >= 150030729) || (__SUNPRO_CC >= 0x5120) || \
(CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1110) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 30200) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300))
#define CRYPTOPP_CLMUL_AVAILABLE 1
#endif

// Requires Sun Studio 12.3 (SunCC 0x5120)
#if !defined(CRYPTOPP_DISABLE_SSE4) && defined(CRYPTOPP_SSSE3_AVAILABLE) && \
#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_AES) && defined(CRYPTOPP_SSE42_AVAILABLE) && \
(defined(__AES__) || (_MSC_FULL_VER >= 150030729) || (__SUNPRO_CC >= 0x5120) || \
(CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1110) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 30200) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300))
Expand Down Expand Up @@ -575,7 +582,8 @@ NAMESPACE_END

// ***************** Miscellaneous ********************

#if CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)
// Nearly all Intel's and AMD's have SSE. Enable it independent of SSE ASM and intrinscs
#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) && !defined(CRYPTOPP_DISABLE_ASM)
#define CRYPTOPP_BOOL_ALIGN16 1
#else
#define CRYPTOPP_BOOL_ALIGN16 0
Expand Down
2 changes: 2 additions & 0 deletions cryptest.mapfile
@@ -1 +1,3 @@
# Solaris mapfile to override hardware caps to avoid kills

hwcap_1 = SSE SSE2 OVERRIDE;
6 changes: 3 additions & 3 deletions secblock.h
Expand Up @@ -199,7 +199,7 @@ class AllocatorWithCleanup : public AllocatorBase<T>

#if CRYPTOPP_BOOL_ALIGN16
// TODO: should this need the test 'size*sizeof(T) >= 16'?
if (T_Align16 && size*sizeof(T) >= 16)
if (T_Align16 && size)
return (pointer)AlignedAllocate(size*sizeof(T));
#endif

Expand All @@ -220,7 +220,7 @@ class AllocatorWithCleanup : public AllocatorBase<T>
SecureWipeArray((pointer)ptr, size);

#if CRYPTOPP_BOOL_ALIGN16
if (T_Align16 && size*sizeof(T) >= 16)
if (T_Align16 && size)
return AlignedDeallocate(ptr);
#endif

Expand All @@ -242,7 +242,7 @@ class AllocatorWithCleanup : public AllocatorBase<T>
SecureWipeArray((pointer)ptr, STDMIN(size, mark));

#if CRYPTOPP_BOOL_ALIGN16
if (T_Align16 && size*sizeof(T) >= 16)
if (T_Align16 && size)
return AlignedDeallocate(ptr);
#endif

Expand Down

1 comment on commit 9731791

@noloader
Copy link
Collaborator Author

@noloader noloader commented on 9731791 Aug 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Pull Request 461, which split sources into base+simd. Also see Issue 473.

Please sign in to comment.