28 #if defined(POLARSSL_DEBUG_C)
35 #if defined _MSC_VER && !defined snprintf
36 #define snprintf _snprintf
39 #if defined _MSC_VER && !defined vsnprintf
40 #define vsnprintf _vsnprintf
43 char *
debug_fmt(
const char *format, ... )
47 int maxlen =
sizeof( str ) - 1;
49 va_start( argp, format );
50 vsnprintf( str, maxlen, format, argp );
58 const char *file,
int line,
const char *text )
61 int maxlen =
sizeof( str ) - 1;
63 if( ssl->
f_dbg == NULL )
66 snprintf( str, maxlen,
"%s(%04d): %s\n", file, line, text );
72 const char *file,
int line,
73 const char *text,
int ret )
76 int maxlen =
sizeof( str ) - 1;
78 if( ssl->
f_dbg == NULL )
81 snprintf( str, maxlen,
"%s(%04d): %s() returned %d (0x%x)\n",
82 file, line, text, ret, ret );
89 const char *file,
int line,
const char *text,
90 unsigned char *buf,
size_t len )
93 size_t i, maxlen =
sizeof( str ) - 1;
95 if( ssl->
f_dbg == NULL )
98 snprintf( str, maxlen,
"%s(%04d): dumping '%s' (%d bytes)\n",
99 file, line, text, (
unsigned int) len );
104 for( i = 0; i < len; i++ )
114 snprintf( str, maxlen,
"%s(%04d): %04x: ", file, line,
121 snprintf( str, maxlen,
" %02x", (
unsigned int) buf[i] );
132 const char *file,
int line,
133 const char *text,
const mpi *X )
136 int j, k, maxlen =
sizeof( str ) - 1, zeros = 1;
139 if( ssl->
f_dbg == NULL || X == NULL )
142 for( n = X->
n - 1; n > 0; n-- )
146 for( j = (
sizeof(
t_uint) << 3 ) - 1; j >= 0; j-- )
147 if( ( ( X->
p[n] >> j ) & 1 ) != 0 )
150 snprintf( str, maxlen,
"%s(%04d): value of '%s' (%d bits) is:\n",
152 (
int) ( ( n * (
sizeof(
t_uint) << 3 ) ) + j + 1 ) );
157 for( i = n + 1, j = 0; i > 0; i-- )
159 if( zeros && X->
p[i - 1] == 0 )
162 for( k =
sizeof(
t_uint ) - 1; k >= 0; k-- )
164 if( zeros && ( ( X->
p[i - 1] >> (k << 3) ) & 0xFF ) == 0 )
174 snprintf( str, maxlen,
"%s(%04d): ", file, line );
180 snprintf( str, maxlen,
" %02x", (
unsigned int)
181 ( X->
p[i - 1] >> (k << 3) ) & 0xFF );
193 snprintf( str, maxlen,
"%s(%04d): ", file, line );
204 const char *file,
int line,
207 char str[1024], prefix[64];
208 int i = 0, maxlen =
sizeof( prefix ) - 1;
210 if( ssl->
f_dbg == NULL || crt == NULL )
213 snprintf( prefix, maxlen,
"%s(%04d): ", file, line );
214 prefix[maxlen] =
'\0';
215 maxlen =
sizeof( str ) - 1;
222 snprintf( str, maxlen,
"%s(%04d): %s #%d:\n%s",
223 file, line, text, ++i, buf );
229 "crt->rsa.N", &crt->
rsa.
N );
232 "crt->rsa.E", &crt->
rsa.
E );
void(* f_dbg)(void *, int, const char *)
void debug_print_crt(const ssl_context *ssl, int level, const char *file, int line, const char *text, const x509_cert *crt)
void debug_print_msg(const ssl_context *ssl, int level, const char *file, int line, const char *text)
Configuration options (set of defines)
int x509parse_cert_info(char *buf, size_t size, const char *prefix, const x509_cert *crt)
Returns an informational string about the certificate.
Container for an X.509 certificate.
void debug_print_mpi(const ssl_context *ssl, int level, const char *file, int line, const char *text, const mpi *X)
void debug_print_buf(const ssl_context *ssl, int level, const char *file, int line, const char *text, unsigned char *buf, size_t len)
void debug_print_ret(const ssl_context *ssl, int level, const char *file, int line, const char *text, int ret)
struct _x509_cert * next
Next certificate in the CA-chain.
char * debug_fmt(const char *format,...)
rsa_context rsa
Container for the RSA context.