/*
- * 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
*
#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>
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);
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);
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.
*/
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
*/
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);
*/
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;
}
{
/* 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;
}
/*
- * 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
*
#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)
{
}
}
-
-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);
-}
/*
- * Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation
+ * Copyright (C) 2000, 2001, 2003, 2004, 2005, 2009 Free Software Foundation
*
* Author: Nikos Mavrogiannopoulos
*
*
*/
-#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);
}
}
+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
;
#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__)
# 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;
#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>
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;
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;
/*
- * Copyright (C) 2007 Free Software Foundation
+ * Copyright (C) 2007, 2009 Free Software Foundation
*
* Author: Simon Josefsson
*
_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)