diff options
author | Simon Josefsson <simon@josefsson.org> | 2009-06-03 09:35:13 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2009-06-03 09:35:13 +0200 |
commit | dd14a82a9c31d173a4c5aeb17be06755cbf183da (patch) | |
tree | f5cb0b02c4653c3cff1a4151320abac6281794bd | |
parent | 9ef9607b64cbaaf940a28a060971a2048ec58eb6 (diff) | |
download | gnutls-dd14a82a9c31d173a4c5aeb17be06755cbf183da.tar.gz |
Rename _gnutls_dump_mpi to _gnutls_mpi_log. Rewrite to use less stack space.
-rw-r--r-- | lib/auth_srp.c | 19 | ||||
-rw-r--r-- | lib/debug.c | 38 | ||||
-rw-r--r-- | lib/debug.h | 6 | ||||
-rw-r--r-- | lib/gnutls_errors.c | 59 | ||||
-rw-r--r-- | lib/gnutls_errors.h | 2 | ||||
-rw-r--r-- | lib/libgnutls.map | 2 | ||||
-rw-r--r-- | lib/pk-libgcrypt.c | 23 | ||||
-rw-r--r-- | tests/mpi.c | 4 |
8 files changed, 86 insertions, 67 deletions
diff --git a/lib/auth_srp.c b/lib/auth_srp.c index 37fab7b221..2e25b260ce 100644 --- a/lib/auth_srp.c +++ b/lib/auth_srp.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2008 Free Software Foundation + * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2008, 2009 Free Software Foundation * * Author: Nikos Mavrogiannopoulos * @@ -31,7 +31,6 @@ #include "gnutls_auth.h" #include "gnutls_auth.h" #include "gnutls_srp.h" -#include "debug.h" #include "gnutls_num.h" #include "auth_srp.h" #include <gnutls_str.h> @@ -318,7 +317,7 @@ _gnutls_gen_srp_client_kx (gnutls_session_t session, opaque ** data) return GNUTLS_E_MEMORY_ERROR; } - _gnutls_dump_mpi ("SRP U: ", session->key->u); + _gnutls_mpi_log ("SRP U: ", session->key->u); /* S = (B - g^x) ^ (a + u * x) % N */ S = _gnutls_calc_srp_S2 (B, G, session->key->x, _a, session->key->u, N); @@ -328,7 +327,7 @@ _gnutls_gen_srp_client_kx (gnutls_session_t session, opaque ** data) return GNUTLS_E_MEMORY_ERROR; } - _gnutls_dump_mpi ("SRP B: ", B); + _gnutls_mpi_log ("SRP B: ", B); _gnutls_mpi_release (&_b); _gnutls_mpi_release (&V); @@ -395,8 +394,8 @@ _gnutls_proc_srp_client_kx (gnutls_session_t session, opaque * data, return GNUTLS_E_MPI_SCAN_FAILED; } - _gnutls_dump_mpi ("SRP A: ", A); - _gnutls_dump_mpi ("SRP B: ", B); + _gnutls_mpi_log ("SRP A: ", A); + _gnutls_mpi_log ("SRP B: ", B); /* Checks if A % n == 0. */ @@ -416,7 +415,7 @@ _gnutls_proc_srp_client_kx (gnutls_session_t session, opaque * data, return GNUTLS_E_MEMORY_ERROR; } - _gnutls_dump_mpi ("SRP U: ", session->key->u); + _gnutls_mpi_log ("SRP U: ", session->key->u); /* S = (A * v^u) ^ b % N */ @@ -427,7 +426,7 @@ _gnutls_proc_srp_client_kx (gnutls_session_t session, opaque * data, return GNUTLS_E_MEMORY_ERROR; } - _gnutls_dump_mpi ("SRP S: ", S); + _gnutls_mpi_log ("SRP S: ", S); _gnutls_mpi_release (&A); _gnutls_mpi_release (&_b); @@ -613,7 +612,7 @@ group_check_g_n (gnutls_session_t session, bigint_t g, bigint_t n) */ if (_gnutls_prime_check (n) != 0) { - _gnutls_dump_mpi ("no prime N: ", n); + _gnutls_mpi_log ("no prime N: ", n); gnutls_assert (); return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; } @@ -646,7 +645,7 @@ group_check_g_n (gnutls_session_t session, bigint_t g, bigint_t n) { /* N was not on the form N=2q+1, where q = prime */ - _gnutls_dump_mpi ("no prime Q: ", q); + _gnutls_mpi_log ("no prime Q: ", q); gnutls_assert (); return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; } diff --git a/lib/debug.c b/lib/debug.c index 8ef29d38e4..4ab8d95ee5 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation + * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation * * Author: Nikos Mavrogiannopoulos * @@ -28,28 +28,6 @@ #include <stdlib.h> #include "debug.h" -#ifdef DEBUG - - -void -_gnutls_print_state (gnutls_session_t session) -{ - - _gnutls_debug_log ("GNUTLS State:\n"); - _gnutls_debug_log ("Connection End: %d\n", - session->security_parameters.entity); - _gnutls_debug_log ("Cipher Algorithm: %d\n", - session->security_parameters.read_bulk_cipher_algorithm); - _gnutls_debug_log ("MAC algorithm: %d\n", - session->security_parameters.read_mac_algorithm); - _gnutls_debug_log ("Compression Algorithm: %d\n", - session->security_parameters.read_compression_algorithm); - _gnutls_debug_log ("\n"); - -} - -#endif - const char * _gnutls_packet2str (content_type_t packet) { @@ -115,17 +93,3 @@ _gnutls_handshake2str (gnutls_handshake_description_t handshake) } } - -void -_gnutls_dump_mpi (const char *prefix, bigint_t a) -{ - opaque mpi_buf[1024]; - opaque buf[1024]; - size_t n = sizeof buf; - - if (_gnutls_mpi_print (a, mpi_buf, &n) < 0) - strcpy (buf, "[can't print value]"); /* Flawfinder: ignore */ - else - _gnutls_bin2hex (mpi_buf, n, buf, sizeof (buf)); - _gnutls_hard_log ("MPI: length: %d\n\t%s%s\n", n, prefix, buf); -} diff --git a/lib/debug.h b/lib/debug.h index 6832ed7284..5fd78917c7 100644 --- a/lib/debug.h +++ b/lib/debug.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation + * Copyright (C) 2000, 2001, 2003, 2004, 2005, 2009 Free Software Foundation * * Author: Nikos Mavrogiannopoulos * @@ -22,9 +22,5 @@ * */ -#ifdef DEBUG -void _gnutls_print_state (gnutls_session_t session); -#endif const char *_gnutls_packet2str (content_type_t packet); const char *_gnutls_handshake2str (gnutls_handshake_description_t handshake); -void _gnutls_dump_mpi (const char *prefix, bigint_t a); diff --git a/lib/gnutls_errors.c b/lib/gnutls_errors.c index 50d8fceb97..01a59de12d 100644 --- a/lib/gnutls_errors.c +++ b/lib/gnutls_errors.c @@ -418,6 +418,65 @@ _gnutls_asn2err (int asn_err) } } +void +_gnutls_mpi_log (const char *prefix, bigint_t a) +{ + size_t binlen = 0; + void *binbuf; + size_t hexlen; + char *hexbuf; + int res; + + res = _gnutls_mpi_print (a, NULL, &binlen); + if (res != 0) + { + gnutls_assert (); + _gnutls_hard_log ("MPI: can't print value (%d/%d)\n", res, binlen); + return; + } + + if (binlen > 1024*1024) + { + gnutls_assert (); + _gnutls_hard_log ("MPI: too large mpi (%d)\n", binlen); + return; + } + + binbuf = gnutls_malloc (binlen); + if (!binbuf) + { + gnutls_assert (); + _gnutls_hard_log ("MPI: out of memory (%d)\n", binlen); + return; + } + + res = _gnutls_mpi_print (a, binbuf, &binlen); + if (res != 0) + { + gnutls_assert (); + _gnutls_hard_log ("MPI: can't print value (%d/%d)\n", res, binlen); + gnutls_free (binbuf); + return; + } + + hexlen = 2 * binlen + 1; + hexbuf = gnutls_malloc (hexlen); + + if (!hexbuf) + { + gnutls_assert (); + _gnutls_hard_log ("MPI: out of memory (hex %d)\n", hexlen); + gnutls_free (binbuf); + return; + } + + _gnutls_bin2hex (binbuf, binlen, hexbuf, hexlen); + + _gnutls_hard_log ("MPI: length: %d\n\t%s%s\n", binlen, prefix, hexbuf); + + gnutls_free (hexbuf); + gnutls_free (binbuf); +} /* this function will output a message using the * caller provided function diff --git a/lib/gnutls_errors.h b/lib/gnutls_errors.h index 4b21550c9d..6f47169b96 100644 --- a/lib/gnutls_errors.h +++ b/lib/gnutls_errors.h @@ -48,6 +48,8 @@ __attribute__ ((format (printf, 2, 3))); ; #endif +void _gnutls_mpi_log (const char *prefix, bigint_t a); + #ifdef C99_MACROS #define LEVEL(l, ...) if (_gnutls_log_level >= l || _gnutls_log_level > 9) \ _gnutls_log( l, __VA_ARGS__) diff --git a/lib/libgnutls.map b/lib/libgnutls.map index b6f7c67ae0..73dc6aa33b 100644 --- a/lib/libgnutls.map +++ b/lib/libgnutls.map @@ -604,7 +604,7 @@ GNUTLS_PRIVATE { # Internal symbols needed by tests/mpi: _gnutls_mpi_ops; _gnutls_mpi_randomize; - _gnutls_dump_mpi; + _gnutls_mpi_log; # Internal symbols needed by tests/pkcs12_s2k: _gnutls_pkcs12_string_to_key; _gnutls_bin2hex; diff --git a/lib/pk-libgcrypt.c b/lib/pk-libgcrypt.c index 861117b411..330fbfb3a8 100644 --- a/lib/pk-libgcrypt.c +++ b/lib/pk-libgcrypt.c @@ -33,7 +33,6 @@ #include <gnutls_datum.h> #include <gnutls_global.h> #include <gnutls_num.h> -#include "debug.h" #include <x509/x509_int.h> #include <x509/common.h> #include <random.h> @@ -609,11 +608,11 @@ _dsa_generate_params (bigint_t * resarr, int *resarr_len, int bits) gcry_sexp_release (list); gcry_sexp_release (key); - _gnutls_dump_mpi ("p: ", resarr[0]); - _gnutls_dump_mpi ("q: ", resarr[1]); - _gnutls_dump_mpi ("g: ", resarr[2]); - _gnutls_dump_mpi ("y: ", resarr[3]); - _gnutls_dump_mpi ("x: ", resarr[4]); + _gnutls_mpi_log ("p: ", resarr[0]); + _gnutls_mpi_log ("q: ", resarr[1]); + _gnutls_mpi_log ("g: ", resarr[2]); + _gnutls_mpi_log ("y: ", resarr[3]); + _gnutls_mpi_log ("x: ", resarr[4]); *resarr_len = 5; @@ -715,12 +714,12 @@ _rsa_generate_params (bigint_t * resarr, int *resarr_len, int bits) gcry_sexp_release (list); gcry_sexp_release (key); - _gnutls_dump_mpi ("n: ", resarr[0]); - _gnutls_dump_mpi ("e: ", resarr[1]); - _gnutls_dump_mpi ("d: ", resarr[2]); - _gnutls_dump_mpi ("p: ", resarr[3]); - _gnutls_dump_mpi ("q: ", resarr[4]); - _gnutls_dump_mpi ("u: ", resarr[5]); + _gnutls_mpi_log ("n: ", resarr[0]); + _gnutls_mpi_log ("e: ", resarr[1]); + _gnutls_mpi_log ("d: ", resarr[2]); + _gnutls_mpi_log ("p: ", resarr[3]); + _gnutls_mpi_log ("q: ", resarr[4]); + _gnutls_mpi_log ("u: ", resarr[5]); *resarr_len = 6; diff --git a/tests/mpi.c b/tests/mpi.c index ba47377d91..5772da81de 100644 --- a/tests/mpi.c +++ b/tests/mpi.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Free Software Foundation + * Copyright (C) 2007, 2009 Free Software Foundation * * Author: Simon Josefsson * @@ -63,7 +63,7 @@ doit (void) _gnutls_mpi_randomize (n1, RND_BITS, GNUTLS_RND_NONCE); - _gnutls_dump_mpi ("rand:", n1); + _gnutls_mpi_log ("rand:", n1); rc = _gnutls_mpi_get_nbits (n1); if (rc > RND_BITS) |