From dab47e0ecb7c96e6737a52e06c7b56fbe93d1237 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Mon, 3 Feb 2003 16:11:43 +0000 Subject: * gnutls_dh_params_generate() and gnutls_rsa_params_generate() now use gnutls_malloc() to allocate the output parameters. * Added gnutls_pkcs3_extract_dh_params() which extracts parameters from PKCS#3 encoded structures. This was in order to read parameters generated using the openssl dhparam tool. * Several changes in the temporary (DH/RSA) parameter codebase. No DH parameters are now included in the library. Also a credentials structure can now hold only one temporary parameter. --- lib/gnutls_rsa_export.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'lib/gnutls_rsa_export.c') diff --git a/lib/gnutls_rsa_export.c b/lib/gnutls_rsa_export.c index 6160d57935..0bcd6d35cf 100644 --- a/lib/gnutls_rsa_export.c +++ b/lib/gnutls_rsa_export.c @@ -32,11 +32,13 @@ * number of bits. Ie a number of bits that we have a prime in the * dh_primes structure. */ -static int supported_bits[] = { 512, 0 }; + +#define MAX_SUPPORTED_BITS 512 + static int normalize_bits(int bits) { - if (bits >= 512) - bits = 512; + if (bits >= MAX_SUPPORTED_BITS) + bits = MAX_SUPPORTED_BITS; return bits; } @@ -154,15 +156,10 @@ int _gnutls_rsa_generate_params(GNUTLS_MPI* resarr, int bits) */ static int check_bits(int bits) { - int i = 0; - do { - if (supported_bits[i] == bits) - return 0; - i++; - } while (supported_bits[i] != 0); - - gnutls_assert(); - return GNUTLS_E_INVALID_REQUEST; + if (bits > MAX_SUPPORTED_BITS) + return GNUTLS_E_INVALID_REQUEST; + + return 0; } #define FREE_PRIVATE_PARAMS for (i=0;idata = malloc(siz); + m->data = gnutls_malloc(siz); if (m->data == NULL) { FREE_ALL_MPIS; return GNUTLS_E_MEMORY_ERROR; @@ -355,7 +353,7 @@ int gnutls_rsa_params_generate(gnutls_datum * m, gnutls_datum *e, siz = 0; _gnutls_mpi_print(NULL, &siz, rsa_params[1]); - e->data = malloc(siz); + e->data = gnutls_malloc(siz); if (e->data == NULL) { FREE_ALL_MPIS; _gnutls_free_datum( m); @@ -369,7 +367,7 @@ int gnutls_rsa_params_generate(gnutls_datum * m, gnutls_datum *e, siz = 0; _gnutls_mpi_print(NULL, &siz, rsa_params[2]); - d->data = malloc(siz); + d->data = gnutls_malloc(siz); if (d->data == NULL) { FREE_ALL_MPIS; _gnutls_free_datum( m); @@ -384,7 +382,7 @@ int gnutls_rsa_params_generate(gnutls_datum * m, gnutls_datum *e, siz = 0; _gnutls_mpi_print(NULL, &siz, rsa_params[3]); - p->data = malloc(siz); + p->data = gnutls_malloc(siz); if (p->data == NULL) { FREE_ALL_MPIS; _gnutls_free_datum( m); @@ -400,7 +398,7 @@ int gnutls_rsa_params_generate(gnutls_datum * m, gnutls_datum *e, siz = 0; _gnutls_mpi_print(NULL, &siz, rsa_params[4]); - q->data = malloc(siz); + q->data = gnutls_malloc(siz); if (q->data == NULL) { FREE_ALL_MPIS; _gnutls_free_datum( m); @@ -417,7 +415,7 @@ int gnutls_rsa_params_generate(gnutls_datum * m, gnutls_datum *e, siz = 0; _gnutls_mpi_print(NULL, &siz, rsa_params[5]); - u->data = malloc(siz); + u->data = gnutls_malloc(siz); if (u->data == NULL) { FREE_ALL_MPIS; _gnutls_free_datum( m); @@ -433,9 +431,11 @@ int gnutls_rsa_params_generate(gnutls_datum * m, gnutls_datum *e, FREE_ALL_MPIS; +#ifdef DEBUG _gnutls_log("rsa_params_generate: Generated %d bits modulus %s, exponent %s.\n", bits, _gnutls_bin2hex(m->data, m->size), _gnutls_bin2hex( e->data, e->size)); +#endif return 0; -- cgit v1.2.1