Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/encauth/eax/eax_decrypt_verify_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ int eax_decrypt_verify_memory(int cipher,
unsigned char *buf;
unsigned long buflen;

/* stat is cleared before anything else can return, it stays 0 unless the tag is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(key != NULL);
LTC_ARGCHK(pt != NULL);
LTC_ARGCHK(ct != NULL);
LTC_ARGCHK(tag != NULL);

/* default to zero */
*stat = 0;

if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
return err;
}
Expand Down
3 changes: 1 addition & 2 deletions src/encauth/ocb3/ocb3_decrypt_verify_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ int ocb3_decrypt_verify_memory(int cipher,
unsigned char *buf;
unsigned long buflen;

/* stat is cleared before anything else can return, it stays 0 unless the tag is good */
LTC_ARGCHK(stat != NULL);

/* default to zero */
*stat = 0;

/* limit taglen */
Expand Down
11 changes: 6 additions & 5 deletions src/pk/dsa/dsa_verify_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ int dsa_verify_hash_raw( void *r, void *s,
void *w, *v, *u1, *u2;
int err;

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(r != NULL);
LTC_ARGCHK(s != NULL);
LTC_ARGCHK(stat != NULL);
LTC_ARGCHK(key != NULL);

/* default to invalid signature */
*stat = 0;

/* init our variables */
if ((err = ltc_mp_init_multi(&w, &v, &u1, &u2, LTC_NULL)) != CRYPT_OK) {
return err;
Expand Down Expand Up @@ -95,8 +95,9 @@ int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
ltc_asn1_list sig_seq[2];
unsigned long reallen = 0;

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

if ((err = ltc_mp_init_multi(&r, &s, LTC_NULL)) != CRYPT_OK) {
return err;
Expand Down
9 changes: 6 additions & 3 deletions src/pk/dsa/dsa_verify_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ int dsa_int_validate_pqg(const dsa_key *key, int *stat)
void *tmp1, *tmp2;
int err;

LTC_ARGCHK(key != NULL);
/* stat is cleared before anything else can return, it stays 0 unless the params are valid */
LTC_ARGCHK(stat != NULL);
*stat = 0;
LTC_ARGCHK(key != NULL);

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

/* stat is cleared before anything else can return, it stays 0 unless the primes are valid */
LTC_ARGCHK(stat != NULL);
*stat = 0;
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(stat != NULL);

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

/* stat is cleared before anything else can return, it stays 0 unless the key is valid */
LTC_ARGCHK(stat != NULL);
*stat = 0;
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(stat != NULL);

/* 1 < y < p-1 */
if ((err = ltc_mp_init(&tmp)) != CRYPT_OK) {
Expand Down
2 changes: 2 additions & 0 deletions src/pk/ecc/ecc_verify_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ int ecc_verify_hash_v2(const unsigned char *sig,
int *stat,
const ecc_key *key)
{
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;
LTC_ARGCHK(opts != NULL);
if (opts->type < 0 || opts->type >= LTC_ARRAY_SIZE(s_ecc_verify_hash))
return CRYPT_PK_INVALID_TYPE;
if (s_ecc_verify_hash[opts->type] == NULL)
Expand Down
4 changes: 4 additions & 0 deletions src/pk/ecc/ecc_verify_hash_eth27.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ int ecc_verify_hash_eth27(const unsigned char *sig, unsigned long siglen,
void *r, *s;
int err;

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(sig != NULL);
LTC_ARGCHK(key != NULL);

Expand Down
8 changes: 4 additions & 4 deletions src/pk/ecc/ecc_verify_hash_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ int ecc_verify_hash_internal(void *r, void *s,
unsigned long pbits, pbytes, i, shift_right;
unsigned char ch, buf[MAXBLOCKSIZE];

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(r != NULL);
LTC_ARGCHK(s != NULL);
LTC_ARGCHK(hash != NULL);
LTC_ARGCHK(stat != NULL);
LTC_ARGCHK(key != NULL);

/* default to invalid signature */
*stat = 0;

/* allocate ints */
if ((err = ltc_mp_init_multi(&v, &w, &u1, &u2, &e, &a_plus3, LTC_NULL)) != CRYPT_OK) {
return err;
Expand Down
4 changes: 4 additions & 0 deletions src/pk/ecc/ecc_verify_hash_rfc5656.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ int ecc_verify_hash_rfc5656(const unsigned char *sig, unsigned long siglen,
unsigned long name2len = sizeof(name2);
unsigned long slen = siglen;

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(sig != NULL);
LTC_ARGCHK(key != NULL);

Expand Down
4 changes: 4 additions & 0 deletions src/pk/ecc/ecc_verify_hash_rfc7518.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ int ecc_verify_hash_rfc7518_internal(const unsigned char *sig, unsigned long si
int err;
unsigned long i;

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(sig != NULL);
LTC_ARGCHK(key != NULL);

Expand Down
4 changes: 4 additions & 0 deletions src/pk/ecc/ecc_verify_hash_x962.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ int ecc_verify_hash_x962(const unsigned char *sig, unsigned long siglen,
void *r, *s;
int err;

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(sig != NULL);

if ((err = ltc_mp_init_multi(&r, &s, NULL)) != CRYPT_OK) return err;
Expand Down
15 changes: 12 additions & 3 deletions src/pk/ed25519/ed25519_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ static int s_ed25519_verify(const unsigned char *msg, unsigned long msglen,
unsigned long long mlen;
int err;

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(msg != NULL);
LTC_ARGCHK(sig != NULL);
LTC_ARGCHK(stat != NULL);
LTC_ARGCHK(public_key != NULL);

*stat = 0;

if (find_hash("sha512") == -1) return CRYPT_INVALID_HASH;
if (siglen != 64uL) return CRYPT_INVALID_ARG;
if (public_key->pka != LTC_PKA_ED25519) return CRYPT_PK_INVALID_TYPE;
Expand Down Expand Up @@ -74,6 +75,10 @@ int ed25519ctx_verify(const unsigned char *msg, unsigned long msglen,
unsigned char ctx_prefix[292];
unsigned long ctx_prefix_size = sizeof(ctx_prefix);

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(ctx != NULL);

if (ec25519_crypto_ctx(ctx_prefix, &ctx_prefix_size, 0, ctx, ctxlen) != CRYPT_OK)
Expand Down Expand Up @@ -105,6 +110,10 @@ int ed25519ph_verify(const unsigned char *msg, unsigned long msglen,
unsigned char ctx_prefix[292];
unsigned long ctx_prefix_size = sizeof(ctx_prefix);

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

if ((err = ec25519_crypto_ctx(ctx_prefix, &ctx_prefix_size, 1, ctx, ctxlen)) != CRYPT_OK)
return err;

Expand Down
19 changes: 16 additions & 3 deletions src/pk/ed448/ed448_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ static int s_ed448_verify(const unsigned char *msg, unsigned long msglen,
unsigned long long mlen;
int err;

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(msg != NULL);
LTC_ARGCHK(sig != NULL);
LTC_ARGCHK(stat != NULL);
LTC_ARGCHK(public_key != NULL);

*stat = 0;

if (siglen != 114uL) return CRYPT_INVALID_ARG;
if (public_key->pka != LTC_PKA_ED448) return CRYPT_PK_INVALID_TYPE;

Expand Down Expand Up @@ -74,6 +75,10 @@ int ed448ctx_verify(const unsigned char *msg, unsigned long msglen,
unsigned char ctx_prefix[266];
unsigned long ctx_prefix_size = sizeof(ctx_prefix);

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(ctx != NULL);

if ((err = ec448_crypto_ctx(ctx_prefix, &ctx_prefix_size, 0, ctx, ctxlen)) != CRYPT_OK)
Expand Down Expand Up @@ -105,6 +110,10 @@ int ed448ph_verify(const unsigned char *msg, unsigned long msglen,
unsigned char ctx_prefix[266];
unsigned long ctx_prefix_size = sizeof(ctx_prefix);

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

if ((err = ec448_crypto_ctx(ctx_prefix, &ctx_prefix_size, 1, ctx, ctxlen)) != CRYPT_OK)
return err;

Expand Down Expand Up @@ -133,6 +142,10 @@ int ed448_verify(const unsigned char *msg, unsigned long msglen,
unsigned char ctx_prefix[266];
unsigned long ctx_prefix_size = sizeof(ctx_prefix);

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

/* Pure Ed448 still uses DOM4 with flag=0 and empty context */
if ((err = ec448_crypto_ctx(ctx_prefix, &ctx_prefix_size, 0, NULL, 0)) != CRYPT_OK)
return err;
Expand Down
8 changes: 4 additions & 4 deletions src/pk/pkcs1/pkcs_1_oaep_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ int ltc_pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
int err, ret;
ltc_rsa_op_checked op_checked = ltc_pkcs1_op_checked_init(params);

/* res is cleared before anything else can return, it stays 0 unless the padding is valid */
LTC_ARGCHK(res != NULL);
*res = 0;

LTC_ARGCHK(msg != NULL);
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
LTC_ARGCHK(res != NULL);

if ((err = rsa_key_valid_op(LTC_PKCS1_DECRYPT, &op_checked)) != CRYPT_OK) {
return err;
}

/* default to invalid packet */
*res = 0;

hLen = hash_descriptor[op_checked.hash_alg].hashsize;
modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);

Expand Down
8 changes: 4 additions & 4 deletions src/pk/pkcs1/pkcs_1_pss_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ int ltc_pkcs_1_pss_decode_mgf1(const unsigned char *msghash, unsigned long msgh
hash_state md;
ltc_rsa_op_checked op_checked = ltc_pkcs1_op_checked_init(params);

/* res is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(res != NULL);
*res = 0;

LTC_ARGCHK(msghash != NULL);
LTC_ARGCHK(sig != NULL);
LTC_ARGCHK(params != NULL);
LTC_ARGCHK(res != NULL);

/* default to invalid */
*res = 0;

if ((err = rsa_key_valid_op(LTC_PKCS1_VERIFY, &op_checked)) != CRYPT_OK) {
return err;
Expand Down
3 changes: 2 additions & 1 deletion src/pk/pkcs1/pkcs_1_v1_5_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ int ltc_pkcs_1_v1_5_decode(const unsigned char *msg,
unsigned long modulus_len, ps_len, i;
int result;

/* default to invalid packet */
/* is_valid is cleared before anything else can return, it stays 0 unless the padding is valid */
LTC_ARGCHK(is_valid != NULL);
*is_valid = 0;

modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
Expand Down
8 changes: 4 additions & 4 deletions src/pk/rsa/rsa_decrypt_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ int rsa_decrypt_key_v2(const unsigned char *in, unsigned long inlen
unsigned long modulus_bitlen, modulus_bytelen, x;
ltc_rsa_op_checked op_checked = ltc_rsa_op_checked_init(key, params);

/* stat is cleared before anything else can return, it stays 0 unless the padding is valid */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(in != NULL);
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
LTC_ARGCHK(stat != NULL);

/* default to invalid */
*stat = 0;

/* valid padding? */
if ((err = rsa_key_valid_op(LTC_RSA_DECRYPT, &op_checked)) != CRYPT_OK) {
Expand Down
8 changes: 4 additions & 4 deletions src/pk/rsa/rsa_verify_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ int rsa_verify_hash_v2(const unsigned char *sig, unsigned long siglen,
unsigned char *tmpbuf;
ltc_rsa_op_checked op_checked = ltc_rsa_op_checked_init(key, params);

/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;

LTC_ARGCHK(hash != NULL);
LTC_ARGCHK(sig != NULL);
LTC_ARGCHK(stat != NULL);
LTC_ARGCHK(key != NULL);

/* default to invalid */
*stat = 0;

if ((err = rsa_key_valid_op(LTC_RSA_VERIFY, &op_checked)) != CRYPT_OK) {
return err;
}
Expand Down
Loading