Browse Source

Merge pull request #593 from libtom/cleanup

Cleanup
Steffen Jaeckel 3 years ago
parent
commit
8fd5dad96b

+ 11 - 0
.github/workflows/main.yml

@@ -65,3 +65,14 @@ jobs:
           cat test_std.txt
           cat test_err.txt
           cat tv.txt
+      - name: pack build directory
+        if: ${{ failure() }}
+        run: |
+          tar cJf build-${{ github.run_id }}.tar.xz --exclude ./build-${{ github.run_id }}.tar.xz .
+      - name: upload Artifact
+        if: ${{ failure() }}
+        uses: actions/upload-artifact@v3
+        with:
+          name: build-${{ github.run_id }}.tar.xz
+          path: build-${{ github.run_id }}.tar.xz
+          retention-days: 1

+ 5 - 1
appveyor.yml

@@ -7,11 +7,15 @@ branches:
   - /^appveyor/
   - /^build-ci/
 image:
+- Visual Studio 2022
+- Visual Studio 2019
 - Visual Studio 2017
 - Visual Studio 2015
 build_script:
 - cmd: >-
-    if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
+    if "Visual Studio 2022"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
+      if "Visual Studio 2019"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
+      if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
       if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
       if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
       cd..

+ 34 - 34
doc/crypt.tex

@@ -2763,40 +2763,40 @@ The following hashes are provided as of this release within the LibTomCrypt libr
 
 \begin{figure}[H]
 \begin{center}
-\begin{tabular}{|c|c|c|}
-      \hline \textbf{Name} & \textbf{Descriptor Name} & \textbf{Size of Message Digest (bytes)} \\
-      \hline WHIRLPOOL & whirlpool\_desc & 64 \\
-      \hline Keccak512 & keccak\_512\_desc & 64 \\
-      \hline SHA3-512 & sha3\_512\_desc & 64 \\
-      \hline SHA-512 & sha512\_desc & 64 \\
-      \hline BLAKE2B-512 & blake2b\_512\_desc & 64 \\
-      \hline Keccak384 & keccak\_384\_desc & 48 \\
-      \hline SHA3-384 & sha3\_384\_desc & 48 \\
-      \hline SHA-384 & sha384\_desc & 48 \\
-      \hline RIPEMD-320 & rmd160\_desc & 40 \\
-      \hline SHA-512/256 & sha512\_256\_desc & 32 \\
-      \hline Keccak256 & keccak\_256\_desc & 32 \\
-      \hline SHA3-256 & sha3\_256\_desc & 32 \\
-      \hline SHA-256 & sha256\_desc & 32 \\
-      \hline RIPEMD-256 & rmd160\_desc & 32 \\
-      \hline BLAKE2S-256 & blake2s\_256\_desc & 32 \\
-      \hline BLAKE2B-256 & blake2b\_256\_desc & 32 \\
-      \hline SHA-512/224 & sha512\_224\_desc & 28 \\
-      \hline Keccak224 & keccak\_224\_desc & 28 \\
-      \hline SHA3-224 & sha3\_224\_desc & 28 \\
-      \hline SHA-224 & sha224\_desc & 28 \\
-      \hline BLAKE2S-224 & blake2s\_224\_desc & 28 \\
-      \hline BLAKE2B-384 & blake2b\_384\_desc & 48 \\
-      \hline TIGER-192 & tiger\_desc & 24 \\
-      \hline SHA-1 & sha1\_desc & 20 \\
-      \hline RIPEMD-160 & rmd160\_desc & 20 \\
-      \hline BLAKE2S-160 & blake2s\_160\_desc & 20 \\
-      \hline BLAKE2B-160 & blake2b\_160\_desc & 20 \\
-      \hline RIPEMD-128 & rmd128\_desc & 16 \\
-      \hline MD5 & md5\_desc & 16 \\
-      \hline MD4 & md4\_desc & 16 \\
-      \hline MD2 & md2\_desc & 16 \\
-      \hline BLAKE2S-128 & blake2s\_128\_desc & 16 \\
+\begin{tabular}{|c|c|c|c|}
+      \hline \textbf{Name} & \textbf{Descriptor Name} & \textbf{Size of Message Digest (bytes)} & \textbf{Id} \\
+      \hline WHIRLPOOL & whirlpool\_desc & 64 & 11 \\
+      \hline Keccak512 & keccak\_512\_desc & 64 & 32 \\
+      \hline SHA3-512 & sha3\_512\_desc & 64 & 20 \\
+      \hline SHA-512 & sha512\_desc & 64 & 5 \\
+      \hline BLAKE2B-512 & blake2b\_512\_desc & 64 & 28 \\
+      \hline Keccak384 & keccak\_384\_desc & 48 & 31 \\
+      \hline SHA3-384 & sha3\_384\_desc & 48 & 19 \\
+      \hline SHA-384 & sha384\_desc & 48 & 4 \\
+      \hline BLAKE2B-384 & blake2b\_384\_desc & 48 & 27 \\
+      \hline RIPEMD-320 & rmd160\_desc & 40 & 14 \\
+      \hline SHA-512/256 & sha512\_256\_desc & 32 & 16 \\
+      \hline Keccak256 & keccak\_256\_desc & 32 & 30 \\
+      \hline SHA3-256 & sha3\_256\_desc & 32 & 18 \\
+      \hline SHA-256 & sha256\_desc & 32 & 0 \\
+      \hline RIPEMD-256 & rmd160\_desc & 32 & 13 \\
+      \hline BLAKE2S-256 & blake2s\_256\_desc & 32 & 24 \\
+      \hline BLAKE2B-256 & blake2b\_256\_desc & 32 & 26 \\
+      \hline SHA-512/224 & sha512\_224\_desc & 28 & 15 \\
+      \hline Keccak224 & keccak\_224\_desc & 28 & 29 \\
+      \hline SHA3-224 & sha3\_224\_desc & 28 & 17 \\
+      \hline SHA-224 & sha224\_desc & 28 & 10 \\
+      \hline BLAKE2S-224 & blake2s\_224\_desc & 28 & 23 \\
+      \hline TIGER-192 & tiger\_desc & 24 & 1 \\
+      \hline SHA-1 & sha1\_desc & 20 & 2 \\
+      \hline RIPEMD-160 & rmd160\_desc & 20 & 9 \\
+      \hline BLAKE2S-160 & blake2s\_160\_desc & 20 & 22 \\
+      \hline BLAKE2B-160 & blake2b\_160\_desc & 20 & 25 \\
+      \hline RIPEMD-128 & rmd128\_desc & 16 & 8 \\
+      \hline MD5 & md5\_desc & 16 & 3 \\
+      \hline MD4 & md4\_desc & 16 & 6 \\
+      \hline MD2 & md2\_desc & 16 & 7 \\
+      \hline BLAKE2S-128 & blake2s\_128\_desc & 16 & 21 \\
       \hline
 \end{tabular}
 \end{center}

+ 1 - 1
src/headers/tomcrypt_cfg.h

@@ -3,7 +3,7 @@
 
 /* This is the build config file.
  *
- * With this you can setup what to inlcude/exclude automatically during any build.  Just comment
+ * With this you can setup what to include/exclude automatically during any build.  Just comment
  * out the line that #define's the word for the thing you want to remove.  phew!
  */
 

+ 2 - 1
src/headers/tomcrypt_private.h

@@ -90,7 +90,8 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
     if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
        return CRYPT_INVALID_ARG;                                                            \
     }                                                                                       \
-    if ((md-> state_var .length + inlen * 8) < md-> state_var .length) {                        \
+    if (((md-> state_var .length + inlen * 8) < md-> state_var .length)                     \
+          || ((inlen * 8) < inlen)) {                                                       \
       return CRYPT_HASH_OVERFLOW;                                                           \
     }                                                                                       \
     while (inlen > 0) {                                                                     \

+ 1 - 1
tests/base16_test.c

@@ -20,7 +20,7 @@ int base16_test(void)
 
    for (idx = 0; idx < 2; idx++) {
       for (x = 0; x < 100; x++) {
-         yarrow_read(in, x, &yarrow_prng);
+         ENSURE(yarrow_read(in, x, &yarrow_prng) == x);
          l1 = sizeof(out);
          DO(base16_encode(in, x, out, &l1, idx));
          l2 = sizeof(tmp);

+ 1 - 1
tests/base32_test.c

@@ -27,7 +27,7 @@ int base32_test(void)
 
    for (idx = 0; idx < 4; idx++) {
       for (x = 0; x < 100; x++) {
-         yarrow_read(in, x, &yarrow_prng);
+         ENSURE(yarrow_read(in, x, &yarrow_prng) == x);
          l1 = sizeof(out);
          DO(base32_encode(in, x, out, &l1, testid[idx]));
          l2 = sizeof(tmp);

+ 1 - 1
tests/base64_test.c

@@ -130,7 +130,7 @@ int base64_test(void)
    }
 
    for  (x = 0; x < 64; x++) {
-       yarrow_read(in, x, &yarrow_prng);
+       ENSURE(yarrow_read(in, x, &yarrow_prng) == x);
        l1 = sizeof(out);
        DO(base64_encode(in, x, out, &l1));
        l2 = sizeof(tmp);

+ 6 - 24
tests/der_test.c

@@ -1700,10 +1700,7 @@ int der_test(void)
 #else
       for (z = 0; z < 1024; z++) {
 #endif
-         if (yarrow_read(buf[0], z, &yarrow_prng) != z) {
-            fprintf(stderr, "%d: Failed to read %lu bytes from yarrow\n", __LINE__, z);
-            return 1;
-         }
+         ENSURE(yarrow_read(buf[0], z, &yarrow_prng) == z);
          DO(mp_read_unsigned_bin(a, buf[0], z));
 /*          if (mp_iszero(a) == LTC_MP_NO) { a.sign = buf[0][0] & 1 ? LTC_MP_ZPOS : LTC_MP_NEG; } */
          x = sizeof(buf[0]);
@@ -1723,10 +1720,7 @@ int der_test(void)
 /* test short integer */
    for (zz = 0; zz < 256; zz++) {
       for (z = 1; z < 4; z++) {
-         if (yarrow_read(buf[2], z, &yarrow_prng) != z) {
-            fprintf(stderr, "%d: Failed to read %lu bytes from yarrow\n", __LINE__, z);
-            return 1;
-         }
+         ENSURE(yarrow_read(buf[2], z, &yarrow_prng) == z);
          /* encode with normal */
          DO(mp_read_unsigned_bin(a, buf[2], z));
 
@@ -1763,10 +1757,7 @@ int der_test(void)
 
 /* Test bit string */
    for (zz = 1; zz < 1536; zz++) {
-       if (yarrow_read(buf[0], zz, &yarrow_prng) != zz) {
-          fprintf(stderr, "%d: Failed to read %lu bytes from yarrow\n", __LINE__, zz);
-          return 1;
-       }
+       ENSURE(yarrow_read(buf[0], zz, &yarrow_prng) == zz);
        for (z = 0; z < zz; z++) {
            buf[0][z] &= 0x01;
        }
@@ -1788,10 +1779,7 @@ int der_test(void)
 
 /* Test octet string */
    for (zz = 1; zz < 1536; zz++) {
-       if (yarrow_read(buf[0], zz, &yarrow_prng) != zz) {
-          fprintf(stderr, "%d: Failed to read %lu bytes from yarrow\n", __LINE__, zz);
-          return 1;
-       }
+       ENSURE(yarrow_read(buf[0], zz, &yarrow_prng) == zz);
        x = sizeof(buf[1]);
        DO(der_encode_octet_string(buf[0], zz, buf[1], &x));
        DO(der_length_octet_string(zz, &y));
@@ -1829,10 +1817,7 @@ int der_test(void)
    /* do random strings */
    for (zz = 0; zz < 5000; zz++) {
        /* pick a random number of words */
-       if (yarrow_read(buf[0], 4, &yarrow_prng) != 4) {
-          fprintf(stderr, "%d: Failed to read %d bytes from yarrow\n", __LINE__, 4);
-          return 1;
-       }
+       ENSURE(yarrow_read(buf[0], 4, &yarrow_prng) == 4);
        LOAD32L(z, buf[0]);
        z = 2 + (z % ((sizeof(oid[0])/sizeof(oid[0][0])) - 2));
 
@@ -1841,10 +1826,7 @@ int der_test(void)
        oid[0][1] = buf[0][1] % 40;
 
        for (y = 2; y < z; y++) {
-          if (yarrow_read(buf[0], 4, &yarrow_prng) != 4) {
-             fprintf(stderr, "%d: Failed to read %d bytes from yarrow\n", __LINE__, 4);
-             return 1;
-          }
+          ENSURE(yarrow_read(buf[0], 4, &yarrow_prng) == 4);
           LOAD32L(oid[0][y], buf[0]);
        }
 

+ 4 - 4
tests/ecc_test.c

@@ -154,9 +154,9 @@ static int s_ecc_test_shamir(void)
        /* do 100 random tests */
        for (y = 0; y < 100; y++) {
           /* pick a random r1, r2 */
-          LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
+          ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
           DO(mp_read_unsigned_bin(rA, buf, sizes[x]));
-          LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
+          ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
           DO(mp_read_unsigned_bin(rB, buf, sizes[x]));
 
           /* compute rA * G = A */
@@ -166,9 +166,9 @@ static int s_ecc_test_shamir(void)
           DO(ltc_mp.ecc_ptmul(rB, G, B, a, modulus, 1));
 
           /* pick a random kA, kB */
-          LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
+          ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
           DO(mp_read_unsigned_bin(kA, buf, sizes[x]));
-          LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
+          ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
           DO(mp_read_unsigned_bin(kB, buf, sizes[x]));
 
           /* now, compute kA*A + kB*B = C1 using the older method */

+ 3 - 3
tests/modes_test.c

@@ -21,9 +21,9 @@ int modes_test(void)
    unsigned long l;
 
    /* make a random pt, key and iv */
-   yarrow_read(pt,  64, &yarrow_prng);
-   yarrow_read(key, 16, &yarrow_prng);
-   yarrow_read(iv,  16, &yarrow_prng);
+   ENSURE(yarrow_read(pt,  64, &yarrow_prng) == 64);
+   ENSURE(yarrow_read(key, 16, &yarrow_prng) == 16);
+   ENSURE(yarrow_read(iv,  16, &yarrow_prng) == 16);
 
    /* get idx of AES handy */
    cipher_idx = find_cipher("aes");

+ 9 - 0
tests/multi_test.c

@@ -15,6 +15,15 @@ int multi_test(void)
 
 /* HASH testing */
    len = sizeof(buf[0]);
+#if defined(ENDIAN_32BITWORD) || defined(_MSC_VER)
+   len2 = 0x80000000UL;
+#else
+   /* Check against the max. input limit of SHA-1 as of RFC8017 */
+   len2 = 0x1ULL << 61;
+#endif
+   SHOULD_FAIL_WITH(hash_memory(find_hash("sha256"), buf[0], len2, buf[0], &len), CRYPT_HASH_OVERFLOW);
+
+   len = sizeof(buf[0]);
    hash_memory(find_hash("sha256"), (unsigned char*)"hello", 5, buf[0], &len);
    len2 = sizeof(buf[0]);
    hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"hello", 5, NULL);

+ 3 - 4
tests/rsa_test.c

@@ -384,8 +384,7 @@ static int s_rsa_public_ubin_e(int prng_idx)
     * Generate about 256 bits to check error when public exponent
     * overflow.
     */
-   DO(rng_make_prng(elen * 8, prng_idx, &yarrow_prng, NULL));
-   LTC_ARGCHK(yarrow_read(e, elen, &yarrow_prng) == elen);
+   ENSURE(yarrow_read(e, elen, &yarrow_prng) == elen);
 
    /* Ensure that public exponent is:
     *  - odd value
@@ -503,7 +502,7 @@ print_hex("q", tmp, len);
    for (cnt = 0; cnt < 4; cnt++) {
    for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
       /* make a random key/msg */
-      yarrow_read(in, rsa_msgsize, &yarrow_prng);
+      ENSURE(yarrow_read(in, rsa_msgsize, &yarrow_prng) == rsa_msgsize);
 
       len  = sizeof(out);
       len2 = rsa_msgsize;
@@ -547,7 +546,7 @@ print_hex("q", tmp, len);
       len  = sizeof(out);
       len2 = rsa_msgsize;
       /* make a random key/msg */
-      yarrow_read(in, rsa_msgsize, &yarrow_prng);
+      ENSURE(yarrow_read(in, rsa_msgsize, &yarrow_prng) == rsa_msgsize);
       DO(rsa_encrypt_key_ex(in, rsa_msgsize, out, &len, NULL, 0, &yarrow_prng, prng_idx, 0, LTC_PKCS_1_V1_5, &key));
 
       len2 = rsa_msgsize;

+ 9 - 9
tests/store_test.c

@@ -6,11 +6,11 @@
 int store_test(void)
 {
   unsigned char buf[256];
-  int y;
+  unsigned long y;
   ulong32 L, L1;
   ulong64 LL, LL1;
 #ifdef LTC_FAST
-  int x, z;
+  unsigned long x, z;
 #endif
 
   for (y = 0; y < 4; y++) {
@@ -19,13 +19,13 @@ int store_test(void)
       STORE32L(L, buf + y);
       LOAD32L(L1, buf + y);
       if (L1 != L) {
-         fprintf(stderr, "\n32L failed at offset %d\n", y);
+         fprintf(stderr, "\n32L failed at offset %lu\n", y);
          return 1;
       }
       STORE32H(L, buf + y);
       LOAD32H(L1, buf + y);
       if (L1 != L) {
-         fprintf(stderr, "\n32H failed at offset %d\n", y);
+         fprintf(stderr, "\n32H failed at offset %lu\n", y);
          return 1;
       }
   }
@@ -36,13 +36,13 @@ int store_test(void)
       STORE64L(LL, buf + y);
       LOAD64L(LL1, buf + y);
       if (LL1 != LL) {
-         fprintf(stderr, "\n64L failed at offset %d\n", y);
+         fprintf(stderr, "\n64L failed at offset %lu\n", y);
          return 1;
       }
       STORE64H(LL, buf + y);
       LOAD64H(LL1, buf + y);
       if (LL1 != LL) {
-         fprintf(stderr, "\n64H failed at offset %d\n", y);
+         fprintf(stderr, "\n64H failed at offset %lu\n", y);
          return 1;
       }
   }
@@ -53,8 +53,8 @@ int store_test(void)
 
   for (z = 0; z < y; z++) {
      /* fill y bytes with random */
-     yarrow_read(buf+z,   y, &yarrow_prng);
-     yarrow_read(buf+z+y, y, &yarrow_prng);
+     ENSURE(yarrow_read(buf+z,   y, &yarrow_prng) == y);
+     ENSURE(yarrow_read(buf+z+y, y, &yarrow_prng) == y);
 
      /* now XOR it byte for byte */
      for (x = 0; x < y; x++) {
@@ -67,7 +67,7 @@ int store_test(void)
      }
 
      if (memcmp(&buf[2*y+z], &buf[3*y+z], y)) {
-        fprintf(stderr, "\nLTC_FAST failed at offset %d\n", z);
+        fprintf(stderr, "\nLTC_FAST failed at offset %lu\n", z);
         return 1;
      }
   }