Browse Source

Merge pull request #139 from libtom/fix/139

rand_prime undefined reference when using  CFLAGS="-DLTM_DESC -DLTC_EASY
Steffen Jaeckel 8 years ago
parent
commit
3dd0845dec
11 changed files with 108 additions and 22 deletions
  1. 8 0
      .travis.yml
  2. 11 1
      build.sh
  3. 1 2
      check-source.pl
  4. 17 0
      check_source.sh
  5. 1 0
      demos/hashsum.c
  6. 4 1
      demos/multi.c
  7. 33 0
      demos/tv_gen.c
  8. 1 1
      src/math/rand_prime.c
  9. 3 2
      src/misc/base64/base64_decode.c
  10. 6 0
      testme.sh
  11. 23 15
      testprof/base64_test.c

+ 8 - 0
.travis.yml

@@ -4,6 +4,10 @@ compiler:
   - clang
   - clang
 script: bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile" "-DUSE_LTM -DLTM_DESC -I/usr/include" "/usr/lib/libtommath.a"
 script: bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile" "-DUSE_LTM -DLTM_DESC -I/usr/include" "/usr/lib/libtommath.a"
 env:
 env:
+  - |
+    BUILDSCRIPT="check_source.sh"
+    BUILDNAME="CHECK_SOURCES"
+    BUILDOPTIONS=" "
   - |
   - |
     BUILDSCRIPT="coverage.sh"
     BUILDSCRIPT="coverage.sh"
     BUILDNAME="COVERAGE"
     BUILDNAME="COVERAGE"
@@ -12,6 +16,10 @@ env:
     BUILDSCRIPT="run.sh"
     BUILDSCRIPT="run.sh"
     BUILDNAME="STOCK"
     BUILDNAME="STOCK"
     BUILDOPTIONS=" "
     BUILDOPTIONS=" "
+  - |
+    BUILDSCRIPT="run.sh"
+    BUILDNAME="EASY"
+    BUILDOPTIONS="-DLTC_EASY"
   - |
   - |
     BUILDSCRIPT="run.sh"
     BUILDSCRIPT="run.sh"
     BUILDNAME="SMALL"
     BUILDNAME="SMALL"

+ 11 - 1
build.sh

@@ -28,7 +28,17 @@ echo -n "testing..."
 if [ -a test ] && [ -f test ] && [ -x test ]; then
 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)
    ((./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
    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
 fi
 fi
 
 

+ 1 - 2
check-source.pl

@@ -9,7 +9,6 @@
 use strict;
 use strict;
 use warnings;
 use warnings;
 
 
-use Test::More;
 use File::Find 'find';
 use File::Find 'find';
 use File::Basename 'basename';
 use File::Basename 'basename';
 use File::Glob 'bsd_glob';
 use File::Glob 'bsd_glob';
@@ -37,7 +36,7 @@ for my $file (sort @all_files) {
     $lineno++;
     $lineno++;
   }
   }
   for my $k (sort keys %$troubles) {
   for my $k (sort keys %$troubles) {
-    warn "FAIL: [$k] $file line:" . join(",", @{$troubles->{$k}}) . "\n";
+    warn "[$k] $file line:" . join(",", @{$troubles->{$k}}) . "\n";
     $fails++;
     $fails++;
   }
   }
 }
 }

+ 17 - 0
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$

+ 1 - 0
demos/hashsum.c

@@ -67,6 +67,7 @@ int main(int argc, char **argv)
 void register_algs(void)
 void register_algs(void)
 {
 {
   int err;
   int err;
+  LTC_UNUSED_PARAM(err);
 
 
 #ifdef LTC_TIGER
 #ifdef LTC_TIGER
   register_hash (&tiger_desc);
   register_hash (&tiger_desc);

+ 4 - 1
demos/multi.c

@@ -56,6 +56,7 @@ int main(void)
    }
    }
 
 
 /* LTC_OMAC */
 /* LTC_OMAC */
+#ifdef LTC_OMAC
    len = sizeof(buf[0]);
    len = sizeof(buf[0]);
    omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
    omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
    len2 = sizeof(buf[0]);
    len2 = sizeof(buf[0]);
@@ -76,8 +77,10 @@ int main(void)
       printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
       printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
       return EXIT_FAILURE;
       return EXIT_FAILURE;
    }
    }
+#endif
 
 
 /* PMAC */
 /* PMAC */
+#ifdef LTC_PMAC
    len = sizeof(buf[0]);
    len = sizeof(buf[0]);
    pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
    pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
    len2 = sizeof(buf[0]);
    len2 = sizeof(buf[0]);
@@ -98,7 +101,7 @@ int main(void)
       printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
       printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
       return EXIT_FAILURE;
       return EXIT_FAILURE;
    }
    }
-
+#endif
 
 
    printf("All passed\n");
    printf("All passed\n");
    return EXIT_SUCCESS;
    return EXIT_SUCCESS;

+ 33 - 0
demos/tv_gen.c

@@ -3,6 +3,7 @@
 void reg_algs(void)
 void reg_algs(void)
 {
 {
   int err;
   int err;
+  LTC_UNUSED_PARAM(err);
 
 
 #ifdef LTC_RIJNDAEL
 #ifdef LTC_RIJNDAEL
   register_cipher (&aes_desc);
   register_cipher (&aes_desc);
@@ -285,6 +286,7 @@ void hmac_gen(void)
 
 
 void omac_gen(void)
 void omac_gen(void)
 {
 {
+#ifdef LTC_OMAC
    unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
    unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
    int err, x, y, z, kl;
    int err, x, y, z, kl;
    FILE *out;
    FILE *out;
@@ -336,10 +338,12 @@ void omac_gen(void)
       fprintf(out, "\n");
       fprintf(out, "\n");
    }
    }
    fclose(out);
    fclose(out);
+#endif
 }
 }
 
 
 void pmac_gen(void)
 void pmac_gen(void)
 {
 {
+#ifdef LTC_PMAC
    unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
    unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
    int err, x, y, z, kl;
    int err, x, y, z, kl;
    FILE *out;
    FILE *out;
@@ -391,10 +395,12 @@ void pmac_gen(void)
       fprintf(out, "\n");
       fprintf(out, "\n");
    }
    }
    fclose(out);
    fclose(out);
+#endif
 }
 }
 
 
 void eax_gen(void)
 void eax_gen(void)
 {
 {
+#ifdef LTC_EAX_MODE
    int err, kl, x, y1, z;
    int err, kl, x, y1, z;
    FILE *out;
    FILE *out;
    unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2],
    unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2],
@@ -451,10 +457,12 @@ void eax_gen(void)
       fprintf(out, "\n");
       fprintf(out, "\n");
    }
    }
    fclose(out);
    fclose(out);
+#endif
 }
 }
 
 
 void ocb_gen(void)
 void ocb_gen(void)
 {
 {
+#ifdef LTC_OCB_MODE
    int err, kl, x, y1, z;
    int err, kl, x, y1, z;
    FILE *out;
    FILE *out;
    unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
    unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
@@ -514,10 +522,12 @@ void ocb_gen(void)
       fprintf(out, "\n");
       fprintf(out, "\n");
    }
    }
    fclose(out);
    fclose(out);
+#endif
 }
 }
 
 
 void ocb3_gen(void)
 void ocb3_gen(void)
 {
 {
+#ifdef LTC_OCB3_MODE
    int err, kl, x, y1, z;
    int err, kl, x, y1, z;
    FILE *out;
    FILE *out;
    unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
    unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
@@ -577,10 +587,12 @@ void ocb3_gen(void)
       fprintf(out, "\n");
       fprintf(out, "\n");
    }
    }
    fclose(out);
    fclose(out);
+#endif
 }
 }
 
 
 void ccm_gen(void)
 void ccm_gen(void)
 {
 {
+#ifdef LTC_CCM_MODE
    int err, kl, x, y1, z;
    int err, kl, x, y1, z;
    FILE *out;
    FILE *out;
    unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
    unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
@@ -640,10 +652,12 @@ void ccm_gen(void)
       fprintf(out, "\n");
       fprintf(out, "\n");
    }
    }
    fclose(out);
    fclose(out);
+#endif
 }
 }
 
 
 void gcm_gen(void)
 void gcm_gen(void)
 {
 {
+#ifdef LTC_GCM_MODE
    int err, kl, x, y1, z;
    int err, kl, x, y1, z;
    FILE *out;
    FILE *out;
    unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
    unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
@@ -697,6 +711,7 @@ void gcm_gen(void)
       fprintf(out, "\n");
       fprintf(out, "\n");
    }
    }
    fclose(out);
    fclose(out);
+#endif
 }
 }
 
 
 void base64_gen(void)
 void base64_gen(void)
@@ -764,6 +779,7 @@ void ecc_gen(void)
 
 
 void lrw_gen(void)
 void lrw_gen(void)
 {
 {
+#ifdef LTC_LRW_MODE
    FILE *out;
    FILE *out;
    unsigned char tweak[16], key[16], iv[16], buf[1024];
    unsigned char tweak[16], key[16], iv[16], buf[1024];
    int x, y, err;
    int x, y, err;
@@ -825,6 +841,7 @@ void lrw_gen(void)
        lrw_done(&lrw);
        lrw_done(&lrw);
    }
    }
    fclose(out);
    fclose(out);
+#endif
 }
 }
 
 
 int main(void)
 int main(void)
@@ -833,17 +850,33 @@ int main(void)
    printf("Generating hash   vectors..."); fflush(stdout); hash_gen();   printf("done\n");
    printf("Generating hash   vectors..."); fflush(stdout); hash_gen();   printf("done\n");
    printf("Generating cipher vectors..."); fflush(stdout); cipher_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");
    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");
    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");
    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");
    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");
    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");
    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");
    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");
    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 BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n");
    printf("Generating MATH   vectors..."); fflush(stdout); math_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");
    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");
    printf("Generating LRW    vectors..."); fflush(stdout); lrw_gen();    printf("done\n");
+#endif
    return 0;
    return 0;
 }
 }
 
 

+ 1 - 1
src/math/rand_prime.c

@@ -10,7 +10,7 @@
  */
  */
 #include "tomcrypt.h"
 #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
   @file rand_prime.c

+ 3 - 2
src/misc/base64/base64_decode.c

@@ -45,8 +45,8 @@ static const unsigned char map_base64[256] = {
 255, 255, 255, 255 };
 255, 255, 255, 255 };
 #endif /* LTC_BASE64 */
 #endif /* LTC_BASE64 */
 
 
+static const unsigned char map_base64url[] = {
 #if defined(LTC_BASE64_URL)
 #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,
 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, 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 */
 #endif /* LTC_BASE64_URL */
+};
 
 
 enum {
 enum {
    relaxed = 0,
    relaxed = 0,

+ 6 - 0
testme.sh

@@ -10,9 +10,15 @@ fi
 # date
 # date
 echo "date="`date`
 echo "date="`date`
 
 
+# check sources
+bash check_source.sh "CHECK_SOURCES" " " "$1" "$2" "$3" || exit 1
+
 # stock build
 # stock build
 bash run.sh "STOCK" " " "$1" "$2" "$3" || exit 1
 bash run.sh "STOCK" " " "$1" "$2" "$3" || exit 1
 
 
+# EASY build
+bash run.sh "EASY" "-DLTC_EASY" "$1" "$2" "$3" || exit 1
+
 # SMALL code
 # SMALL code
 bash run.sh "SMALL" "-DLTC_SMALL_CODE" "$1" "$2" "$3" || exit 1
 bash run.sh "SMALL" "-DLTC_SMALL_CODE" "$1" "$2" "$3" || exit 1
 
 

+ 23 - 15
testprof/base64_test.c

@@ -1,10 +1,12 @@
 #include  <tomcrypt_test.h>
 #include  <tomcrypt_test.h>
 
 
-#ifdef LTC_BASE64
+#if defined(LTC_BASE64) || defined(LTC_BASE64_URL)
 int base64_test(void)
 int base64_test(void)
 {
 {
    unsigned char in[64], out[256], tmp[64];
    unsigned char in[64], out[256], tmp[64];
    unsigned long x, l1, l2, slen1;
    unsigned long x, l1, l2, slen1;
+
+#if defined(LTC_BASE64)
    const char special_case[] = {
    const char special_case[] = {
          0xbe, 0xe8, 0x92, 0x3c, 0xa2, 0x25, 0xf0, 0xf8,
          0xbe, 0xe8, 0x92, 0x3c, 0xa2, 0x25, 0xf0, 0xf8,
          0x91, 0xe4, 0xef, 0xab, 0x0b, 0x8c, 0xfd, 0xff,
          0x91, 0xe4, 0xef, 0xab, 0x0b, 0x8c, 0xfd, 0xff,
@@ -31,7 +33,9 @@ int base64_test(void)
        {"foobar", "Zm9vYmFy"},
        {"foobar", "Zm9vYmFy"},
        {special_case,"vuiSPKIl8PiR5O+rC4z9/xTQKZ0="}
        {special_case,"vuiSPKIl8PiR5O+rC4z9/xTQKZ0="}
    };
    };
+#endif
 
 
+#ifdef LTC_BASE64_URL
    const struct {
    const struct {
       const char* s;
       const char* s;
       int is_strict;
       int is_strict;
@@ -48,20 +52,6 @@ int base64_test(void)
          {"vuiS*===PKIl8P*iR5O-rC4*z9_xTQKZ0=", 0},
          {"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) {
    for (x = 0; x < sizeof(url_cases)/sizeof(url_cases[0]); ++x) {
        slen1 = strlen(url_cases[x].s);
        slen1 = strlen(url_cases[x].s);
        l1 = sizeof(out);
        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);
    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++) {
    for  (x = 0; x < 64; x++) {
        yarrow_read(in, x, &yarrow_prng);
        yarrow_read(in, x, &yarrow_prng);
@@ -109,6 +115,8 @@ int base64_test(void)
    }
    }
    l2 = sizeof(tmp);
    l2 = sizeof(tmp);
    DO(base64_strict_decode(out, l1, tmp, &l2) == CRYPT_INVALID_PACKET ? CRYPT_OK : CRYPT_INVALID_PACKET);
    DO(base64_strict_decode(out, l1, tmp, &l2) == CRYPT_INVALID_PACKET ? CRYPT_OK : CRYPT_INVALID_PACKET);
+#endif
+
    return 0;
    return 0;
 }
 }
 #endif
 #endif