diff --git a/makefile b/makefile index 901a3ef2..53f80f45 100644 --- a/makefile +++ b/makefile @@ -329,23 +329,23 @@ profile: #This rule cleans the source tree of all compiled code, not including the pdf #documentation. clean: - rm -f `find . -type f | grep "[.]o" | xargs` - rm -f `find . -type f | grep "[.]lo" | xargs` - rm -f `find . -type f | grep "[.]a" | xargs` - rm -f `find . -type f | grep "[.]la" | xargs` - rm -f `find . -type f | grep "[.]obj" | xargs` - rm -f `find . -type f | grep "[.]lib" | xargs` - rm -f `find . -type f | grep "[.]exe" | xargs` - rm -f `find . -type f | grep "[.]gcda" | xargs` - rm -f `find . -type f | grep "[.]gcno" | xargs` - rm -f `find . -type f | grep "[.]il" | xargs` - rm -f `find . -type f | grep "[.]dyn" | xargs` - rm -f `find . -type f | grep "[.]dpi" | xargs` - rm -rf `find . -type d | grep "[.]libs" | xargs` + rm -f `find . -type f -name "*.o" | xargs` + rm -f `find . -type f -name "*.lo" | xargs` + rm -f `find . -type f -name "*.a" | xargs` + rm -f `find . -type f -name "*.la" | xargs` + rm -f `find . -type f -name "*.obj" | xargs` + rm -f `find . -type f -name "*.lib" | xargs` + rm -f `find . -type f -name "*.exe" | xargs` + rm -f `find . -type f -name "*.gcda" | xargs` + rm -f `find . -type f -name "*.gcno" | xargs` + rm -f `find . -type f -name "*.il" | xargs` + rm -f `find . -type f -name "*.dyn" | xargs` + rm -f `find . -type f -name "*.dpi" | xargs` + rm -rf `find . -type d -name "*.libs" | xargs` rm -f crypt.aux crypt.dvi crypt.idx crypt.ilg crypt.ind crypt.log crypt.toc rm -f $(TV) $(PROF) $(SMALL) $(CRYPT) $(HASHSUM) $(MULTI) $(TIMING) $(TEST) rm -rf doc/doxygen - rm -f doc/*.pdf + rm -f `find . -type f -name "*.pdf" | grep -FL crypt.pdf | xargs` rm -f *.txt #build the doxy files (requires Doxygen, tetex and patience) diff --git a/src/ciphers/camellia.c b/src/ciphers/camellia.c index 06510125..e7b172f0 100644 --- a/src/ciphers/camellia.c +++ b/src/ciphers/camellia.c @@ -686,6 +686,21 @@ int camellia_test(void) } camellia_done(&skey); if (XMEMCMP(tests[x].ct, buf[0], 16) || XMEMCMP(tests[x].pt, buf[1], 16)) { +#if 0 + int i, j; + printf ("\n\nLTC_CAMELLIA failed for x=%d, I got:\n", x); + for (i = 0; i < 2; i++) { + const unsigned char *expected, *actual; + expected = (i ? tests[x].pt : tests[x].ct); + actual = buf[i]; + printf ("expected actual (%s)\n", (i ? "plaintext" : "ciphertext")); + for (j = 0; j < 16; j++) { + const char *eq = (expected[j] == actual[j] ? "==" : "!="); + printf (" %02x %s %02x\n", expected[j], eq, actual[j]); + } + printf ("\n"); + } +#endif return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/ciphers/kseed.c b/src/ciphers/kseed.c index a163c954..1065d8ca 100644 --- a/src/ciphers/kseed.c +++ b/src/ciphers/kseed.c @@ -346,6 +346,21 @@ int kseed_test(void) kseed_ecb_encrypt(tests[x].pt, buf[0], &skey); kseed_ecb_decrypt(buf[0], buf[1], &skey); if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) { +#if 0 + int i, j; + printf ("\n\nLTC_KSEED failed for x=%d, I got:\n", x); + for (i = 0; i < 2; i++) { + const unsigned char *expected, *actual; + expected = (i ? tests[x].pt : tests[x].ct); + actual = buf[i]; + printf ("expected actual (%s)\n", (i ? "plaintext" : "ciphertext")); + for (j = 0; j < 16; j++) { + const char *eq = (expected[j] == actual[j] ? "==" : "!="); + printf (" %02x %s %02x\n", expected[j], eq, actual[j]); + } + printf ("\n"); + } +#endif return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/headers/tomcrypt_cfg.h b/src/headers/tomcrypt_cfg.h index f7ad3cc0..cc3b6dff 100644 --- a/src/headers/tomcrypt_cfg.h +++ b/src/headers/tomcrypt_cfg.h @@ -128,6 +128,22 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); #define ENDIAN_NEUTRAL #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 diff --git a/src/headers/tomcrypt_custom.h b/src/headers/tomcrypt_custom.h index 362403bc..97de5de8 100644 --- a/src/headers/tomcrypt_custom.h +++ b/src/headers/tomcrypt_custom.h @@ -306,8 +306,8 @@ /* #define LTC_RSA_BLINDING */ /* Include Diffie-Hellman support */ -#ifndef GPM_DESC -/* is_prime fails for GPM */ +#ifndef GMP_DESC +/* is_prime fails for GMP */ #define MDH /* Supported Key Sizes */ #define DH768 diff --git a/src/headers/tomcrypt_macros.h b/src/headers/tomcrypt_macros.h index 6e4d757a..86156cce 100644 --- a/src/headers/tomcrypt_macros.h +++ b/src/headers/tomcrypt_macros.h @@ -67,7 +67,17 @@ #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) \ asm __volatile__ ( \ @@ -96,22 +106,31 @@ asm __volatile__ ( \ #endif +#ifdef LTC_HAVE_BSWAP_BUILTIN + +#define STORE64H(x, y) \ + { ulong64 __t = __builtin_bswap64 ((x)); \ + XMEMCPY ((y), &__t, 8); } + +#define LOAD64H(x, y) \ + { XMEMCPY (&(x), (y), 8); \ + (x) = __builtin_bswap64 ((x)); } /* x86_64 processor */ -#if !defined(LTC_NO_BSWAP) && (defined(__GNUC__) && defined(__x86_64__)) +#elif !defined(LTC_NO_BSWAP) && (defined(__GNUC__) && defined(__x86_64__)) #define STORE64H(x, y) \ asm __volatile__ ( \ "bswapq %0 \n\t" \ "movq %0,(%1)\n\t" \ "bswapq %0 \n\t" \ - ::"r"(x), "r"(y)); + ::"r"(x), "r"(y): "memory"); #define LOAD64H(x, y) \ asm __volatile__ ( \ "movq (%1),%0\n\t" \ "bswapq %0\n\t" \ - :"=r"(x): "r"(y)); + :"=r"(x): "r"(y): "memory"); #else diff --git a/src/math/gmp_desc.c b/src/math/gmp_desc.c index 9d7ff072..403211ba 100644 --- a/src/math/gmp_desc.c +++ b/src/math/gmp_desc.c @@ -487,7 +487,7 @@ const ltc_math_descriptor gmp_desc = { NULL, #endif /* LTC_ECC_SHAMIR */ #else - NULL, NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, NULL, #endif /* LTC_MECC */ #ifdef LTC_MRSA diff --git a/src/misc/crypt/crypt.c b/src/misc/crypt/crypt.c index 12983979..e1b1ce03 100644 --- a/src/misc/crypt/crypt.c +++ b/src/misc/crypt/crypt.c @@ -286,7 +286,9 @@ const char *crypt_build_settings = #if defined(_MSC_VER) " MSVC compiler detected.\n" #endif -#if defined(__GNUC__) +#if defined(__clang_version__) + " Clang compiler " __clang_version__ ".\n" +#elif defined(__GNUC__) /* clang also defines __GNUC__ */ " GCC compiler detected.\n" #endif #if defined(INTEL_CC) diff --git a/testprof/cipher_hash_test.c b/testprof/cipher_hash_test.c index 666d9139..dba7d9ad 100644 --- a/testprof/cipher_hash_test.c +++ b/testprof/cipher_hash_test.c @@ -11,25 +11,25 @@ int cipher_hash_test(void) /* test ciphers */ for (x = 0; cipher_descriptor[x].name != NULL; x++) { - DO(cipher_descriptor[x].test()); + DOX(cipher_descriptor[x].test(), cipher_descriptor[x].name); } /* test hashes */ for (x = 0; hash_descriptor[x].name != NULL; x++) { - DO(hash_descriptor[x].test()); + DOX(hash_descriptor[x].test(), hash_descriptor[x].name); } /* test prngs (test, import/export */ for (x = 0; prng_descriptor[x].name != NULL; x++) { - DO(prng_descriptor[x].test()); - DO(prng_descriptor[x].start(&nprng)); - DO(prng_descriptor[x].add_entropy((unsigned char *)"helloworld12", 12, &nprng)); - DO(prng_descriptor[x].ready(&nprng)); + DOX(prng_descriptor[x].test(), prng_descriptor[x].name); + DOX(prng_descriptor[x].start(&nprng), prng_descriptor[x].name); + DOX(prng_descriptor[x].add_entropy((unsigned char *)"helloworld12", 12, &nprng), prng_descriptor[x].name); + DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name); n = sizeof(buf); - DO(prng_descriptor[x].pexport(buf, &n, &nprng)); + DOX(prng_descriptor[x].pexport(buf, &n, &nprng), prng_descriptor[x].name); prng_descriptor[x].done(&nprng); - DO(prng_descriptor[x].pimport(buf, n, &nprng)); - DO(prng_descriptor[x].ready(&nprng)); + DOX(prng_descriptor[x].pimport(buf, n, &nprng), prng_descriptor[x].name); + DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name); if (prng_descriptor[x].read(buf, 100, &nprng) != 100) { fprintf(stderr, "Error reading from imported PRNG!\n"); exit(EXIT_FAILURE); diff --git a/testprof/test_driver.c b/testprof/test_driver.c index 6e546684..b728f911 100644 --- a/testprof/test_driver.c +++ b/testprof/test_driver.c @@ -1,9 +1,12 @@ #include -void run_cmd(int res, int line, char *file, char *cmd) +void run_cmd(int res, int line, char *file, char *cmd, const char *algorithm) { if (res != CRYPT_OK) { - fprintf(stderr, "%s (%d)\n%s:%d:%s\n", error_to_string(res), res, file, line, cmd); + fprintf(stderr, "%s (%d)%s%s\n%s:%d:%s\n", + error_to_string(res), res, + (algorithm ? " - " : ""), (algorithm ? algorithm : ""), + file, line, cmd); if (res != CRYPT_NOP) { exit(EXIT_FAILURE); } diff --git a/testprof/tomcrypt_test.h b/testprof/tomcrypt_test.h index 237eee32..84e173c6 100644 --- a/testprof/tomcrypt_test.h +++ b/testprof/tomcrypt_test.h @@ -36,12 +36,14 @@ typedef struct { extern prng_state yarrow_prng; -void run_cmd(int res, int line, char *file, char *cmd); +void run_cmd(int res, int line, char *file, char *cmd, const char *algorithm); #ifdef LTC_VERBOSE -#define DO(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x), __LINE__, __FILE__, #x); } while (0); +#define DO(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0); +#define DOX(x, str) do { fprintf(stderr, "%s - %s:\n", #x, (str)); run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0); #else -#define DO(x) do { run_cmd((x), __LINE__, __FILE__, #x); } while (0); +#define DO(x) do { run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0); +#define DOX(x, str) do { run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0); #endif /* TESTS */