]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Updated the rest of the MPI function prototypes.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 26 Jan 2014 09:50:24 +0000 (10:50 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 26 Jan 2014 09:50:24 +0000 (10:50 +0100)
lib/crypto-backend.h
lib/gnutls_srp.c
lib/nettle/mpi.c
lib/x509/pkcs12_encr.c
tests/mpi.c

index 42f83635e13e4ad2a4ea0a27ce7748ab656604fa..f7267c827ccd21f1396edf137d069b556ea05a1d 100644 (file)
@@ -125,22 +125,22 @@ typedef struct gnutls_crypto_bigint {
        int (*bigint_powm) (bigint_t w, const bigint_t b,
                                 const bigint_t e, const bigint_t m);
        /* w = a + b mod m */
-        bigint_t(*bigint_addm) (bigint_t w, const bigint_t a,
+       int (*bigint_addm) (bigint_t w, const bigint_t a,
                                 const bigint_t b, const bigint_t m);
        /* w = a - b mod m */
-        bigint_t(*bigint_subm) (bigint_t w, const bigint_t a,
+       int (*bigint_subm) (bigint_t w, const bigint_t a,
                                 const bigint_t b, const bigint_t m);
        /* w = a * b mod m */
-        bigint_t(*bigint_mulm) (bigint_t w, const bigint_t a,
+       int (*bigint_mulm) (bigint_t w, const bigint_t a,
                                 const bigint_t b, const bigint_t m);
-       /* w = a + b */ bigint_t(*bigint_add) (bigint_t w,
+       /* w = a + b */ int (*bigint_add) (bigint_t w,
                                               const bigint_t a,
                                               const bigint_t b);
-       /* w = a - b */ bigint_t(*bigint_sub) (bigint_t w,
+       /* w = a - b */ int (*bigint_sub) (bigint_t w,
                                               const bigint_t a,
                                               const bigint_t b);
        /* w = a * b */
-       bigint_t(*bigint_mul) (bigint_t w, const bigint_t a,
+       int (*bigint_mul) (bigint_t w, const bigint_t a,
                                const bigint_t b);
        /* w = a + b */
        int (*bigint_add_ui) (bigint_t w, const bigint_t a,
index db01c74bb9146e087b45cec58ba00322848de9ea..1ee7473703352c7aa1aa00a883662e1a50417992 100644 (file)
@@ -115,13 +115,23 @@ _gnutls_calc_srp_B(bigint_t * ret_b, bigint_t g, bigint_t n, bigint_t v)
                goto error;
        }
 
-       _gnutls_mpi_mulm(tmpV, k, v, n);
-       
+       ret = _gnutls_mpi_mulm(tmpV, k, v, n);
+       if (ret < 0) {
+               gnutls_assert();
+               goto error;
+       }
+
        ret = _gnutls_mpi_powm(tmpB, g, b, n);
-       if (ret < 0)
+       if (ret < 0) {
+               gnutls_assert();
                goto error;
+       }
 
-       _gnutls_mpi_addm(B, tmpV, tmpB, n);
+       ret = _gnutls_mpi_addm(B, tmpV, tmpB, n);
+       if (ret < 0) {
+               gnutls_assert();
+               goto error;
+       }
 
        _gnutls_mpi_release(&k);
        _gnutls_mpi_release(&tmpB);
@@ -212,10 +222,17 @@ _gnutls_calc_srp_S1(bigint_t A, bigint_t b, bigint_t u, bigint_t v,
                return NULL;
 
        ret = _gnutls_mpi_powm(tmp1, v, u, n);
-       if (ret < 0)
+       if (ret < 0) {
+               gnutls_assert();
                goto error;
+       }
+
+       ret = _gnutls_mpi_mulm(tmp2, A, tmp1, n);
+       if (ret < 0) {
+               gnutls_assert();
+               goto error;
+       }
 
-       _gnutls_mpi_mulm(tmp2, A, tmp1, n);
        _gnutls_mpi_powm(S, tmp2, b, n);
 
        _gnutls_mpi_release(&tmp1);
@@ -338,12 +355,30 @@ _gnutls_calc_srp_S2(bigint_t B, bigint_t g, bigint_t x, bigint_t a,
                goto freeall;
        }
 
-       _gnutls_mpi_mulm(tmp3, tmp1, k, n);     /* k*g^x mod n */
-       _gnutls_mpi_subm(tmp2, B, tmp3, n);
+       ret = _gnutls_mpi_mulm(tmp3, tmp1, k, n);       /* k*g^x mod n */
+       if (ret < 0) {
+               gnutls_assert();
+               goto freeall;
+       }
+
+       ret = _gnutls_mpi_subm(tmp2, B, tmp3, n);
+       if (ret < 0) {
+               gnutls_assert();
+               goto freeall;
+       }
+
+       ret = _gnutls_mpi_mul(tmp1, u, x);
+       if (ret < 0) {
+               gnutls_assert();
+               goto freeall;
+       }
+
+       ret = _gnutls_mpi_add(tmp4, a, tmp1);
+       if (ret < 0) {
+               gnutls_assert();
+               goto freeall;
+       }
 
-       _gnutls_mpi_mul(tmp1, u, x);
-       _gnutls_mpi_add(tmp4, a, tmp1);
-       
        ret = _gnutls_mpi_powm(S, tmp2, tmp4, n);
        if (ret < 0) {
                gnutls_assert();
index f8bb6dc135bade97824391cd4416f49a5a62f553..54ec77bcf7f6de007632082566097010ad817a3d 100644 (file)
@@ -251,106 +251,58 @@ wrap_nettle_mpi_powm(bigint_t w, const bigint_t b, const bigint_t e,
        return 0;
 }
 
-static bigint_t
+static int
 wrap_nettle_mpi_addm(bigint_t w, const bigint_t a, const bigint_t b,
                     const bigint_t m)
 {
-int ret;
-
-       if (w == NULL) {
-               ret = wrap_nettle_mpi_init(&w);
-               if (ret < 0)
-                       return NULL;
-       }
-
        mpz_add(TOMPZ(w), TOMPZ(b), TOMPZ(a));
        mpz_fdiv_r(TOMPZ(w), TOMPZ(w), TOMPZ(m));
 
-       return w;
+       return 0;
 }
 
-static bigint_t
+static int
 wrap_nettle_mpi_subm(bigint_t w, const bigint_t a, const bigint_t b,
                     const bigint_t m)
 {
-int ret;
-
-       if (w == NULL) {
-               ret = wrap_nettle_mpi_init(&w);
-               if (ret < 0)
-                       return NULL;
-       }
-
        mpz_sub(TOMPZ(w), TOMPZ(a), TOMPZ(b));
        mpz_fdiv_r(TOMPZ(w), TOMPZ(w), TOMPZ(m));
 
-       return w;
+       return 0;
 }
 
-static bigint_t
+static int
 wrap_nettle_mpi_mulm(bigint_t w, const bigint_t a, const bigint_t b,
                     const bigint_t m)
 {
-int ret;
-
-       if (w == NULL) {
-               ret = wrap_nettle_mpi_init(&w);
-               if (ret < 0)
-                       return NULL;
-       }
-
        mpz_mul(TOMPZ(w), TOMPZ(a), TOMPZ(b));
        mpz_fdiv_r(TOMPZ(w), TOMPZ(w), TOMPZ(m));
 
-       return w;
+       return 0;
 }
 
-static bigint_t
+static int
 wrap_nettle_mpi_add(bigint_t w, const bigint_t a, const bigint_t b)
 {
-int ret;
-
-       if (w == NULL) {
-               ret = wrap_nettle_mpi_init(&w);
-               if (ret < 0)
-                       return NULL;
-       }
-
        mpz_add(TOMPZ(w), TOMPZ(a), TOMPZ(b));
 
-       return w;
+       return 0;
 }
 
-static bigint_t
+static int
 wrap_nettle_mpi_sub(bigint_t w, const bigint_t a, const bigint_t b)
 {
-int ret;
-
-       if (w == NULL) {
-               ret = wrap_nettle_mpi_init(&w);
-               if (ret < 0)
-                       return NULL;
-       }
-
        mpz_sub(TOMPZ(w), TOMPZ(a), TOMPZ(b));
 
-       return w;
+       return 0;
 }
 
-static bigint_t
+static int
 wrap_nettle_mpi_mul(bigint_t w, const bigint_t a, const bigint_t b)
 {
-int ret;
-
-       if (w == NULL) {
-               ret = wrap_nettle_mpi_init(&w);
-               if (ret < 0)
-                       return NULL;
-       }
-
        mpz_mul(TOMPZ(w), TOMPZ(a), TOMPZ(b));
 
-       return w;
+       return 0;
 }
 
 /* q = a / b */
@@ -370,7 +322,7 @@ wrap_nettle_mpi_add_ui(bigint_t w, const bigint_t a, unsigned long b)
        return 0;
 }
 
-static bigint_t
+static int
 wrap_nettle_mpi_sub_ui(bigint_t w, const bigint_t a, unsigned long b)
 {
        mpz_sub_ui(TOMPZ(w), TOMPZ(a), b);
index 950f98405ca635bc766736b945cec13fb1331f22..bac1840bff8755f6dcdfb38c572884ed8dd09f4e 100644 (file)
@@ -171,7 +171,13 @@ _gnutls_pkcs12_string_to_key(unsigned int id, const uint8_t * salt,
                                gnutls_assert();
                                goto cleanup;
                        }
-                       _gnutls_mpi_addm(num_ij, num_ij, num_b1, mpi512);
+
+                       rc = _gnutls_mpi_addm(num_ij, num_ij, num_b1, mpi512);
+                       if (rc < 0) {
+                               gnutls_assert();
+                               goto cleanup;
+                       }
+
                        n = 64;
 #ifndef PKCS12_BROKEN_KEYGEN
                        m = (_gnutls_mpi_get_nbits(num_ij) + 7) / 8;
index 58aa527815ce2f1b9f80fec9fb9c421e3b61923c..f0cf9aba8ae20b28fd608db14c3f1c2f4500a1af 100644 (file)
@@ -48,7 +48,7 @@ void doit(void)
        if (debug)
                gnutls_global_set_log_level(99);
 
-       ret = _gnutls_mpi_init_multi(&n1, &n2, &n3, NULL);
+       ret = _gnutls_mpi_init_multi(&n1, &n2, &n3, &n4, NULL);
        if (ret < 0)
                fail("mpi_new failed\n");
 
@@ -64,8 +64,8 @@ void doit(void)
        if (ret < 0)
                fail("mpi_set_ui failed\n");
 
-       n4 = _gnutls_mpi_addm(NULL, n1, n3, n2);
-       if (n4 == 0)
+       ret = _gnutls_mpi_addm(n4, n1, n3, n2);
+       if (ret < 0)
                fail("mpi_set_ui failed\n");
 
        if (_gnutls_mpi_cmp_ui(n4, 0) != 0