Browse Source

Merge pull request #499 from libtom/minor-improvements

Minor improvements
Steffen Jaeckel 6 years ago
parent
commit
734ba7ec50
10 changed files with 93 additions and 43 deletions
  1. 16 0
      .ci/build.sh
  2. 2 2
      .ci/meta_builds.sh
  3. 4 4
      .ci/run.sh
  4. 4 12
      .travis.yml
  5. 3 0
      makefile
  6. 13 12
      makefile_include.mk
  7. 10 4
      src/hashes/chc/chc.c
  8. 6 1
      src/headers/tomcrypt_cfg.h
  9. 32 7
      src/headers/tomcrypt_macros.h
  10. 3 1
      src/misc/crypt/crypt.c

+ 16 - 0
.ci/build.sh

@@ -23,6 +23,22 @@ if [[ $mret -ne 0 ]] || [[ $cnt -gt 1 ]]; then
    exit 1
 fi
 
+# remove the standard arguments from the make options
+opts=${3//makefile.shared/}
+opts=${opts//makefile/}
+opts=${opts//V=1/}
+opts=${opts//COVERAGE=1/}
+opts=$(echo $opts | tr -d '[:space:]')
+
+# if there's something else than the standard arguments we check if we're currently
+# building a Travis PR and if it's like that, we skip those tests
+if [ ! -z "$opts" ]; then
+  if [ ! -z "$TRAVIS_PULL_REQUEST" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
+    echo "PR Tests skipped" | tee testok.txt
+    exit 0
+  fi
+fi
+
 echo -n "testing..."
 
 if [ -a test ] && [ -f test ] && [ -x test ]; then

+ 2 - 2
.ci/meta_builds.sh

@@ -53,8 +53,8 @@ function run_clang() {
    # output version
    bash .ci/printinfo.sh
 
-   scan_build=$(which scan-build)
-   [ -z "$scan_build" ] && scan_build=$(find /usr/bin/ -name 'scan-build-*' | sort -nr | head -n1) || true
+   scan_build=$(which scan-build) || true
+   [ -z "$scan_build" ] && scan_build=$(find /usr/bin/ -name 'scan-build-[0-9]*' | sort -nr | head -n1) || true
    [ -z "$scan_build" ] && { echo "couldn't find clang scan-build"; exit 1; } || echo "run $scan_build"
    $scan_build --status-bugs make -j$MAKE_JOBS all CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5"
 

+ 4 - 4
.ci/run.sh

@@ -3,7 +3,7 @@
 # output version
 bash .ci/printinfo.sh
 
-bash .ci/build.sh " $1" "$2 -O2" "$3 IGNORE_SPEED=1" "$4" "$5"
+bash .ci/build.sh " $1" "$2" "$3" "$4" "$5"
 if [ -a testok.txt ] && [ -f testok.txt ]; then
    echo
 else
@@ -13,7 +13,7 @@ else
 fi
 
 rm -f testok.txt
-bash .ci/build.sh " $1" "$2 -Os" "$3 IGNORE_SPEED=1 LTC_SMALL=1" "$4" "$5"
+bash .ci/build.sh " $1" "$2" "$3 LTC_DEBUG=1" "$4" "$5"
 if [ -a testok.txt ] && [ -f testok.txt ]; then
    echo
 else
@@ -23,7 +23,7 @@ else
 fi
 
 rm -f testok.txt
-bash .ci/build.sh " $1" "$2" "$3 LTC_DEBUG=1" "$4" "$5"
+bash .ci/build.sh " $1" "$2 -O2" "$3 IGNORE_SPEED=1" "$4" "$5"
 if [ -a testok.txt ] && [ -f testok.txt ]; then
    echo
 else
@@ -33,7 +33,7 @@ else
 fi
 
 rm -f testok.txt
-bash .ci/build.sh " $1" "$2" "$3" "$4" "$5"
+bash .ci/build.sh " $1" "$2" "$3 IGNORE_SPEED=1 LTC_SMALL=1" "$4" "$5"
 if [ -a testok.txt ] && [ -f testok.txt ]; then
    echo
 else

+ 4 - 12
.travis.yml

@@ -1,26 +1,18 @@
-dist: trusty
+dist: bionic
 sudo: required
 
 language: c
 
-addons:
-  apt:
-    sources:
-    - ubuntu-toolchain-r-test
-    - llvm-toolchain-precise-3.8
-    packages:
-    - clang-3.8
-
-install:
+before_install:
     - sudo apt-get update -qq
-    - sudo apt-get install libtommath-dev libgmp-dev valgrind
+    - sudo apt-get install -y libtommath-dev libgmp-dev libtfm-dev valgrind libtool-bin
 
 before_script:
   - gem install coveralls-lcov
   - curl http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz | tar xz
   - export PATH=$PATH:`pwd`/lcov-1.11/bin
   - curl -s https://packagecloud.io/install/repositories/libtom/packages/script.deb.sh | sudo bash
-  - sudo apt-get install libtfm-dev=0.13-5 libtommath-dev=1.0-5
+  - sudo apt-get install libtfm1=0.13-5ubuntu1
 
 matrix:
   fast_finish: true

+ 3 - 0
makefile

@@ -41,6 +41,9 @@ LTC_EXTRALIBS += $(EXTRALIBS)
 
 #AES comes in two flavours... enc+dec and enc
 src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
+ifneq ($V,1)
+	@echo "   * ${CC} $@"
+endif
 	${silent} ${CC} ${LTC_CFLAGS} -DENCRYPT_ONLY -c $< -o $@
 
 .c.o:

+ 13 - 12
makefile_include.mk

@@ -76,7 +76,7 @@ endef
 # by giving them as a parameter to make:
 #  make CFLAGS="-I./src/headers/ -DLTC_SOURCE ..." ...
 #
-LTC_CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow -DLTC_SOURCE
+LTC_CFLAGS += -I./src/headers/ -DLTC_SOURCE -Wall -Wsign-compare -Wshadow
 
 ifdef OLD_GCC
 LTC_CFLAGS += -W
@@ -92,23 +92,17 @@ LTC_CFLAGS += -Wdeclaration-after-statement
 LTC_CFLAGS += -Wwrite-strings
 endif
 
-LTC_CFLAGS += -Wno-type-limits
-
 ifdef LTC_DEBUG
 $(info Debug build)
 # compile for DEBUGGING (required for ccmalloc checking!!!)
 LTC_CFLAGS += -g3 -DLTC_NO_ASM
+
 ifneq (,$(strip $(LTC_DEBUG)))
 LTC_CFLAGS += -DLTC_TEST_DBG=$(LTC_DEBUG)
 else
 LTC_CFLAGS += -DLTC_TEST_DBG
 endif
-else
-
-ifdef LTC_SMALL
-# optimize for SIZE
-LTC_CFLAGS += -Os -DLTC_SMALL_CODE
-else
+endif # LTC_DEBUG
 
 ifndef IGNORE_SPEED
 # optimize for SPEED
@@ -116,10 +110,12 @@ LTC_CFLAGS += -O3 -funroll-loops
 
 # add -fomit-frame-pointer.  hinders debugging!
 LTC_CFLAGS += -fomit-frame-pointer
-endif
+endif # IGNORE_SPEED
 
-endif # COMPILE_SMALL
-endif # COMPILE_DEBUG
+ifdef LTC_SMALL
+# optimize for SIZE
+LTC_CFLAGS += -Os -DLTC_SMALL_CODE
+endif # LTC_SMALL
 
 
 ifneq ($(findstring clang,$(CC)),)
@@ -147,6 +143,11 @@ endif
 
 LTC_LDFLAGS := $(LTC_LDFLAGS) $(LDFLAGS)
 
+ifeq ($(V)$(filter clean,$(MAKECMDGOALS)),0)
+$(warning CFLAGS=$(LTC_CFLAGS))
+$(warning LDFLAGS=$(LTC_LDFLAGS))
+endif
+
 #List of demo objects
 DSOURCES = $(wildcard demos/*.c)
 DOBJECTS = $(DSOURCES:.c=.o)

+ 10 - 4
src/hashes/chc/chc.c

@@ -270,7 +270,7 @@ int chc_test(void)
    16
 }
 };
-   int i, oldhashidx, idx;
+   int i, oldhashidx, idx, err;
    unsigned char tmp[MAXBLOCKSIZE];
    hash_state md;
 
@@ -284,9 +284,15 @@ int chc_test(void)
    chc_register(idx);
 
    for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
-       chc_init(&md);
-       chc_process(&md, tests[i].msg, strlen((char *)tests[i].msg));
-       chc_done(&md, tmp);
+       if ((err = chc_init(&md)) != CRYPT_OK) {
+          return err;
+       }
+       if ((err = chc_process(&md, tests[i].msg, strlen((char *)tests[i].msg))) != CRYPT_OK) {
+          return err;
+       }
+       if ((err = chc_done(&md, tmp)) != CRYPT_OK) {
+          return err;
+       }
        if (compare_testvector(tmp, tests[i].len, tests[i].hash, tests[i].len, "CHC", i)) {
           return CRYPT_FAIL_TESTVECTOR;
        }

+ 6 - 1
src/headers/tomcrypt_cfg.h

@@ -243,8 +243,9 @@ typedef unsigned long ltc_mp_digit;
    #undef ENDIAN_32BITWORD
    #undef ENDIAN_64BITWORD
    #undef LTC_FAST
-   #define LTC_NO_ROLC
    #define LTC_NO_BSWAP
+   #define LTC_NO_ROLC
+   #define LTC_NO_ROTATE
 #endif
 
 /* No LTC_FAST if: explicitly disabled OR non-gcc/non-clang compiler OR old gcc OR using -ansi -std=c99 */
@@ -289,6 +290,10 @@ typedef unsigned long ltc_mp_digit;
    #define LTC_HAVE_BSWAP_BUILTIN
 #endif
 
+#if !defined(LTC_NO_ROTATE) && (__has_builtin(__builtin_rotateleft32) && __has_builtin(__builtin_rotateright32))
+   #define LTC_HAVE_ROTATE_BUILTIN
+#endif
+
 #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 301)
    #define LTC_DEPRECATED __attribute__((deprecated))
 #elif defined(_MSC_VER) && _MSC_VER >= 1500

+ 32 - 7
src/headers/tomcrypt_macros.h

@@ -241,15 +241,23 @@ do { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48) | \
 
 /* 32-bit Rotates */
 #if defined(_MSC_VER)
-#define LTC_ROx_ASM
+#define LTC_ROx_BUILTIN
 
 /* instrinsic rotate */
 #include <stdlib.h>
-#pragma intrinsic(_lrotr,_lrotl)
-#define ROR(x,n) _lrotr(x,n)
-#define ROL(x,n) _lrotl(x,n)
-#define RORc(x,n) _lrotr(x,n)
-#define ROLc(x,n) _lrotl(x,n)
+#pragma intrinsic(_rotr,_rotl)
+#define ROR(x,n) _rotr(x,n)
+#define ROL(x,n) _rotl(x,n)
+#define RORc(x,n) ROR(x,n)
+#define ROLc(x,n) ROL(x,n)
+
+#elif defined(LTC_HAVE_ROTATE_BUILTIN)
+#define LTC_ROx_BUILTIN
+
+#define ROR(x,n) __builtin_rotateright32(x,n)
+#define ROL(x,n) __builtin_rotateleft32(x,n)
+#define ROLc(x,n) ROL(x,n)
+#define RORc(x,n) ROR(x,n)
 
 #elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
 #define LTC_ROx_ASM
@@ -353,7 +361,24 @@ static inline ulong32 RORc(ulong32 word, const int i)
 
 
 /* 64-bit Rotates */
-#if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__x86_64__) && !defined(_WIN64) && !defined(LTC_NO_ASM)
+#if defined(_MSC_VER)
+
+/* instrinsic rotate */
+#include <stdlib.h>
+#pragma intrinsic(_rotr64,_rotr64)
+#define ROR64(x,n) _rotr64(x,n)
+#define ROL64(x,n) _rotl64(x,n)
+#define ROR64c(x,n) ROR64(x,n)
+#define ROL64c(x,n) ROL64(x,n)
+
+#elif defined(LTC_HAVE_ROTATE_BUILTIN)
+
+#define ROR64(x,n) __builtin_rotateright64(x,n)
+#define ROL64(x,n) __builtin_rotateleft64(x,n)
+#define ROR64c(x,n) ROR64(x,n)
+#define ROL64c(x,n) ROL64(x,n)
+
+#elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
 
 static inline ulong64 ROL64(ulong64 word, int i)
 {

+ 3 - 1
src/misc/crypt/crypt.c

@@ -514,7 +514,9 @@ const char *crypt_build_settings =
 #if defined(LTC_NO_ASM)
     " LTC_NO_ASM "
 #endif
-#if defined(LTC_ROx_ASM)
+#if defined(LTC_ROx_BUILTIN)
+    " LTC_ROx_BUILTIN "
+#elif defined(LTC_ROx_ASM)
     " LTC_ROx_ASM "
 #if defined(LTC_NO_ROLC)
     " LTC_NO_ROLC "