Skip to content

Commit 8fd5dad

Browse files
authored
Merge pull request #593 from libtom/cleanup
Cleanup
2 parents 06a81ae + a921112 commit 8fd5dad

File tree

14 files changed

+90
-84
lines changed

14 files changed

+90
-84
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,14 @@ jobs:
6565
cat test_std.txt
6666
cat test_err.txt
6767
cat tv.txt
68+
- name: pack build directory
69+
if: ${{ failure() }}
70+
run: |
71+
tar cJf build-${{ github.run_id }}.tar.xz --exclude ./build-${{ github.run_id }}.tar.xz .
72+
- name: upload Artifact
73+
if: ${{ failure() }}
74+
uses: actions/upload-artifact@v3
75+
with:
76+
name: build-${{ github.run_id }}.tar.xz
77+
path: build-${{ github.run_id }}.tar.xz
78+
retention-days: 1

appveyor.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ branches:
77
- /^appveyor/
88
- /^build-ci/
99
image:
10+
- Visual Studio 2022
11+
- Visual Studio 2019
1012
- Visual Studio 2017
1113
- Visual Studio 2015
1214
build_script:
1315
- cmd: >-
14-
if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
16+
if "Visual Studio 2022"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
17+
if "Visual Studio 2019"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
18+
if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
1519
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
1620
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
1721
cd..

doc/crypt.tex

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,40 +2763,40 @@ \subsection{Hash Registration}
27632763

27642764
\begin{figure}[H]
27652765
\begin{center}
2766-
\begin{tabular}{|c|c|c|}
2767-
\hline \textbf{Name} & \textbf{Descriptor Name} & \textbf{Size of Message Digest (bytes)} \\
2768-
\hline WHIRLPOOL & whirlpool\_desc & 64 \\
2769-
\hline Keccak512 & keccak\_512\_desc & 64 \\
2770-
\hline SHA3-512 & sha3\_512\_desc & 64 \\
2771-
\hline SHA-512 & sha512\_desc & 64 \\
2772-
\hline BLAKE2B-512 & blake2b\_512\_desc & 64 \\
2773-
\hline Keccak384 & keccak\_384\_desc & 48 \\
2774-
\hline SHA3-384 & sha3\_384\_desc & 48 \\
2775-
\hline SHA-384 & sha384\_desc & 48 \\
2776-
\hline RIPEMD-320 & rmd160\_desc & 40 \\
2777-
\hline SHA-512/256 & sha512\_256\_desc & 32 \\
2778-
\hline Keccak256 & keccak\_256\_desc & 32 \\
2779-
\hline SHA3-256 & sha3\_256\_desc & 32 \\
2780-
\hline SHA-256 & sha256\_desc & 32 \\
2781-
\hline RIPEMD-256 & rmd160\_desc & 32 \\
2782-
\hline BLAKE2S-256 & blake2s\_256\_desc & 32 \\
2783-
\hline BLAKE2B-256 & blake2b\_256\_desc & 32 \\
2784-
\hline SHA-512/224 & sha512\_224\_desc & 28 \\
2785-
\hline Keccak224 & keccak\_224\_desc & 28 \\
2786-
\hline SHA3-224 & sha3\_224\_desc & 28 \\
2787-
\hline SHA-224 & sha224\_desc & 28 \\
2788-
\hline BLAKE2S-224 & blake2s\_224\_desc & 28 \\
2789-
\hline BLAKE2B-384 & blake2b\_384\_desc & 48 \\
2790-
\hline TIGER-192 & tiger\_desc & 24 \\
2791-
\hline SHA-1 & sha1\_desc & 20 \\
2792-
\hline RIPEMD-160 & rmd160\_desc & 20 \\
2793-
\hline BLAKE2S-160 & blake2s\_160\_desc & 20 \\
2794-
\hline BLAKE2B-160 & blake2b\_160\_desc & 20 \\
2795-
\hline RIPEMD-128 & rmd128\_desc & 16 \\
2796-
\hline MD5 & md5\_desc & 16 \\
2797-
\hline MD4 & md4\_desc & 16 \\
2798-
\hline MD2 & md2\_desc & 16 \\
2799-
\hline BLAKE2S-128 & blake2s\_128\_desc & 16 \\
2766+
\begin{tabular}{|c|c|c|c|}
2767+
\hline \textbf{Name} & \textbf{Descriptor Name} & \textbf{Size of Message Digest (bytes)} & \textbf{Id} \\
2768+
\hline WHIRLPOOL & whirlpool\_desc & 64 & 11 \\
2769+
\hline Keccak512 & keccak\_512\_desc & 64 & 32 \\
2770+
\hline SHA3-512 & sha3\_512\_desc & 64 & 20 \\
2771+
\hline SHA-512 & sha512\_desc & 64 & 5 \\
2772+
\hline BLAKE2B-512 & blake2b\_512\_desc & 64 & 28 \\
2773+
\hline Keccak384 & keccak\_384\_desc & 48 & 31 \\
2774+
\hline SHA3-384 & sha3\_384\_desc & 48 & 19 \\
2775+
\hline SHA-384 & sha384\_desc & 48 & 4 \\
2776+
\hline BLAKE2B-384 & blake2b\_384\_desc & 48 & 27 \\
2777+
\hline RIPEMD-320 & rmd160\_desc & 40 & 14 \\
2778+
\hline SHA-512/256 & sha512\_256\_desc & 32 & 16 \\
2779+
\hline Keccak256 & keccak\_256\_desc & 32 & 30 \\
2780+
\hline SHA3-256 & sha3\_256\_desc & 32 & 18 \\
2781+
\hline SHA-256 & sha256\_desc & 32 & 0 \\
2782+
\hline RIPEMD-256 & rmd160\_desc & 32 & 13 \\
2783+
\hline BLAKE2S-256 & blake2s\_256\_desc & 32 & 24 \\
2784+
\hline BLAKE2B-256 & blake2b\_256\_desc & 32 & 26 \\
2785+
\hline SHA-512/224 & sha512\_224\_desc & 28 & 15 \\
2786+
\hline Keccak224 & keccak\_224\_desc & 28 & 29 \\
2787+
\hline SHA3-224 & sha3\_224\_desc & 28 & 17 \\
2788+
\hline SHA-224 & sha224\_desc & 28 & 10 \\
2789+
\hline BLAKE2S-224 & blake2s\_224\_desc & 28 & 23 \\
2790+
\hline TIGER-192 & tiger\_desc & 24 & 1 \\
2791+
\hline SHA-1 & sha1\_desc & 20 & 2 \\
2792+
\hline RIPEMD-160 & rmd160\_desc & 20 & 9 \\
2793+
\hline BLAKE2S-160 & blake2s\_160\_desc & 20 & 22 \\
2794+
\hline BLAKE2B-160 & blake2b\_160\_desc & 20 & 25 \\
2795+
\hline RIPEMD-128 & rmd128\_desc & 16 & 8 \\
2796+
\hline MD5 & md5\_desc & 16 & 3 \\
2797+
\hline MD4 & md4\_desc & 16 & 6 \\
2798+
\hline MD2 & md2\_desc & 16 & 7 \\
2799+
\hline BLAKE2S-128 & blake2s\_128\_desc & 16 & 21 \\
28002800
\hline
28012801
\end{tabular}
28022802
\end{center}

src/headers/tomcrypt_cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

src/headers/tomcrypt_private.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
9090
if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \
9191
return CRYPT_INVALID_ARG; \
9292
} \
93-
if ((md-> state_var .length + inlen * 8) < md-> state_var .length) { \
93+
if (((md-> state_var .length + inlen * 8) < md-> state_var .length) \
94+
|| ((inlen * 8) < inlen)) { \
9495
return CRYPT_HASH_OVERFLOW; \
9596
} \
9697
while (inlen > 0) { \

tests/base16_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int base16_test(void)
2020

2121
for (idx = 0; idx < 2; idx++) {
2222
for (x = 0; x < 100; x++) {
23-
yarrow_read(in, x, &yarrow_prng);
23+
ENSURE(yarrow_read(in, x, &yarrow_prng) == x);
2424
l1 = sizeof(out);
2525
DO(base16_encode(in, x, out, &l1, idx));
2626
l2 = sizeof(tmp);

tests/base32_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int base32_test(void)
2727

2828
for (idx = 0; idx < 4; idx++) {
2929
for (x = 0; x < 100; x++) {
30-
yarrow_read(in, x, &yarrow_prng);
30+
ENSURE(yarrow_read(in, x, &yarrow_prng) == x);
3131
l1 = sizeof(out);
3232
DO(base32_encode(in, x, out, &l1, testid[idx]));
3333
l2 = sizeof(tmp);

tests/base64_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int base64_test(void)
130130
}
131131

132132
for (x = 0; x < 64; x++) {
133-
yarrow_read(in, x, &yarrow_prng);
133+
ENSURE(yarrow_read(in, x, &yarrow_prng) == x);
134134
l1 = sizeof(out);
135135
DO(base64_encode(in, x, out, &l1));
136136
l2 = sizeof(tmp);

tests/der_test.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,10 +1700,7 @@ int der_test(void)
17001700
#else
17011701
for (z = 0; z < 1024; z++) {
17021702
#endif
1703-
if (yarrow_read(buf[0], z, &yarrow_prng) != z) {
1704-
fprintf(stderr, "%d: Failed to read %lu bytes from yarrow\n", __LINE__, z);
1705-
return 1;
1706-
}
1703+
ENSURE(yarrow_read(buf[0], z, &yarrow_prng) == z);
17071704
DO(mp_read_unsigned_bin(a, buf[0], z));
17081705
/* if (mp_iszero(a) == LTC_MP_NO) { a.sign = buf[0][0] & 1 ? LTC_MP_ZPOS : LTC_MP_NEG; } */
17091706
x = sizeof(buf[0]);
@@ -1723,10 +1720,7 @@ int der_test(void)
17231720
/* test short integer */
17241721
for (zz = 0; zz < 256; zz++) {
17251722
for (z = 1; z < 4; z++) {
1726-
if (yarrow_read(buf[2], z, &yarrow_prng) != z) {
1727-
fprintf(stderr, "%d: Failed to read %lu bytes from yarrow\n", __LINE__, z);
1728-
return 1;
1729-
}
1723+
ENSURE(yarrow_read(buf[2], z, &yarrow_prng) == z);
17301724
/* encode with normal */
17311725
DO(mp_read_unsigned_bin(a, buf[2], z));
17321726

@@ -1763,10 +1757,7 @@ int der_test(void)
17631757

17641758
/* Test bit string */
17651759
for (zz = 1; zz < 1536; zz++) {
1766-
if (yarrow_read(buf[0], zz, &yarrow_prng) != zz) {
1767-
fprintf(stderr, "%d: Failed to read %lu bytes from yarrow\n", __LINE__, zz);
1768-
return 1;
1769-
}
1760+
ENSURE(yarrow_read(buf[0], zz, &yarrow_prng) == zz);
17701761
for (z = 0; z < zz; z++) {
17711762
buf[0][z] &= 0x01;
17721763
}
@@ -1788,10 +1779,7 @@ int der_test(void)
17881779

17891780
/* Test octet string */
17901781
for (zz = 1; zz < 1536; zz++) {
1791-
if (yarrow_read(buf[0], zz, &yarrow_prng) != zz) {
1792-
fprintf(stderr, "%d: Failed to read %lu bytes from yarrow\n", __LINE__, zz);
1793-
return 1;
1794-
}
1782+
ENSURE(yarrow_read(buf[0], zz, &yarrow_prng) == zz);
17951783
x = sizeof(buf[1]);
17961784
DO(der_encode_octet_string(buf[0], zz, buf[1], &x));
17971785
DO(der_length_octet_string(zz, &y));
@@ -1829,10 +1817,7 @@ int der_test(void)
18291817
/* do random strings */
18301818
for (zz = 0; zz < 5000; zz++) {
18311819
/* pick a random number of words */
1832-
if (yarrow_read(buf[0], 4, &yarrow_prng) != 4) {
1833-
fprintf(stderr, "%d: Failed to read %d bytes from yarrow\n", __LINE__, 4);
1834-
return 1;
1835-
}
1820+
ENSURE(yarrow_read(buf[0], 4, &yarrow_prng) == 4);
18361821
LOAD32L(z, buf[0]);
18371822
z = 2 + (z % ((sizeof(oid[0])/sizeof(oid[0][0])) - 2));
18381823

@@ -1841,10 +1826,7 @@ int der_test(void)
18411826
oid[0][1] = buf[0][1] % 40;
18421827

18431828
for (y = 2; y < z; y++) {
1844-
if (yarrow_read(buf[0], 4, &yarrow_prng) != 4) {
1845-
fprintf(stderr, "%d: Failed to read %d bytes from yarrow\n", __LINE__, 4);
1846-
return 1;
1847-
}
1829+
ENSURE(yarrow_read(buf[0], 4, &yarrow_prng) == 4);
18481830
LOAD32L(oid[0][y], buf[0]);
18491831
}
18501832

tests/ecc_test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ static int s_ecc_test_shamir(void)
154154
/* do 100 random tests */
155155
for (y = 0; y < 100; y++) {
156156
/* pick a random r1, r2 */
157-
LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
157+
ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
158158
DO(mp_read_unsigned_bin(rA, buf, sizes[x]));
159-
LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
159+
ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
160160
DO(mp_read_unsigned_bin(rB, buf, sizes[x]));
161161

162162
/* compute rA * G = A */
@@ -166,9 +166,9 @@ static int s_ecc_test_shamir(void)
166166
DO(ltc_mp.ecc_ptmul(rB, G, B, a, modulus, 1));
167167

168168
/* pick a random kA, kB */
169-
LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
169+
ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
170170
DO(mp_read_unsigned_bin(kA, buf, sizes[x]));
171-
LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
171+
ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
172172
DO(mp_read_unsigned_bin(kB, buf, sizes[x]));
173173

174174
/* now, compute kA*A + kB*B = C1 using the older method */

tests/modes_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ int modes_test(void)
2121
unsigned long l;
2222

2323
/* make a random pt, key and iv */
24-
yarrow_read(pt, 64, &yarrow_prng);
25-
yarrow_read(key, 16, &yarrow_prng);
26-
yarrow_read(iv, 16, &yarrow_prng);
24+
ENSURE(yarrow_read(pt, 64, &yarrow_prng) == 64);
25+
ENSURE(yarrow_read(key, 16, &yarrow_prng) == 16);
26+
ENSURE(yarrow_read(iv, 16, &yarrow_prng) == 16);
2727

2828
/* get idx of AES handy */
2929
cipher_idx = find_cipher("aes");

tests/multi_test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ int multi_test(void)
1515

1616
/* HASH testing */
1717
len = sizeof(buf[0]);
18+
#if defined(ENDIAN_32BITWORD) || defined(_MSC_VER)
19+
len2 = 0x80000000UL;
20+
#else
21+
/* Check against the max. input limit of SHA-1 as of RFC8017 */
22+
len2 = 0x1ULL << 61;
23+
#endif
24+
SHOULD_FAIL_WITH(hash_memory(find_hash("sha256"), buf[0], len2, buf[0], &len), CRYPT_HASH_OVERFLOW);
25+
26+
len = sizeof(buf[0]);
1827
hash_memory(find_hash("sha256"), (unsigned char*)"hello", 5, buf[0], &len);
1928
len2 = sizeof(buf[0]);
2029
hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"hello", 5, NULL);

tests/rsa_test.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ static int s_rsa_public_ubin_e(int prng_idx)
384384
* Generate about 256 bits to check error when public exponent
385385
* overflow.
386386
*/
387-
DO(rng_make_prng(elen * 8, prng_idx, &yarrow_prng, NULL));
388-
LTC_ARGCHK(yarrow_read(e, elen, &yarrow_prng) == elen);
387+
ENSURE(yarrow_read(e, elen, &yarrow_prng) == elen);
389388

390389
/* Ensure that public exponent is:
391390
* - odd value
@@ -503,7 +502,7 @@ print_hex("q", tmp, len);
503502
for (cnt = 0; cnt < 4; cnt++) {
504503
for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
505504
/* make a random key/msg */
506-
yarrow_read(in, rsa_msgsize, &yarrow_prng);
505+
ENSURE(yarrow_read(in, rsa_msgsize, &yarrow_prng) == rsa_msgsize);
507506

508507
len = sizeof(out);
509508
len2 = rsa_msgsize;
@@ -547,7 +546,7 @@ print_hex("q", tmp, len);
547546
len = sizeof(out);
548547
len2 = rsa_msgsize;
549548
/* make a random key/msg */
550-
yarrow_read(in, rsa_msgsize, &yarrow_prng);
549+
ENSURE(yarrow_read(in, rsa_msgsize, &yarrow_prng) == rsa_msgsize);
551550
DO(rsa_encrypt_key_ex(in, rsa_msgsize, out, &len, NULL, 0, &yarrow_prng, prng_idx, 0, LTC_PKCS_1_V1_5, &key));
552551

553552
len2 = rsa_msgsize;

tests/store_test.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
int store_test(void)
77
{
88
unsigned char buf[256];
9-
int y;
9+
unsigned long y;
1010
ulong32 L, L1;
1111
ulong64 LL, LL1;
1212
#ifdef LTC_FAST
13-
int x, z;
13+
unsigned long x, z;
1414
#endif
1515

1616
for (y = 0; y < 4; y++) {
@@ -19,13 +19,13 @@ int store_test(void)
1919
STORE32L(L, buf + y);
2020
LOAD32L(L1, buf + y);
2121
if (L1 != L) {
22-
fprintf(stderr, "\n32L failed at offset %d\n", y);
22+
fprintf(stderr, "\n32L failed at offset %lu\n", y);
2323
return 1;
2424
}
2525
STORE32H(L, buf + y);
2626
LOAD32H(L1, buf + y);
2727
if (L1 != L) {
28-
fprintf(stderr, "\n32H failed at offset %d\n", y);
28+
fprintf(stderr, "\n32H failed at offset %lu\n", y);
2929
return 1;
3030
}
3131
}
@@ -36,13 +36,13 @@ int store_test(void)
3636
STORE64L(LL, buf + y);
3737
LOAD64L(LL1, buf + y);
3838
if (LL1 != LL) {
39-
fprintf(stderr, "\n64L failed at offset %d\n", y);
39+
fprintf(stderr, "\n64L failed at offset %lu\n", y);
4040
return 1;
4141
}
4242
STORE64H(LL, buf + y);
4343
LOAD64H(LL1, buf + y);
4444
if (LL1 != LL) {
45-
fprintf(stderr, "\n64H failed at offset %d\n", y);
45+
fprintf(stderr, "\n64H failed at offset %lu\n", y);
4646
return 1;
4747
}
4848
}
@@ -53,8 +53,8 @@ int store_test(void)
5353

5454
for (z = 0; z < y; z++) {
5555
/* fill y bytes with random */
56-
yarrow_read(buf+z, y, &yarrow_prng);
57-
yarrow_read(buf+z+y, y, &yarrow_prng);
56+
ENSURE(yarrow_read(buf+z, y, &yarrow_prng) == y);
57+
ENSURE(yarrow_read(buf+z+y, y, &yarrow_prng) == y);
5858

5959
/* now XOR it byte for byte */
6060
for (x = 0; x < y; x++) {
@@ -67,7 +67,7 @@ int store_test(void)
6767
}
6868

6969
if (memcmp(&buf[2*y+z], &buf[3*y+z], y)) {
70-
fprintf(stderr, "\nLTC_FAST failed at offset %d\n", z);
70+
fprintf(stderr, "\nLTC_FAST failed at offset %lu\n", z);
7171
return 1;
7272
}
7373
}

0 commit comments

Comments
 (0)