summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-08-29 18:28:15 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-08-29 18:28:15 +0200
commit85c70639b4a51833e254726f47ec74b788deaa56 (patch)
tree0086ba1f34a60384996a8a0c6a9deb940248219b
parent3274e47af5d0731f3e3fd6ccd19af66e0a66aba5 (diff)
downloadgnutls-85c70639b4a51833e254726f47ec74b788deaa56.tar.gz
Avoid assert() and do not include needless headers.
-rw-r--r--lib/nettle/ecc.h5
-rw-r--r--lib/nettle/ecc_free.c1
-rw-r--r--lib/nettle/ecc_make_key.c8
-rw-r--r--lib/nettle/ecc_map.c3
-rw-r--r--lib/nettle/ecc_mulmod.c6
-rw-r--r--lib/nettle/ecc_projective_add_point.c6
-rw-r--r--lib/nettle/ecc_projective_dbl_point.c5
-rw-r--r--lib/nettle/ecc_projective_dbl_point_3.c5
-rw-r--r--lib/nettle/ecc_shared_secret.c6
-rw-r--r--lib/nettle/ecc_sign_hash.c5
-rw-r--r--lib/nettle/ecc_verify_hash.c6
11 files changed, 20 insertions, 36 deletions
diff --git a/lib/nettle/ecc.h b/lib/nettle/ecc.h
index 07a882c3fd..caa465b75b 100644
--- a/lib/nettle/ecc.h
+++ b/lib/nettle/ecc.h
@@ -2,10 +2,7 @@
#include <nettle/nettle-types.h>
#include <nettle/dsa.h>
#include <nettle/bignum.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <assert.h>
+#include <gnutls_int.h>
/* assume y^2 = x^3 - 3x + b
* instead of the generic y^2 = x^3 + ax + b
diff --git a/lib/nettle/ecc_free.c b/lib/nettle/ecc_free.c
index 1d7dd64eed..81a9241173 100644
--- a/lib/nettle/ecc_free.c
+++ b/lib/nettle/ecc_free.c
@@ -36,7 +36,6 @@
void
ecc_free (ecc_key * key)
{
- assert (key != NULL);
mp_clear_multi (&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k,
&key->prime, &key->order, &key->Gx, &key->Gy, NULL);
}
diff --git a/lib/nettle/ecc_make_key.c b/lib/nettle/ecc_make_key.c
index 42ac6df25c..3476276d97 100644
--- a/lib/nettle/ecc_make_key.c
+++ b/lib/nettle/ecc_make_key.c
@@ -50,8 +50,8 @@ ecc_make_key_ex (void *random_ctx, nettle_random_func random, ecc_key * key,
unsigned char *buf;
int keysize;
- assert (key != NULL);
- assert (random != NULL);
+ if (key == NULL || random == NULL)
+ return -1;
keysize = nettle_mpz_sizeinbase_256_u (order);
@@ -59,9 +59,7 @@ ecc_make_key_ex (void *random_ctx, nettle_random_func random, ecc_key * key,
base = NULL;
buf = malloc (keysize);
if (buf == NULL)
- {
- return -1;
- }
+ return -1;
/* make up random string */
random (random_ctx, keysize, buf);
diff --git a/lib/nettle/ecc_map.c b/lib/nettle/ecc_map.c
index 561c3b2de3..30484da495 100644
--- a/lib/nettle/ecc_map.c
+++ b/lib/nettle/ecc_map.c
@@ -42,7 +42,8 @@ ecc_map (ecc_point * P, mpz_t modulus)
mpz_t t1, t2;
int err;
- assert (P != NULL);
+ if (P == NULL)
+ return -1;
if ((err = mp_init_multi (&t1, &t2, NULL)) != 0)
{
diff --git a/lib/nettle/ecc_mulmod.c b/lib/nettle/ecc_mulmod.c
index fff0fd005b..e9eebe3f5b 100644
--- a/lib/nettle/ecc_mulmod.c
+++ b/lib/nettle/ecc_mulmod.c
@@ -48,10 +48,8 @@ ecc_mulmod (mpz_t k, ecc_point * G, ecc_point * R, mpz_t a, mpz_t modulus,
unsigned long buf;
int bitcnt, mode, digidx;
- assert (k != NULL);
- assert (G != NULL);
- assert (R != NULL);
- assert (modulus != NULL);
+ if (k == NULL || G == NULL || R == NULL || modulus == NULL)
+ return -1;
/* alloc ram for window temps */
for (i = 0; i < 3; i++)
diff --git a/lib/nettle/ecc_projective_add_point.c b/lib/nettle/ecc_projective_add_point.c
index 5a8caafea8..292a0a3486 100644
--- a/lib/nettle/ecc_projective_add_point.c
+++ b/lib/nettle/ecc_projective_add_point.c
@@ -45,10 +45,8 @@ ecc_projective_add_point (ecc_point * P, ecc_point * Q, ecc_point * R,
mpz_t t1, t2, x, y, z;
int err;
- assert (P != NULL);
- assert (Q != NULL);
- assert (R != NULL);
- assert (modulus != NULL);
+ if (P == NULL || Q == NULL || R == NULL || modulus == NULL)
+ return -1;
if ((err = mp_init_multi (&t1, &t2, &x, &y, &z, NULL)) != 0)
{
diff --git a/lib/nettle/ecc_projective_dbl_point.c b/lib/nettle/ecc_projective_dbl_point.c
index 6f73c4e818..4128062e17 100644
--- a/lib/nettle/ecc_projective_dbl_point.c
+++ b/lib/nettle/ecc_projective_dbl_point.c
@@ -41,9 +41,8 @@ ecc_projective_dbl_point (ecc_point * P, ecc_point * R, mpz_t a,
mpz_t t1, m, s;
int err;
- assert (P != NULL);
- assert (R != NULL);
- assert (modulus != NULL);
+ if (P == NULL || R == NULL || modulus == NULL)
+ return -1;
/*
algorithm used:
diff --git a/lib/nettle/ecc_projective_dbl_point_3.c b/lib/nettle/ecc_projective_dbl_point_3.c
index 18f7cb2c4d..e25c612afa 100644
--- a/lib/nettle/ecc_projective_dbl_point_3.c
+++ b/lib/nettle/ecc_projective_dbl_point_3.c
@@ -46,9 +46,8 @@ ecc_projective_dbl_point (ecc_point * P, ecc_point * R, mpz_t a /* a is -3 */,
mpz_t t1, t2;
int err;
- assert(P != NULL);
- assert(R != NULL);
- assert(modulus != NULL);
+ if (P == NULL || R == NULL || modulus == NULL)
+ return -1;
if ((err = mp_init_multi(&t1, &t2, NULL)) != 0) {
return err;
diff --git a/lib/nettle/ecc_shared_secret.c b/lib/nettle/ecc_shared_secret.c
index e24c1409ff..46a0793bc8 100644
--- a/lib/nettle/ecc_shared_secret.c
+++ b/lib/nettle/ecc_shared_secret.c
@@ -46,10 +46,8 @@ ecc_shared_secret (ecc_key * private_key, ecc_key * public_key,
ecc_point *result;
int err;
- assert (private_key != NULL);
- assert (public_key != NULL);
- assert (out != NULL);
- assert (outlen != NULL);
+ if (private_key == NULL || public_key == NULL || out == NULL || outlen == NULL)
+ return -1;
/* type valid? */
if (private_key->type != PK_PRIVATE)
diff --git a/lib/nettle/ecc_sign_hash.c b/lib/nettle/ecc_sign_hash.c
index cc58a23f59..ab7f94309d 100644
--- a/lib/nettle/ecc_sign_hash.c
+++ b/lib/nettle/ecc_sign_hash.c
@@ -49,9 +49,8 @@ ecc_sign_hash (const unsigned char *in, unsigned long inlen,
mpz_t e;
int err;
- assert (in != NULL);
- assert (sig != NULL);
- assert (key != NULL);
+ if (in == NULL || sig == NULL || key == NULL)
+ return -1;
/* is this a private key? */
if (key->type != PK_PRIVATE)
diff --git a/lib/nettle/ecc_verify_hash.c b/lib/nettle/ecc_verify_hash.c
index 92a996e6b4..b10215978a 100644
--- a/lib/nettle/ecc_verify_hash.c
+++ b/lib/nettle/ecc_verify_hash.c
@@ -57,10 +57,8 @@ ecc_verify_hash (struct dsa_signature *signature,
mpz_t v, w, u1, u2, e;
int err;
- assert (signature != NULL);
- assert (hash != NULL);
- assert (stat != NULL);
- assert (key != NULL);
+ if (signature == NULL || hash == NULL || stat == NULL || key == NULL)
+ return -1;
/* default to invalid signature */
*stat = 0;