Skip to content

Commit 014cc99

Browse files
authored
Merge pull request #789 from libtom/pr/zero-stat
verify functions always set stat=0 before any other return
2 parents 0278848 + 47479c4 commit 014cc99

17 files changed

Lines changed: 84 additions & 40 deletions

src/encauth/eax/eax_decrypt_verify_memory.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ int eax_decrypt_verify_memory(int cipher,
4040
unsigned char *buf;
4141
unsigned long buflen;
4242

43+
/* stat is cleared before anything else can return, it stays 0 unless the tag is good */
4344
LTC_ARGCHK(stat != NULL);
45+
*stat = 0;
46+
4447
LTC_ARGCHK(key != NULL);
4548
LTC_ARGCHK(pt != NULL);
4649
LTC_ARGCHK(ct != NULL);
4750
LTC_ARGCHK(tag != NULL);
4851

49-
/* default to zero */
50-
*stat = 0;
51-
5252
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
5353
return err;
5454
}

src/encauth/ocb3/ocb3_decrypt_verify_memory.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ int ocb3_decrypt_verify_memory(int cipher,
4040
unsigned char *buf;
4141
unsigned long buflen;
4242

43+
/* stat is cleared before anything else can return, it stays 0 unless the tag is good */
4344
LTC_ARGCHK(stat != NULL);
44-
45-
/* default to zero */
4645
*stat = 0;
4746

4847
/* limit taglen */

src/pk/dsa/dsa_verify_hash.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ int dsa_verify_hash_raw( void *r, void *s,
2727
void *w, *v, *u1, *u2;
2828
int err;
2929

30+
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
31+
LTC_ARGCHK(stat != NULL);
32+
*stat = 0;
33+
3034
LTC_ARGCHK(r != NULL);
3135
LTC_ARGCHK(s != NULL);
32-
LTC_ARGCHK(stat != NULL);
3336
LTC_ARGCHK(key != NULL);
3437

35-
/* default to invalid signature */
36-
*stat = 0;
37-
3838
/* init our variables */
3939
if ((err = ltc_mp_init_multi(&w, &v, &u1, &u2, LTC_NULL)) != CRYPT_OK) {
4040
return err;
@@ -95,8 +95,9 @@ int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
9595
ltc_asn1_list sig_seq[2];
9696
unsigned long reallen = 0;
9797

98+
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
9899
LTC_ARGCHK(stat != NULL);
99-
*stat = 0; /* must be set before the first return */
100+
*stat = 0;
100101

101102
if ((err = ltc_mp_init_multi(&r, &s, LTC_NULL)) != CRYPT_OK) {
102103
return err;

src/pk/dsa/dsa_verify_key.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ int dsa_int_validate_pqg(const dsa_key *key, int *stat)
4343
void *tmp1, *tmp2;
4444
int err;
4545

46-
LTC_ARGCHK(key != NULL);
46+
/* stat is cleared before anything else can return, it stays 0 unless the params are valid */
4747
LTC_ARGCHK(stat != NULL);
4848
*stat = 0;
49+
LTC_ARGCHK(key != NULL);
4950

5051
/* check q-order */
5152
if ( key->qord >= LTC_MDSA_MAX_GROUP || key->qord <= 15 ||
@@ -96,9 +97,10 @@ int dsa_int_validate_primes(const dsa_key *key, int *stat)
9697
{
9798
int err, res;
9899

100+
/* stat is cleared before anything else can return, it stays 0 unless the primes are valid */
101+
LTC_ARGCHK(stat != NULL);
99102
*stat = 0;
100103
LTC_ARGCHK(key != NULL);
101-
LTC_ARGCHK(stat != NULL);
102104

103105
/* key->q prime? */
104106
if ((err = ltc_mp_prime_is_prime(key->q, LTC_MILLER_RABIN_REPS, &res)) != CRYPT_OK) {
@@ -132,9 +134,10 @@ int dsa_int_validate_xy(const dsa_key *key, int *stat)
132134
void *tmp;
133135
int err;
134136

137+
/* stat is cleared before anything else can return, it stays 0 unless the key is valid */
138+
LTC_ARGCHK(stat != NULL);
135139
*stat = 0;
136140
LTC_ARGCHK(key != NULL);
137-
LTC_ARGCHK(stat != NULL);
138141

139142
/* 1 < y < p-1 */
140143
if ((err = ltc_mp_init(&tmp)) != CRYPT_OK) {

src/pk/ecc/ecc_verify_hash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ int ecc_verify_hash_v2(const unsigned char *sig,
4646
int *stat,
4747
const ecc_key *key)
4848
{
49+
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
4950
LTC_ARGCHK(stat != NULL);
5051
*stat = 0;
52+
LTC_ARGCHK(opts != NULL);
5153
if (opts->type < 0 || opts->type >= LTC_ARRAY_SIZE(s_ecc_verify_hash))
5254
return CRYPT_PK_INVALID_TYPE;
5355
if (s_ecc_verify_hash[opts->type] == NULL)

src/pk/ecc/ecc_verify_hash_eth27.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ int ecc_verify_hash_eth27(const unsigned char *sig, unsigned long siglen,
2727
void *r, *s;
2828
int err;
2929

30+
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
31+
LTC_ARGCHK(stat != NULL);
32+
*stat = 0;
33+
3034
LTC_ARGCHK(sig != NULL);
3135
LTC_ARGCHK(key != NULL);
3236

src/pk/ecc/ecc_verify_hash_internal.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ int ecc_verify_hash_internal(void *r, void *s,
1717
unsigned long pbits, pbytes, i, shift_right;
1818
unsigned char ch, buf[MAXBLOCKSIZE];
1919

20+
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
21+
LTC_ARGCHK(stat != NULL);
22+
*stat = 0;
23+
2024
LTC_ARGCHK(r != NULL);
2125
LTC_ARGCHK(s != NULL);
2226
LTC_ARGCHK(hash != NULL);
23-
LTC_ARGCHK(stat != NULL);
2427
LTC_ARGCHK(key != NULL);
2528

26-
/* default to invalid signature */
27-
*stat = 0;
28-
2929
/* allocate ints */
3030
if ((err = ltc_mp_init_multi(&v, &w, &u1, &u2, &e, &a_plus3, LTC_NULL)) != CRYPT_OK) {
3131
return err;

src/pk/ecc/ecc_verify_hash_rfc5656.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ int ecc_verify_hash_rfc5656(const unsigned char *sig, unsigned long siglen,
3131
unsigned long name2len = sizeof(name2);
3232
unsigned long slen = siglen;
3333

34+
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
35+
LTC_ARGCHK(stat != NULL);
36+
*stat = 0;
37+
3438
LTC_ARGCHK(sig != NULL);
3539
LTC_ARGCHK(key != NULL);
3640

src/pk/ecc/ecc_verify_hash_rfc7518.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ int ecc_verify_hash_rfc7518_internal(const unsigned char *sig, unsigned long si
1818
int err;
1919
unsigned long i;
2020

21+
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
22+
LTC_ARGCHK(stat != NULL);
23+
*stat = 0;
24+
2125
LTC_ARGCHK(sig != NULL);
2226
LTC_ARGCHK(key != NULL);
2327

src/pk/ecc/ecc_verify_hash_x962.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ int ecc_verify_hash_x962(const unsigned char *sig, unsigned long siglen,
1717
void *r, *s;
1818
int err;
1919

20+
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
21+
LTC_ARGCHK(stat != NULL);
22+
*stat = 0;
23+
2024
LTC_ARGCHK(sig != NULL);
2125

2226
if ((err = ltc_mp_init_multi(&r, &s, NULL)) != CRYPT_OK) return err;

0 commit comments

Comments
 (0)