]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
updated prototypes of _gnutls_mpi_sub_ui, _gnutls_mpi_add_ui, _gnutls_mpi_mul_ui
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 26 Jan 2014 09:41:04 +0000 (10:41 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 26 Jan 2014 09:41:04 +0000 (10:41 +0100)
lib/auth/srp.c
lib/crypto-backend.h
lib/gnutls_mpi.c
lib/nettle/mpi.c
lib/nettle/pk.c
lib/x509/pkcs12_encr.c

index 090776072164679f9a4996515496977ce38bbdff..dcbb7edd7f2c72754e0fcefeb497118a4e51d36e 100644 (file)
@@ -90,7 +90,12 @@ inline static int check_param_mod_n(bigint_t a, bigint_t n, int is_a)
                if (ret == 0)
                        err = 1;
 
-               _gnutls_mpi_add_ui(r, r, 1);
+               ret = _gnutls_mpi_add_ui(r, r, 1);
+               if (ret < 0) {
+                       _gnutls_mpi_release(&r);
+                       return gnutls_assert_val(ret);
+               }
+               
                ret = _gnutls_mpi_cmp(r, n);
                if (ret == 0)
                        err = 1;
@@ -734,7 +739,11 @@ group_check_g_n(gnutls_session_t session, bigint_t g, bigint_t n)
 
        /* q = n-1 
         */
-       _gnutls_mpi_sub_ui(q, n, 1);
+       ret = _gnutls_mpi_sub_ui(q, n, 1);
+       if (ret < 0) {
+               gnutls_assert();
+               goto error;
+       }
 
        /* q = q/2, remember that q is divisible by 2 (prime - 1)
         */
@@ -777,7 +786,11 @@ group_check_g_n(gnutls_session_t session, bigint_t g, bigint_t n)
 
        /* w++
         */
-       _gnutls_mpi_add_ui(w, w, 1);
+       ret = _gnutls_mpi_add_ui(w, w, 1);
+       if (ret < 0) {
+               gnutls_assert();
+               goto error;
+       }
 
        if (_gnutls_mpi_cmp(w, n) != 0) {
                gnutls_assert();
index 7b06e15eab4a66818278e690f25f33e3fe3cce81..6627a9f68a61071f468437cbb83dff8484a1bcd9 100644 (file)
@@ -140,16 +140,16 @@ typedef struct gnutls_crypto_bigint {
                                               const bigint_t a,
                                               const bigint_t b);
        /* w = a * b */
-        bigint_t(*bigint_mul) (bigint_t w, const bigint_t a,
+       bigint_t(*bigint_mul) (bigint_t w, const bigint_t a,
                                const bigint_t b);
        /* w = a + b */
-        bigint_t(*bigint_add_ui) (bigint_t w, const bigint_t a,
+       int (*bigint_add_ui) (bigint_t w, const bigint_t a,
                                   unsigned long b);
        /* w = a - b */
-        bigint_t(*bigint_sub_ui) (bigint_t w, const bigint_t a,
+       int (*bigint_sub_ui) (bigint_t w, const bigint_t a,
                                   unsigned long b);
        /* w = a * b */
-        bigint_t(*bigint_mul_ui) (bigint_t w, const bigint_t a,
+       int (*bigint_mul_ui) (bigint_t w, const bigint_t a,
                                   unsigned long b);
        /* q = a / b */
         bigint_t(*bigint_div) (bigint_t q, const bigint_t a,
index c820f7d18e1f6a85f324b656830a9d4ac95b93cc..9348b5905ea25d488586d09b1520c178a0543262 100644 (file)
@@ -78,8 +78,13 @@ _gnutls_mpi_random_modp(bigint_t r, bigint_t p,
                goto cleanup;
        }
 
-       if (_gnutls_mpi_cmp_ui(tmp, 0) == 0)
-               _gnutls_mpi_add_ui(tmp, tmp, 1);
+       if (_gnutls_mpi_cmp_ui(tmp, 0) == 0) {
+               ret = _gnutls_mpi_add_ui(tmp, tmp, 1);
+               if (ret < 0) {
+                       gnutls_assert();
+                       goto cleanup;
+               }
+       }
 
        if (buf_release != 0) {
                gnutls_free(buf);
index f36d7273697e0cc1a0f6aa2418af3ecfc2a1d434..d0a9221a665eee42d729b8a47741cf1dd2d2ac88 100644 (file)
@@ -370,54 +370,28 @@ int ret;
        return q;
 }
 
-static bigint_t
+static int
 wrap_nettle_mpi_add_ui(bigint_t w, const bigint_t a, unsigned long b)
 {
-int ret;
-
-       if (w == NULL) {
-               ret = wrap_nettle_mpi_init(&w);
-               if (ret < 0)
-                       return NULL;
-       }
-
        mpz_add_ui(TOMPZ(w), TOMPZ(a), b);
 
-       return w;
+       return 0;
 }
 
 static bigint_t
 wrap_nettle_mpi_sub_ui(bigint_t w, const bigint_t a, unsigned long b)
 {
-int ret;
-
-       if (w == NULL) {
-               ret = wrap_nettle_mpi_init(&w);
-               if (ret < 0)
-                       return NULL;
-       }
-
        mpz_sub_ui(TOMPZ(w), TOMPZ(a), b);
 
-       return w;
-
+       return 0;
 }
 
-static bigint_t
+static int
 wrap_nettle_mpi_mul_ui(bigint_t w, const bigint_t a, unsigned long b)
 {
-int ret;
-
-       if (w == NULL) {
-               ret = wrap_nettle_mpi_init(&w);
-               if (ret < 0)
-                       return NULL;
-       }
-
        mpz_mul_ui(TOMPZ(w), TOMPZ(a), b);
 
-       return w;
-
+       return 0;
 }
 
 static int wrap_nettle_prime_check(bigint_t pp)
index bbfd85ea6dfccfc3809ba7f819981a5281e8e966..ef01d5fcc44a560d941008bdeb71c323a05f8c1e 100644 (file)
@@ -204,7 +204,11 @@ static int _wrap_nettle_pk_derive(gnutls_pk_algorithm_t algo,
                        goto dh_cleanup;
                }
 
-               _gnutls_mpi_add_ui(ff, ff, 1);
+               ret = _gnutls_mpi_add_ui(ff, ff, 1);
+               if (ret < 0) {
+                       gnutls_assert();
+                       goto dh_cleanup;
+               }
 
                /* check if f==0,1,p-1. 
                 * or (ff=f+1) equivalently ff==1,2,p */
index dac627814e00f804c182b6ab1ffd5f3d23f650aa..950f98405ca635bc766736b945cec13fb1331f22 100644 (file)
@@ -157,7 +157,13 @@ _gnutls_pkcs12_string_to_key(unsigned int id, const uint8_t * salt,
                        gnutls_assert();
                        goto cleanup;
                }
-               _gnutls_mpi_add_ui(num_b1, num_b1, 1);
+
+               rc = _gnutls_mpi_add_ui(num_b1, num_b1, 1);
+               if (rc < 0) {
+                       gnutls_assert();
+                       goto cleanup;
+               }
+               
                for (i = 0; i < 128; i += 64) {
                        n = 64;
                        rc = _gnutls_mpi_init_scan(&num_ij, buf_i + i, n);