diff --git a/.travis.yml b/.travis.yml index 88d7fe74..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" @@ -12,6 +16,10 @@ env: BUILDSCRIPT="run.sh" BUILDNAME="STOCK" BUILDOPTIONS=" " + - | + BUILDSCRIPT="run.sh" + BUILDNAME="EASY" + BUILDOPTIONS="-DLTC_EASY" - | BUILDSCRIPT="run.sh" BUILDNAME="SMALL" diff --git a/build.sh b/build.sh index 7731b3f3..94f27bf8 100755 --- a/build.sh +++ b/build.sh @@ -28,7 +28,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++; } } 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/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..a4903af1 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); @@ -285,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; @@ -336,10 +338,12 @@ void omac_gen(void) fprintf(out, "\n"); } fclose(out); +#endif } 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 +395,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 +457,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 +522,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 +587,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 +652,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 +711,7 @@ void gcm_gen(void) fprintf(out, "\n"); } fclose(out); +#endif } void base64_gen(void) @@ -764,6 +779,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 +841,7 @@ void lrw_gen(void) lrw_done(&lrw); } fclose(out); +#endif } int main(void) @@ -833,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; } 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 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/testme.sh b/testme.sh index 873ad45a..c1b3c238 100755 --- a/testme.sh +++ b/testme.sh @@ -10,9 +10,15 @@ 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 +# 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 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