Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ addons:

install:
- sudo apt-get update -qq
- sudo apt-get install libtommath-dev
- sudo apt-get install libtommath-dev libgmp-dev valgrind
Copy link
Member

Choose a reason for hiding this comment

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

This is what was needed in ecc branch (latest ltm + tfm)
https://github.com/libtom/libtomcrypt/blob/pr/ecc-asn1-part/.travis.yml#L22

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I'd like to stay on standard-built packages as long as possible as the packages that are installed in the ecc branch are built by me ;)


before_script:
- gem install coveralls-lcov
Expand All @@ -38,17 +38,9 @@ script:
- bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile.shared V=1" "-DUSE_TFM -DTFM_DESC" "-ltfm"
env:
- |
BUILDSCRIPT="check_source.sh"
BUILDNAME="CHECK_SOURCES"
BUILDOPTIONS=" "
- |
BUILDSCRIPT="scan_build.sh"
BUILDNAME="SCAN_BUILD"
BUILDOPTIONS=" "
- |
BUILDSCRIPT="coverage.sh"
BUILDNAME="COVERAGE"
BUILDOPTIONS=" "
BUILDSCRIPT="meta_builds.sh"
BUILDNAME="META_BUILS"
BUILDOPTIONS="-DGMP_DESC"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="STOCK"
Expand Down Expand Up @@ -113,14 +105,6 @@ env:
BUILDSCRIPT="run.sh"
BUILDNAME="CLEANSTACK+NOTABLES+SMALL+NO_ASM+NO_TIMING_RESISTANCE+PTHREAD"
BUILDOPTIONS="-DLTC_CLEAN_STACK -DLTC_NO_TABLES -DLTC_SMALL_CODE -DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING -DLTC_PTHREAD"
- |
BUILDSCRIPT="testbuild.sh"
BUILDNAME="NOTEST"
BUILDOPTIONS="-DLTC_NO_TEST"
- |
BUILDSCRIPT="testbuild.sh"
BUILDNAME="NOFILE"
BUILDOPTIONS="-DLTC_NO_FILE"

after_failure:
- cat test_std.txt
Expand Down
53 changes: 30 additions & 23 deletions demos/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,20 +520,15 @@ static void time_hash(void)
}

/*#warning you need an mp_rand!!!*/
#if !defined(USE_LTM) && !defined(USE_TFM) && !defined(USE_GMP) && !defined(EXT_MATH_LIB)
#undef LTC_MPI
#undef LTC_TEST_MPI
#else
#define LTC_TEST_MPI
#endif

#ifdef LTC_MPI
static void time_mult(void)
{
ulong64 t1, t2;
unsigned long x, y;
void *a, *b, *c;

if (ltc_mp.name == NULL) return;

fprintf(stderr, "Timing Multiplying:\n");
mp_init_multi(&a,&b,&c,NULL);
for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) {
Expand Down Expand Up @@ -565,6 +560,8 @@ static void time_sqr(void)
unsigned long x, y;
void *a, *b;

if (ltc_mp.name == NULL) return;

fprintf(stderr, "Timing Squaring:\n");
mp_init_multi(&a,&b,NULL);
for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) {
Expand All @@ -588,10 +585,6 @@ static void time_sqr(void)
#undef DO1
#undef DO2
}
#else
static void time_mult(void) { fprintf(stderr, "NO MULT\n"); }
static void time_sqr(void) { fprintf(stderr, "NO SQR\n"); }
#endif

static void time_prng(void)
{
Expand Down Expand Up @@ -645,7 +638,7 @@ static void time_prng(void)
}
}

#if defined(LTC_MDSA) && defined(LTC_TEST_MPI)
#if defined(LTC_MDSA)
/* time various DSA operations */
static void time_dsa(void)
{
Expand All @@ -665,6 +658,8 @@ static const struct {
#endif
};

if (ltc_mp.name == NULL) return;

for (x = 0; x < (sizeof(groups)/sizeof(groups[0])); x++) {
t2 = 0;
for (y = 0; y < 4; y++) {
Expand Down Expand Up @@ -700,7 +695,7 @@ static void time_dsa(void) { fprintf(stderr, "NO DSA\n"); }
#endif


#if defined(LTC_MRSA) && defined(LTC_TEST_MPI)
#if defined(LTC_MRSA)
/* time various RSA operations */
static void time_rsa(void)
{
Expand All @@ -710,6 +705,8 @@ static void time_rsa(void)
unsigned long x, y, z, zzz;
int err, zz, stat;

if (ltc_mp.name == NULL) return;

for (x = 1024; x <= 2048; x += 256) {
t2 = 0;
for (y = 0; y < 4; y++) {
Expand Down Expand Up @@ -824,7 +821,7 @@ static void time_rsa(void)
static void time_rsa(void) { fprintf(stderr, "NO RSA\n"); }
#endif

#if defined(LTC_MKAT) && defined(LTC_TEST_MPI)
#if defined(LTC_MKAT)
/* time various KAT operations */
static void time_katja(void)
{
Expand All @@ -834,6 +831,8 @@ static void time_katja(void)
unsigned long x, y, z, zzz;
int err, zz;

if (ltc_mp.name == NULL) return;

for (x = 1024; x <= 2048; x += 256) {
t2 = 0;
for (y = 0; y < 4; y++) {
Expand Down Expand Up @@ -894,7 +893,7 @@ static void time_katja(void)
static void time_katja(void) { fprintf(stderr, "NO Katja\n"); }
#endif

#if defined(LTC_MDH) && defined(LTC_TEST_MPI)
#if defined(LTC_MDH)
/* time various DH operations */
static void time_dh(void)
{
Expand All @@ -909,6 +908,8 @@ static void time_dh(void)
100000
};

if (ltc_mp.name == NULL) return;

for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
t2 = 0;
for (y = 0; y < 16; y++) {
Expand Down Expand Up @@ -936,7 +937,7 @@ static void time_dh(void)
static void time_dh(void) { fprintf(stderr, "NO DH\n"); }
#endif

#if defined(LTC_MECC) && defined(LTC_TEST_MPI)
#if defined(LTC_MECC)
/* time various ECC operations */
static void time_ecc(void)
{
Expand Down Expand Up @@ -972,6 +973,8 @@ static void time_ecc(void)
#endif
100000};

if (ltc_mp.name == NULL) return;

for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
t2 = 0;
for (y = 0; y < 256; y++) {
Expand Down Expand Up @@ -1425,25 +1428,29 @@ const struct
};
char *single_test = NULL;
unsigned int i;
const char* mpi_provider = NULL;

init_timer();
register_all_ciphers();
register_all_hashes();
register_all_prngs();

#ifdef USE_LTM
ltc_mp = ltm_desc;
mpi_provider = "ltm";
#elif defined(USE_TFM)
ltc_mp = tfm_desc;
mpi_provider = "tfm";
#elif defined(USE_GMP)
ltc_mp = gmp_desc;
mpi_provider = "gmp";
#elif defined(EXT_MATH_LIB)
{
extern ltc_math_descriptor EXT_MATH_LIB;
ltc_mp = EXT_MATH_LIB;
}
mpi_provider = "ext";
#endif

if (argc > 2) {
mpi_provider = argv[2];
}

crypt_mp_init(mpi_provider);

if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) {
fprintf(stderr, "rng_make_prng failed: %s\n", error_to_string(err));
exit(EXIT_FAILURE);
Expand Down
24 changes: 22 additions & 2 deletions demos/tv_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ void omac_gen(void)
}
len = sizeof(output);
if ((err = omac_memory(x, key, kl, input, y, output, &len)) != CRYPT_OK) {
printf("Error omacing: %s\n", error_to_string(err));
printf("Error OMAC'ing: %s\n", error_to_string(err));
exit(EXIT_FAILURE);
}
if (len == 0) {
printf("Error OMAC'ing: zero length\n");
exit(EXIT_FAILURE);
}
fprintf(out, "%3d: ", y);
Expand Down Expand Up @@ -270,7 +274,11 @@ void pmac_gen(void)
}
len = sizeof(output);
if ((err = pmac_memory(x, key, kl, input, y, output, &len)) != CRYPT_OK) {
printf("Error omacing: %s\n", error_to_string(err));
printf("Error PMACing: %s\n", error_to_string(err));
exit(EXIT_FAILURE);
}
if (len == 0) {
printf("Error PMAC'ing: zero length\n");
exit(EXIT_FAILURE);
}
fprintf(out, "%3d: ", y);
Expand Down Expand Up @@ -331,6 +339,10 @@ void eax_gen(void)
printf("Error EAX'ing: %s\n", error_to_string(err));
exit(EXIT_FAILURE);
}
if (len == 0) {
printf("Error EAX'ing: zero length\n");
exit(EXIT_FAILURE);
}
fprintf(out, "%3d: ", y1);
for (z = 0; z < y1; z++) {
fprintf(out, "%02X", plaintext[z]);
Expand Down Expand Up @@ -396,6 +408,10 @@ void ocb_gen(void)
printf("Error OCB'ing: %s\n", error_to_string(err));
exit(EXIT_FAILURE);
}
if (len == 0) {
printf("Error OCB'ing: zero length\n");
exit(EXIT_FAILURE);
}
fprintf(out, "%3d: ", y1);
for (z = 0; z < y1; z++) {
fprintf(out, "%02X", plaintext[z]);
Expand Down Expand Up @@ -462,6 +478,10 @@ void ocb3_gen(void)
printf("Error OCB3'ing: %s\n", error_to_string(err));
exit(EXIT_FAILURE);
}
if (len == 0) {
printf("Error OCB3'ing: zero length\n");
exit(EXIT_FAILURE);
}
fprintf(out, "%3d: ", y1);
for (z = 0; z < y1; z++) {
fprintf(out, "%02X", plaintext[z]);
Expand Down
62 changes: 62 additions & 0 deletions meta_builds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
#
# This builds different stuff depending on the compiler:
# gcc - valgrind, coverage
# clang - asan, ubsan, scan-build
# both - the two testbuild's NOTEST and NOFILE

set -e

if [ "$#" = "5" -a "$(echo $3 | grep -v 'makefile[.]')" = "" ]; then
echo "only run $0 for the regular makefile, early exit success"
exit 0
fi

function run_gcc() {
bash check_source.sh "CHECK_SOURCES" "$2" "$3" "$4" "$5"

make clean &>/dev/null

bash coverage.sh "COVERAGE" "$2" "$3" "$4" "$5"

make clean &>/dev/null

make CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" test LTC_DEBUG=1 1>gcc_1.txt 2>gcc_2.txt

valgrind --error-exitcode=666 --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all ./test 1>test_std.txt 2> test_err.txt

make clean &>/dev/null

make CFLAGS="-fsanitize=address -fno-omit-frame-pointer -static-libasan $2 $CFLAGS $4" EXTRALIBS="-lasan $5" test LTC_DEBUG=1 1>gcc_1.txt 2>gcc_2.txt
ASAN_OPTIONS=verbosity=1 ./test t ltm 1>test_std.txt 2> test_err.txt
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't ASAN go into run_clang ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought so too ... then I wasn't able to get the ASAN build done with clang which can be installed in xenial ... but it worked with gcc, so I thought let's give it a try...

ASAN_OPTIONS=verbosity=1 ./test t gmp 1>test_std.txt 2> test_err.txt
}

function run_clang() {
bash scan_build.sh "SCAN_BUILD" "$2" "$3" "$4" "$5"

make clean &>/dev/null

make LDFLAGS="-fsanitize=undefined" CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" all LTC_DEBUG=1 1>gcc_1.txt 2>gcc_2.txt
UBSAN_OPTIONS=verbosity=1 ./test t ltm 1>test_std.txt 2> test_err.txt
UBSAN_OPTIONS=verbosity=1 ./test t gmp 1>test_std.txt 2> test_err.txt
}


make clean &>/dev/null

EXTRALIBS="$5 -lgmp"

if [ -z "$(echo $CC | grep "clang")" ]; then
run_gcc "$1" "$2" "$3" "$4" "$EXTRALIBS"
else
run_clang "$1" "$2" "$3" "$4" "$EXTRALIBS"
fi

make clean &>/dev/null

bash testbuild.sh "NOTEST" "-DLTC_NO_TEST" "$3" "$4" "$5"

make clean &>/dev/null

bash testbuild.sh "NOFILE" "-DLTC_NO_FILE" "$3" "$4" "$5"
12 changes: 8 additions & 4 deletions scan_build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth a separate script (scan_build.sh)? What about incorporating the stuff into meta_builds.sh?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope, I just re-used it as it mostly worked OOTB - I'm going to incorporate it.

[ "$TRAVIS_CI" != "" ] && { [ -z "$(which scan-build)" ] && { echo "installing clang"; sudo apt-get install clang -y -qq; }; } || true

set -e

if [ "$TRAVIS_CI" != "" ] && [ -z "$(echo $CC | grep "clang")" ]; then
echo "no clang detected, early exit success"
exit 0
fi

if [ "$#" = "5" -a "$(echo $3 | grep -v 'makefile[.]')" = "" ]; then
echo "only run $0 for the regular makefile, early exit success"
Expand All @@ -14,6 +20,4 @@ make clean > /dev/null
scan_build=$(which scan-build)
[ -z "$scan_build" ] && scan_build=$(find /usr/bin/ -name 'scan-build-*' | sort -nr | head -n1) || true
[ -z "$scan_build" ] && { echo "couldn't find clang scan-build"; exit 1; } || echo "run $scan_build"
export CFLAGS="-DUSE_LTM -DLTM_DESC -I/usr/include"
export EXTRALIBS="-ltommath"
$scan_build --status-bugs make -f makefile.unix all CFLAGS="$CFLAGS" EXTRALIBS="$EXTRALIBS"
$scan_build --status-bugs make all CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5"
9 changes: 9 additions & 0 deletions src/headers/tomcrypt_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ typedef unsigned long ltc_mp_digit;
#define LTC_HAVE_BSWAP_BUILTIN
#endif

#ifdef __GNUC__
#define LTC_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define LTC_DEPRECATED __declspec(deprecated)
#endif

#ifndef LTC_DEPRECATED
#error "You need to define LTC_DEPRECATED for this compiler"
Copy link
Member

Choose a reason for hiding this comment

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

I do not like this. It is very unfriendly to non-gcc/non-msvc compilers.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hoped you're going to build this on "the other compilers" and then either fill it in or define it to nothing if the "deprecation" feature doesn't exist for "the other compilers"

Copy link
Member

Choose a reason for hiding this comment

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

Consider:

#ifdef __GNUC__
   #define LTC_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
   #define LTC_DEPRECATED __declspec(deprecated)
#else
   #define LTC_DEPRECATED
#endif

It might also cause troubles on older gcc as I do not know since what version this attribute is supported.

Copy link
Member Author

@sjaeckel sjaeckel Oct 12, 2017

Choose a reason for hiding this comment

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

looks like gcc-3.1 introduced it as it wasn't in gcc-3.0.4

but yeah, let's be a bit less strict

Copy link
Member

Choose a reason for hiding this comment

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

It seems to be supported on gcc 3.1+

Copy link
Member

@karel-m karel-m Oct 12, 2017

Choose a reason for hiding this comment

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

#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)

#endif

/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
Expand Down
7 changes: 4 additions & 3 deletions src/headers/tomcrypt_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ int crypt_get_size(const char* namein, unsigned int *sizeout);
int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size);

#ifdef LTM_DESC
void init_LTM(void);
LTC_DEPRECATED void init_LTM(void);
#endif
#ifdef TFM_DESC
void init_TFM(void);
LTC_DEPRECATED void init_TFM(void);
#endif
#ifdef GMP_DESC
void init_GMP(void);
LTC_DEPRECATED void init_GMP(void);
#endif
int crypt_mp_init(const char* mpi);

#ifdef LTC_ADLER32
typedef struct adler32_state_s
Expand Down
Loading