Skip to content

Commit ac0f8e9

Browse files
committed
make sure to check yarrow_read() return values
Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent f1762c1 commit ac0f8e9

File tree

8 files changed

+21
-39
lines changed

8 files changed

+21
-39
lines changed

tests/base16_test.c

+1-1
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

+1-1
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

+1-1
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

+6-24
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ static int s_ecc_test_shamir(void)
176176
/* do 100 random tests */
177177
for (y = 0; y < 100; y++) {
178178
/* pick a random r1, r2 */
179-
LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
179+
ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
180180
DO(mp_read_unsigned_bin(rA, buf, sizes[x]));
181-
LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
181+
ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
182182
DO(mp_read_unsigned_bin(rB, buf, sizes[x]));
183183

184184
/* compute rA * G = A */
@@ -188,9 +188,9 @@ static int s_ecc_test_shamir(void)
188188
DO(ltc_mp.ecc_ptmul(rB, G, B, a, modulus, 1));
189189

190190
/* pick a random kA, kB */
191-
LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
191+
ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
192192
DO(mp_read_unsigned_bin(kA, buf, sizes[x]));
193-
LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
193+
ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
194194
DO(mp_read_unsigned_bin(kB, buf, sizes[x]));
195195

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

tests/modes_test.c

+3-3
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/rsa_test.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static int s_rsa_public_ubin_e(int prng_idx)
387387
* overflow.
388388
*/
389389
DO(rng_make_prng(elen * 8, prng_idx, &yarrow_prng, NULL));
390-
LTC_ARGCHK(yarrow_read(e, elen, &yarrow_prng) == elen);
390+
ENSURE(yarrow_read(e, elen, &yarrow_prng) == elen);
391391

392392
/* Ensure that public exponent is:
393393
* - odd value
@@ -515,7 +515,7 @@ print_hex("q", tmp, len);
515515
for (cnt = 0; cnt < 4; cnt++) {
516516
for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
517517
/* make a random key/msg */
518-
yarrow_read(in, rsa_msgsize, &yarrow_prng);
518+
ENSURE(yarrow_read(in, rsa_msgsize, &yarrow_prng) == rsa_msgsize);
519519

520520
len = sizeof(out);
521521
len2 = rsa_msgsize;
@@ -559,7 +559,7 @@ print_hex("q", tmp, len);
559559
len = sizeof(out);
560560
len2 = rsa_msgsize;
561561
/* make a random key/msg */
562-
yarrow_read(in, rsa_msgsize, &yarrow_prng);
562+
ENSURE(yarrow_read(in, rsa_msgsize, &yarrow_prng) == rsa_msgsize);
563563
DO(rsa_encrypt_key_ex(in, rsa_msgsize, out, &len, NULL, 0, &yarrow_prng, prng_idx, 0, LTC_PKCS_1_V1_5, &key));
564564

565565
len2 = rsa_msgsize;

tests/store_test.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -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++) {

0 commit comments

Comments
 (0)