Skip to content

Commit 734ba7e

Browse files
authored
Merge pull request #499 from libtom/minor-improvements
Minor improvements
2 parents 1e67d81 + da9f552 commit 734ba7e

File tree

10 files changed

+93
-43
lines changed

10 files changed

+93
-43
lines changed

.ci/build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ if [[ $mret -ne 0 ]] || [[ $cnt -gt 1 ]]; then
2323
exit 1
2424
fi
2525

26+
# remove the standard arguments from the make options
27+
opts=${3//makefile.shared/}
28+
opts=${opts//makefile/}
29+
opts=${opts//V=1/}
30+
opts=${opts//COVERAGE=1/}
31+
opts=$(echo $opts | tr -d '[:space:]')
32+
33+
# if there's something else than the standard arguments we check if we're currently
34+
# building a Travis PR and if it's like that, we skip those tests
35+
if [ ! -z "$opts" ]; then
36+
if [ ! -z "$TRAVIS_PULL_REQUEST" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
37+
echo "PR Tests skipped" | tee testok.txt
38+
exit 0
39+
fi
40+
fi
41+
2642
echo -n "testing..."
2743

2844
if [ -a test ] && [ -f test ] && [ -x test ]; then

.ci/meta_builds.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function run_clang() {
5353
# output version
5454
bash .ci/printinfo.sh
5555

56-
scan_build=$(which scan-build)
57-
[ -z "$scan_build" ] && scan_build=$(find /usr/bin/ -name 'scan-build-*' | sort -nr | head -n1) || true
56+
scan_build=$(which scan-build) || true
57+
[ -z "$scan_build" ] && scan_build=$(find /usr/bin/ -name 'scan-build-[0-9]*' | sort -nr | head -n1) || true
5858
[ -z "$scan_build" ] && { echo "couldn't find clang scan-build"; exit 1; } || echo "run $scan_build"
5959
$scan_build --status-bugs make -j$MAKE_JOBS all CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5"
6060

.ci/run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# output version
44
bash .ci/printinfo.sh
55

6-
bash .ci/build.sh " $1" "$2 -O2" "$3 IGNORE_SPEED=1" "$4" "$5"
6+
bash .ci/build.sh " $1" "$2" "$3" "$4" "$5"
77
if [ -a testok.txt ] && [ -f testok.txt ]; then
88
echo
99
else
@@ -13,7 +13,7 @@ else
1313
fi
1414

1515
rm -f testok.txt
16-
bash .ci/build.sh " $1" "$2 -Os" "$3 IGNORE_SPEED=1 LTC_SMALL=1" "$4" "$5"
16+
bash .ci/build.sh " $1" "$2" "$3 LTC_DEBUG=1" "$4" "$5"
1717
if [ -a testok.txt ] && [ -f testok.txt ]; then
1818
echo
1919
else
@@ -23,7 +23,7 @@ else
2323
fi
2424

2525
rm -f testok.txt
26-
bash .ci/build.sh " $1" "$2" "$3 LTC_DEBUG=1" "$4" "$5"
26+
bash .ci/build.sh " $1" "$2 -O2" "$3 IGNORE_SPEED=1" "$4" "$5"
2727
if [ -a testok.txt ] && [ -f testok.txt ]; then
2828
echo
2929
else
@@ -33,7 +33,7 @@ else
3333
fi
3434

3535
rm -f testok.txt
36-
bash .ci/build.sh " $1" "$2" "$3" "$4" "$5"
36+
bash .ci/build.sh " $1" "$2" "$3 IGNORE_SPEED=1 LTC_SMALL=1" "$4" "$5"
3737
if [ -a testok.txt ] && [ -f testok.txt ]; then
3838
echo
3939
else

.travis.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
dist: trusty
1+
dist: bionic
22
sudo: required
33

44
language: c
55

6-
addons:
7-
apt:
8-
sources:
9-
- ubuntu-toolchain-r-test
10-
- llvm-toolchain-precise-3.8
11-
packages:
12-
- clang-3.8
13-
14-
install:
6+
before_install:
157
- sudo apt-get update -qq
16-
- sudo apt-get install libtommath-dev libgmp-dev valgrind
8+
- sudo apt-get install -y libtommath-dev libgmp-dev libtfm-dev valgrind libtool-bin
179

1810
before_script:
1911
- gem install coveralls-lcov
2012
- curl http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz | tar xz
2113
- export PATH=$PATH:`pwd`/lcov-1.11/bin
2214
- curl -s https://packagecloud.io/install/repositories/libtom/packages/script.deb.sh | sudo bash
23-
- sudo apt-get install libtfm-dev=0.13-5 libtommath-dev=1.0-5
15+
- sudo apt-get install libtfm1=0.13-5ubuntu1
2416

2517
matrix:
2618
fast_finish: true

makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ LTC_EXTRALIBS += $(EXTRALIBS)
4141

4242
#AES comes in two flavours... enc+dec and enc
4343
src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
44+
ifneq ($V,1)
45+
@echo " * ${CC} $@"
46+
endif
4447
${silent} ${CC} ${LTC_CFLAGS} -DENCRYPT_ONLY -c $< -o $@
4548

4649
.c.o:

makefile_include.mk

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ endef
7676
# by giving them as a parameter to make:
7777
# make CFLAGS="-I./src/headers/ -DLTC_SOURCE ..." ...
7878
#
79-
LTC_CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow -DLTC_SOURCE
79+
LTC_CFLAGS += -I./src/headers/ -DLTC_SOURCE -Wall -Wsign-compare -Wshadow
8080

8181
ifdef OLD_GCC
8282
LTC_CFLAGS += -W
@@ -92,34 +92,30 @@ LTC_CFLAGS += -Wdeclaration-after-statement
9292
LTC_CFLAGS += -Wwrite-strings
9393
endif
9494

95-
LTC_CFLAGS += -Wno-type-limits
96-
9795
ifdef LTC_DEBUG
9896
$(info Debug build)
9997
# compile for DEBUGGING (required for ccmalloc checking!!!)
10098
LTC_CFLAGS += -g3 -DLTC_NO_ASM
99+
101100
ifneq (,$(strip $(LTC_DEBUG)))
102101
LTC_CFLAGS += -DLTC_TEST_DBG=$(LTC_DEBUG)
103102
else
104103
LTC_CFLAGS += -DLTC_TEST_DBG
105104
endif
106-
else
107-
108-
ifdef LTC_SMALL
109-
# optimize for SIZE
110-
LTC_CFLAGS += -Os -DLTC_SMALL_CODE
111-
else
105+
endif # LTC_DEBUG
112106

113107
ifndef IGNORE_SPEED
114108
# optimize for SPEED
115109
LTC_CFLAGS += -O3 -funroll-loops
116110

117111
# add -fomit-frame-pointer. hinders debugging!
118112
LTC_CFLAGS += -fomit-frame-pointer
119-
endif
113+
endif # IGNORE_SPEED
120114

121-
endif # COMPILE_SMALL
122-
endif # COMPILE_DEBUG
115+
ifdef LTC_SMALL
116+
# optimize for SIZE
117+
LTC_CFLAGS += -Os -DLTC_SMALL_CODE
118+
endif # LTC_SMALL
123119

124120

125121
ifneq ($(findstring clang,$(CC)),)
@@ -147,6 +143,11 @@ endif
147143

148144
LTC_LDFLAGS := $(LTC_LDFLAGS) $(LDFLAGS)
149145

146+
ifeq ($(V)$(filter clean,$(MAKECMDGOALS)),0)
147+
$(warning CFLAGS=$(LTC_CFLAGS))
148+
$(warning LDFLAGS=$(LTC_LDFLAGS))
149+
endif
150+
150151
#List of demo objects
151152
DSOURCES = $(wildcard demos/*.c)
152153
DOBJECTS = $(DSOURCES:.c=.o)

src/hashes/chc/chc.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ int chc_test(void)
270270
16
271271
}
272272
};
273-
int i, oldhashidx, idx;
273+
int i, oldhashidx, idx, err;
274274
unsigned char tmp[MAXBLOCKSIZE];
275275
hash_state md;
276276

@@ -284,9 +284,15 @@ int chc_test(void)
284284
chc_register(idx);
285285

286286
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
287-
chc_init(&md);
288-
chc_process(&md, tests[i].msg, strlen((char *)tests[i].msg));
289-
chc_done(&md, tmp);
287+
if ((err = chc_init(&md)) != CRYPT_OK) {
288+
return err;
289+
}
290+
if ((err = chc_process(&md, tests[i].msg, strlen((char *)tests[i].msg))) != CRYPT_OK) {
291+
return err;
292+
}
293+
if ((err = chc_done(&md, tmp)) != CRYPT_OK) {
294+
return err;
295+
}
290296
if (compare_testvector(tmp, tests[i].len, tests[i].hash, tests[i].len, "CHC", i)) {
291297
return CRYPT_FAIL_TESTVECTOR;
292298
}

src/headers/tomcrypt_cfg.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ typedef unsigned long ltc_mp_digit;
243243
#undef ENDIAN_32BITWORD
244244
#undef ENDIAN_64BITWORD
245245
#undef LTC_FAST
246-
#define LTC_NO_ROLC
247246
#define LTC_NO_BSWAP
247+
#define LTC_NO_ROLC
248+
#define LTC_NO_ROTATE
248249
#endif
249250

250251
/* 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;
289290
#define LTC_HAVE_BSWAP_BUILTIN
290291
#endif
291292

293+
#if !defined(LTC_NO_ROTATE) && (__has_builtin(__builtin_rotateleft32) && __has_builtin(__builtin_rotateright32))
294+
#define LTC_HAVE_ROTATE_BUILTIN
295+
#endif
296+
292297
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 301)
293298
#define LTC_DEPRECATED __attribute__((deprecated))
294299
#elif defined(_MSC_VER) && _MSC_VER >= 1500

src/headers/tomcrypt_macros.h

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,23 @@ do { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48) | \
241241

242242
/* 32-bit Rotates */
243243
#if defined(_MSC_VER)
244-
#define LTC_ROx_ASM
244+
#define LTC_ROx_BUILTIN
245245

246246
/* instrinsic rotate */
247247
#include <stdlib.h>
248-
#pragma intrinsic(_lrotr,_lrotl)
249-
#define ROR(x,n) _lrotr(x,n)
250-
#define ROL(x,n) _lrotl(x,n)
251-
#define RORc(x,n) _lrotr(x,n)
252-
#define ROLc(x,n) _lrotl(x,n)
248+
#pragma intrinsic(_rotr,_rotl)
249+
#define ROR(x,n) _rotr(x,n)
250+
#define ROL(x,n) _rotl(x,n)
251+
#define RORc(x,n) ROR(x,n)
252+
#define ROLc(x,n) ROL(x,n)
253+
254+
#elif defined(LTC_HAVE_ROTATE_BUILTIN)
255+
#define LTC_ROx_BUILTIN
256+
257+
#define ROR(x,n) __builtin_rotateright32(x,n)
258+
#define ROL(x,n) __builtin_rotateleft32(x,n)
259+
#define ROLc(x,n) ROL(x,n)
260+
#define RORc(x,n) ROR(x,n)
253261

254262
#elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
255263
#define LTC_ROx_ASM
@@ -353,7 +361,24 @@ static inline ulong32 RORc(ulong32 word, const int i)
353361

354362

355363
/* 64-bit Rotates */
356-
#if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__x86_64__) && !defined(_WIN64) && !defined(LTC_NO_ASM)
364+
#if defined(_MSC_VER)
365+
366+
/* instrinsic rotate */
367+
#include <stdlib.h>
368+
#pragma intrinsic(_rotr64,_rotr64)
369+
#define ROR64(x,n) _rotr64(x,n)
370+
#define ROL64(x,n) _rotl64(x,n)
371+
#define ROR64c(x,n) ROR64(x,n)
372+
#define ROL64c(x,n) ROL64(x,n)
373+
374+
#elif defined(LTC_HAVE_ROTATE_BUILTIN)
375+
376+
#define ROR64(x,n) __builtin_rotateright64(x,n)
377+
#define ROL64(x,n) __builtin_rotateleft64(x,n)
378+
#define ROR64c(x,n) ROR64(x,n)
379+
#define ROL64c(x,n) ROL64(x,n)
380+
381+
#elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
357382

358383
static inline ulong64 ROL64(ulong64 word, int i)
359384
{

src/misc/crypt/crypt.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ const char *crypt_build_settings =
514514
#if defined(LTC_NO_ASM)
515515
" LTC_NO_ASM "
516516
#endif
517-
#if defined(LTC_ROx_ASM)
517+
#if defined(LTC_ROx_BUILTIN)
518+
" LTC_ROx_BUILTIN "
519+
#elif defined(LTC_ROx_ASM)
518520
" LTC_ROx_ASM "
519521
#if defined(LTC_NO_ROLC)
520522
" LTC_NO_ROLC "

0 commit comments

Comments
 (0)