Some fixes necessary to support the Clang compiler
First of all, it had a failure in SEED: LTC_KSEED failed for x=0, I got: expected actual (ciphertext) 5e == 5e ba == ba c6 == c6 e0 == e0 05 != 00 4e != 00 16 != 00 68 != 00 19 == 19 af == af f1 == f1 cc == cc 6d != 00 34 != 00 6c != 00 db != 00 Since SEED uses the 32H macros, this is really analogous to the problem I saw with the 64H macros in Camellia with gcc. Not sure why gcc only had a problem with 64H and not 32H, but since this is an interaction with the optimizer, it's not going to happen every time the macro is used (hence why the store tests pass; only when you get into the complexity of a real cipher do you start having problems) and it makes sense it will vary from compiler to compiler. Anyway, I went ahead and added the ability to use __builtin_bswap32, in addition to __builtin_bswap64, which I already did in a previous commit. This solves the problem for clang, although I had to add new logic to detect the bswap builtins in clang, since it has a different way to detect them than gcc (see the comments in the code). The detection logic was complicated enough, and applied to both the 32H and 64H macros, so I factored out the detection logic into tomcrypt_cfg.h.
This commit is contained in:
parent
ad566e1b00
commit
382c9d4d85
@ -128,6 +128,22 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
|
|||||||
#define ENDIAN_NEUTRAL
|
#define ENDIAN_NEUTRAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* gcc 4.3 and up has a bswap builtin; detect it by gcc version.
|
||||||
|
* clang also supports the bswap builtin, and although clang pretends
|
||||||
|
* to be gcc (macro-wise, anyway), clang pretends to be a version
|
||||||
|
* prior to gcc 4.3, so we can't detect bswap that way. Instead,
|
||||||
|
* clang has a __has_builtin mechanism that can be used to check
|
||||||
|
* for builtins:
|
||||||
|
* http://clang.llvm.org/docs/LanguageExtensions.html#feature_check */
|
||||||
|
#ifndef __has_builtin
|
||||||
|
#define __has_builtin(x) 0
|
||||||
|
#endif
|
||||||
|
#if !defined(LTC_NO_BSWAP) && defined(__GNUC__) && \
|
||||||
|
((__GNUC__ * 100 + __GNUC_MINOR__ >= 403) || \
|
||||||
|
(__has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)))
|
||||||
|
#define LTC_HAVE_BSWAP_BUILTIN
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,7 +67,17 @@
|
|||||||
|
|
||||||
#ifdef ENDIAN_LITTLE
|
#ifdef ENDIAN_LITTLE
|
||||||
|
|
||||||
#if !defined(LTC_NO_BSWAP) && (defined(INTEL_CC) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__) || defined(__x86_64__))))
|
#ifdef LTC_HAVE_BSWAP_BUILTIN
|
||||||
|
|
||||||
|
#define STORE32H(x, y) \
|
||||||
|
{ ulong32 __t = __builtin_bswap32 ((x)); \
|
||||||
|
XMEMCPY ((y), &__t, 4); }
|
||||||
|
|
||||||
|
#define LOAD32H(x, y) \
|
||||||
|
{ XMEMCPY (&(x), (y), 4); \
|
||||||
|
(x) = __builtin_bswap32 ((x)); }
|
||||||
|
|
||||||
|
#elif !defined(LTC_NO_BSWAP) && (defined(INTEL_CC) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__) || defined(__x86_64__))))
|
||||||
|
|
||||||
#define STORE32H(x, y) \
|
#define STORE32H(x, y) \
|
||||||
asm __volatile__ ( \
|
asm __volatile__ ( \
|
||||||
@ -96,9 +106,7 @@ asm __volatile__ ( \
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* gcc 4.3 and up has a bswap builtin */
|
#ifdef LTC_HAVE_BSWAP_BUILTIN
|
||||||
#if !defined(LTC_NO_BSWAP) && \
|
|
||||||
(defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403))
|
|
||||||
|
|
||||||
#define STORE64H(x, y) \
|
#define STORE64H(x, y) \
|
||||||
{ ulong64 __t = __builtin_bswap64 ((x)); \
|
{ ulong64 __t = __builtin_bswap64 ((x)); \
|
||||||
|
@ -286,7 +286,9 @@ const char *crypt_build_settings =
|
|||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
" MSVC compiler detected.\n"
|
" MSVC compiler detected.\n"
|
||||||
#endif
|
#endif
|
||||||
#if defined(__GNUC__)
|
#if defined(__clang_version__)
|
||||||
|
" Clang compiler " __clang_version__ ".\n"
|
||||||
|
#elif defined(__GNUC__) /* clang also defines __GNUC__ */
|
||||||
" GCC compiler detected.\n"
|
" GCC compiler detected.\n"
|
||||||
#endif
|
#endif
|
||||||
#if defined(INTEL_CC)
|
#if defined(INTEL_CC)
|
||||||
|
Loading…
Reference in New Issue
Block a user