From: Nikos Mavrogiannopoulos Date: Sun, 26 Jan 2014 09:41:04 +0000 (+0100) Subject: updated prototypes of _gnutls_mpi_sub_ui, _gnutls_mpi_add_ui, _gnutls_mpi_mul_ui X-Git-Tag: gnutls_3_3_0pre0~272 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ecfee395560a5fd24aa053594640ce74eb8b2d5;p=thirdparty%2Fgnutls.git updated prototypes of _gnutls_mpi_sub_ui, _gnutls_mpi_add_ui, _gnutls_mpi_mul_ui --- diff --git a/lib/auth/srp.c b/lib/auth/srp.c index 0907760721..dcbb7edd7f 100644 --- a/lib/auth/srp.c +++ b/lib/auth/srp.c @@ -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(); diff --git a/lib/crypto-backend.h b/lib/crypto-backend.h index 7b06e15eab..6627a9f68a 100644 --- a/lib/crypto-backend.h +++ b/lib/crypto-backend.h @@ -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, diff --git a/lib/gnutls_mpi.c b/lib/gnutls_mpi.c index c820f7d18e..9348b5905e 100644 --- a/lib/gnutls_mpi.c +++ b/lib/gnutls_mpi.c @@ -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); diff --git a/lib/nettle/mpi.c b/lib/nettle/mpi.c index f36d727369..d0a9221a66 100644 --- a/lib/nettle/mpi.c +++ b/lib/nettle/mpi.c @@ -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) diff --git a/lib/nettle/pk.c b/lib/nettle/pk.c index bbfd85ea6d..ef01d5fcc4 100644 --- a/lib/nettle/pk.c +++ b/lib/nettle/pk.c @@ -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 */ diff --git a/lib/x509/pkcs12_encr.c b/lib/x509/pkcs12_encr.c index dac627814e..950f98405c 100644 --- a/lib/x509/pkcs12_encr.c +++ b/lib/x509/pkcs12_encr.c @@ -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);