From 6cfc27d3107aff250f329e53977c3089ccd21aca Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 28 Feb 2017 21:19:27 +0100 Subject: [PATCH 1/8] add EASY build to tests --- .travis.yml | 4 ++++ testme.sh | 3 +++ 2 files changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 88d7fe74..287a5859 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,10 @@ env: BUILDSCRIPT="run.sh" BUILDNAME="STOCK" BUILDOPTIONS=" " + - | + BUILDSCRIPT="run.sh" + BUILDNAME="EASY" + BUILDOPTIONS="-DLTC_EASY" - | BUILDSCRIPT="run.sh" BUILDNAME="SMALL" diff --git a/testme.sh b/testme.sh index 873ad45a..d50fae5c 100755 --- a/testme.sh +++ b/testme.sh @@ -13,6 +13,9 @@ echo "date="`date` # stock build bash run.sh "STOCK" " " "$1" "$2" "$3" || exit 1 +# EASY build +bash run.sh "EASY" "-DLTC_EASY" "$1" "$2" "$3" || exit 1 + # SMALL code bash run.sh "SMALL" "-DLTC_SMALL_CODE" "$1" "$2" "$3" || exit 1 From 0b79bbaf5bf063b50dfd63797d8185e236ac2928 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 28 Feb 2017 21:21:39 +0100 Subject: [PATCH 2/8] fix missing symbol rand_prime --- src/math/rand_prime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/rand_prime.c b/src/math/rand_prime.c index 1c779acb..9dd737bf 100644 --- a/src/math/rand_prime.c +++ b/src/math/rand_prime.c @@ -10,7 +10,7 @@ */ #include "tomcrypt.h" -#if !defined LTC_NO_MATH && !defined LTC_NO_PRNGS +#if defined(LTC_MRSA) || (!defined(LTC_NO_MATH) && !defined(LTC_NO_PRNGS)) /** @file rand_prime.c From 00308d8651820b0f4c645aacc03da72012cb5523 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 28 Feb 2017 21:23:16 +0100 Subject: [PATCH 3/8] fix base64url related errors when only LTC_BASE64 is defined --- src/misc/base64/base64_decode.c | 5 +++-- testprof/base64_test.c | 38 ++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/misc/base64/base64_decode.c b/src/misc/base64/base64_decode.c index 1babfbcb..d3b89b12 100644 --- a/src/misc/base64/base64_decode.c +++ b/src/misc/base64/base64_decode.c @@ -45,8 +45,8 @@ static const unsigned char map_base64[256] = { 255, 255, 255, 255 }; #endif /* LTC_BASE64 */ +static const unsigned char map_base64url[] = { #if defined(LTC_BASE64_URL) -static const unsigned char map_base64url[256] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, @@ -68,8 +68,9 @@ static const unsigned char map_base64url[256] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, -255, 255, 255, 255 }; +255, 255, 255, 255 #endif /* LTC_BASE64_URL */ +}; enum { relaxed = 0, diff --git a/testprof/base64_test.c b/testprof/base64_test.c index 9868a0fc..251822ba 100644 --- a/testprof/base64_test.c +++ b/testprof/base64_test.c @@ -1,10 +1,12 @@ #include -#ifdef LTC_BASE64 +#if defined(LTC_BASE64) || defined(LTC_BASE64_URL) int base64_test(void) { unsigned char in[64], out[256], tmp[64]; unsigned long x, l1, l2, slen1; + +#if defined(LTC_BASE64) const char special_case[] = { 0xbe, 0xe8, 0x92, 0x3c, 0xa2, 0x25, 0xf0, 0xf8, 0x91, 0xe4, 0xef, 0xab, 0x0b, 0x8c, 0xfd, 0xff, @@ -31,7 +33,9 @@ int base64_test(void) {"foobar", "Zm9vYmFy"}, {special_case,"vuiSPKIl8PiR5O+rC4z9/xTQKZ0="} }; +#endif +#ifdef LTC_BASE64_URL const struct { const char* s; int is_strict; @@ -48,20 +52,6 @@ int base64_test(void) {"vuiS*===PKIl8P*iR5O-rC4*z9_xTQKZ0=", 0}, }; - for (x = 0; x < sizeof(cases)/sizeof(cases[0]); ++x) { - memset(out, 0, sizeof(out)); - memset(tmp, 0, sizeof(tmp)); - slen1 = strlen(cases[x].s); - l1 = sizeof(out); - DO(base64_encode((unsigned char*)cases[x].s, slen1, out, &l1)); - l2 = sizeof(tmp); - DO(base64_strict_decode(out, l1, tmp, &l2)); - if (compare_testvector(out, l1, cases[x].b64, strlen(cases[x].b64), "base64 encode", x) || - compare_testvector(tmp, l2, cases[x].s, slen1, "base64 decode", x)) { - return 1; - } - } - for (x = 0; x < sizeof(url_cases)/sizeof(url_cases[0]); ++x) { slen1 = strlen(url_cases[x].s); l1 = sizeof(out); @@ -85,6 +75,22 @@ int base64_test(void) } DO(base64url_strict_decode((unsigned char*)url_cases[4].s, slen1, out, &l1) == CRYPT_INVALID_PACKET ? CRYPT_OK : CRYPT_INVALID_PACKET); +#endif + +#if defined(LTC_BASE64) + for (x = 0; x < sizeof(cases)/sizeof(cases[0]); ++x) { + memset(out, 0, sizeof(out)); + memset(tmp, 0, sizeof(tmp)); + slen1 = strlen(cases[x].s); + l1 = sizeof(out); + DO(base64_encode((unsigned char*)cases[x].s, slen1, out, &l1)); + l2 = sizeof(tmp); + DO(base64_strict_decode(out, l1, tmp, &l2)); + if (compare_testvector(out, l1, cases[x].b64, strlen(cases[x].b64), "base64 encode", x) || + compare_testvector(tmp, l2, cases[x].s, slen1, "base64 decode", x)) { + return 1; + } + } for (x = 0; x < 64; x++) { yarrow_read(in, x, &yarrow_prng); @@ -109,6 +115,8 @@ int base64_test(void) } l2 = sizeof(tmp); DO(base64_strict_decode(out, l1, tmp, &l2) == CRYPT_INVALID_PACKET ? CRYPT_OK : CRYPT_INVALID_PACKET); +#endif + return 0; } #endif From dde11de78117624d484d43442cb52b269857697d Mon Sep 17 00:00:00 2001 From: Karel Miko Date: Wed, 1 Mar 2017 11:48:39 +0100 Subject: [PATCH 4/8] fixing compile failure in demos for -DLTC_EASY --- demos/hashsum.c | 1 + demos/multi.c | 5 ++++- demos/tv_gen.c | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/demos/hashsum.c b/demos/hashsum.c index 78d63697..8f94af55 100644 --- a/demos/hashsum.c +++ b/demos/hashsum.c @@ -67,6 +67,7 @@ int main(int argc, char **argv) void register_algs(void) { int err; + LTC_UNUSED_PARAM(err); #ifdef LTC_TIGER register_hash (&tiger_desc); diff --git a/demos/multi.c b/demos/multi.c index 82d543f8..84d41367 100644 --- a/demos/multi.c +++ b/demos/multi.c @@ -56,6 +56,7 @@ int main(void) } /* LTC_OMAC */ +#ifdef LTC_OMAC len = sizeof(buf[0]); omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); len2 = sizeof(buf[0]); @@ -76,8 +77,10 @@ int main(void) printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } +#endif /* PMAC */ +#ifdef LTC_PMAC len = sizeof(buf[0]); pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); len2 = sizeof(buf[0]); @@ -98,7 +101,7 @@ int main(void) printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } - +#endif printf("All passed\n"); return EXIT_SUCCESS; diff --git a/demos/tv_gen.c b/demos/tv_gen.c index 1a6a6a10..f84bcfe4 100644 --- a/demos/tv_gen.c +++ b/demos/tv_gen.c @@ -3,6 +3,7 @@ void reg_algs(void) { int err; + LTC_UNUSED_PARAM(err); #ifdef LTC_RIJNDAEL register_cipher (&aes_desc); @@ -340,6 +341,7 @@ void omac_gen(void) void pmac_gen(void) { +#ifdef LTC_PMAC unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2]; int err, x, y, z, kl; FILE *out; @@ -391,10 +393,12 @@ void pmac_gen(void) fprintf(out, "\n"); } fclose(out); +#endif } void eax_gen(void) { +#ifdef LTC_EAX_MODE int err, kl, x, y1, z; FILE *out; unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2], @@ -451,10 +455,12 @@ void eax_gen(void) fprintf(out, "\n"); } fclose(out); +#endif } void ocb_gen(void) { +#ifdef LTC_OCB_MODE int err, kl, x, y1, z; FILE *out; unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], @@ -514,10 +520,12 @@ void ocb_gen(void) fprintf(out, "\n"); } fclose(out); +#endif } void ocb3_gen(void) { +#ifdef LTC_OCB3_MODE int err, kl, x, y1, z; FILE *out; unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], @@ -577,10 +585,12 @@ void ocb3_gen(void) fprintf(out, "\n"); } fclose(out); +#endif } void ccm_gen(void) { +#ifdef LTC_CCM_MODE int err, kl, x, y1, z; FILE *out; unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], @@ -640,10 +650,12 @@ void ccm_gen(void) fprintf(out, "\n"); } fclose(out); +#endif } void gcm_gen(void) { +#ifdef LTC_GCM_MODE int err, kl, x, y1, z; FILE *out; unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE]; @@ -697,6 +709,7 @@ void gcm_gen(void) fprintf(out, "\n"); } fclose(out); +#endif } void base64_gen(void) @@ -764,6 +777,7 @@ void ecc_gen(void) void lrw_gen(void) { +#ifdef LTC_LRW_MODE FILE *out; unsigned char tweak[16], key[16], iv[16], buf[1024]; int x, y, err; @@ -825,6 +839,7 @@ void lrw_gen(void) lrw_done(&lrw); } fclose(out); +#endif } int main(void) From 856be9cae8a994812107232dd0c9076bf06f58ff Mon Sep 17 00:00:00 2001 From: Karel Miko Date: Wed, 1 Mar 2017 12:09:50 +0100 Subject: [PATCH 5/8] tv_gen needs more #ifdefs --- demos/tv_gen.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/demos/tv_gen.c b/demos/tv_gen.c index f84bcfe4..a4903af1 100644 --- a/demos/tv_gen.c +++ b/demos/tv_gen.c @@ -286,6 +286,7 @@ void hmac_gen(void) void omac_gen(void) { +#ifdef LTC_OMAC unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2]; int err, x, y, z, kl; FILE *out; @@ -337,6 +338,7 @@ void omac_gen(void) fprintf(out, "\n"); } fclose(out); +#endif } void pmac_gen(void) @@ -848,17 +850,33 @@ int main(void) printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n"); printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n"); printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n"); +#ifdef LTC_OMAC printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n"); +#endif +#ifdef LTC_PMAC printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n"); +#endif +#ifdef LTC_EAX_MODE printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n"); +#endif +#ifdef LTC_OCB_MODE printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n"); +#endif +#ifdef LTC_OCB3_MODE printf("Generating OCB3 vectors..."); fflush(stdout); ocb3_gen(); printf("done\n"); +#endif +#ifdef LTC_CCM_MODE printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n"); +#endif +#ifdef LTC_GCM_MODE printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n"); +#endif printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n"); printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n"); printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n"); +#ifdef LTC_LRW_MODE printf("Generating LRW vectors..."); fflush(stdout); lrw_gen(); printf("done\n"); +#endif return 0; } From be9c66ab431fb68a4a2cb9c4195c7816068fa3cf Mon Sep 17 00:00:00 2001 From: Karel Miko Date: Wed, 1 Mar 2017 13:35:19 +0100 Subject: [PATCH 6/8] tuning build.sh to handle -DLTC_EASY --- build.sh | 17 ++++++++++++++++- check-source.pl | 3 +-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index 7731b3f3..82e61ce8 100755 --- a/build.sh +++ b/build.sh @@ -3,6 +3,11 @@ echo "$1 ($2, $3)..." make clean 1>/dev/null 2>/dev/null +if [ -f check-source.pl ] ; then + echo "checking white spaces..." + perl check-source.pl || exit 1 +fi + echo -n "building..." if [ -f /proc/cpuinfo ] @@ -28,7 +33,17 @@ echo -n "testing..." if [ -a test ] && [ -f test ] && [ -x test ]; then ((./test >test_std.txt 2>test_err.txt && ./tv_gen > tv.txt) && echo "$1 test passed." && echo "y" > testok.txt) || (echo "$1 test failed, look at test_err.txt" && exit 1) if find *_tv.txt -type f 1>/dev/null 2>/dev/null ; then - for f in *_tv.txt; do if (diff -i -w -B $f notes/$f) then true; else (echo "tv_gen $f failed" && rm -f testok.txt && exit 1); fi; done + for f in *_tv.txt; do + # check for lines starting with '<' ($f might be a subset of notes/$f) + difftroubles=$(diff -i -w -B $f notes/$f | grep '^<') + if [ -n "$difftroubles" ]; then + echo "FAILURE: $f" + diff -i -w -B $f notes/$f + echo "tv_gen $f failed" && rm -f testok.txt && exit 1 + else + true + fi + done fi fi diff --git a/check-source.pl b/check-source.pl index a81ce24c..cfd9a8cf 100755 --- a/check-source.pl +++ b/check-source.pl @@ -9,7 +9,6 @@ use strict; use warnings; -use Test::More; use File::Find 'find'; use File::Basename 'basename'; use File::Glob 'bsd_glob'; @@ -37,7 +36,7 @@ for my $file (sort @all_files) { $lineno++; } for my $k (sort keys %$troubles) { - warn "FAIL: [$k] $file line:" . join(",", @{$troubles->{$k}}) . "\n"; + warn "[$k] $file line:" . join(",", @{$troubles->{$k}}) . "\n"; $fails++; } } From 631a11cd35dbe816a4f1d92442078dfcf7da83fe Mon Sep 17 00:00:00 2001 From: Karel Miko Date: Wed, 1 Mar 2017 14:00:45 +0100 Subject: [PATCH 7/8] removing "checking white spaces" part from build.sh --- build.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build.sh b/build.sh index 82e61ce8..94f27bf8 100755 --- a/build.sh +++ b/build.sh @@ -3,11 +3,6 @@ echo "$1 ($2, $3)..." make clean 1>/dev/null 2>/dev/null -if [ -f check-source.pl ] ; then - echo "checking white spaces..." - perl check-source.pl || exit 1 -fi - echo -n "building..." if [ -f /proc/cpuinfo ] From 4f120531ab5f97d412e1bb223f4b8615b607bfab Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 1 Mar 2017 14:09:08 +0100 Subject: [PATCH 8/8] add separate CHECK_SOURCES build target --- .travis.yml | 4 ++++ check_source.sh | 17 +++++++++++++++++ testme.sh | 3 +++ 3 files changed, 24 insertions(+) create mode 100755 check_source.sh diff --git a/.travis.yml b/.travis.yml index 287a5859..3b95cb23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,10 @@ compiler: - clang script: bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile" "-DUSE_LTM -DLTM_DESC -I/usr/include" "/usr/lib/libtommath.a" env: + - | + BUILDSCRIPT="check_source.sh" + BUILDNAME="CHECK_SOURCES" + BUILDOPTIONS=" " - | BUILDSCRIPT="coverage.sh" BUILDNAME="COVERAGE" diff --git a/check_source.sh b/check_source.sh new file mode 100755 index 00000000..b1e9afdc --- /dev/null +++ b/check_source.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# output version +bash printinfo.sh + +make clean > /dev/null + +if [ -f check-source.pl ] ; then + echo "checking white spaces..." + perl check-source.pl || exit 1 +fi + +exit 0 + +# $Source$ +# $Revision$ +# $Date$ diff --git a/testme.sh b/testme.sh index d50fae5c..c1b3c238 100755 --- a/testme.sh +++ b/testme.sh @@ -10,6 +10,9 @@ fi # date echo "date="`date` +# check sources +bash check_source.sh "CHECK_SOURCES" " " "$1" "$2" "$3" || exit 1 + # stock build bash run.sh "STOCK" " " "$1" "$2" "$3" || exit 1